@@ -7,37 +7,37 @@ discard block |
||
7 | 7 | |
8 | 8 | class Route4Me |
9 | 9 | { |
10 | - static public $apiKey; |
|
11 | - static public $baseUrl = 'https://api.route4me.com'; |
|
10 | + static public $apiKey; |
|
11 | + static public $baseUrl = 'https://api.route4me.com'; |
|
12 | 12 | |
13 | - public static function setApiKey($apiKey) |
|
14 | - { |
|
15 | - self::$apiKey = $apiKey; |
|
16 | - } |
|
13 | + public static function setApiKey($apiKey) |
|
14 | + { |
|
15 | + self::$apiKey = $apiKey; |
|
16 | + } |
|
17 | 17 | |
18 | - public static function getApiKey() |
|
19 | - { |
|
20 | - return self::$apiKey; |
|
21 | - } |
|
18 | + public static function getApiKey() |
|
19 | + { |
|
20 | + return self::$apiKey; |
|
21 | + } |
|
22 | 22 | |
23 | - public static function setBaseUrl($baseUrl) |
|
24 | - { |
|
25 | - self::$baseUrl = $baseUrl; |
|
26 | - } |
|
23 | + public static function setBaseUrl($baseUrl) |
|
24 | + { |
|
25 | + self::$baseUrl = $baseUrl; |
|
26 | + } |
|
27 | 27 | |
28 | - public static function getBaseUrl() |
|
29 | - { |
|
30 | - return self::$baseUrl; |
|
31 | - } |
|
28 | + public static function getBaseUrl() |
|
29 | + { |
|
30 | + return self::$baseUrl; |
|
31 | + } |
|
32 | 32 | |
33 | 33 | public static function fileUploadRequest($options) { |
34 | 34 | $query = isset($options['query']) ? |
35 | - array_filter($options['query']) : array(); |
|
35 | + array_filter($options['query']) : array(); |
|
36 | 36 | |
37 | 37 | if (sizeof($query)==0) return null; |
38 | 38 | |
39 | 39 | $body = isset($options['body']) ? |
40 | - array_filter($options['body']) : null; |
|
40 | + array_filter($options['body']) : null; |
|
41 | 41 | |
42 | 42 | $fname = isset($body['strFilename']) ? $body['strFilename'] : ''; |
43 | 43 | if ($fname=='') return null; |
@@ -47,8 +47,8 @@ discard block |
||
47 | 47 | $fp=fopen(realpath($fname),"r"); |
48 | 48 | |
49 | 49 | $url = self::$baseUrl.$options['url'] . '?' . http_build_query(array_merge( |
50 | - array( 'api_key' => self::getApiKey()), $query) |
|
51 | - ); |
|
50 | + array( 'api_key' => self::getApiKey()), $query) |
|
51 | + ); |
|
52 | 52 | |
53 | 53 | //self::simplePrint($body);die(""); |
54 | 54 | //echo "url=".$url."<br>";die(""); |
@@ -56,12 +56,12 @@ discard block |
||
56 | 56 | $ch = curl_init($url); |
57 | 57 | |
58 | 58 | $curlOpts = array( |
59 | - CURLOPT_RETURNTRANSFER => true, |
|
60 | - CURLOPT_TIMEOUT => 60, |
|
61 | - CURLOPT_FOLLOWLOCATION => true, |
|
62 | - CURLOPT_SSL_VERIFYHOST => FALSE, |
|
63 | - CURLOPT_SSL_VERIFYPEER => FALSE |
|
64 | - ); |
|
59 | + CURLOPT_RETURNTRANSFER => true, |
|
60 | + CURLOPT_TIMEOUT => 60, |
|
61 | + CURLOPT_FOLLOWLOCATION => true, |
|
62 | + CURLOPT_SSL_VERIFYHOST => FALSE, |
|
63 | + CURLOPT_SSL_VERIFYPEER => FALSE |
|
64 | + ); |
|
65 | 65 | |
66 | 66 | curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); |
67 | 67 | |
@@ -77,65 +77,65 @@ discard block |
||
77 | 77 | fclose($fp); |
78 | 78 | //var_dump($result); die(''); |
79 | 79 | $code = curl_getinfo($ch, CURLINFO_HTTP_CODE); |
80 | - curl_close($ch); |
|
80 | + curl_close($ch); |
|
81 | 81 | //echo "code = $code <br>"; |
82 | 82 | $json = json_decode($result, true); |
83 | 83 | //var_dump($json); die(""); |
84 | - if (200 == $code) { |
|
85 | - return $json; |
|
86 | - } elseif (isset($json['errors'])) { |
|
87 | - throw new ApiError(implode(', ', $json['errors'])); |
|
88 | - } else { |
|
89 | - throw new ApiError('Something wrong'); |
|
90 | - } |
|
84 | + if (200 == $code) { |
|
85 | + return $json; |
|
86 | + } elseif (isset($json['errors'])) { |
|
87 | + throw new ApiError(implode(', ', $json['errors'])); |
|
88 | + } else { |
|
89 | + throw new ApiError('Something wrong'); |
|
90 | + } |
|
91 | 91 | } |
92 | 92 | |
93 | - public static function makeRequst($options) { |
|
94 | - $errorHandler = new myErrorHandler(); |
|
93 | + public static function makeRequst($options) { |
|
94 | + $errorHandler = new myErrorHandler(); |
|
95 | 95 | |
96 | - $old_error_handler = set_error_handler(array( $errorHandler, "proc_error")); |
|
97 | - $method = isset($options['method']) ? $options['method'] : 'GET'; |
|
98 | - $query = isset($options['query']) ? |
|
99 | - array_filter($options['query']) : array(); |
|
96 | + $old_error_handler = set_error_handler(array( $errorHandler, "proc_error")); |
|
97 | + $method = isset($options['method']) ? $options['method'] : 'GET'; |
|
98 | + $query = isset($options['query']) ? |
|
99 | + array_filter($options['query']) : array(); |
|
100 | 100 | //echo "query=".$query['member_id'];die(""); |
101 | - $body = isset($options['body']) ? |
|
102 | - array_filter($options['body']) : null; |
|
101 | + $body = isset($options['body']) ? |
|
102 | + array_filter($options['body']) : null; |
|
103 | 103 | $file = isset($options['FILE']) ? $options['FILE'] : null; |
104 | - $headers = array( |
|
105 | - "User-Agent: Route4Me php-sdk" |
|
106 | - ); |
|
104 | + $headers = array( |
|
105 | + "User-Agent: Route4Me php-sdk" |
|
106 | + ); |
|
107 | 107 | |
108 | - if (isset($options['HTTPHEADER'])) { |
|
109 | - $headers[]=$options['HTTPHEADER']; |
|
110 | - } |
|
108 | + if (isset($options['HTTPHEADER'])) { |
|
109 | + $headers[]=$options['HTTPHEADER']; |
|
110 | + } |
|
111 | 111 | |
112 | 112 | if (isset($options['HTTPHEADERS'])) { |
113 | - foreach ($options['HTTPHEADERS'] As $header) $headers[]=$header; |
|
114 | - } |
|
115 | - //self::simplePrint($headers); die(""); |
|
116 | - $ch = curl_init(); |
|
117 | - $url = $options['url'] . '?' . http_build_query(array_merge( |
|
118 | - $query, array( 'api_key' => self::getApiKey()) |
|
119 | - )); |
|
113 | + foreach ($options['HTTPHEADERS'] As $header) $headers[]=$header; |
|
114 | + } |
|
115 | + //self::simplePrint($headers); die(""); |
|
116 | + $ch = curl_init(); |
|
117 | + $url = $options['url'] . '?' . http_build_query(array_merge( |
|
118 | + $query, array( 'api_key' => self::getApiKey()) |
|
119 | + )); |
|
120 | 120 | //var_dump($body); echo "<br><br>"; |
121 | 121 | //$jfile=json_encode($body); echo "<br><br>".$jfile; die("STOPPPP"); |
122 | 122 | |
123 | - //self::simplePrint($headers); die(""); |
|
123 | + //self::simplePrint($headers); die(""); |
|
124 | 124 | $baseUrl=self::getBaseUrl(); |
125 | 125 | |
126 | 126 | if (strpos($url,'move_route_destination')>0) $baseUrl='https://api.route4me.com'; |
127 | - $curlOpts = arraY( |
|
128 | - CURLOPT_URL => $baseUrl. $url, |
|
129 | - CURLOPT_RETURNTRANSFER => true, |
|
130 | - CURLOPT_TIMEOUT => 60, |
|
131 | - CURLOPT_FOLLOWLOCATION => true, |
|
132 | - CURLOPT_SSL_VERIFYHOST => FALSE, |
|
133 | - CURLOPT_SSL_VERIFYPEER => FALSE, |
|
134 | - CURLOPT_HTTPHEADER => $headers |
|
135 | - ); |
|
127 | + $curlOpts = arraY( |
|
128 | + CURLOPT_URL => $baseUrl. $url, |
|
129 | + CURLOPT_RETURNTRANSFER => true, |
|
130 | + CURLOPT_TIMEOUT => 60, |
|
131 | + CURLOPT_FOLLOWLOCATION => true, |
|
132 | + CURLOPT_SSL_VERIFYHOST => FALSE, |
|
133 | + CURLOPT_SSL_VERIFYPEER => FALSE, |
|
134 | + CURLOPT_HTTPHEADER => $headers |
|
135 | + ); |
|
136 | 136 | |
137 | 137 | //echo "url=".$baseUrl.$url."<br>";die(""); |
138 | - curl_setopt_array($ch, $curlOpts); |
|
138 | + curl_setopt_array($ch, $curlOpts); |
|
139 | 139 | |
140 | 140 | if ($file !=null) { |
141 | 141 | curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); |
@@ -144,21 +144,21 @@ discard block |
||
144 | 144 | curl_setopt($ch, CURLOPT_INFILESIZE, filesize($file)); |
145 | 145 | } |
146 | 146 | |
147 | - switch($method) { |
|
148 | - case 'DELETE': |
|
149 | - curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE"); |
|
147 | + switch($method) { |
|
148 | + case 'DELETE': |
|
149 | + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE"); |
|
150 | 150 | |
151 | 151 | if (isset($body)) { |
152 | 152 | curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($body)); |
153 | 153 | } |
154 | - break; |
|
154 | + break; |
|
155 | 155 | case 'DELETEARRAY': |
156 | 156 | curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE"); |
157 | - curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($query)); |
|
158 | - break; |
|
159 | - case 'PUT': |
|
157 | + curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($query)); |
|
158 | + break; |
|
159 | + case 'PUT': |
|
160 | 160 | //$jfile=json_encode($body); echo $jfile; die(""); |
161 | - curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT"); |
|
161 | + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT"); |
|
162 | 162 | if (isset($query)) { |
163 | 163 | curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($query)); |
164 | 164 | } |
@@ -167,9 +167,9 @@ discard block |
||
167 | 167 | curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($body)); |
168 | 168 | } |
169 | 169 | break; |
170 | - case 'POST': |
|
170 | + case 'POST': |
|
171 | 171 | if (isset($query)) { |
172 | - curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($query)); |
|
172 | + curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($query)); |
|
173 | 173 | } |
174 | 174 | |
175 | 175 | //echo "<br><br>". json_encode($body); |
@@ -178,10 +178,10 @@ discard block |
||
178 | 178 | } |
179 | 179 | break; |
180 | 180 | case 'ADD': |
181 | - curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($query)); break; |
|
182 | - } |
|
181 | + curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($query)); break; |
|
182 | + } |
|
183 | 183 | |
184 | - $result = curl_exec($ch); |
|
184 | + $result = curl_exec($ch); |
|
185 | 185 | //var_dump($result); die(""); |
186 | 186 | $isxml=FALSE; |
187 | 187 | $jxml=""; |
@@ -192,64 +192,64 @@ discard block |
||
192 | 192 | $isxml = TRUE; |
193 | 193 | } |
194 | 194 | |
195 | - $code = curl_getinfo($ch, CURLINFO_HTTP_CODE); |
|
196 | - curl_close($ch); |
|
195 | + $code = curl_getinfo($ch, CURLINFO_HTTP_CODE); |
|
196 | + curl_close($ch); |
|
197 | 197 | //echo "code -> $code <br>"; |
198 | 198 | |
199 | - if (200 == $code) { |
|
200 | - if ($isxml) { |
|
201 | - $json = $jxml; |
|
202 | - } else $json = json_decode($result, true); |
|
203 | - //var_dump($json); die(""); |
|
204 | - if (isset($json['errors'])) { |
|
205 | - throw new ApiError(implode(', ', $json['errors'])); |
|
206 | - } else { |
|
207 | - return $json; |
|
208 | - } |
|
209 | - } elseif (409 == $code) { |
|
199 | + if (200 == $code) { |
|
200 | + if ($isxml) { |
|
201 | + $json = $jxml; |
|
202 | + } else $json = json_decode($result, true); |
|
203 | + //var_dump($json); die(""); |
|
204 | + if (isset($json['errors'])) { |
|
205 | + throw new ApiError(implode(', ', $json['errors'])); |
|
206 | + } else { |
|
207 | + return $json; |
|
208 | + } |
|
209 | + } elseif (409 == $code) { |
|
210 | 210 | |
211 | - //throw new ApiError('Wrong API key'); |
|
212 | - } else { |
|
213 | - throw new ApiError('Something wrong'); |
|
214 | - } |
|
215 | - } |
|
211 | + //throw new ApiError('Wrong API key'); |
|
212 | + } else { |
|
213 | + throw new ApiError('Something wrong'); |
|
214 | + } |
|
215 | + } |
|
216 | 216 | |
217 | 217 | public static function makeUrlRequst($url, $options) { |
218 | 218 | $method = isset($options['method']) ? $options['method'] : 'GET'; |
219 | - $query = isset($options['query']) ? |
|
220 | - array_filter($options['query']) : array(); |
|
221 | - $body = isset($options['body']) ? |
|
222 | - array_filter($options['body']) : null; |
|
223 | - $ch = curl_init(); |
|
219 | + $query = isset($options['query']) ? |
|
220 | + array_filter($options['query']) : array(); |
|
221 | + $body = isset($options['body']) ? |
|
222 | + array_filter($options['body']) : null; |
|
223 | + $ch = curl_init(); |
|
224 | 224 | |
225 | 225 | $curlOpts = arraY( |
226 | - CURLOPT_URL => $url, |
|
227 | - CURLOPT_RETURNTRANSFER => true, |
|
228 | - CURLOPT_TIMEOUT => 60, |
|
229 | - CURLOPT_FOLLOWLOCATION => true, |
|
230 | - CURLOPT_SSL_VERIFYHOST => FALSE, |
|
231 | - CURLOPT_SSL_VERIFYPEER => FALSE, |
|
232 | - CURLOPT_HTTPHEADER => array( |
|
233 | - 'User-Agent' => 'Route4Me php-sdk' |
|
234 | - ) |
|
235 | - ); |
|
226 | + CURLOPT_URL => $url, |
|
227 | + CURLOPT_RETURNTRANSFER => true, |
|
228 | + CURLOPT_TIMEOUT => 60, |
|
229 | + CURLOPT_FOLLOWLOCATION => true, |
|
230 | + CURLOPT_SSL_VERIFYHOST => FALSE, |
|
231 | + CURLOPT_SSL_VERIFYPEER => FALSE, |
|
232 | + CURLOPT_HTTPHEADER => array( |
|
233 | + 'User-Agent' => 'Route4Me php-sdk' |
|
234 | + ) |
|
235 | + ); |
|
236 | 236 | |
237 | 237 | curl_setopt_array($ch, $curlOpts); |
238 | 238 | |
239 | - switch($method) { |
|
240 | - case 'DELETE': |
|
241 | - curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE"); |
|
239 | + switch($method) { |
|
240 | + case 'DELETE': |
|
241 | + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE"); |
|
242 | 242 | |
243 | 243 | if (isset($body)) { |
244 | 244 | curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($body)); |
245 | 245 | } |
246 | - break; |
|
246 | + break; |
|
247 | 247 | case 'DELETEARRAY': |
248 | 248 | curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE"); |
249 | - curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($query)); |
|
250 | - break; |
|
251 | - case 'PUT': |
|
252 | - curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT"); |
|
249 | + curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($query)); |
|
250 | + break; |
|
251 | + case 'PUT': |
|
252 | + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT"); |
|
253 | 253 | if (isset($query)) { |
254 | 254 | curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($query)); |
255 | 255 | } |
@@ -258,10 +258,10 @@ discard block |
||
258 | 258 | curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($body)); |
259 | 259 | } |
260 | 260 | break; |
261 | - case 'POST': |
|
261 | + case 'POST': |
|
262 | 262 | curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); |
263 | 263 | if (isset($query)) { |
264 | - curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($query)); |
|
264 | + curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($query)); |
|
265 | 265 | } |
266 | 266 | |
267 | 267 | if (isset($body)) { |
@@ -269,8 +269,8 @@ discard block |
||
269 | 269 | } |
270 | 270 | break; |
271 | 271 | case 'ADD': |
272 | - curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($query)); break; |
|
273 | - } |
|
272 | + curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($query)); break; |
|
273 | + } |
|
274 | 274 | |
275 | 275 | $result = curl_exec($ch); |
276 | 276 | |
@@ -283,21 +283,21 @@ discard block |
||
283 | 283 | $isxml = TRUE; |
284 | 284 | } |
285 | 285 | |
286 | - $code = curl_getinfo($ch, CURLINFO_HTTP_CODE); |
|
287 | - curl_close($ch); |
|
286 | + $code = curl_getinfo($ch, CURLINFO_HTTP_CODE); |
|
287 | + curl_close($ch); |
|
288 | 288 | |
289 | 289 | if ($isxml) { |
290 | 290 | $json = $jxml; |
291 | 291 | } else $json = json_decode($result, true); |
292 | 292 | |
293 | 293 | |
294 | - if (200 == $code) { |
|
295 | - return $json; |
|
296 | - } elseif (isset($json['errors'])) { |
|
297 | - throw new ApiError(implode(', ', $json['errors'])); |
|
298 | - } else { |
|
299 | - throw new ApiError('Something wrong'); |
|
300 | - } |
|
294 | + if (200 == $code) { |
|
295 | + return $json; |
|
296 | + } elseif (isset($json['errors'])) { |
|
297 | + throw new ApiError(implode(', ', $json['errors'])); |
|
298 | + } else { |
|
299 | + throw new ApiError('Something wrong'); |
|
300 | + } |
|
301 | 301 | } |
302 | 302 | |
303 | 303 | /** |