-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patheasypost.php
65 lines (49 loc) · 1.61 KB
/
easypost.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
class EasyPost {
private static $base_url = 'https://www.geteasypost.com/api';
public static $api_key = '...';
public static function setApiKey($api_key) {
self::$api_key = $api_key;
}
public static function apiUrl($type, $action) {
return self::$base_url . '/' . $type . '/' . $action;
}
public static function post($url, $params) {
$process = curl_init($url);
curl_setopt($process, CURLOPT_USERPWD, self::$api_key . ":");
curl_setopt($process, CURLOPT_POST, 1);
if(empty($params)) {
$params = array();
}
curl_setopt($process, CURLOPT_POSTFIELDS, http_build_query($params));
$return = json_decode(curl_exec($process));
return $return;
}
}
class EasyPost_Address {
private static $type = "address";
public static function verify($address) {
$params = array('address' => $address);
return EasyPost::post(EasyPost::apiUrl(self::$type, "verify"), $params);
}
}
class EasyPost_Postage {
private static $type = "postage";
public static function rates($params) {
return EasyPost::post(EasyPost::apiUrl(self::$type, "rates"), $params);
}
public static function compare($params) {
return self::rates($params);
}
public static function buy($params) {
return EasyPost::post(EasyPost::apiUrl(self::$type, "buy"), $params);
}
public static function get($filename) {
array('label_file_name' => $filename);
return EasyPost::post(EasyPost::apiUrl(self::$type, "get"), array('label_file_name' => $filename));
}
public static function listAll() {
return EasyPost::post(EasyPost::apiUrl(self::$type, "list"), array());
}
}
?>