@@ -12,156 +12,156 @@ discard block |
||
12 | 12 | |
13 | 13 | class OptimizationProblem extends Common |
14 | 14 | { |
15 | - static public $apiUrl = '/api.v4/optimization_problem.php'; |
|
15 | + static public $apiUrl = '/api.v4/optimization_problem.php'; |
|
16 | 16 | static public $apiUrl_addr = '/api.v4/address.php'; |
17 | - static public $apiHybridUrl = '/api.v4/hybrid_date_optimization.php'; |
|
18 | - static public $apiHybridDepotUrl = '/api/change_hybrid_optimization_depot.php'; |
|
17 | + static public $apiHybridUrl = '/api.v4/hybrid_date_optimization.php'; |
|
18 | + static public $apiHybridDepotUrl = '/api/change_hybrid_optimization_depot.php'; |
|
19 | 19 | |
20 | - public $optimization_problem_id; |
|
21 | - public $user_errors = array(); |
|
22 | - public $state; |
|
23 | - public $parameters; |
|
24 | - public $sent_to_background; |
|
25 | - public $addresses = array(); |
|
26 | - public $routes = array(); |
|
27 | - public $links = array(); |
|
20 | + public $optimization_problem_id; |
|
21 | + public $user_errors = array(); |
|
22 | + public $state; |
|
23 | + public $parameters; |
|
24 | + public $sent_to_background; |
|
25 | + public $addresses = array(); |
|
26 | + public $routes = array(); |
|
27 | + public $links = array(); |
|
28 | 28 | |
29 | - function __construct() |
|
30 | - { |
|
31 | - $this->parameters = new RouteParameters; |
|
32 | - } |
|
29 | + function __construct() |
|
30 | + { |
|
31 | + $this->parameters = new RouteParameters; |
|
32 | + } |
|
33 | 33 | |
34 | - public static function fromArray(array $params) |
|
35 | - { |
|
36 | - $problem = new OptimizationProblem; |
|
37 | - $problem->optimization_problem_id = Common::getValue($params, 'optimization_problem_id'); |
|
38 | - $problem->user_errors = Common::getValue($params, 'user_errors', array()); |
|
39 | - $problem->state = Common::getValue($params, 'state', array()); |
|
40 | - $problem->sent_to_background = Common::getValue($params, 'sent_to_background', array()); |
|
41 | - $problem->links = Common::getValue($params, 'links', array()); |
|
34 | + public static function fromArray(array $params) |
|
35 | + { |
|
36 | + $problem = new OptimizationProblem; |
|
37 | + $problem->optimization_problem_id = Common::getValue($params, 'optimization_problem_id'); |
|
38 | + $problem->user_errors = Common::getValue($params, 'user_errors', array()); |
|
39 | + $problem->state = Common::getValue($params, 'state', array()); |
|
40 | + $problem->sent_to_background = Common::getValue($params, 'sent_to_background', array()); |
|
41 | + $problem->links = Common::getValue($params, 'links', array()); |
|
42 | 42 | |
43 | - if (isset($params['parameters'])) { |
|
44 | - $problem->parameters = RouteParameters::fromArray($params['parameters']); |
|
45 | - } |
|
43 | + if (isset($params['parameters'])) { |
|
44 | + $problem->parameters = RouteParameters::fromArray($params['parameters']); |
|
45 | + } |
|
46 | 46 | |
47 | - if (isset($params['addresses'])) { |
|
48 | - $addresses = array(); |
|
49 | - foreach ($params['addresses'] as $address) { |
|
50 | - $addresses[] = Address::fromArray($address); |
|
51 | - } |
|
52 | - $problem->addresses = $addresses; |
|
53 | - } |
|
47 | + if (isset($params['addresses'])) { |
|
48 | + $addresses = array(); |
|
49 | + foreach ($params['addresses'] as $address) { |
|
50 | + $addresses[] = Address::fromArray($address); |
|
51 | + } |
|
52 | + $problem->addresses = $addresses; |
|
53 | + } |
|
54 | 54 | |
55 | - if (isset($params['routes'])) { |
|
56 | - $routes = array(); |
|
57 | - foreach ($params['routes'] as $route) { |
|
58 | - $routes[] = Route::fromArray($route); |
|
59 | - } |
|
60 | - $problem->routes = $routes; |
|
61 | - } |
|
55 | + if (isset($params['routes'])) { |
|
56 | + $routes = array(); |
|
57 | + foreach ($params['routes'] as $route) { |
|
58 | + $routes[] = Route::fromArray($route); |
|
59 | + } |
|
60 | + $problem->routes = $routes; |
|
61 | + } |
|
62 | 62 | |
63 | - return $problem; |
|
64 | - } |
|
63 | + return $problem; |
|
64 | + } |
|
65 | 65 | |
66 | - public static function optimize(OptimizationProblemParams $params) |
|
67 | - { |
|
68 | - $optimize = Route4Me::makeRequst(array( |
|
69 | - 'url' => self::$apiUrl, |
|
70 | - 'method' => 'POST', |
|
71 | - 'query' => array( |
|
72 | - 'directions' => isset($params->directions) ? $params->directions: null, |
|
73 | - 'format' => isset($params->format) ? $params->format: null, |
|
74 | - 'route_path_output' => isset($params->route_path_output) ? $params->route_path_output: null, |
|
75 | - 'optimized_callback_url' => isset($params->optimized_callback_url) ? $params->optimized_callback_url: null |
|
76 | - ), |
|
77 | - 'body' => array( |
|
78 | - 'addresses' => $params->getAddressesArray(), |
|
79 | - 'parameters' => $params->getParametersArray() |
|
80 | - ) |
|
81 | - )); |
|
66 | + public static function optimize(OptimizationProblemParams $params) |
|
67 | + { |
|
68 | + $optimize = Route4Me::makeRequst(array( |
|
69 | + 'url' => self::$apiUrl, |
|
70 | + 'method' => 'POST', |
|
71 | + 'query' => array( |
|
72 | + 'directions' => isset($params->directions) ? $params->directions: null, |
|
73 | + 'format' => isset($params->format) ? $params->format: null, |
|
74 | + 'route_path_output' => isset($params->route_path_output) ? $params->route_path_output: null, |
|
75 | + 'optimized_callback_url' => isset($params->optimized_callback_url) ? $params->optimized_callback_url: null |
|
76 | + ), |
|
77 | + 'body' => array( |
|
78 | + 'addresses' => $params->getAddressesArray(), |
|
79 | + 'parameters' => $params->getParametersArray() |
|
80 | + ) |
|
81 | + )); |
|
82 | 82 | |
83 | - return OptimizationProblem::fromArray($optimize); |
|
84 | - } |
|
83 | + return OptimizationProblem::fromArray($optimize); |
|
84 | + } |
|
85 | 85 | |
86 | - public static function get($params) |
|
87 | - { |
|
88 | - $optimize = Route4Me::makeRequst(array( |
|
89 | - 'url' => self::$apiUrl, |
|
90 | - 'method' => 'GET', |
|
91 | - 'query' => array( |
|
92 | - 'state' => isset($params['state']) ? $params['state'] : null, |
|
93 | - 'limit' => isset($params['limit']) ? $params['limit'] : null, |
|
94 | - 'offset' => isset($params['offset']) ? $params['offset'] : null, |
|
95 | - 'optimization_problem_id' => isset($params['optimization_problem_id']) |
|
96 | - ? $params['optimization_problem_id'] : null, |
|
97 | - 'wait_for_final_state' => isset($params['wait_for_final_state']) |
|
98 | - ? $params['wait_for_final_state'] : null, |
|
99 | - ) |
|
100 | - )); |
|
86 | + public static function get($params) |
|
87 | + { |
|
88 | + $optimize = Route4Me::makeRequst(array( |
|
89 | + 'url' => self::$apiUrl, |
|
90 | + 'method' => 'GET', |
|
91 | + 'query' => array( |
|
92 | + 'state' => isset($params['state']) ? $params['state'] : null, |
|
93 | + 'limit' => isset($params['limit']) ? $params['limit'] : null, |
|
94 | + 'offset' => isset($params['offset']) ? $params['offset'] : null, |
|
95 | + 'optimization_problem_id' => isset($params['optimization_problem_id']) |
|
96 | + ? $params['optimization_problem_id'] : null, |
|
97 | + 'wait_for_final_state' => isset($params['wait_for_final_state']) |
|
98 | + ? $params['wait_for_final_state'] : null, |
|
99 | + ) |
|
100 | + )); |
|
101 | 101 | |
102 | - if (isset($optimize['optimizations'])) { |
|
103 | - $problems = array(); |
|
104 | - foreach($optimize['optimizations'] as $problem) { |
|
105 | - $problems[] = OptimizationProblem::fromArray($problem); |
|
106 | - } |
|
107 | - return $problems; |
|
108 | - } else { |
|
109 | - return OptimizationProblem::fromArray($optimize); |
|
110 | - } |
|
111 | - } |
|
102 | + if (isset($optimize['optimizations'])) { |
|
103 | + $problems = array(); |
|
104 | + foreach($optimize['optimizations'] as $problem) { |
|
105 | + $problems[] = OptimizationProblem::fromArray($problem); |
|
106 | + } |
|
107 | + return $problems; |
|
108 | + } else { |
|
109 | + return OptimizationProblem::fromArray($optimize); |
|
110 | + } |
|
111 | + } |
|
112 | 112 | |
113 | - public static function reoptimize($params) |
|
114 | - { |
|
115 | - $param = new OptimizationProblemParams; |
|
116 | - $param->optimization_problem_id = isset($params['optimization_problem_id']) ? $params['optimization_problem_id'] : null; |
|
117 | - $param->reoptimize = 1; |
|
113 | + public static function reoptimize($params) |
|
114 | + { |
|
115 | + $param = new OptimizationProblemParams; |
|
116 | + $param->optimization_problem_id = isset($params['optimization_problem_id']) ? $params['optimization_problem_id'] : null; |
|
117 | + $param->reoptimize = 1; |
|
118 | 118 | |
119 | - return self::update((array)$param); |
|
120 | - } |
|
119 | + return self::update((array)$param); |
|
120 | + } |
|
121 | 121 | |
122 | - public static function update($params) |
|
123 | - { |
|
122 | + public static function update($params) |
|
123 | + { |
|
124 | 124 | $optimize = Route4Me::makeRequst(array( |
125 | - 'url' => self::$apiUrl, |
|
126 | - 'method' => 'PUT', |
|
127 | - 'query' => array( |
|
128 | - 'optimization_problem_id' => isset($params['optimization_problem_id']) ? $params['optimization_problem_id'] : null, |
|
129 | - 'addresses' => isset($params['addresses']) ? $params['addresses'] : null, |
|
130 | - 'reoptimize' => isset($params['reoptimize']) ? $params['reoptimize'] : null, |
|
131 | - ) |
|
132 | - )); |
|
125 | + 'url' => self::$apiUrl, |
|
126 | + 'method' => 'PUT', |
|
127 | + 'query' => array( |
|
128 | + 'optimization_problem_id' => isset($params['optimization_problem_id']) ? $params['optimization_problem_id'] : null, |
|
129 | + 'addresses' => isset($params['addresses']) ? $params['addresses'] : null, |
|
130 | + 'reoptimize' => isset($params['reoptimize']) ? $params['reoptimize'] : null, |
|
131 | + ) |
|
132 | + )); |
|
133 | 133 | |
134 | 134 | return $optimize; |
135 | - } |
|
135 | + } |
|
136 | 136 | |
137 | - public function getOptimizationId() |
|
138 | - { |
|
139 | - return $this->optimization_problem_id; |
|
140 | - } |
|
137 | + public function getOptimizationId() |
|
138 | + { |
|
139 | + return $this->optimization_problem_id; |
|
140 | + } |
|
141 | 141 | |
142 | - public function getRoutes() |
|
143 | - { |
|
144 | - return $this->routes; |
|
145 | - } |
|
142 | + public function getRoutes() |
|
143 | + { |
|
144 | + return $this->routes; |
|
145 | + } |
|
146 | 146 | |
147 | 147 | public function getRandomOptimizationId($offset,$limit) |
148 | 148 | { |
149 | 149 | $query['limit'] = isset($params['limit']) ? $params['limit'] : 30; |
150 | - $query['offset'] = isset($params['offset']) ? $params['offset'] : 0; |
|
150 | + $query['offset'] = isset($params['offset']) ? $params['offset'] : 0; |
|
151 | 151 | |
152 | 152 | $json = Route4Me::makeRequst(array( |
153 | - 'url' => self::$apiUrl, |
|
154 | - 'method' => 'GET', |
|
155 | - 'query' => $query |
|
156 | - )); |
|
153 | + 'url' => self::$apiUrl, |
|
154 | + 'method' => 'GET', |
|
155 | + 'query' => $query |
|
156 | + )); |
|
157 | 157 | |
158 | 158 | $optimizations = array(); |
159 | - foreach($json as $optimization) { |
|
159 | + foreach($json as $optimization) { |
|
160 | 160 | if (gettype($optimization)!="array") continue; |
161 | 161 | foreach ($optimization as $otp1) { |
162 | 162 | $optimizations[] = $otp1; |
163 | 163 | } |
164 | - } |
|
164 | + } |
|
165 | 165 | |
166 | 166 | $num=rand(0,sizeof($optimizations)-1); |
167 | 167 | //echo "num=$num.<br>".sizeof($optimizations)."<br>"; |
@@ -201,13 +201,13 @@ discard block |
||
201 | 201 | public function removeAddress($params) |
202 | 202 | { |
203 | 203 | $response = Route4Me::makeRequst(array( |
204 | - 'url' => self::$apiUrl_addr, |
|
205 | - 'method' => 'DELETE', |
|
206 | - 'query' => array( |
|
207 | - 'optimization_problem_id' => isset($params['optimization_problem_id']) ? $params['optimization_problem_id'] : null, |
|
208 | - 'route_destination_id' => isset($params['route_destination_id']) ? $params['route_destination_id'] : null, |
|
209 | - ) |
|
210 | - )); |
|
204 | + 'url' => self::$apiUrl_addr, |
|
205 | + 'method' => 'DELETE', |
|
206 | + 'query' => array( |
|
207 | + 'optimization_problem_id' => isset($params['optimization_problem_id']) ? $params['optimization_problem_id'] : null, |
|
208 | + 'route_destination_id' => isset($params['route_destination_id']) ? $params['route_destination_id'] : null, |
|
209 | + ) |
|
210 | + )); |
|
211 | 211 | |
212 | 212 | return $response; |
213 | 213 | } |
@@ -215,48 +215,48 @@ discard block |
||
215 | 215 | public function removeOptimization($params) |
216 | 216 | { |
217 | 217 | $response = Route4Me::makeRequst(array( |
218 | - 'url' => self::$apiUrl, |
|
219 | - 'method' => 'DELETE', |
|
220 | - 'query' => array( |
|
221 | - 'redirect' => isset($params['redirect']) ? $params['redirect'] : null, |
|
222 | - ), |
|
223 | - 'body' => array( |
|
218 | + 'url' => self::$apiUrl, |
|
219 | + 'method' => 'DELETE', |
|
220 | + 'query' => array( |
|
221 | + 'redirect' => isset($params['redirect']) ? $params['redirect'] : null, |
|
222 | + ), |
|
223 | + 'body' => array( |
|
224 | 224 | 'optimization_problem_ids' => isset($params['optimization_problem_ids']) ? $params['optimization_problem_ids'] : null, |
225 | 225 | ) |
226 | - )); |
|
226 | + )); |
|
227 | 227 | |
228 | 228 | return $response; |
229 | 229 | } |
230 | 230 | |
231 | - public function getHybridOptimization($params) |
|
232 | - { |
|
233 | - $optimize = Route4Me::makeRequst(array( |
|
234 | - 'url' => self::$apiHybridUrl, |
|
235 | - 'method' => 'GET', |
|
236 | - 'query' => array( |
|
237 | - 'target_date_string' => isset($params['target_date_string']) ? $params['target_date_string'] : null, |
|
238 | - 'timezone_offset_minutes' => isset($params['timezone_offset_minutes']) ? $params['timezone_offset_minutes'] : null |
|
239 | - ) |
|
240 | - )); |
|
231 | + public function getHybridOptimization($params) |
|
232 | + { |
|
233 | + $optimize = Route4Me::makeRequst(array( |
|
234 | + 'url' => self::$apiHybridUrl, |
|
235 | + 'method' => 'GET', |
|
236 | + 'query' => array( |
|
237 | + 'target_date_string' => isset($params['target_date_string']) ? $params['target_date_string'] : null, |
|
238 | + 'timezone_offset_minutes' => isset($params['timezone_offset_minutes']) ? $params['timezone_offset_minutes'] : null |
|
239 | + ) |
|
240 | + )); |
|
241 | 241 | |
242 | - return $optimize; |
|
243 | - } |
|
242 | + return $optimize; |
|
243 | + } |
|
244 | 244 | |
245 | - Public function addDepotsToHybrid($params) |
|
246 | - { |
|
247 | - $depots = Route4Me::makeRequst(array( |
|
248 | - 'url' => self::$apiHybridDepotUrl, |
|
249 | - 'method' => 'POST', |
|
250 | - 'query' => array( |
|
251 | - 'optimization_problem_id' => isset($params['optimization_problem_id']) ? $params['optimization_problem_id'] : null, |
|
252 | - ), |
|
253 | - 'body' => array( |
|
254 | - 'optimization_problem_id' => isset($params['optimization_problem_id']) ? $params['optimization_problem_id'] : null, |
|
255 | - 'delete_old_depots' => isset($params['delete_old_depots']) ? $params['delete_old_depots'] : null, |
|
256 | - 'new_depots' => isset($params['new_depots']) ? $params['new_depots'] : null, |
|
257 | - ) |
|
258 | - )); |
|
245 | + Public function addDepotsToHybrid($params) |
|
246 | + { |
|
247 | + $depots = Route4Me::makeRequst(array( |
|
248 | + 'url' => self::$apiHybridDepotUrl, |
|
249 | + 'method' => 'POST', |
|
250 | + 'query' => array( |
|
251 | + 'optimization_problem_id' => isset($params['optimization_problem_id']) ? $params['optimization_problem_id'] : null, |
|
252 | + ), |
|
253 | + 'body' => array( |
|
254 | + 'optimization_problem_id' => isset($params['optimization_problem_id']) ? $params['optimization_problem_id'] : null, |
|
255 | + 'delete_old_depots' => isset($params['delete_old_depots']) ? $params['delete_old_depots'] : null, |
|
256 | + 'new_depots' => isset($params['new_depots']) ? $params['new_depots'] : null, |
|
257 | + ) |
|
258 | + )); |
|
259 | 259 | |
260 | - return $depots; |
|
261 | - } |
|
260 | + return $depots; |
|
261 | + } |
|
262 | 262 | } |
@@ -11,7 +11,7 @@ discard block |
||
11 | 11 | |
12 | 12 | class Route extends Common |
13 | 13 | { |
14 | - static public $apiUrl = '/api.v4/route.php'; |
|
14 | + static public $apiUrl = '/api.v4/route.php'; |
|
15 | 15 | static public $apiUrlAddress = '/api.v4/address.php'; |
16 | 16 | static public $apiUrlDuplicate='/actions/duplicate_route.php'; |
17 | 17 | static public $apiUrlDelete='/actions/delete_routes.php'; |
@@ -22,21 +22,21 @@ discard block |
||
22 | 22 | static public $apiUrlAsset='/api.v4/status.php'; |
23 | 23 | static public $apiUrlDeviceLocation='/api/track/get_device_location.php'; |
24 | 24 | //static public $apiUrlMove='/actions/route/move_route_destination.php'; |
25 | - public $route_id; |
|
25 | + public $route_id; |
|
26 | 26 | public $route_destination_id; |
27 | - public $optimization_problem_id; |
|
28 | - public $vehicle_alias; |
|
29 | - public $driver_alias; |
|
30 | - public $trip_distance; |
|
31 | - public $mpg; |
|
32 | - public $gas_price; |
|
33 | - public $route_duration_sec; |
|
34 | - public $parameters; |
|
35 | - public $addresses = array(); |
|
36 | - public $links = array(); |
|
37 | - public $directions = array(); |
|
38 | - public $path = array(); |
|
39 | - public $tracking_history = array(); |
|
27 | + public $optimization_problem_id; |
|
28 | + public $vehicle_alias; |
|
29 | + public $driver_alias; |
|
30 | + public $trip_distance; |
|
31 | + public $mpg; |
|
32 | + public $gas_price; |
|
33 | + public $route_duration_sec; |
|
34 | + public $parameters; |
|
35 | + public $addresses = array(); |
|
36 | + public $links = array(); |
|
37 | + public $directions = array(); |
|
38 | + public $path = array(); |
|
39 | + public $tracking_history = array(); |
|
40 | 40 | public $recipient_email; |
41 | 41 | public $httpheaders; |
42 | 42 | public $is_unrouted; |
@@ -44,101 +44,101 @@ discard block |
||
44 | 44 | public $dev_lat; |
45 | 45 | public $dev_lng; |
46 | 46 | |
47 | - public static function fromArray(array $params) |
|
48 | - { |
|
49 | - $route = new Route(); |
|
50 | - $route->route_id = Common::getValue($params, 'route_id'); |
|
51 | - $route->optimization_problem_id = Common::getValue($params, 'optimization_problem_id'); |
|
52 | - $route->vehicle_alias = Common::getValue($params, 'vehicle_alias'); |
|
53 | - $route->driver_alias = Common::getValue($params, 'driver_alias'); |
|
54 | - $route->trip_distance = Common::getValue($params, 'trip_distance'); |
|
55 | - $route->mpg = Common::getValue($params, 'mpg'); |
|
56 | - $route->gas_price = Common::getValue($params, 'gas_price'); |
|
57 | - $route->route_duration_sec = Common::getvalue($params, 'route_duration_sec'); |
|
58 | - $route->is_unrouted = Common::getvalue($params, 'is_unrouted'); |
|
59 | - |
|
60 | - // Make RouteParameters |
|
61 | - if (isset($params['parameters'])) { |
|
62 | - $route->parameters = RouteParameters::fromArray($params['parameters']); |
|
63 | - } |
|
64 | - |
|
65 | - if (isset($params['addresses'])) { |
|
66 | - $addresses = array(); |
|
67 | - foreach ($params['addresses'] as $address) { |
|
68 | - $addresses[] = Address::fromArray($address); |
|
69 | - } |
|
70 | - |
|
71 | - $route->addresses = $addresses; |
|
72 | - } |
|
73 | - |
|
74 | - $route->links = Common::getValue($params, 'links', array()); |
|
75 | - $route->directions = Common::getValue($params, 'directions', array()); |
|
76 | - $route->path = Common::getValue($params, 'path', array()); |
|
77 | - $route->tracking_history = Common::getValue($params, 'tracking_history', array()); |
|
78 | - |
|
79 | - return $route; |
|
80 | - } |
|
81 | - |
|
82 | - public static function getRoutes($routeId=null, $params=null) |
|
83 | - { |
|
84 | - $query = array( |
|
85 | - 'api_key' => Route4Me::getApiKey() |
|
86 | - ); |
|
87 | - |
|
88 | - if ($routeId) { |
|
89 | - $query['route_id'] = implode(',', (array) $routeId); |
|
90 | - } |
|
91 | - |
|
92 | - if ($params) { |
|
93 | - if (isset($params['directions'])) { |
|
94 | - $query['directions'] = $params['directions']; |
|
95 | - } |
|
96 | - |
|
97 | - if (isset($params['route_path_output'])) { |
|
98 | - $query['route_path_output'] = $params['route_path_output']; |
|
99 | - } |
|
100 | - |
|
101 | - if (isset($params['device_tracking_history'])) { |
|
102 | - $query['device_tracking_history'] = $params['device_tracking_history']; |
|
103 | - } |
|
47 | + public static function fromArray(array $params) |
|
48 | + { |
|
49 | + $route = new Route(); |
|
50 | + $route->route_id = Common::getValue($params, 'route_id'); |
|
51 | + $route->optimization_problem_id = Common::getValue($params, 'optimization_problem_id'); |
|
52 | + $route->vehicle_alias = Common::getValue($params, 'vehicle_alias'); |
|
53 | + $route->driver_alias = Common::getValue($params, 'driver_alias'); |
|
54 | + $route->trip_distance = Common::getValue($params, 'trip_distance'); |
|
55 | + $route->mpg = Common::getValue($params, 'mpg'); |
|
56 | + $route->gas_price = Common::getValue($params, 'gas_price'); |
|
57 | + $route->route_duration_sec = Common::getvalue($params, 'route_duration_sec'); |
|
58 | + $route->is_unrouted = Common::getvalue($params, 'is_unrouted'); |
|
59 | + |
|
60 | + // Make RouteParameters |
|
61 | + if (isset($params['parameters'])) { |
|
62 | + $route->parameters = RouteParameters::fromArray($params['parameters']); |
|
63 | + } |
|
64 | + |
|
65 | + if (isset($params['addresses'])) { |
|
66 | + $addresses = array(); |
|
67 | + foreach ($params['addresses'] as $address) { |
|
68 | + $addresses[] = Address::fromArray($address); |
|
69 | + } |
|
70 | + |
|
71 | + $route->addresses = $addresses; |
|
72 | + } |
|
73 | + |
|
74 | + $route->links = Common::getValue($params, 'links', array()); |
|
75 | + $route->directions = Common::getValue($params, 'directions', array()); |
|
76 | + $route->path = Common::getValue($params, 'path', array()); |
|
77 | + $route->tracking_history = Common::getValue($params, 'tracking_history', array()); |
|
78 | + |
|
79 | + return $route; |
|
80 | + } |
|
81 | + |
|
82 | + public static function getRoutes($routeId=null, $params=null) |
|
83 | + { |
|
84 | + $query = array( |
|
85 | + 'api_key' => Route4Me::getApiKey() |
|
86 | + ); |
|
87 | + |
|
88 | + if ($routeId) { |
|
89 | + $query['route_id'] = implode(',', (array) $routeId); |
|
90 | + } |
|
91 | + |
|
92 | + if ($params) { |
|
93 | + if (isset($params['directions'])) { |
|
94 | + $query['directions'] = $params['directions']; |
|
95 | + } |
|
96 | + |
|
97 | + if (isset($params['route_path_output'])) { |
|
98 | + $query['route_path_output'] = $params['route_path_output']; |
|
99 | + } |
|
100 | + |
|
101 | + if (isset($params['device_tracking_history'])) { |
|
102 | + $query['device_tracking_history'] = $params['device_tracking_history']; |
|
103 | + } |
|
104 | 104 | |
105 | 105 | if (isset($params['query'])) { |
106 | - $query['query'] = $params['query']; |
|
107 | - } |
|
108 | - |
|
109 | - $query['limit'] = isset($params['limit']) ? $params['limit'] : 30; |
|
110 | - $query['offset'] = isset($params['offset']) ? $params['offset'] : 0; |
|
111 | - } |
|
106 | + $query['query'] = $params['query']; |
|
107 | + } |
|
112 | 108 | |
113 | - $json = Route4Me::makeRequst(array( |
|
114 | - 'url' => self::$apiUrl, |
|
115 | - 'method' => 'GET', |
|
116 | - 'query' => $query |
|
117 | - )); |
|
109 | + $query['limit'] = isset($params['limit']) ? $params['limit'] : 30; |
|
110 | + $query['offset'] = isset($params['offset']) ? $params['offset'] : 0; |
|
111 | + } |
|
118 | 112 | |
119 | - if ($routeId) { |
|
120 | - return Route::fromArray($json); die(""); |
|
121 | - } else { |
|
122 | - $routes = array(); |
|
123 | - foreach($json as $route) { |
|
124 | - $routes[] = Route::fromArray($route); |
|
125 | - } |
|
126 | - return $routes; |
|
127 | - } |
|
128 | - } |
|
113 | + $json = Route4Me::makeRequst(array( |
|
114 | + 'url' => self::$apiUrl, |
|
115 | + 'method' => 'GET', |
|
116 | + 'query' => $query |
|
117 | + )); |
|
118 | + |
|
119 | + if ($routeId) { |
|
120 | + return Route::fromArray($json); die(""); |
|
121 | + } else { |
|
122 | + $routes = array(); |
|
123 | + foreach($json as $route) { |
|
124 | + $routes[] = Route::fromArray($route); |
|
125 | + } |
|
126 | + return $routes; |
|
127 | + } |
|
128 | + } |
|
129 | 129 | |
130 | 130 | public function getRoutePoints($routeId, $params) |
131 | 131 | { |
132 | 132 | $result = Route4Me::makeRequst(array( |
133 | - 'url' => self::$apiUrl, |
|
134 | - 'method' => 'GET', |
|
135 | - 'query' => array( |
|
136 | - 'api_key' => Route4Me::getApiKey(), |
|
137 | - 'route_id' => $routeId, |
|
138 | - 'route_path_output' => isset($params['route_path_output']) ? $params['route_path_output'] : null, |
|
139 | - 'directions' => isset($params['directions']) ? $params['directions'] : null, |
|
140 | - ) |
|
141 | - )); |
|
133 | + 'url' => self::$apiUrl, |
|
134 | + 'method' => 'GET', |
|
135 | + 'query' => array( |
|
136 | + 'api_key' => Route4Me::getApiKey(), |
|
137 | + 'route_id' => $routeId, |
|
138 | + 'route_path_output' => isset($params['route_path_output']) ? $params['route_path_output'] : null, |
|
139 | + 'directions' => isset($params['directions']) ? $params['directions'] : null, |
|
140 | + ) |
|
141 | + )); |
|
142 | 142 | |
143 | 143 | return $result; |
144 | 144 | } |
@@ -146,14 +146,14 @@ discard block |
||
146 | 146 | public function duplicateRoute($route_id) |
147 | 147 | { |
148 | 148 | $result = Route4Me::makeRequst(array( |
149 | - 'url' => self::$apiUrlDuplicate, |
|
150 | - 'method' => 'GET', |
|
151 | - 'query' => array( |
|
152 | - 'api_key' => Route4Me::getApiKey(), |
|
153 | - 'route_id' => $route_id, |
|
154 | - 'to' => 'none', |
|
155 | - ) |
|
156 | - )); |
|
149 | + 'url' => self::$apiUrlDuplicate, |
|
150 | + 'method' => 'GET', |
|
151 | + 'query' => array( |
|
152 | + 'api_key' => Route4Me::getApiKey(), |
|
153 | + 'route_id' => $route_id, |
|
154 | + 'to' => 'none', |
|
155 | + ) |
|
156 | + )); |
|
157 | 157 | |
158 | 158 | return $result; |
159 | 159 | } |
@@ -161,17 +161,17 @@ discard block |
||
161 | 161 | public function resequenceRoute($params) |
162 | 162 | { |
163 | 163 | $result = Route4Me::makeRequst(array( |
164 | - 'url' => self::$apiUrl, |
|
165 | - 'method' => 'PUT', |
|
166 | - 'query' => array( |
|
167 | - 'api_key' => Route4Me::getApiKey(), |
|
168 | - 'route_id' => isset($params['route_id']) ? $params['route_id'] : null, |
|
169 | - 'route_destination_id' => isset($params['route_destination_id']) ? $params['route_destination_id'] : null, |
|
170 | - ), |
|
171 | - 'body' => array( |
|
164 | + 'url' => self::$apiUrl, |
|
165 | + 'method' => 'PUT', |
|
166 | + 'query' => array( |
|
167 | + 'api_key' => Route4Me::getApiKey(), |
|
168 | + 'route_id' => isset($params['route_id']) ? $params['route_id'] : null, |
|
169 | + 'route_destination_id' => isset($params['route_destination_id']) ? $params['route_destination_id'] : null, |
|
170 | + ), |
|
171 | + 'body' => array( |
|
172 | 172 | 'addresses' => isset($params['addresses']) ? $params['addresses'] : null, |
173 | 173 | ) |
174 | - )); |
|
174 | + )); |
|
175 | 175 | |
176 | 176 | return $result; |
177 | 177 | } |
@@ -179,15 +179,15 @@ discard block |
||
179 | 179 | public function resequenceAllAddresses($params) |
180 | 180 | { |
181 | 181 | $result = Route4Me::makeRequst(array( |
182 | - 'url' => self::$apiUrlReseq, |
|
183 | - 'method' => 'GET', |
|
184 | - 'query' => array( |
|
185 | - 'api_key' => Route4Me::getApiKey(), |
|
186 | - 'route_id' => isset($params['route_id']) ? $params['route_id'] : null, |
|
187 | - 'disable_optimization' => isset($params['disable_optimization']) ? $params['disable_optimization'] : null, |
|
188 | - 'optimize' => isset($params['optimize']) ? $params['optimize'] : null, |
|
189 | - ) |
|
190 | - )); |
|
182 | + 'url' => self::$apiUrlReseq, |
|
183 | + 'method' => 'GET', |
|
184 | + 'query' => array( |
|
185 | + 'api_key' => Route4Me::getApiKey(), |
|
186 | + 'route_id' => isset($params['route_id']) ? $params['route_id'] : null, |
|
187 | + 'disable_optimization' => isset($params['disable_optimization']) ? $params['disable_optimization'] : null, |
|
188 | + 'optimize' => isset($params['optimize']) ? $params['optimize'] : null, |
|
189 | + ) |
|
190 | + )); |
|
191 | 191 | |
192 | 192 | return $result; |
193 | 193 | |
@@ -196,16 +196,16 @@ discard block |
||
196 | 196 | public function mergeRoutes($params) |
197 | 197 | { |
198 | 198 | $result = Route4Me::makeRequst(array( |
199 | - 'url' => self::$apiUrlMerge, |
|
200 | - 'method' => 'POST', |
|
201 | - 'query' => array( |
|
202 | - 'api_key' => Route4Me::getApiKey(), |
|
203 | - ), |
|
204 | - 'body' => array( |
|
199 | + 'url' => self::$apiUrlMerge, |
|
200 | + 'method' => 'POST', |
|
201 | + 'query' => array( |
|
202 | + 'api_key' => Route4Me::getApiKey(), |
|
203 | + ), |
|
204 | + 'body' => array( |
|
205 | 205 | 'route_ids' => isset($params['route_ids']) ? $params['route_ids'] : null, |
206 | 206 | ), |
207 | 207 | 'HTTPHEADER' => isset($this->httpheaders) ? $this->httpheaders : null, |
208 | - )); |
|
208 | + )); |
|
209 | 209 | |
210 | 210 | return $result; |
211 | 211 | } |
@@ -213,17 +213,17 @@ discard block |
||
213 | 213 | public function shareRoute($params) |
214 | 214 | { |
215 | 215 | $result = Route4Me::makeRequst(array( |
216 | - 'url' => self::$apiUrlShare, |
|
217 | - 'method' => 'POST', |
|
218 | - 'query' => array( |
|
219 | - 'api_key' => Route4Me::getApiKey(), |
|
220 | - 'route_id' => isset($params['route_id']) ? $params['route_id'] : null, |
|
221 | - ), |
|
222 | - 'body' => array( |
|
216 | + 'url' => self::$apiUrlShare, |
|
217 | + 'method' => 'POST', |
|
218 | + 'query' => array( |
|
219 | + 'api_key' => Route4Me::getApiKey(), |
|
220 | + 'route_id' => isset($params['route_id']) ? $params['route_id'] : null, |
|
221 | + ), |
|
222 | + 'body' => array( |
|
223 | 223 | 'recipient_email' => isset($params['recipient_email']) ? $params['recipient_email'] : null, |
224 | 224 | ), |
225 | 225 | 'Content-Type' => 'multipart/form-data' |
226 | - )); |
|
226 | + )); |
|
227 | 227 | |
228 | 228 | return $result; |
229 | 229 | } |
@@ -232,18 +232,18 @@ discard block |
||
232 | 232 | public function getRandomRouteId($offset,$limit) |
233 | 233 | { |
234 | 234 | $query['limit'] = isset($params['limit']) ? $params['limit'] : 30; |
235 | - $query['offset'] = isset($params['offset']) ? $params['offset'] : 0; |
|
235 | + $query['offset'] = isset($params['offset']) ? $params['offset'] : 0; |
|
236 | 236 | |
237 | 237 | $json = Route4Me::makeRequst(array( |
238 | - 'url' => self::$apiUrl, |
|
239 | - 'method' => 'GET', |
|
240 | - 'query' => $query |
|
241 | - )); |
|
238 | + 'url' => self::$apiUrl, |
|
239 | + 'method' => 'GET', |
|
240 | + 'query' => $query |
|
241 | + )); |
|
242 | 242 | |
243 | 243 | $routes = array(); |
244 | - foreach($json as $route) { |
|
245 | - $routes[] = Route::fromArray($route); |
|
246 | - } |
|
244 | + foreach($json as $route) { |
|
245 | + $routes[] = Route::fromArray($route); |
|
246 | + } |
|
247 | 247 | |
248 | 248 | $num=rand(0,sizeof($routes)-1); |
249 | 249 | $rRoute=(array)$routes[$num]; |
@@ -255,71 +255,71 @@ discard block |
||
255 | 255 | else return null; |
256 | 256 | } |
257 | 257 | |
258 | - public function update() |
|
259 | - { |
|
260 | - $route = Route4Me::makeRequst(array( |
|
261 | - 'url' => self::$apiUrl, |
|
262 | - 'method' => 'PUT', |
|
263 | - 'query' => array( |
|
264 | - 'route_id' => isset($this->route_id) ? $this->route_id : null, |
|
265 | - 'route_destination_id' => isset($this->route_destination_id) ? $this->route_destination_id : null, |
|
266 | - ), |
|
267 | - 'body' => array ( |
|
268 | - 'parameters' => $this->parameters, |
|
269 | - ), |
|
270 | - 'HTTPHEADER' => isset($this->httpheaders) ? $this->httpheaders : null, |
|
271 | - )); |
|
258 | + public function update() |
|
259 | + { |
|
260 | + $route = Route4Me::makeRequst(array( |
|
261 | + 'url' => self::$apiUrl, |
|
262 | + 'method' => 'PUT', |
|
263 | + 'query' => array( |
|
264 | + 'route_id' => isset($this->route_id) ? $this->route_id : null, |
|
265 | + 'route_destination_id' => isset($this->route_destination_id) ? $this->route_destination_id : null, |
|
266 | + ), |
|
267 | + 'body' => array ( |
|
268 | + 'parameters' => $this->parameters, |
|
269 | + ), |
|
270 | + 'HTTPHEADER' => isset($this->httpheaders) ? $this->httpheaders : null, |
|
271 | + )); |
|
272 | 272 | |
273 | - return Route::fromArray($route); |
|
274 | - } |
|
273 | + return Route::fromArray($route); |
|
274 | + } |
|
275 | 275 | |
276 | 276 | public function updateAddress() |
277 | - { |
|
278 | - $result = Route4Me::makeRequst(array( |
|
279 | - 'url' => self::$apiUrlAddress, |
|
280 | - 'method' => 'PUT', |
|
281 | - 'query' => array( |
|
282 | - 'route_id' => isset($this->route_id) ? $this->route_id : null, |
|
283 | - 'route_destination_id' => isset($this->route_destination_id) ? $this->route_destination_id : null, |
|
284 | - ), |
|
285 | - 'body' => get_object_vars($this->parameters), |
|
286 | - 'HTTPHEADER' => isset($this->httpheaders) ? $this->httpheaders : null, |
|
287 | - )); |
|
277 | + { |
|
278 | + $result = Route4Me::makeRequst(array( |
|
279 | + 'url' => self::$apiUrlAddress, |
|
280 | + 'method' => 'PUT', |
|
281 | + 'query' => array( |
|
282 | + 'route_id' => isset($this->route_id) ? $this->route_id : null, |
|
283 | + 'route_destination_id' => isset($this->route_destination_id) ? $this->route_destination_id : null, |
|
284 | + ), |
|
285 | + 'body' => get_object_vars($this->parameters), |
|
286 | + 'HTTPHEADER' => isset($this->httpheaders) ? $this->httpheaders : null, |
|
287 | + )); |
|
288 | 288 | |
289 | - return $result; |
|
290 | - } |
|
289 | + return $result; |
|
290 | + } |
|
291 | 291 | |
292 | - public function addAddresses(array $params) |
|
293 | - { |
|
294 | - $route = Route4Me::makeRequst(array( |
|
295 | - 'url' => self::$apiUrl, |
|
296 | - 'method' => 'PUT', |
|
297 | - 'query' => array( |
|
298 | - 'api_key' => Route4Me::getApiKey(), |
|
299 | - 'route_id' => isset($params['route_id']) ? $params['route_id'] : null, |
|
300 | - 'addresses' => isset($params['addresses']) ? $params['addresses'] : null |
|
301 | - ) |
|
302 | - )); |
|
292 | + public function addAddresses(array $params) |
|
293 | + { |
|
294 | + $route = Route4Me::makeRequst(array( |
|
295 | + 'url' => self::$apiUrl, |
|
296 | + 'method' => 'PUT', |
|
297 | + 'query' => array( |
|
298 | + 'api_key' => Route4Me::getApiKey(), |
|
299 | + 'route_id' => isset($params['route_id']) ? $params['route_id'] : null, |
|
300 | + 'addresses' => isset($params['addresses']) ? $params['addresses'] : null |
|
301 | + ) |
|
302 | + )); |
|
303 | 303 | |
304 | - return Route::fromArray($route); |
|
305 | - } |
|
304 | + return Route::fromArray($route); |
|
305 | + } |
|
306 | 306 | |
307 | 307 | public function insertAddressOptimalPosition(array $params) |
308 | 308 | { |
309 | 309 | $route = Route4Me::makeRequst(array( |
310 | - 'url' => self::$apiUrl, |
|
311 | - 'method' => 'PUT', |
|
312 | - 'query' => array( |
|
313 | - 'api_key' => Route4Me::getApiKey(), |
|
314 | - 'route_id' => isset($params['route_id']) ? $params['route_id'] : null, |
|
315 | - ), |
|
316 | - 'body' => array( |
|
310 | + 'url' => self::$apiUrl, |
|
311 | + 'method' => 'PUT', |
|
312 | + 'query' => array( |
|
313 | + 'api_key' => Route4Me::getApiKey(), |
|
314 | + 'route_id' => isset($params['route_id']) ? $params['route_id'] : null, |
|
315 | + ), |
|
316 | + 'body' => array( |
|
317 | 317 | 'addresses' => isset($params['addresses']) ? $params['addresses'] : null, |
318 | 318 | 'optimal_position' => isset($params['optimal_position']) ? $params['optimal_position'] : null, |
319 | 319 | ) |
320 | - )); |
|
320 | + )); |
|
321 | 321 | |
322 | - return Route::fromArray($route); |
|
322 | + return Route::fromArray($route); |
|
323 | 323 | } |
324 | 324 | |
325 | 325 | public function addNoteFile($params) |
@@ -328,18 +328,18 @@ discard block |
||
328 | 328 | $rpath = realpath($fname); |
329 | 329 | //echo $rpath;die(""); |
330 | 330 | $result= Route4Me::makeRequst(array( |
331 | - 'url' => self::$apiUrlNoteFile, |
|
332 | - 'method' => 'POST', |
|
333 | - 'query' => array( |
|
334 | - 'api_key' => Route4Me::getApiKey(), |
|
335 | - 'route_id' => isset($params['route_id']) ? $params['route_id'] : null, |
|
336 | - 'address_id' => isset($params['address_id']) ? $params['address_id'] : null, |
|
337 | - 'dev_lat' => isset($params['dev_lat']) ? $params['dev_lat'] : null, |
|
338 | - 'dev_lng' => isset($params['dev_lng']) ? $params['dev_lng'] : null, |
|
339 | - 'device_type' => isset($params['device_type']) ? $params['device_type'] : null, |
|
340 | - 'dev_lng' => isset($params['dev_lng']) ? $params['dev_lng'] : null, |
|
341 | - ), |
|
342 | - 'body' => array( |
|
331 | + 'url' => self::$apiUrlNoteFile, |
|
332 | + 'method' => 'POST', |
|
333 | + 'query' => array( |
|
334 | + 'api_key' => Route4Me::getApiKey(), |
|
335 | + 'route_id' => isset($params['route_id']) ? $params['route_id'] : null, |
|
336 | + 'address_id' => isset($params['address_id']) ? $params['address_id'] : null, |
|
337 | + 'dev_lat' => isset($params['dev_lat']) ? $params['dev_lat'] : null, |
|
338 | + 'dev_lng' => isset($params['dev_lng']) ? $params['dev_lng'] : null, |
|
339 | + 'device_type' => isset($params['device_type']) ? $params['device_type'] : null, |
|
340 | + 'dev_lng' => isset($params['dev_lng']) ? $params['dev_lng'] : null, |
|
341 | + ), |
|
342 | + 'body' => array( |
|
343 | 343 | 'strUpdateType' => isset($params['strUpdateType']) ? $params['strUpdateType'] : null, |
344 | 344 | 'strFilename' => isset($params['strFilename']) ? $params['strFilename'] : null, |
345 | 345 | 'strNoteContents' => isset($params['strNoteContents']) ? $params['strNoteContents'] : null, |
@@ -349,18 +349,18 @@ discard block |
||
349 | 349 | 'HTTPHEADER' => array( |
350 | 350 | 'Content-Type: application/x-www-form-urlencoded' |
351 | 351 | ) |
352 | - )); |
|
352 | + )); |
|
353 | 353 | |
354 | - return $result; |
|
354 | + return $result; |
|
355 | 355 | } |
356 | 356 | |
357 | - public function delete($route_id) |
|
358 | - { |
|
359 | - $result = Route4Me::makeRequst(array( |
|
360 | - 'url' => self::$apiUrl, |
|
361 | - 'method' => 'DELETE', |
|
362 | - 'query' => array( 'route_id' => $route_id ) |
|
363 | - )); |
|
357 | + public function delete($route_id) |
|
358 | + { |
|
359 | + $result = Route4Me::makeRequst(array( |
|
360 | + 'url' => self::$apiUrl, |
|
361 | + 'method' => 'DELETE', |
|
362 | + 'query' => array( 'route_id' => $route_id ) |
|
363 | + )); |
|
364 | 364 | |
365 | 365 | // The code below doesn't work, altough this method is described as workable in REST API |
366 | 366 | /* |
@@ -373,8 +373,8 @@ discard block |
||
373 | 373 | ) |
374 | 374 | )); |
375 | 375 | */ |
376 | - return $result; |
|
377 | - } |
|
376 | + return $result; |
|
377 | + } |
|
378 | 378 | |
379 | 379 | public function GetAddressesFromRoute($route_id) |
380 | 380 | { |
@@ -398,63 +398,63 @@ discard block |
||
398 | 398 | } else { return null;} |
399 | 399 | } |
400 | 400 | |
401 | - public function getRouteId() |
|
402 | - { |
|
403 | - return $this->route_id; |
|
404 | - } |
|
401 | + public function getRouteId() |
|
402 | + { |
|
403 | + return $this->route_id; |
|
404 | + } |
|
405 | 405 | |
406 | - public function getOptimizationId() |
|
407 | - { |
|
408 | - return $this->optimization_problem_id; |
|
409 | - } |
|
406 | + public function getOptimizationId() |
|
407 | + { |
|
408 | + return $this->optimization_problem_id; |
|
409 | + } |
|
410 | 410 | |
411 | 411 | public function GetLastLocation(array $params) |
412 | 412 | { |
413 | 413 | $route = Route4Me::makeRequst(array( |
414 | - 'url' => self::$apiUrl, |
|
415 | - 'method' => 'GET', |
|
416 | - 'query' => array( |
|
417 | - 'api_key' => Route4Me::getApiKey(), |
|
418 | - 'route_id' => isset($params['route_id']) ? $params['route_id'] : null, |
|
419 | - 'device_tracking_history' => isset($params['device_tracking_history']) ? $params['device_tracking_history'] : null |
|
420 | - ) |
|
421 | - )); |
|
414 | + 'url' => self::$apiUrl, |
|
415 | + 'method' => 'GET', |
|
416 | + 'query' => array( |
|
417 | + 'api_key' => Route4Me::getApiKey(), |
|
418 | + 'route_id' => isset($params['route_id']) ? $params['route_id'] : null, |
|
419 | + 'device_tracking_history' => isset($params['device_tracking_history']) ? $params['device_tracking_history'] : null |
|
420 | + ) |
|
421 | + )); |
|
422 | 422 | |
423 | - return Route::fromArray($route); |
|
423 | + return Route::fromArray($route); |
|
424 | 424 | |
425 | 425 | } |
426 | 426 | |
427 | 427 | public function GetTrackingHistoryFromTimeRange(array $params) |
428 | 428 | { |
429 | 429 | $route = Route4Me::makeRequst(array( |
430 | - 'url' => self::$apiUrlDeviceLocation, |
|
431 | - 'method' => 'GET', |
|
432 | - 'query' => array( |
|
433 | - 'api_key' => Route4Me::getApiKey(), |
|
434 | - 'route_id' => isset($params['route_id']) ? $params['route_id'] : null, |
|
435 | - 'format' => isset($params['format']) ? $params['format'] : null, |
|
436 | - 'time_period' => isset($params['time_period']) ? $params['time_period'] : null, |
|
437 | - 'start_date' => isset($params['start_date']) ? $params['start_date'] : null, |
|
438 | - 'end_date' => isset($params['end_date']) ? $params['end_date'] : null |
|
439 | - ) |
|
440 | - )); |
|
441 | - |
|
442 | - return $route; |
|
430 | + 'url' => self::$apiUrlDeviceLocation, |
|
431 | + 'method' => 'GET', |
|
432 | + 'query' => array( |
|
433 | + 'api_key' => Route4Me::getApiKey(), |
|
434 | + 'route_id' => isset($params['route_id']) ? $params['route_id'] : null, |
|
435 | + 'format' => isset($params['format']) ? $params['format'] : null, |
|
436 | + 'time_period' => isset($params['time_period']) ? $params['time_period'] : null, |
|
437 | + 'start_date' => isset($params['start_date']) ? $params['start_date'] : null, |
|
438 | + 'end_date' => isset($params['end_date']) ? $params['end_date'] : null |
|
439 | + ) |
|
440 | + )); |
|
441 | + |
|
442 | + return $route; |
|
443 | 443 | |
444 | 444 | } |
445 | 445 | |
446 | 446 | public function GetAssetTracking(array $params) |
447 | 447 | { |
448 | 448 | $route = Route4Me::makeRequst(array( |
449 | - 'url' => self::$apiUrlAsset, |
|
450 | - 'method' => 'GET', |
|
451 | - 'query' => array( |
|
452 | - 'api_key' => Route4Me::getApiKey(), |
|
453 | - 'tracking' => isset($params['tracking']) ? $params['tracking'] : null |
|
454 | - ) |
|
455 | - )); |
|
456 | - |
|
457 | - return $route; |
|
449 | + 'url' => self::$apiUrlAsset, |
|
450 | + 'method' => 'GET', |
|
451 | + 'query' => array( |
|
452 | + 'api_key' => Route4Me::getApiKey(), |
|
453 | + 'tracking' => isset($params['tracking']) ? $params['tracking'] : null |
|
454 | + ) |
|
455 | + )); |
|
456 | + |
|
457 | + return $route; |
|
458 | 458 | |
459 | 459 | } |
460 | 460 | } |
@@ -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,63 +192,63 @@ 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) { |
|
210 | - throw new ApiError('Wrong API key'); |
|
211 | - } else { |
|
212 | - throw new ApiError('Something wrong'); |
|
213 | - } |
|
214 | - } |
|
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 | + throw new ApiError('Wrong API key'); |
|
211 | + } else { |
|
212 | + throw new ApiError('Something wrong'); |
|
213 | + } |
|
214 | + } |
|
215 | 215 | |
216 | 216 | public static function makeUrlRequst($url, $options) { |
217 | 217 | $method = isset($options['method']) ? $options['method'] : 'GET'; |
218 | - $query = isset($options['query']) ? |
|
219 | - array_filter($options['query']) : array(); |
|
220 | - $body = isset($options['body']) ? |
|
221 | - array_filter($options['body']) : null; |
|
222 | - $ch = curl_init(); |
|
218 | + $query = isset($options['query']) ? |
|
219 | + array_filter($options['query']) : array(); |
|
220 | + $body = isset($options['body']) ? |
|
221 | + array_filter($options['body']) : null; |
|
222 | + $ch = curl_init(); |
|
223 | 223 | |
224 | 224 | $curlOpts = arraY( |
225 | - CURLOPT_URL => $url, |
|
226 | - CURLOPT_RETURNTRANSFER => true, |
|
227 | - CURLOPT_TIMEOUT => 60, |
|
228 | - CURLOPT_FOLLOWLOCATION => true, |
|
229 | - CURLOPT_SSL_VERIFYHOST => FALSE, |
|
230 | - CURLOPT_SSL_VERIFYPEER => FALSE, |
|
231 | - CURLOPT_HTTPHEADER => array( |
|
232 | - 'User-Agent' => 'Route4Me php-sdk' |
|
233 | - ) |
|
234 | - ); |
|
225 | + CURLOPT_URL => $url, |
|
226 | + CURLOPT_RETURNTRANSFER => true, |
|
227 | + CURLOPT_TIMEOUT => 60, |
|
228 | + CURLOPT_FOLLOWLOCATION => true, |
|
229 | + CURLOPT_SSL_VERIFYHOST => FALSE, |
|
230 | + CURLOPT_SSL_VERIFYPEER => FALSE, |
|
231 | + CURLOPT_HTTPHEADER => array( |
|
232 | + 'User-Agent' => 'Route4Me php-sdk' |
|
233 | + ) |
|
234 | + ); |
|
235 | 235 | |
236 | 236 | curl_setopt_array($ch, $curlOpts); |
237 | 237 | |
238 | - switch($method) { |
|
239 | - case 'DELETE': |
|
240 | - curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE"); |
|
238 | + switch($method) { |
|
239 | + case 'DELETE': |
|
240 | + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE"); |
|
241 | 241 | |
242 | 242 | if (isset($body)) { |
243 | 243 | curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($body)); |
244 | 244 | } |
245 | - break; |
|
245 | + break; |
|
246 | 246 | case 'DELETEARRAY': |
247 | 247 | curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE"); |
248 | - curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($query)); |
|
249 | - break; |
|
250 | - case 'PUT': |
|
251 | - curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT"); |
|
248 | + curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($query)); |
|
249 | + break; |
|
250 | + case 'PUT': |
|
251 | + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT"); |
|
252 | 252 | if (isset($query)) { |
253 | 253 | curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($query)); |
254 | 254 | } |
@@ -257,10 +257,10 @@ discard block |
||
257 | 257 | curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($body)); |
258 | 258 | } |
259 | 259 | break; |
260 | - case 'POST': |
|
260 | + case 'POST': |
|
261 | 261 | curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); |
262 | 262 | if (isset($query)) { |
263 | - curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($query)); |
|
263 | + curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($query)); |
|
264 | 264 | } |
265 | 265 | |
266 | 266 | if (isset($body)) { |
@@ -268,8 +268,8 @@ discard block |
||
268 | 268 | } |
269 | 269 | break; |
270 | 270 | case 'ADD': |
271 | - curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($query)); break; |
|
272 | - } |
|
271 | + curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($query)); break; |
|
272 | + } |
|
273 | 273 | |
274 | 274 | $result = curl_exec($ch); |
275 | 275 | |
@@ -282,21 +282,21 @@ discard block |
||
282 | 282 | $isxml = TRUE; |
283 | 283 | } |
284 | 284 | |
285 | - $code = curl_getinfo($ch, CURLINFO_HTTP_CODE); |
|
286 | - curl_close($ch); |
|
285 | + $code = curl_getinfo($ch, CURLINFO_HTTP_CODE); |
|
286 | + curl_close($ch); |
|
287 | 287 | |
288 | 288 | if ($isxml) { |
289 | 289 | $json = $jxml; |
290 | 290 | } else $json = json_decode($result, true); |
291 | 291 | |
292 | 292 | |
293 | - if (200 == $code) { |
|
294 | - return $json; |
|
295 | - } elseif (isset($json['errors'])) { |
|
296 | - throw new ApiError(implode(', ', $json['errors'])); |
|
297 | - } else { |
|
298 | - throw new ApiError('Something wrong'); |
|
299 | - } |
|
293 | + if (200 == $code) { |
|
294 | + return $json; |
|
295 | + } elseif (isset($json['errors'])) { |
|
296 | + throw new ApiError(implode(', ', $json['errors'])); |
|
297 | + } else { |
|
298 | + throw new ApiError('Something wrong'); |
|
299 | + } |
|
300 | 300 | } |
301 | 301 | |
302 | 302 | /** |
@@ -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 | throw new ApiError('Wrong API key'); |
211 | 211 | } else { |
212 | 212 | throw new ApiError('Something wrong'); |
@@ -235,7 +235,7 @@ discard block |
||
235 | 235 | |
236 | 236 | curl_setopt_array($ch, $curlOpts); |
237 | 237 | |
238 | - switch($method) { |
|
238 | + switch ($method) { |
|
239 | 239 | case 'DELETE': |
240 | 240 | curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE"); |
241 | 241 | |
@@ -273,8 +273,8 @@ discard block |
||
273 | 273 | |
274 | 274 | $result = curl_exec($ch); |
275 | 275 | |
276 | - $isxml=FALSE; |
|
277 | - $jxml=""; |
|
276 | + $isxml = FALSE; |
|
277 | + $jxml = ""; |
|
278 | 278 | if (strpos($result, '<?xml')>-1) |
279 | 279 | { |
280 | 280 | $xml = simplexml_load_string($result); |
@@ -290,7 +290,7 @@ discard block |
||
290 | 290 | } else $json = json_decode($result, true); |
291 | 291 | |
292 | 292 | |
293 | - if (200 == $code) { |
|
293 | + if (200==$code) { |
|
294 | 294 | return $json; |
295 | 295 | } elseif (isset($json['errors'])) { |
296 | 296 | 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 | throw new ApiError('Wrong API key'); |
211 | 221 | } else { |
212 | 222 | throw new ApiError('Something wrong'); |
@@ -287,7 +297,9 @@ discard block |
||
287 | 297 | |
288 | 298 | if ($isxml) { |
289 | 299 | $json = $jxml; |
290 | - } else $json = json_decode($result, true); |
|
300 | + } else { |
|
301 | + $json = json_decode($result, true); |
|
302 | + } |
|
291 | 303 | |
292 | 304 | |
293 | 305 | if (200 == $code) { |