@@ -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 | /** |
@@ -44,10 +44,10 @@ discard block |
||
| 44 | 44 | |
| 45 | 45 | $rpath = realpath($fname); |
| 46 | 46 | |
| 47 | - $fp=fopen(realpath($fname),"r"); |
|
| 47 | + $fp = fopen(realpath($fname), "r"); |
|
| 48 | 48 | |
| 49 | - $url = self::$baseUrl.$options['url'] . '?' . http_build_query(array_merge( |
|
| 50 | - array( 'api_key' => self::getApiKey()), $query) |
|
| 49 | + $url = self::$baseUrl.$options['url'].'?'.http_build_query(array_merge( |
|
| 50 | + array('api_key' => self::getApiKey()), $query) |
|
| 51 | 51 | ); |
| 52 | 52 | |
| 53 | 53 | //self::simplePrint($body);die(""); |
@@ -81,7 +81,7 @@ discard block |
||
| 81 | 81 | //echo "code = $code <br>"; |
| 82 | 82 | $json = json_decode($result, true); |
| 83 | 83 | //var_dump($json); die(""); |
| 84 | - if (200 == $code) { |
|
| 84 | + if (200==$code) { |
|
| 85 | 85 | return $json; |
| 86 | 86 | } elseif (isset($json['errors'])) { |
| 87 | 87 | throw new ApiError(implode(', ', $json['errors'])); |
@@ -93,7 +93,7 @@ discard block |
||
| 93 | 93 | public static function makeRequst($options) { |
| 94 | 94 | $errorHandler = new myErrorHandler(); |
| 95 | 95 | |
| 96 | - $old_error_handler = set_error_handler(array( $errorHandler, "proc_error")); |
|
| 96 | + $old_error_handler = set_error_handler(array($errorHandler, "proc_error")); |
|
| 97 | 97 | $method = isset($options['method']) ? $options['method'] : 'GET'; |
| 98 | 98 | $query = isset($options['query']) ? |
| 99 | 99 | array_filter($options['query']) : array(); |
@@ -106,26 +106,26 @@ discard block |
||
| 106 | 106 | ); |
| 107 | 107 | |
| 108 | 108 | if (isset($options['HTTPHEADER'])) { |
| 109 | - $headers[]=$options['HTTPHEADER']; |
|
| 109 | + $headers[] = $options['HTTPHEADER']; |
|
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | if (isset($options['HTTPHEADERS'])) { |
| 113 | - foreach ($options['HTTPHEADERS'] As $header) $headers[]=$header; |
|
| 113 | + foreach ($options['HTTPHEADERS'] As $header) $headers[] = $header; |
|
| 114 | 114 | } |
| 115 | 115 | //self::simplePrint($headers); die(""); |
| 116 | 116 | $ch = curl_init(); |
| 117 | - $url = $options['url'] . '?' . http_build_query(array_merge( |
|
| 118 | - $query, array( 'api_key' => self::getApiKey()) |
|
| 117 | + $url = $options['url'].'?'.http_build_query(array_merge( |
|
| 118 | + $query, array('api_key' => self::getApiKey()) |
|
| 119 | 119 | )); |
| 120 | 120 | //var_dump($body); echo "<br><br>"; |
| 121 | 121 | //$jfile=json_encode($body); echo "<br><br>".$jfile; die("STOPPPP"); |
| 122 | 122 | |
| 123 | 123 | //self::simplePrint($headers); die(""); |
| 124 | - $baseUrl=self::getBaseUrl(); |
|
| 124 | + $baseUrl = self::getBaseUrl(); |
|
| 125 | 125 | |
| 126 | - if (strpos($url,'move_route_destination')>0) $baseUrl='https://api.route4me.com'; |
|
| 126 | + if (strpos($url, 'move_route_destination')>0) $baseUrl = 'https://api.route4me.com'; |
|
| 127 | 127 | $curlOpts = arraY( |
| 128 | - CURLOPT_URL => $baseUrl. $url, |
|
| 128 | + CURLOPT_URL => $baseUrl.$url, |
|
| 129 | 129 | CURLOPT_RETURNTRANSFER => true, |
| 130 | 130 | CURLOPT_TIMEOUT => 60, |
| 131 | 131 | CURLOPT_FOLLOWLOCATION => true, |
@@ -137,14 +137,14 @@ discard block |
||
| 137 | 137 | //echo "url=".$baseUrl.$url."<br>";die(""); |
| 138 | 138 | curl_setopt_array($ch, $curlOpts); |
| 139 | 139 | |
| 140 | - if ($file !=null) { |
|
| 140 | + if ($file!=null) { |
|
| 141 | 141 | curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); |
| 142 | - $fp=fopen($file,'r'); |
|
| 143 | - curl_setopt($ch, CURLOPT_INFILE , $fp); |
|
| 142 | + $fp = fopen($file, 'r'); |
|
| 143 | + curl_setopt($ch, CURLOPT_INFILE, $fp); |
|
| 144 | 144 | curl_setopt($ch, CURLOPT_INFILESIZE, filesize($file)); |
| 145 | 145 | } |
| 146 | 146 | |
| 147 | - switch($method) { |
|
| 147 | + switch ($method) { |
|
| 148 | 148 | case 'DELETE': |
| 149 | 149 | curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE"); |
| 150 | 150 | |
@@ -169,7 +169,7 @@ discard block |
||
| 169 | 169 | break; |
| 170 | 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); |
@@ -183,8 +183,8 @@ discard block |
||
| 183 | 183 | |
| 184 | 184 | $result = curl_exec($ch); |
| 185 | 185 | //var_dump($result); die(""); |
| 186 | - $isxml=FALSE; |
|
| 187 | - $jxml=""; |
|
| 186 | + $isxml = FALSE; |
|
| 187 | + $jxml = ""; |
|
| 188 | 188 | if (strpos($result, '<?xml')>-1) |
| 189 | 189 | { |
| 190 | 190 | $xml = simplexml_load_string($result); |
@@ -196,7 +196,7 @@ discard block |
||
| 196 | 196 | curl_close($ch); |
| 197 | 197 | //echo "code -> $code <br>"; |
| 198 | 198 | |
| 199 | - if (200 == $code) { |
|
| 199 | + if (200==$code) { |
|
| 200 | 200 | if ($isxml) { |
| 201 | 201 | $json = $jxml; |
| 202 | 202 | } else $json = json_decode($result, true); |
@@ -206,7 +206,7 @@ discard block |
||
| 206 | 206 | } else { |
| 207 | 207 | return $json; |
| 208 | 208 | } |
| 209 | - } elseif (409 == $code) { |
|
| 209 | + } elseif (409==$code) { |
|
| 210 | 210 | |
| 211 | 211 | //throw new ApiError('Wrong API key'); |
| 212 | 212 | } else { |
@@ -236,7 +236,7 @@ discard block |
||
| 236 | 236 | |
| 237 | 237 | curl_setopt_array($ch, $curlOpts); |
| 238 | 238 | |
| 239 | - switch($method) { |
|
| 239 | + switch ($method) { |
|
| 240 | 240 | case 'DELETE': |
| 241 | 241 | curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE"); |
| 242 | 242 | |
@@ -274,8 +274,8 @@ discard block |
||
| 274 | 274 | |
| 275 | 275 | $result = curl_exec($ch); |
| 276 | 276 | |
| 277 | - $isxml=FALSE; |
|
| 278 | - $jxml=""; |
|
| 277 | + $isxml = FALSE; |
|
| 278 | + $jxml = ""; |
|
| 279 | 279 | if (strpos($result, '<?xml')>-1) |
| 280 | 280 | { |
| 281 | 281 | $xml = simplexml_load_string($result); |
@@ -291,7 +291,7 @@ discard block |
||
| 291 | 291 | } else $json = json_decode($result, true); |
| 292 | 292 | |
| 293 | 293 | |
| 294 | - if (200 == $code) { |
|
| 294 | + if (200==$code) { |
|
| 295 | 295 | return $json; |
| 296 | 296 | } elseif (isset($json['errors'])) { |
| 297 | 297 | throw new ApiError(implode(', ', $json['errors'])); |
@@ -34,13 +34,17 @@ discard block |
||
| 34 | 34 | $query = isset($options['query']) ? |
| 35 | 35 | array_filter($options['query']) : array(); |
| 36 | 36 | |
| 37 | - if (sizeof($query)==0) return null; |
|
| 37 | + if (sizeof($query)==0) { |
|
| 38 | + return null; |
|
| 39 | + } |
|
| 38 | 40 | |
| 39 | 41 | $body = isset($options['body']) ? |
| 40 | 42 | array_filter($options['body']) : null; |
| 41 | 43 | |
| 42 | 44 | $fname = isset($body['strFilename']) ? $body['strFilename'] : ''; |
| 43 | - if ($fname=='') return null; |
|
| 45 | + if ($fname=='') { |
|
| 46 | + return null; |
|
| 47 | + } |
|
| 44 | 48 | |
| 45 | 49 | $rpath = realpath($fname); |
| 46 | 50 | |
@@ -110,7 +114,9 @@ discard block |
||
| 110 | 114 | } |
| 111 | 115 | |
| 112 | 116 | if (isset($options['HTTPHEADERS'])) { |
| 113 | - foreach ($options['HTTPHEADERS'] As $header) $headers[]=$header; |
|
| 117 | + foreach ($options['HTTPHEADERS'] As $header) { |
|
| 118 | + $headers[]=$header; |
|
| 119 | + } |
|
| 114 | 120 | } |
| 115 | 121 | //self::simplePrint($headers); die(""); |
| 116 | 122 | $ch = curl_init(); |
@@ -123,7 +129,9 @@ discard block |
||
| 123 | 129 | //self::simplePrint($headers); die(""); |
| 124 | 130 | $baseUrl=self::getBaseUrl(); |
| 125 | 131 | |
| 126 | - if (strpos($url,'move_route_destination')>0) $baseUrl='https://api.route4me.com'; |
|
| 132 | + if (strpos($url,'move_route_destination')>0) { |
|
| 133 | + $baseUrl='https://api.route4me.com'; |
|
| 134 | + } |
|
| 127 | 135 | $curlOpts = arraY( |
| 128 | 136 | CURLOPT_URL => $baseUrl. $url, |
| 129 | 137 | CURLOPT_RETURNTRANSFER => true, |
@@ -199,14 +207,16 @@ discard block |
||
| 199 | 207 | if (200 == $code) { |
| 200 | 208 | if ($isxml) { |
| 201 | 209 | $json = $jxml; |
| 202 | - } else $json = json_decode($result, true); |
|
| 210 | + } else { |
|
| 211 | + $json = json_decode($result, true); |
|
| 212 | + } |
|
| 203 | 213 | //var_dump($json); die(""); |
| 204 | 214 | if (isset($json['errors'])) { |
| 205 | 215 | throw new ApiError(implode(', ', $json['errors'])); |
| 206 | 216 | } else { |
| 207 | 217 | return $json; |
| 208 | 218 | } |
| 209 | - } elseif (409 == $code) { |
|
| 219 | + } elseif (409 == $code) { |
|
| 210 | 220 | |
| 211 | 221 | //throw new ApiError('Wrong API key'); |
| 212 | 222 | } else { |
@@ -288,7 +298,9 @@ discard block |
||
| 288 | 298 | |
| 289 | 299 | if ($isxml) { |
| 290 | 300 | $json = $jxml; |
| 291 | - } else $json = json_decode($result, true); |
|
| 301 | + } else { |
|
| 302 | + $json = json_decode($result, true); |
|
| 303 | + } |
|
| 292 | 304 | |
| 293 | 305 | |
| 294 | 306 | if (200 == $code) { |