@@ -6,20 +6,20 @@ |
||
6 | 6 | |
7 | 7 | class RapidAddressSearchResponse |
8 | 8 | { |
9 | - public $zipcode; |
|
10 | - public $street_name; |
|
11 | - public $county_no; |
|
9 | + public $zipcode; |
|
10 | + public $street_name; |
|
11 | + public $county_no; |
|
12 | 12 | |
13 | - public static function fromArray(array $params) |
|
14 | - { |
|
15 | - $rapidSearch = new self(); |
|
13 | + public static function fromArray(array $params) |
|
14 | + { |
|
15 | + $rapidSearch = new self(); |
|
16 | 16 | |
17 | - foreach ($params as $key => $value) { |
|
18 | - if (property_exists($rapidSearch, $key)) { |
|
19 | - $rapidSearch->{$key} = $value; |
|
20 | - } |
|
21 | - } |
|
17 | + foreach ($params as $key => $value) { |
|
18 | + if (property_exists($rapidSearch, $key)) { |
|
19 | + $rapidSearch->{$key} = $value; |
|
20 | + } |
|
21 | + } |
|
22 | 22 | |
23 | - return $rapidSearch; |
|
24 | - } |
|
23 | + return $rapidSearch; |
|
24 | + } |
|
25 | 25 | } |
@@ -7,291 +7,291 @@ |
||
7 | 7 | |
8 | 8 | class Route4Me |
9 | 9 | { |
10 | - public static $apiKey; |
|
11 | - public static $baseUrl = Endpoint::BASE_URL; |
|
12 | - |
|
13 | - public static function setApiKey($apiKey) |
|
14 | - { |
|
15 | - self::$apiKey = $apiKey; |
|
16 | - } |
|
17 | - |
|
18 | - public static function getApiKey() |
|
19 | - { |
|
20 | - return self::$apiKey; |
|
21 | - } |
|
22 | - |
|
23 | - public static function setBaseUrl($baseUrl) |
|
24 | - { |
|
25 | - self::$baseUrl = $baseUrl; |
|
26 | - } |
|
27 | - |
|
28 | - public static function getBaseUrl() |
|
29 | - { |
|
30 | - return self::$baseUrl; |
|
31 | - } |
|
32 | - |
|
33 | - public static function makeRequst($options) |
|
34 | - { |
|
35 | - $method = isset($options['method']) ? $options['method'] : 'GET'; |
|
36 | - $query = isset($options['query']) ? array_filter($options['query'], function ($x) { return !is_null($x); }) : []; |
|
37 | - |
|
38 | - $body = isset($options['body']) ? $options['body'] : null; |
|
39 | - $file = isset($options['FILE']) ? $options['FILE'] : null; |
|
40 | - $headers = [ |
|
41 | - 'User-Agent: Route4Me php-sdk', |
|
42 | - ]; |
|
43 | - |
|
44 | - if (isset($options['HTTPHEADER'])) { |
|
45 | - $headers[] = $options['HTTPHEADER']; |
|
46 | - } |
|
47 | - |
|
48 | - if (isset($options['HTTPHEADERS'])) { |
|
49 | - foreach ($options['HTTPHEADERS'] as $header) { |
|
50 | - $headers[] = $header; |
|
51 | - } |
|
52 | - } |
|
53 | - |
|
54 | - $ch = curl_init(); |
|
55 | - |
|
56 | - $url = isset($options['url']) ? $options['url'].'?'.http_build_query(array_merge( |
|
57 | - $query, ['api_key' => self::getApiKey()] |
|
58 | - )) : ''; |
|
59 | - |
|
60 | - $baseUrl = self::getBaseUrl(); |
|
61 | - |
|
62 | - $curlOpts = [ |
|
63 | - CURLOPT_URL => $baseUrl.$url, |
|
64 | - CURLOPT_RETURNTRANSFER => true, |
|
65 | - CURLOPT_TIMEOUT => 120, |
|
66 | - CURLOPT_FOLLOWLOCATION => true, |
|
67 | - CURLOPT_SSL_VERIFYHOST => false, |
|
68 | - CURLOPT_SSL_VERIFYPEER => false, |
|
69 | - CURLOPT_HTTPHEADER => $headers, |
|
70 | - ]; |
|
71 | - |
|
72 | - curl_setopt_array($ch, $curlOpts); |
|
73 | - |
|
74 | - if (null != $file) { |
|
75 | - $cfile = new \CURLFile($file,'',''); |
|
76 | - $body['strFilename']=$cfile; |
|
77 | - curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); |
|
78 | - curl_setopt($ch, CURLOPT_POST,true); |
|
79 | - curl_setopt($ch, CURLOPT_POSTFIELDS, $body); |
|
80 | - } else { |
|
81 | - switch ($method) { |
|
82 | - case 'DELETE': |
|
83 | - curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE'); |
|
84 | - break; |
|
85 | - case 'DELETEARRAY': |
|
86 | - curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE'); |
|
87 | - curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($query)); |
|
88 | - break; |
|
89 | - case 'PUT': |
|
90 | - curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT'); |
|
91 | - break; |
|
92 | - case 'POST': |
|
93 | - if (isset($body)) { |
|
94 | - $bodyData = json_encode($body); |
|
95 | - if (isset($options['HTTPHEADER'])) { |
|
96 | - if (strpos($options['HTTPHEADER'], 'multipart/form-data') > 0) { |
|
97 | - $bodyData = $body; |
|
98 | - } |
|
99 | - } |
|
100 | - |
|
101 | - curl_setopt($ch, CURLOPT_POSTFIELDS, $bodyData); |
|
102 | - } |
|
103 | - break; |
|
104 | - case 'ADD': |
|
105 | - curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($query)); break; |
|
106 | - } |
|
107 | - |
|
108 | - if (is_numeric(array_search($method, ['DELETE', 'PUT']))) { |
|
109 | - if (isset($body)) { |
|
110 | - curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($body)); |
|
111 | - } |
|
112 | - } |
|
113 | - } |
|
114 | - |
|
115 | - $result = curl_exec($ch); |
|
116 | - |
|
117 | - $isxml = false; |
|
118 | - $jxml = ''; |
|
119 | - if (strpos($result, '<?xml') > -1) { |
|
120 | - $xml = simplexml_load_string($result); |
|
121 | - //$jxml = json_encode($xml); |
|
122 | - $jxml = self::object2array($xml); |
|
123 | - $isxml = true; |
|
124 | - } |
|
125 | - |
|
126 | - $code = curl_getinfo($ch, CURLINFO_HTTP_CODE); |
|
127 | - curl_close($ch); |
|
128 | - |
|
129 | - if (200 == $code) { |
|
130 | - if ($isxml) { |
|
131 | - $json = $jxml; |
|
132 | - } else { |
|
133 | - $json = json_decode($result, true); |
|
134 | - } |
|
135 | - |
|
136 | - if (isset($json['errors'])) { |
|
137 | - throw new ApiError(implode(', ', $json['errors'])); |
|
138 | - } else { |
|
139 | - return $json; |
|
140 | - } |
|
141 | - } elseif (409 == $code) { |
|
142 | - throw new ApiError('Wrong API key'); |
|
143 | - } else { |
|
144 | - throw new ApiError('Something wrong'); |
|
145 | - } |
|
146 | - } |
|
147 | - |
|
148 | - /** |
|
149 | - * @param $object: JSON object |
|
150 | - */ |
|
151 | - public static function object2array($object) |
|
152 | - { |
|
153 | - return @json_decode(@json_encode($object), 1); |
|
154 | - } |
|
155 | - |
|
156 | - /** |
|
157 | - * Prints on the screen main keys and values of the array. |
|
158 | - * |
|
159 | - * @param $results: object to be printed on the screen |
|
160 | - * @param $deepPrinting: if true, object will be printed recursively |
|
161 | - */ |
|
162 | - public static function simplePrint($results, $deepPrinting = null) |
|
163 | - { |
|
164 | - if (isset($results)) { |
|
165 | - if (is_array($results)) { |
|
166 | - foreach ($results as $key => $result) { |
|
167 | - if (is_array($result)) { |
|
168 | - foreach ($result as $key1 => $result1) { |
|
169 | - if (is_array($result1)) { |
|
170 | - if ($deepPrinting) { |
|
171 | - echo "<br>$key1 ------><br>"; |
|
172 | - self::simplePrint($result1, true); |
|
173 | - echo '------<br>'; |
|
174 | - } else { |
|
175 | - echo $key1.' --> '.'Array() <br>'; |
|
176 | - } |
|
177 | - } else { |
|
178 | - if (is_object($result1)) { |
|
179 | - if ($deepPrinting) { |
|
180 | - echo "<br>$key1 ------><br>"; |
|
181 | - $oarray = (array) $result1; |
|
182 | - self::simplePrint($oarray, true); |
|
183 | - echo '------<br>'; |
|
184 | - } else { |
|
185 | - echo $key1.' --> '.'Object <br>'; |
|
186 | - } |
|
187 | - } else { |
|
188 | - if (!is_null($result1)) { |
|
189 | - echo $key1.' --> '.$result1.'<br>'; |
|
190 | - } |
|
191 | - } |
|
192 | - } |
|
193 | - } |
|
194 | - } else { |
|
195 | - if (is_object($result)) { |
|
196 | - if ($deepPrinting) { |
|
197 | - echo "<br>$key ------><br>"; |
|
198 | - $oarray = (array) $result; |
|
199 | - self::simplePrint($oarray, true); |
|
200 | - echo '------<br>'; |
|
201 | - } else { |
|
202 | - echo $key.' --> '.'Object <br>'; |
|
203 | - } |
|
204 | - } else { |
|
205 | - if (!is_null($result)) { |
|
206 | - echo $key.' --> '.$result.'<br>'; |
|
207 | - } |
|
208 | - } |
|
209 | - } |
|
210 | - //echo "<br>"; |
|
211 | - } |
|
212 | - } |
|
213 | - } |
|
214 | - } |
|
215 | - |
|
216 | - /** |
|
217 | - * Generates query or body parameters. |
|
218 | - * |
|
219 | - * @param $allFields: all known fields could be used for parameters generation |
|
220 | - * @param $params: input parameters (array or object) |
|
221 | - */ |
|
222 | - public static function generateRequestParameters($allFields, $params) |
|
223 | - { |
|
224 | - $generatedParams = []; |
|
225 | - |
|
226 | - if (is_array($params)) { |
|
227 | - foreach ($allFields as $field) { |
|
228 | - if (isset($params[$field])) { |
|
229 | - $generatedParams[$field] = $params[$field]; |
|
230 | - } |
|
231 | - } |
|
232 | - } elseif (is_object($params)) { |
|
233 | - foreach ($allFields as $field) { |
|
234 | - if (isset($params->{$field})) { |
|
235 | - $generatedParams[$field] = $params->{$field}; |
|
236 | - } |
|
237 | - } |
|
238 | - } |
|
239 | - |
|
240 | - return $generatedParams; |
|
241 | - } |
|
242 | - |
|
243 | - /** |
|
244 | - * Returns an array of the object properties. |
|
245 | - * |
|
246 | - * @param $object: An object |
|
247 | - * @param $exclude: array of the object parameters to be excluded from the returned array |
|
248 | - */ |
|
249 | - public static function getObjectProperties($object, $exclude) |
|
250 | - { |
|
251 | - $objectParameters = []; |
|
252 | - |
|
253 | - foreach (get_object_vars($object) as $key => $value) { |
|
254 | - if (property_exists($object, $key)) { |
|
255 | - if (!is_numeric(array_search($key, $exclude))) { |
|
256 | - array_push($objectParameters, $key); |
|
257 | - } |
|
258 | - } |
|
259 | - } |
|
260 | - |
|
261 | - return $objectParameters; |
|
262 | - } |
|
263 | - |
|
264 | - /** |
|
265 | - * Returns url path generated from the array of the fields and parameters. |
|
266 | - * |
|
267 | - * @param $allFields; array of the paossible fields (parameter names) |
|
268 | - * @param $params: input parameters (array or object) |
|
269 | - */ |
|
270 | - public static function generateUrlPath($allFields, $params) |
|
271 | - { |
|
272 | - $generatedPath = ''; |
|
273 | - |
|
274 | - if (is_array($params)) { |
|
275 | - foreach ($allFields as $field) { |
|
276 | - if (isset($params[$field])) { |
|
277 | - $generatedPath .= $params[$field].'/'; |
|
278 | - } |
|
279 | - } |
|
280 | - } elseif (is_object($params)) { |
|
281 | - foreach ($allFields as $field) { |
|
282 | - if (isset($params->{$field})) { |
|
283 | - $generatedPath .= $params->{$field}.'/'; |
|
284 | - } |
|
285 | - } |
|
286 | - } |
|
287 | - |
|
288 | - return $generatedPath; |
|
289 | - } |
|
290 | - |
|
291 | - public static function getFileRealPath($fileName) |
|
292 | - { |
|
293 | - $rpath = function_exists('curl_file_create') ? curl_file_create(realpath($fileName)) : '@'.realpath($fileName); |
|
294 | - |
|
295 | - return $rpath; |
|
296 | - } |
|
10 | + public static $apiKey; |
|
11 | + public static $baseUrl = Endpoint::BASE_URL; |
|
12 | + |
|
13 | + public static function setApiKey($apiKey) |
|
14 | + { |
|
15 | + self::$apiKey = $apiKey; |
|
16 | + } |
|
17 | + |
|
18 | + public static function getApiKey() |
|
19 | + { |
|
20 | + return self::$apiKey; |
|
21 | + } |
|
22 | + |
|
23 | + public static function setBaseUrl($baseUrl) |
|
24 | + { |
|
25 | + self::$baseUrl = $baseUrl; |
|
26 | + } |
|
27 | + |
|
28 | + public static function getBaseUrl() |
|
29 | + { |
|
30 | + return self::$baseUrl; |
|
31 | + } |
|
32 | + |
|
33 | + public static function makeRequst($options) |
|
34 | + { |
|
35 | + $method = isset($options['method']) ? $options['method'] : 'GET'; |
|
36 | + $query = isset($options['query']) ? array_filter($options['query'], function ($x) { return !is_null($x); }) : []; |
|
37 | + |
|
38 | + $body = isset($options['body']) ? $options['body'] : null; |
|
39 | + $file = isset($options['FILE']) ? $options['FILE'] : null; |
|
40 | + $headers = [ |
|
41 | + 'User-Agent: Route4Me php-sdk', |
|
42 | + ]; |
|
43 | + |
|
44 | + if (isset($options['HTTPHEADER'])) { |
|
45 | + $headers[] = $options['HTTPHEADER']; |
|
46 | + } |
|
47 | + |
|
48 | + if (isset($options['HTTPHEADERS'])) { |
|
49 | + foreach ($options['HTTPHEADERS'] as $header) { |
|
50 | + $headers[] = $header; |
|
51 | + } |
|
52 | + } |
|
53 | + |
|
54 | + $ch = curl_init(); |
|
55 | + |
|
56 | + $url = isset($options['url']) ? $options['url'].'?'.http_build_query(array_merge( |
|
57 | + $query, ['api_key' => self::getApiKey()] |
|
58 | + )) : ''; |
|
59 | + |
|
60 | + $baseUrl = self::getBaseUrl(); |
|
61 | + |
|
62 | + $curlOpts = [ |
|
63 | + CURLOPT_URL => $baseUrl.$url, |
|
64 | + CURLOPT_RETURNTRANSFER => true, |
|
65 | + CURLOPT_TIMEOUT => 120, |
|
66 | + CURLOPT_FOLLOWLOCATION => true, |
|
67 | + CURLOPT_SSL_VERIFYHOST => false, |
|
68 | + CURLOPT_SSL_VERIFYPEER => false, |
|
69 | + CURLOPT_HTTPHEADER => $headers, |
|
70 | + ]; |
|
71 | + |
|
72 | + curl_setopt_array($ch, $curlOpts); |
|
73 | + |
|
74 | + if (null != $file) { |
|
75 | + $cfile = new \CURLFile($file,'',''); |
|
76 | + $body['strFilename']=$cfile; |
|
77 | + curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); |
|
78 | + curl_setopt($ch, CURLOPT_POST,true); |
|
79 | + curl_setopt($ch, CURLOPT_POSTFIELDS, $body); |
|
80 | + } else { |
|
81 | + switch ($method) { |
|
82 | + case 'DELETE': |
|
83 | + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE'); |
|
84 | + break; |
|
85 | + case 'DELETEARRAY': |
|
86 | + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE'); |
|
87 | + curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($query)); |
|
88 | + break; |
|
89 | + case 'PUT': |
|
90 | + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT'); |
|
91 | + break; |
|
92 | + case 'POST': |
|
93 | + if (isset($body)) { |
|
94 | + $bodyData = json_encode($body); |
|
95 | + if (isset($options['HTTPHEADER'])) { |
|
96 | + if (strpos($options['HTTPHEADER'], 'multipart/form-data') > 0) { |
|
97 | + $bodyData = $body; |
|
98 | + } |
|
99 | + } |
|
100 | + |
|
101 | + curl_setopt($ch, CURLOPT_POSTFIELDS, $bodyData); |
|
102 | + } |
|
103 | + break; |
|
104 | + case 'ADD': |
|
105 | + curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($query)); break; |
|
106 | + } |
|
107 | + |
|
108 | + if (is_numeric(array_search($method, ['DELETE', 'PUT']))) { |
|
109 | + if (isset($body)) { |
|
110 | + curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($body)); |
|
111 | + } |
|
112 | + } |
|
113 | + } |
|
114 | + |
|
115 | + $result = curl_exec($ch); |
|
116 | + |
|
117 | + $isxml = false; |
|
118 | + $jxml = ''; |
|
119 | + if (strpos($result, '<?xml') > -1) { |
|
120 | + $xml = simplexml_load_string($result); |
|
121 | + //$jxml = json_encode($xml); |
|
122 | + $jxml = self::object2array($xml); |
|
123 | + $isxml = true; |
|
124 | + } |
|
125 | + |
|
126 | + $code = curl_getinfo($ch, CURLINFO_HTTP_CODE); |
|
127 | + curl_close($ch); |
|
128 | + |
|
129 | + if (200 == $code) { |
|
130 | + if ($isxml) { |
|
131 | + $json = $jxml; |
|
132 | + } else { |
|
133 | + $json = json_decode($result, true); |
|
134 | + } |
|
135 | + |
|
136 | + if (isset($json['errors'])) { |
|
137 | + throw new ApiError(implode(', ', $json['errors'])); |
|
138 | + } else { |
|
139 | + return $json; |
|
140 | + } |
|
141 | + } elseif (409 == $code) { |
|
142 | + throw new ApiError('Wrong API key'); |
|
143 | + } else { |
|
144 | + throw new ApiError('Something wrong'); |
|
145 | + } |
|
146 | + } |
|
147 | + |
|
148 | + /** |
|
149 | + * @param $object: JSON object |
|
150 | + */ |
|
151 | + public static function object2array($object) |
|
152 | + { |
|
153 | + return @json_decode(@json_encode($object), 1); |
|
154 | + } |
|
155 | + |
|
156 | + /** |
|
157 | + * Prints on the screen main keys and values of the array. |
|
158 | + * |
|
159 | + * @param $results: object to be printed on the screen |
|
160 | + * @param $deepPrinting: if true, object will be printed recursively |
|
161 | + */ |
|
162 | + public static function simplePrint($results, $deepPrinting = null) |
|
163 | + { |
|
164 | + if (isset($results)) { |
|
165 | + if (is_array($results)) { |
|
166 | + foreach ($results as $key => $result) { |
|
167 | + if (is_array($result)) { |
|
168 | + foreach ($result as $key1 => $result1) { |
|
169 | + if (is_array($result1)) { |
|
170 | + if ($deepPrinting) { |
|
171 | + echo "<br>$key1 ------><br>"; |
|
172 | + self::simplePrint($result1, true); |
|
173 | + echo '------<br>'; |
|
174 | + } else { |
|
175 | + echo $key1.' --> '.'Array() <br>'; |
|
176 | + } |
|
177 | + } else { |
|
178 | + if (is_object($result1)) { |
|
179 | + if ($deepPrinting) { |
|
180 | + echo "<br>$key1 ------><br>"; |
|
181 | + $oarray = (array) $result1; |
|
182 | + self::simplePrint($oarray, true); |
|
183 | + echo '------<br>'; |
|
184 | + } else { |
|
185 | + echo $key1.' --> '.'Object <br>'; |
|
186 | + } |
|
187 | + } else { |
|
188 | + if (!is_null($result1)) { |
|
189 | + echo $key1.' --> '.$result1.'<br>'; |
|
190 | + } |
|
191 | + } |
|
192 | + } |
|
193 | + } |
|
194 | + } else { |
|
195 | + if (is_object($result)) { |
|
196 | + if ($deepPrinting) { |
|
197 | + echo "<br>$key ------><br>"; |
|
198 | + $oarray = (array) $result; |
|
199 | + self::simplePrint($oarray, true); |
|
200 | + echo '------<br>'; |
|
201 | + } else { |
|
202 | + echo $key.' --> '.'Object <br>'; |
|
203 | + } |
|
204 | + } else { |
|
205 | + if (!is_null($result)) { |
|
206 | + echo $key.' --> '.$result.'<br>'; |
|
207 | + } |
|
208 | + } |
|
209 | + } |
|
210 | + //echo "<br>"; |
|
211 | + } |
|
212 | + } |
|
213 | + } |
|
214 | + } |
|
215 | + |
|
216 | + /** |
|
217 | + * Generates query or body parameters. |
|
218 | + * |
|
219 | + * @param $allFields: all known fields could be used for parameters generation |
|
220 | + * @param $params: input parameters (array or object) |
|
221 | + */ |
|
222 | + public static function generateRequestParameters($allFields, $params) |
|
223 | + { |
|
224 | + $generatedParams = []; |
|
225 | + |
|
226 | + if (is_array($params)) { |
|
227 | + foreach ($allFields as $field) { |
|
228 | + if (isset($params[$field])) { |
|
229 | + $generatedParams[$field] = $params[$field]; |
|
230 | + } |
|
231 | + } |
|
232 | + } elseif (is_object($params)) { |
|
233 | + foreach ($allFields as $field) { |
|
234 | + if (isset($params->{$field})) { |
|
235 | + $generatedParams[$field] = $params->{$field}; |
|
236 | + } |
|
237 | + } |
|
238 | + } |
|
239 | + |
|
240 | + return $generatedParams; |
|
241 | + } |
|
242 | + |
|
243 | + /** |
|
244 | + * Returns an array of the object properties. |
|
245 | + * |
|
246 | + * @param $object: An object |
|
247 | + * @param $exclude: array of the object parameters to be excluded from the returned array |
|
248 | + */ |
|
249 | + public static function getObjectProperties($object, $exclude) |
|
250 | + { |
|
251 | + $objectParameters = []; |
|
252 | + |
|
253 | + foreach (get_object_vars($object) as $key => $value) { |
|
254 | + if (property_exists($object, $key)) { |
|
255 | + if (!is_numeric(array_search($key, $exclude))) { |
|
256 | + array_push($objectParameters, $key); |
|
257 | + } |
|
258 | + } |
|
259 | + } |
|
260 | + |
|
261 | + return $objectParameters; |
|
262 | + } |
|
263 | + |
|
264 | + /** |
|
265 | + * Returns url path generated from the array of the fields and parameters. |
|
266 | + * |
|
267 | + * @param $allFields; array of the paossible fields (parameter names) |
|
268 | + * @param $params: input parameters (array or object) |
|
269 | + */ |
|
270 | + public static function generateUrlPath($allFields, $params) |
|
271 | + { |
|
272 | + $generatedPath = ''; |
|
273 | + |
|
274 | + if (is_array($params)) { |
|
275 | + foreach ($allFields as $field) { |
|
276 | + if (isset($params[$field])) { |
|
277 | + $generatedPath .= $params[$field].'/'; |
|
278 | + } |
|
279 | + } |
|
280 | + } elseif (is_object($params)) { |
|
281 | + foreach ($allFields as $field) { |
|
282 | + if (isset($params->{$field})) { |
|
283 | + $generatedPath .= $params->{$field}.'/'; |
|
284 | + } |
|
285 | + } |
|
286 | + } |
|
287 | + |
|
288 | + return $generatedPath; |
|
289 | + } |
|
290 | + |
|
291 | + public static function getFileRealPath($fileName) |
|
292 | + { |
|
293 | + $rpath = function_exists('curl_file_create') ? curl_file_create(realpath($fileName)) : '@'.realpath($fileName); |
|
294 | + |
|
295 | + return $rpath; |
|
296 | + } |
|
297 | 297 | } |
@@ -79,30 +79,30 @@ |
||
79 | 79 | curl_setopt($ch, CURLOPT_POSTFIELDS, $body); |
80 | 80 | } else { |
81 | 81 | switch ($method) { |
82 | - case 'DELETE': |
|
83 | - curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE'); |
|
84 | - break; |
|
85 | - case 'DELETEARRAY': |
|
86 | - curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE'); |
|
87 | - curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($query)); |
|
88 | - break; |
|
89 | - case 'PUT': |
|
90 | - curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT'); |
|
91 | - break; |
|
92 | - case 'POST': |
|
93 | - if (isset($body)) { |
|
94 | - $bodyData = json_encode($body); |
|
95 | - if (isset($options['HTTPHEADER'])) { |
|
96 | - if (strpos($options['HTTPHEADER'], 'multipart/form-data') > 0) { |
|
97 | - $bodyData = $body; |
|
98 | - } |
|
82 | + case 'DELETE': |
|
83 | + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE'); |
|
84 | + break; |
|
85 | + case 'DELETEARRAY': |
|
86 | + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE'); |
|
87 | + curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($query)); |
|
88 | + break; |
|
89 | + case 'PUT': |
|
90 | + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT'); |
|
91 | + break; |
|
92 | + case 'POST': |
|
93 | + if (isset($body)) { |
|
94 | + $bodyData = json_encode($body); |
|
95 | + if (isset($options['HTTPHEADER'])) { |
|
96 | + if (strpos($options['HTTPHEADER'], 'multipart/form-data') > 0) { |
|
97 | + $bodyData = $body; |
|
99 | 98 | } |
100 | - |
|
101 | - curl_setopt($ch, CURLOPT_POSTFIELDS, $bodyData); |
|
102 | 99 | } |
103 | - break; |
|
104 | - case 'ADD': |
|
105 | - curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($query)); break; |
|
100 | + |
|
101 | + curl_setopt($ch, CURLOPT_POSTFIELDS, $bodyData); |
|
102 | + } |
|
103 | + break; |
|
104 | + case 'ADD': |
|
105 | + curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($query)); break; |
|
106 | 106 | } |
107 | 107 | |
108 | 108 | if (is_numeric(array_search($method, ['DELETE', 'PUT']))) { |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | public static function makeRequst($options) |
34 | 34 | { |
35 | 35 | $method = isset($options['method']) ? $options['method'] : 'GET'; |
36 | - $query = isset($options['query']) ? array_filter($options['query'], function ($x) { return !is_null($x); }) : []; |
|
36 | + $query = isset($options['query']) ? array_filter($options['query'], function($x) { return !is_null($x); }) : []; |
|
37 | 37 | |
38 | 38 | $body = isset($options['body']) ? $options['body'] : null; |
39 | 39 | $file = isset($options['FILE']) ? $options['FILE'] : null; |
@@ -71,11 +71,11 @@ discard block |
||
71 | 71 | |
72 | 72 | curl_setopt_array($ch, $curlOpts); |
73 | 73 | |
74 | - if (null != $file) { |
|
75 | - $cfile = new \CURLFile($file,'',''); |
|
76 | - $body['strFilename']=$cfile; |
|
74 | + if (null!=$file) { |
|
75 | + $cfile = new \CURLFile($file, '', ''); |
|
76 | + $body['strFilename'] = $cfile; |
|
77 | 77 | curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); |
78 | - curl_setopt($ch, CURLOPT_POST,true); |
|
78 | + curl_setopt($ch, CURLOPT_POST, true); |
|
79 | 79 | curl_setopt($ch, CURLOPT_POSTFIELDS, $body); |
80 | 80 | } else { |
81 | 81 | switch ($method) { |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | if (isset($body)) { |
94 | 94 | $bodyData = json_encode($body); |
95 | 95 | if (isset($options['HTTPHEADER'])) { |
96 | - if (strpos($options['HTTPHEADER'], 'multipart/form-data') > 0) { |
|
96 | + if (strpos($options['HTTPHEADER'], 'multipart/form-data')>0) { |
|
97 | 97 | $bodyData = $body; |
98 | 98 | } |
99 | 99 | } |
@@ -116,7 +116,7 @@ discard block |
||
116 | 116 | |
117 | 117 | $isxml = false; |
118 | 118 | $jxml = ''; |
119 | - if (strpos($result, '<?xml') > -1) { |
|
119 | + if (strpos($result, '<?xml')>-1) { |
|
120 | 120 | $xml = simplexml_load_string($result); |
121 | 121 | //$jxml = json_encode($xml); |
122 | 122 | $jxml = self::object2array($xml); |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | $code = curl_getinfo($ch, CURLINFO_HTTP_CODE); |
127 | 127 | curl_close($ch); |
128 | 128 | |
129 | - if (200 == $code) { |
|
129 | + if (200==$code) { |
|
130 | 130 | if ($isxml) { |
131 | 131 | $json = $jxml; |
132 | 132 | } else { |
@@ -138,7 +138,7 @@ discard block |
||
138 | 138 | } else { |
139 | 139 | return $json; |
140 | 140 | } |
141 | - } elseif (409 == $code) { |
|
141 | + } elseif (409==$code) { |
|
142 | 142 | throw new ApiError('Wrong API key'); |
143 | 143 | } else { |
144 | 144 | throw new ApiError('Something wrong'); |
@@ -178,7 +178,7 @@ discard block |
||
178 | 178 | if (is_object($result1)) { |
179 | 179 | if ($deepPrinting) { |
180 | 180 | echo "<br>$key1 ------><br>"; |
181 | - $oarray = (array) $result1; |
|
181 | + $oarray = (array)$result1; |
|
182 | 182 | self::simplePrint($oarray, true); |
183 | 183 | echo '------<br>'; |
184 | 184 | } else { |
@@ -195,7 +195,7 @@ discard block |
||
195 | 195 | if (is_object($result)) { |
196 | 196 | if ($deepPrinting) { |
197 | 197 | echo "<br>$key ------><br>"; |
198 | - $oarray = (array) $result; |
|
198 | + $oarray = (array)$result; |
|
199 | 199 | self::simplePrint($oarray, true); |
200 | 200 | echo '------<br>'; |
201 | 201 | } else { |
@@ -6,22 +6,22 @@ |
||
6 | 6 | |
7 | 7 | class AddressBookLocationSearchResponse |
8 | 8 | { |
9 | - public $results=[]; |
|
10 | - public $total; |
|
11 | - public $fields=[]; |
|
9 | + public $results=[]; |
|
10 | + public $total; |
|
11 | + public $fields=[]; |
|
12 | 12 | |
13 | - public static function fromArray(array $params) |
|
14 | - { |
|
15 | - $ablSearchResponse = new self(); |
|
13 | + public static function fromArray(array $params) |
|
14 | + { |
|
15 | + $ablSearchResponse = new self(); |
|
16 | 16 | |
17 | - foreach ($params as $key => $value) { |
|
18 | - if (property_exists($ablSearchResponse, $key)) { |
|
19 | - $ablSearchResponse->{$key} = $value; |
|
20 | - } else { |
|
21 | - throw new BadParam("Correct parameter must be provided. Wrong Parameter: $key"); |
|
22 | - } |
|
23 | - } |
|
17 | + foreach ($params as $key => $value) { |
|
18 | + if (property_exists($ablSearchResponse, $key)) { |
|
19 | + $ablSearchResponse->{$key} = $value; |
|
20 | + } else { |
|
21 | + throw new BadParam("Correct parameter must be provided. Wrong Parameter: $key"); |
|
22 | + } |
|
23 | + } |
|
24 | 24 | |
25 | - return $ablSearchResponse; |
|
26 | - } |
|
25 | + return $ablSearchResponse; |
|
26 | + } |
|
27 | 27 | } |
28 | 28 | \ No newline at end of file |
@@ -6,9 +6,9 @@ |
||
6 | 6 | |
7 | 7 | class AddressBookLocationSearchResponse |
8 | 8 | { |
9 | - public $results=[]; |
|
9 | + public $results = []; |
|
10 | 10 | public $total; |
11 | - public $fields=[]; |
|
11 | + public $fields = []; |
|
12 | 12 | |
13 | 13 | public static function fromArray(array $params) |
14 | 14 | { |
@@ -11,28 +11,28 @@ |
||
11 | 11 | */ |
12 | 12 | class GeoPoint extends Common |
13 | 13 | { |
14 | - /** |
|
15 | - * Latitude |
|
16 | - * @var double |
|
17 | - */ |
|
18 | - public $lat; |
|
19 | - |
|
20 | - /** |
|
21 | - * Longitude |
|
22 | - * @var double |
|
23 | - */ |
|
24 | - public $lng; |
|
25 | - |
|
26 | - public static function fromArray(array $params) |
|
27 | - { |
|
28 | - $thisParams = new self(); |
|
29 | - |
|
30 | - foreach ($params as $key => $value) { |
|
31 | - if (property_exists($thisParams, $key)) { |
|
32 | - $thisParams->{$key} = $value; |
|
33 | - } |
|
34 | - } |
|
35 | - |
|
36 | - return $thisParams; |
|
37 | - } |
|
14 | + /** |
|
15 | + * Latitude |
|
16 | + * @var double |
|
17 | + */ |
|
18 | + public $lat; |
|
19 | + |
|
20 | + /** |
|
21 | + * Longitude |
|
22 | + * @var double |
|
23 | + */ |
|
24 | + public $lng; |
|
25 | + |
|
26 | + public static function fromArray(array $params) |
|
27 | + { |
|
28 | + $thisParams = new self(); |
|
29 | + |
|
30 | + foreach ($params as $key => $value) { |
|
31 | + if (property_exists($thisParams, $key)) { |
|
32 | + $thisParams->{$key} = $value; |
|
33 | + } |
|
34 | + } |
|
35 | + |
|
36 | + return $thisParams; |
|
37 | + } |
|
38 | 38 | } |
39 | 39 | \ No newline at end of file |
@@ -9,23 +9,23 @@ |
||
9 | 9 | */ |
10 | 10 | class AddressNoteResponse extends Common |
11 | 11 | { |
12 | - public $status; |
|
13 | - public $note_id; |
|
14 | - public $upload_id; |
|
15 | - public $note; |
|
12 | + public $status; |
|
13 | + public $note_id; |
|
14 | + public $upload_id; |
|
15 | + public $note; |
|
16 | 16 | |
17 | - public static function fromArray(array $params) |
|
18 | - { |
|
19 | - $addressNoteResponse = new self(); |
|
17 | + public static function fromArray(array $params) |
|
18 | + { |
|
19 | + $addressNoteResponse = new self(); |
|
20 | 20 | |
21 | - foreach ($params as $key => $value) { |
|
22 | - if (property_exists($addressNoteResponse, $key)) { |
|
23 | - $addressNoteResponse->{$key} = $value; |
|
24 | - } else { |
|
25 | - throw new BadParam("Correct parameter must be provided. Wrong Parameter: $key"); |
|
26 | - } |
|
27 | - } |
|
21 | + foreach ($params as $key => $value) { |
|
22 | + if (property_exists($addressNoteResponse, $key)) { |
|
23 | + $addressNoteResponse->{$key} = $value; |
|
24 | + } else { |
|
25 | + throw new BadParam("Correct parameter must be provided. Wrong Parameter: $key"); |
|
26 | + } |
|
27 | + } |
|
28 | 28 | |
29 | - return $addressNoteResponse; |
|
30 | - } |
|
29 | + return $addressNoteResponse; |
|
30 | + } |
|
31 | 31 | } |
32 | 32 | \ No newline at end of file |
@@ -10,36 +10,36 @@ |
||
10 | 10 | */ |
11 | 11 | class ScheduleCalendarResponse extends Common |
12 | 12 | { |
13 | - /** |
|
14 | - * The address book contact quantity by dates |
|
15 | - * (dates are in the string format, e.g. 2020-10-18). |
|
16 | - * @var array |
|
17 | - */ |
|
18 | - public $address_book = []; |
|
13 | + /** |
|
14 | + * The address book contact quantity by dates |
|
15 | + * (dates are in the string format, e.g. 2020-10-18). |
|
16 | + * @var array |
|
17 | + */ |
|
18 | + public $address_book = []; |
|
19 | 19 | |
20 | - /* |
|
20 | + /* |
|
21 | 21 | * The order quantity by dates |
22 | 22 | * (dates are in the string format, e.g. 2020-10-18). |
23 | 23 | * @var array |
24 | 24 | */ |
25 | - public $orders = []; |
|
25 | + public $orders = []; |
|
26 | 26 | |
27 | - /* |
|
27 | + /* |
|
28 | 28 | * The order quantity by dates |
29 | 29 | * (dates are in the string format, e.g. 2020-10-18). |
30 | 30 | * @var array |
31 | 31 | */ |
32 | - public $routes_count = []; |
|
32 | + public $routes_count = []; |
|
33 | 33 | |
34 | - public static function fromArray(array $params) |
|
35 | - { |
|
36 | - $order = new self(); |
|
37 | - foreach ($params as $key => $value) { |
|
38 | - if (property_exists($order, $key)) { |
|
39 | - $order->{$key} = $value; |
|
40 | - } |
|
41 | - } |
|
34 | + public static function fromArray(array $params) |
|
35 | + { |
|
36 | + $order = new self(); |
|
37 | + foreach ($params as $key => $value) { |
|
38 | + if (property_exists($order, $key)) { |
|
39 | + $order->{$key} = $value; |
|
40 | + } |
|
41 | + } |
|
42 | 42 | |
43 | - return $order; |
|
44 | - } |
|
43 | + return $order; |
|
44 | + } |
|
45 | 45 | } |
@@ -7,226 +7,226 @@ |
||
7 | 7 | |
8 | 8 | class Address extends Common |
9 | 9 | { |
10 | - public $route_destination_id; |
|
11 | - public $alias; |
|
12 | - public $member_id; |
|
13 | - public $address; |
|
14 | - public $addressUpdate; |
|
15 | - public $is_depot = false; |
|
16 | - public $lat; |
|
17 | - public $lng; |
|
18 | - public $route_id; |
|
19 | - public $original_route_id; |
|
20 | - public $optimization_problem_id; |
|
21 | - public $sequence_no; |
|
22 | - public $geocoded; |
|
23 | - public $preferred_geocoding; |
|
24 | - public $failed_geocoding; |
|
25 | - public $geocodings = []; |
|
26 | - public $contact_id; |
|
27 | - public $is_visited; |
|
28 | - public $customer_po; |
|
29 | - public $invoice_no; |
|
30 | - public $reference_no; |
|
31 | - public $order_no; |
|
32 | - public $weight; |
|
33 | - public $cost; |
|
34 | - public $revenue; |
|
35 | - public $cube; |
|
36 | - public $pieces; |
|
37 | - public $email; |
|
38 | - public $phone; |
|
39 | - public $tracking_number; |
|
40 | - public $destination_note_count; |
|
41 | - public $drive_time_to_next_destination; |
|
42 | - public $distance_to_next_destination; |
|
43 | - public $generated_time_window_start; |
|
44 | - public $generated_time_window_end; |
|
45 | - public $time_window_start; |
|
46 | - public $time_window_end; |
|
47 | - public $time; |
|
48 | - public $notes; |
|
49 | - public $timestamp_last_visited; |
|
50 | - public $custom_fields = []; |
|
51 | - public $manifest = []; |
|
52 | - |
|
53 | - public $first_name; |
|
54 | - public $last_name; |
|
55 | - public $is_departed; |
|
56 | - public $timestamp_last_departed; |
|
57 | - public $order_id; |
|
58 | - public $priority; |
|
59 | - public $curbside_lat; |
|
60 | - public $curbside_lng; |
|
61 | - public $time_window_start_2; |
|
62 | - public $time_window_end_2; |
|
63 | - |
|
64 | - public $timeframe_violation_state; |
|
65 | - public $timeframe_violation_time; |
|
66 | - public $timeframe_violation_rate; |
|
67 | - public $route_name; |
|
68 | - public $address_stop_type; |
|
69 | - public $visited_lat; |
|
70 | - public $visited_lng; |
|
71 | - public $departed_lat; |
|
72 | - public $departed_lng; |
|
73 | - public $group; |
|
74 | - public $abnormal_traffic_time_to_next_destination; |
|
75 | - public $uncongested_time_to_next_destination; |
|
76 | - public $traffic_time_to_next_destination; |
|
77 | - public $channel_name; |
|
78 | - public $pickup; |
|
79 | - public $dropoff; |
|
80 | - public $joint; |
|
81 | - public $geofence_detected_visited_timestamp; |
|
82 | - public $geofence_detected_departed_timestamp; |
|
83 | - public $geofence_detected_service_time; |
|
84 | - public $geofence_detected_visited_lat; |
|
85 | - public $geofence_detected_visited_lng; |
|
86 | - public $geofence_detected_departed_lat; |
|
87 | - public $geofence_detected_departed_lng; |
|
88 | - public $custom_fields_str_json; |
|
89 | - public $custom_fields_config; |
|
90 | - public $custom_fields_config_str_json; |
|
91 | - public $bundle_count; |
|
92 | - public $bundle_items; |
|
93 | - public $order_inventory; |
|
94 | - public $required_skills; |
|
95 | - public $udu_distance_to_next_destination; |
|
96 | - public $wait_time_to_next_destination; |
|
97 | - public $path_to_next = []; |
|
98 | - public $additional_status; |
|
99 | - |
|
100 | - public function __construct() |
|
101 | - { |
|
102 | - Route4Me::setBaseUrl(Endpoint::BASE_URL); |
|
103 | - } |
|
104 | - |
|
105 | - public static function fromArray(array $params) |
|
106 | - { |
|
107 | - $address = new self(); |
|
108 | - |
|
109 | - foreach ($params as $key => $value) { |
|
110 | - if (property_exists($address, $key)) { |
|
111 | - $address->{$key} = $value; |
|
112 | - } else { |
|
113 | - throw new BadParam("Correct parameter must be provided. Wrong Parameter: $key"); |
|
114 | - } |
|
115 | - } |
|
116 | - |
|
117 | - return $address; |
|
118 | - } |
|
119 | - |
|
120 | - public static function getAddress($routeId, $addressId) |
|
121 | - { |
|
122 | - $address = Route4Me::makeRequst([ |
|
123 | - 'url' => Endpoint::ADDRESS_V4, |
|
124 | - 'method' => 'GET', |
|
125 | - 'query' => [ |
|
126 | - 'route_id' => $routeId, |
|
127 | - 'route_destination_id' => $addressId, |
|
128 | - ], |
|
129 | - ]); |
|
130 | - |
|
131 | - return self::fromArray($address); |
|
132 | - } |
|
133 | - |
|
134 | - public function update() |
|
135 | - { |
|
136 | - $addressUpdate = Route4Me::makeRequst([ |
|
137 | - 'url' => Endpoint::ADDRESS_V4, |
|
138 | - 'method' => 'PUT', |
|
139 | - 'body' => $this->toArray(), |
|
140 | - 'query' => [ |
|
141 | - 'route_id' => $this->route_id, |
|
142 | - 'route_destination_id' => $this->route_destination_id, |
|
143 | - ], |
|
144 | - ]); |
|
145 | - |
|
146 | - return self::fromArray($addressUpdate); |
|
147 | - } |
|
148 | - |
|
149 | - /* |
|
10 | + public $route_destination_id; |
|
11 | + public $alias; |
|
12 | + public $member_id; |
|
13 | + public $address; |
|
14 | + public $addressUpdate; |
|
15 | + public $is_depot = false; |
|
16 | + public $lat; |
|
17 | + public $lng; |
|
18 | + public $route_id; |
|
19 | + public $original_route_id; |
|
20 | + public $optimization_problem_id; |
|
21 | + public $sequence_no; |
|
22 | + public $geocoded; |
|
23 | + public $preferred_geocoding; |
|
24 | + public $failed_geocoding; |
|
25 | + public $geocodings = []; |
|
26 | + public $contact_id; |
|
27 | + public $is_visited; |
|
28 | + public $customer_po; |
|
29 | + public $invoice_no; |
|
30 | + public $reference_no; |
|
31 | + public $order_no; |
|
32 | + public $weight; |
|
33 | + public $cost; |
|
34 | + public $revenue; |
|
35 | + public $cube; |
|
36 | + public $pieces; |
|
37 | + public $email; |
|
38 | + public $phone; |
|
39 | + public $tracking_number; |
|
40 | + public $destination_note_count; |
|
41 | + public $drive_time_to_next_destination; |
|
42 | + public $distance_to_next_destination; |
|
43 | + public $generated_time_window_start; |
|
44 | + public $generated_time_window_end; |
|
45 | + public $time_window_start; |
|
46 | + public $time_window_end; |
|
47 | + public $time; |
|
48 | + public $notes; |
|
49 | + public $timestamp_last_visited; |
|
50 | + public $custom_fields = []; |
|
51 | + public $manifest = []; |
|
52 | + |
|
53 | + public $first_name; |
|
54 | + public $last_name; |
|
55 | + public $is_departed; |
|
56 | + public $timestamp_last_departed; |
|
57 | + public $order_id; |
|
58 | + public $priority; |
|
59 | + public $curbside_lat; |
|
60 | + public $curbside_lng; |
|
61 | + public $time_window_start_2; |
|
62 | + public $time_window_end_2; |
|
63 | + |
|
64 | + public $timeframe_violation_state; |
|
65 | + public $timeframe_violation_time; |
|
66 | + public $timeframe_violation_rate; |
|
67 | + public $route_name; |
|
68 | + public $address_stop_type; |
|
69 | + public $visited_lat; |
|
70 | + public $visited_lng; |
|
71 | + public $departed_lat; |
|
72 | + public $departed_lng; |
|
73 | + public $group; |
|
74 | + public $abnormal_traffic_time_to_next_destination; |
|
75 | + public $uncongested_time_to_next_destination; |
|
76 | + public $traffic_time_to_next_destination; |
|
77 | + public $channel_name; |
|
78 | + public $pickup; |
|
79 | + public $dropoff; |
|
80 | + public $joint; |
|
81 | + public $geofence_detected_visited_timestamp; |
|
82 | + public $geofence_detected_departed_timestamp; |
|
83 | + public $geofence_detected_service_time; |
|
84 | + public $geofence_detected_visited_lat; |
|
85 | + public $geofence_detected_visited_lng; |
|
86 | + public $geofence_detected_departed_lat; |
|
87 | + public $geofence_detected_departed_lng; |
|
88 | + public $custom_fields_str_json; |
|
89 | + public $custom_fields_config; |
|
90 | + public $custom_fields_config_str_json; |
|
91 | + public $bundle_count; |
|
92 | + public $bundle_items; |
|
93 | + public $order_inventory; |
|
94 | + public $required_skills; |
|
95 | + public $udu_distance_to_next_destination; |
|
96 | + public $wait_time_to_next_destination; |
|
97 | + public $path_to_next = []; |
|
98 | + public $additional_status; |
|
99 | + |
|
100 | + public function __construct() |
|
101 | + { |
|
102 | + Route4Me::setBaseUrl(Endpoint::BASE_URL); |
|
103 | + } |
|
104 | + |
|
105 | + public static function fromArray(array $params) |
|
106 | + { |
|
107 | + $address = new self(); |
|
108 | + |
|
109 | + foreach ($params as $key => $value) { |
|
110 | + if (property_exists($address, $key)) { |
|
111 | + $address->{$key} = $value; |
|
112 | + } else { |
|
113 | + throw new BadParam("Correct parameter must be provided. Wrong Parameter: $key"); |
|
114 | + } |
|
115 | + } |
|
116 | + |
|
117 | + return $address; |
|
118 | + } |
|
119 | + |
|
120 | + public static function getAddress($routeId, $addressId) |
|
121 | + { |
|
122 | + $address = Route4Me::makeRequst([ |
|
123 | + 'url' => Endpoint::ADDRESS_V4, |
|
124 | + 'method' => 'GET', |
|
125 | + 'query' => [ |
|
126 | + 'route_id' => $routeId, |
|
127 | + 'route_destination_id' => $addressId, |
|
128 | + ], |
|
129 | + ]); |
|
130 | + |
|
131 | + return self::fromArray($address); |
|
132 | + } |
|
133 | + |
|
134 | + public function update() |
|
135 | + { |
|
136 | + $addressUpdate = Route4Me::makeRequst([ |
|
137 | + 'url' => Endpoint::ADDRESS_V4, |
|
138 | + 'method' => 'PUT', |
|
139 | + 'body' => $this->toArray(), |
|
140 | + 'query' => [ |
|
141 | + 'route_id' => $this->route_id, |
|
142 | + 'route_destination_id' => $this->route_destination_id, |
|
143 | + ], |
|
144 | + ]); |
|
145 | + |
|
146 | + return self::fromArray($addressUpdate); |
|
147 | + } |
|
148 | + |
|
149 | + /* |
|
150 | 150 | * Marks an address as marked as visited/as departed |
151 | 151 | * depending on which parameter is specified: 'is_visited' or 'is_departed'. |
152 | 152 | */ |
153 | - public function markAddress($params) |
|
154 | - { |
|
155 | - $allQueryFields = ['route_id', 'route_destination_id']; |
|
156 | - $allBodyFields = ['is_visited', 'is_departed']; |
|
157 | - |
|
158 | - $result = Route4Me::makeRequst([ |
|
159 | - 'url' => Endpoint::ADDRESS_V4, |
|
160 | - 'method' => 'PUT', |
|
161 | - 'query' => Route4Me::generateRequestParameters($allQueryFields, $params), |
|
162 | - 'body' => Route4Me::generateRequestParameters($allBodyFields, $params), |
|
163 | - ]); |
|
164 | - |
|
165 | - return $result; |
|
166 | - } |
|
167 | - |
|
168 | - /* |
|
153 | + public function markAddress($params) |
|
154 | + { |
|
155 | + $allQueryFields = ['route_id', 'route_destination_id']; |
|
156 | + $allBodyFields = ['is_visited', 'is_departed']; |
|
157 | + |
|
158 | + $result = Route4Me::makeRequst([ |
|
159 | + 'url' => Endpoint::ADDRESS_V4, |
|
160 | + 'method' => 'PUT', |
|
161 | + 'query' => Route4Me::generateRequestParameters($allQueryFields, $params), |
|
162 | + 'body' => Route4Me::generateRequestParameters($allBodyFields, $params), |
|
163 | + ]); |
|
164 | + |
|
165 | + return $result; |
|
166 | + } |
|
167 | + |
|
168 | + /* |
|
169 | 169 | * Marks an address as departed. |
170 | 170 | */ |
171 | - public function markAsDeparted($params) |
|
172 | - { |
|
173 | - $allQueryFields = ['route_id', 'address_id', 'is_departed', 'member_id']; |
|
171 | + public function markAsDeparted($params) |
|
172 | + { |
|
173 | + $allQueryFields = ['route_id', 'address_id', 'is_departed', 'member_id']; |
|
174 | 174 | |
175 | - $address = Route4Me::makeRequst([ |
|
176 | - 'url' => Endpoint::MARK_ADDRESS_DEPARTED, |
|
177 | - 'method' => 'PUT', |
|
178 | - 'query' => Route4Me::generateRequestParameters($allQueryFields, $params), |
|
179 | - ]); |
|
175 | + $address = Route4Me::makeRequst([ |
|
176 | + 'url' => Endpoint::MARK_ADDRESS_DEPARTED, |
|
177 | + 'method' => 'PUT', |
|
178 | + 'query' => Route4Me::generateRequestParameters($allQueryFields, $params), |
|
179 | + ]); |
|
180 | 180 | |
181 | - return $address; |
|
182 | - } |
|
181 | + return $address; |
|
182 | + } |
|
183 | 183 | |
184 | - /* |
|
184 | + /* |
|
185 | 185 | * Marks an address as visited. |
186 | 186 | */ |
187 | - public function markAsVisited($params) |
|
188 | - { |
|
189 | - $allQueryFields = ['route_id', 'address_id', 'is_visited', 'member_id']; |
|
190 | - |
|
191 | - $address = Route4Me::makeRequst([ |
|
192 | - 'url' => Endpoint::UPDATE_ADDRESS_VISITED, |
|
193 | - 'method' => 'PUT', |
|
194 | - 'query' => Route4Me::generateRequestParameters($allQueryFields, $params), |
|
195 | - ]); |
|
196 | - |
|
197 | - return $address; |
|
198 | - } |
|
199 | - |
|
200 | - public function deleteAddress() |
|
201 | - { |
|
202 | - $address = Route4Me::makeRequst([ |
|
203 | - 'url' => Endpoint::ADDRESS_V4, |
|
204 | - 'method' => 'DELETE', |
|
205 | - 'query' => [ |
|
206 | - 'route_id' => $this->route_id, |
|
207 | - 'route_destination_id' => $this->route_destination_id, |
|
208 | - ], |
|
209 | - ]); |
|
210 | - |
|
211 | - return (bool) $address['deleted']; |
|
212 | - } |
|
213 | - |
|
214 | - public function moveDestinationToRoute($params) |
|
215 | - { |
|
216 | - $allBodyFields = ['to_route_id', 'route_destination_id', 'after_destination_id']; |
|
217 | - |
|
218 | - $result = Route4Me::makeRequst([ |
|
219 | - 'url' => Endpoint::MOVE_ROUTE_DESTINATION, |
|
220 | - 'method' => 'POST', |
|
221 | - 'body' => Route4Me::generateRequestParameters($allBodyFields, $params), |
|
222 | - 'HTTPHEADER' => 'Content-Type: multipart/form-data', |
|
223 | - ]); |
|
224 | - |
|
225 | - return $result; |
|
226 | - } |
|
227 | - |
|
228 | - public function getAddressId() |
|
229 | - { |
|
230 | - return $this->route_destination_id; |
|
231 | - } |
|
187 | + public function markAsVisited($params) |
|
188 | + { |
|
189 | + $allQueryFields = ['route_id', 'address_id', 'is_visited', 'member_id']; |
|
190 | + |
|
191 | + $address = Route4Me::makeRequst([ |
|
192 | + 'url' => Endpoint::UPDATE_ADDRESS_VISITED, |
|
193 | + 'method' => 'PUT', |
|
194 | + 'query' => Route4Me::generateRequestParameters($allQueryFields, $params), |
|
195 | + ]); |
|
196 | + |
|
197 | + return $address; |
|
198 | + } |
|
199 | + |
|
200 | + public function deleteAddress() |
|
201 | + { |
|
202 | + $address = Route4Me::makeRequst([ |
|
203 | + 'url' => Endpoint::ADDRESS_V4, |
|
204 | + 'method' => 'DELETE', |
|
205 | + 'query' => [ |
|
206 | + 'route_id' => $this->route_id, |
|
207 | + 'route_destination_id' => $this->route_destination_id, |
|
208 | + ], |
|
209 | + ]); |
|
210 | + |
|
211 | + return (bool) $address['deleted']; |
|
212 | + } |
|
213 | + |
|
214 | + public function moveDestinationToRoute($params) |
|
215 | + { |
|
216 | + $allBodyFields = ['to_route_id', 'route_destination_id', 'after_destination_id']; |
|
217 | + |
|
218 | + $result = Route4Me::makeRequst([ |
|
219 | + 'url' => Endpoint::MOVE_ROUTE_DESTINATION, |
|
220 | + 'method' => 'POST', |
|
221 | + 'body' => Route4Me::generateRequestParameters($allBodyFields, $params), |
|
222 | + 'HTTPHEADER' => 'Content-Type: multipart/form-data', |
|
223 | + ]); |
|
224 | + |
|
225 | + return $result; |
|
226 | + } |
|
227 | + |
|
228 | + public function getAddressId() |
|
229 | + { |
|
230 | + return $this->route_destination_id; |
|
231 | + } |
|
232 | 232 | } |
@@ -208,7 +208,7 @@ |
||
208 | 208 | ], |
209 | 209 | ]); |
210 | 210 | |
211 | - return (bool) $address['deleted']; |
|
211 | + return (bool)$address['deleted']; |
|
212 | 212 | } |
213 | 213 | |
214 | 214 | public function moveDestinationToRoute($params) |