@@ -23,24 +23,24 @@ |
||
23 | 23 | |
24 | 24 | // Get a route with the path points |
25 | 25 | $params = array( |
26 | - "route_path_output" => "Points", |
|
27 | - "compress_path_points" => TRUE, |
|
28 | - "route_id" => $route_id |
|
26 | + "route_path_output" => "Points", |
|
27 | + "compress_path_points" => TRUE, |
|
28 | + "route_id" => $route_id |
|
29 | 29 | ); |
30 | 30 | |
31 | 31 | $routeResults = (array)$route->getRoutePoints($params); |
32 | 32 | |
33 | 33 | if (isset($routeResults['addresses'])) { |
34 | - foreach ($routeResults['addresses'] as $key => $address) { |
|
35 | - $araddress = (array)$address; |
|
34 | + foreach ($routeResults['addresses'] as $key => $address) { |
|
35 | + $araddress = (array)$address; |
|
36 | 36 | |
37 | - if (isset($araddress['route_destination_id'])) echo "route_destination_id=".$araddress['route_destination_id']."<br>"; |
|
37 | + if (isset($araddress['route_destination_id'])) echo "route_destination_id=".$araddress['route_destination_id']."<br>"; |
|
38 | 38 | |
39 | - if (isset($araddress['path_to_next'])) { |
|
40 | - echo "path_to_next:<br>"; |
|
41 | - Route4Me::simplePrint((array)$araddress['path_to_next']); |
|
42 | - } |
|
39 | + if (isset($araddress['path_to_next'])) { |
|
40 | + echo "path_to_next:<br>"; |
|
41 | + Route4Me::simplePrint((array)$araddress['path_to_next']); |
|
42 | + } |
|
43 | 43 | |
44 | - echo "<br>"; |
|
45 | - } |
|
44 | + echo "<br>"; |
|
45 | + } |
|
46 | 46 | } |
@@ -23,8 +23,8 @@ |
||
23 | 23 | |
24 | 24 | // Get a route with the directions |
25 | 25 | $params = array( |
26 | - "directions" => 1, |
|
27 | - "route_id" => $route_id |
|
26 | + "directions" => 1, |
|
27 | + "route_id" => $route_id |
|
28 | 28 | ); |
29 | 29 | |
30 | 30 | $routeResults = (array)$route->getRoutePoints($params); |
@@ -7,16 +7,16 @@ |
||
7 | 7 | |
8 | 8 | class Track extends Common |
9 | 9 | { |
10 | - public static function set(TrackSetParams $params) |
|
11 | - { |
|
12 | - $allQueryFields = Route4Me::getObjectProperties(new TrackSetParams(), array('tx_id')); |
|
10 | + public static function set(TrackSetParams $params) |
|
11 | + { |
|
12 | + $allQueryFields = Route4Me::getObjectProperties(new TrackSetParams(), array('tx_id')); |
|
13 | 13 | |
14 | - $json = Route4Me::makeRequst(array( |
|
15 | - 'url' => Endpoint::TRACK_SET, |
|
16 | - 'method' => 'GET', |
|
17 | - 'query' => Route4Me::generateRequestParameters($allQueryFields, $params) |
|
18 | - )); |
|
14 | + $json = Route4Me::makeRequst(array( |
|
15 | + 'url' => Endpoint::TRACK_SET, |
|
16 | + 'method' => 'GET', |
|
17 | + 'query' => Route4Me::generateRequestParameters($allQueryFields, $params) |
|
18 | + )); |
|
19 | 19 | |
20 | - return $json; |
|
21 | - } |
|
20 | + return $json; |
|
21 | + } |
|
22 | 22 | } |
@@ -6,79 +6,79 @@ |
||
6 | 6 | |
7 | 7 | class ActivityParameters extends Common |
8 | 8 | { |
9 | - public $route_id; |
|
10 | - public $device_id; |
|
11 | - public $member_id; |
|
12 | - public $team; |
|
13 | - public $limit; |
|
14 | - public $offset; |
|
15 | - public $start; |
|
16 | - public $end; |
|
17 | - public $activity_type; |
|
18 | - public $activity_message; |
|
9 | + public $route_id; |
|
10 | + public $device_id; |
|
11 | + public $member_id; |
|
12 | + public $team; |
|
13 | + public $limit; |
|
14 | + public $offset; |
|
15 | + public $start; |
|
16 | + public $end; |
|
17 | + public $activity_type; |
|
18 | + public $activity_message; |
|
19 | 19 | |
20 | - public $activity_id; |
|
21 | - public $activity_timestamp; |
|
22 | - public $route_destination_id; |
|
23 | - public $note_id; |
|
24 | - public $member; |
|
25 | - public $note_type; |
|
26 | - public $note_contents; |
|
27 | - public $route_name; |
|
28 | - public $note_file; |
|
29 | - public $destination_name; |
|
30 | - public $destination_alias; |
|
20 | + public $activity_id; |
|
21 | + public $activity_timestamp; |
|
22 | + public $route_destination_id; |
|
23 | + public $note_id; |
|
24 | + public $member; |
|
25 | + public $note_type; |
|
26 | + public $note_contents; |
|
27 | + public $route_name; |
|
28 | + public $note_file; |
|
29 | + public $destination_name; |
|
30 | + public $destination_alias; |
|
31 | 31 | |
32 | - public static function fromArray(array $params) |
|
33 | - { |
|
34 | - $activityparameters = new ActivityParameters(); |
|
32 | + public static function fromArray(array $params) |
|
33 | + { |
|
34 | + $activityparameters = new ActivityParameters(); |
|
35 | 35 | |
36 | - foreach($params as $key => $value) { |
|
37 | - if (property_exists($activityparameters, $key)) { |
|
38 | - $activityparameters->{$key} = $value; |
|
39 | - } |
|
40 | - } |
|
36 | + foreach($params as $key => $value) { |
|
37 | + if (property_exists($activityparameters, $key)) { |
|
38 | + $activityparameters->{$key} = $value; |
|
39 | + } |
|
40 | + } |
|
41 | 41 | |
42 | - return $activityparameters; |
|
43 | - } |
|
42 | + return $activityparameters; |
|
43 | + } |
|
44 | 44 | |
45 | - public static function get($params) |
|
46 | - { |
|
47 | - $allQueryFields = array('route_id', 'team', 'limit', 'offset', 'start'); |
|
45 | + public static function get($params) |
|
46 | + { |
|
47 | + $allQueryFields = array('route_id', 'team', 'limit', 'offset', 'start'); |
|
48 | 48 | |
49 | - $activity = Route4Me::makeRequst(array( |
|
50 | - 'url' => Endpoint::GET_ACTIVITIES, |
|
51 | - 'method' => 'GET', |
|
52 | - 'query' => Route4Me::generateRequestParameters($allQueryFields, $params) |
|
53 | - )); |
|
49 | + $activity = Route4Me::makeRequst(array( |
|
50 | + 'url' => Endpoint::GET_ACTIVITIES, |
|
51 | + 'method' => 'GET', |
|
52 | + 'query' => Route4Me::generateRequestParameters($allQueryFields, $params) |
|
53 | + )); |
|
54 | 54 | |
55 | - return $activity; |
|
56 | - } |
|
55 | + return $activity; |
|
56 | + } |
|
57 | 57 | |
58 | - public static function searcActivities($params) |
|
59 | - { |
|
60 | - $allQueryFields = array('route_id', 'limit', 'offset', 'activity_type'); |
|
58 | + public static function searcActivities($params) |
|
59 | + { |
|
60 | + $allQueryFields = array('route_id', 'limit', 'offset', 'activity_type'); |
|
61 | 61 | |
62 | - $activity = Route4Me::makeRequst(array( |
|
63 | - 'url' => Endpoint::GET_ACTIVITIES, |
|
64 | - 'method' => 'GET', |
|
65 | - 'query' => Route4Me::generateRequestParameters($allQueryFields, $params) |
|
66 | - )); |
|
62 | + $activity = Route4Me::makeRequst(array( |
|
63 | + 'url' => Endpoint::GET_ACTIVITIES, |
|
64 | + 'method' => 'GET', |
|
65 | + 'query' => Route4Me::generateRequestParameters($allQueryFields, $params) |
|
66 | + )); |
|
67 | 67 | |
68 | - return $activity; |
|
69 | - } |
|
68 | + return $activity; |
|
69 | + } |
|
70 | 70 | |
71 | - public static function sendUserMessage($params) |
|
72 | - { |
|
73 | - $allBodyFields = array('activity_type', 'activity_message', 'route_id'); |
|
71 | + public static function sendUserMessage($params) |
|
72 | + { |
|
73 | + $allBodyFields = array('activity_type', 'activity_message', 'route_id'); |
|
74 | 74 | |
75 | - $result = Route4Me::makeRequst(array( |
|
76 | - 'url' => Endpoint::ACTIVITY_FEED, |
|
77 | - 'method' => 'POST', |
|
78 | - 'body' => Route4Me::generateRequestParameters($allBodyFields, $params) |
|
79 | - )); |
|
75 | + $result = Route4Me::makeRequst(array( |
|
76 | + 'url' => Endpoint::ACTIVITY_FEED, |
|
77 | + 'method' => 'POST', |
|
78 | + 'body' => Route4Me::generateRequestParameters($allBodyFields, $params) |
|
79 | + )); |
|
80 | 80 | |
81 | - return $result; |
|
82 | - } |
|
81 | + return $result; |
|
82 | + } |
|
83 | 83 | |
84 | 84 | } |
@@ -6,333 +6,333 @@ |
||
6 | 6 | |
7 | 7 | class Order extends Common |
8 | 8 | { |
9 | - public $address_1; |
|
10 | - public $address_2; |
|
11 | - public $cached_lat; |
|
12 | - public $cached_lng; |
|
13 | - public $curbside_lat; |
|
14 | - public $curbside_lng; |
|
15 | - public $address_alias; |
|
16 | - public $address_city; |
|
17 | - public $EXT_FIELD_first_name; |
|
18 | - public $EXT_FIELD_last_name; |
|
19 | - public $EXT_FIELD_email; |
|
20 | - public $EXT_FIELD_phone; |
|
21 | - public $EXT_FIELD_custom_data; |
|
9 | + public $address_1; |
|
10 | + public $address_2; |
|
11 | + public $cached_lat; |
|
12 | + public $cached_lng; |
|
13 | + public $curbside_lat; |
|
14 | + public $curbside_lng; |
|
15 | + public $address_alias; |
|
16 | + public $address_city; |
|
17 | + public $EXT_FIELD_first_name; |
|
18 | + public $EXT_FIELD_last_name; |
|
19 | + public $EXT_FIELD_email; |
|
20 | + public $EXT_FIELD_phone; |
|
21 | + public $EXT_FIELD_custom_data; |
|
22 | 22 | |
23 | - public $color; |
|
24 | - public $order_icon; |
|
25 | - public $local_time_window_start; |
|
26 | - public $local_time_window_end; |
|
27 | - public $local_time_window_start_2; |
|
28 | - public $local_time_window_end_2; |
|
29 | - public $service_time; |
|
23 | + public $color; |
|
24 | + public $order_icon; |
|
25 | + public $local_time_window_start; |
|
26 | + public $local_time_window_end; |
|
27 | + public $local_time_window_start_2; |
|
28 | + public $local_time_window_end_2; |
|
29 | + public $service_time; |
|
30 | 30 | |
31 | - public $day_scheduled_for_YYMMDD; |
|
31 | + public $day_scheduled_for_YYMMDD; |
|
32 | 32 | |
33 | - public $route_id; |
|
34 | - public $redirect; |
|
35 | - public $optimization_problem_id; |
|
36 | - public $order_id; |
|
37 | - public $order_ids; |
|
33 | + public $route_id; |
|
34 | + public $redirect; |
|
35 | + public $optimization_problem_id; |
|
36 | + public $order_id; |
|
37 | + public $order_ids; |
|
38 | 38 | |
39 | - public $day_added_YYMMDD; |
|
40 | - public $scheduled_for_YYMMDD; |
|
41 | - public $fields; |
|
42 | - public $offset; |
|
43 | - public $limit; |
|
44 | - public $query; |
|
39 | + public $day_added_YYMMDD; |
|
40 | + public $scheduled_for_YYMMDD; |
|
41 | + public $fields; |
|
42 | + public $offset; |
|
43 | + public $limit; |
|
44 | + public $query; |
|
45 | 45 | |
46 | - public $created_timestamp; |
|
47 | - public $order_status_id; |
|
48 | - public $member_id; |
|
49 | - public $address_state_id; |
|
50 | - public $address_country_id; |
|
51 | - public $address_zip; |
|
52 | - public $in_route_count; |
|
53 | - public $last_visited_timestamp; |
|
54 | - public $last_routed_timestamp; |
|
55 | - public $local_timezone_string; |
|
56 | - public $is_validated; |
|
57 | - public $is_pending; |
|
58 | - public $is_accepted; |
|
59 | - public $is_started; |
|
60 | - public $is_completed; |
|
61 | - public $custom_user_fields; |
|
46 | + public $created_timestamp; |
|
47 | + public $order_status_id; |
|
48 | + public $member_id; |
|
49 | + public $address_state_id; |
|
50 | + public $address_country_id; |
|
51 | + public $address_zip; |
|
52 | + public $in_route_count; |
|
53 | + public $last_visited_timestamp; |
|
54 | + public $last_routed_timestamp; |
|
55 | + public $local_timezone_string; |
|
56 | + public $is_validated; |
|
57 | + public $is_pending; |
|
58 | + public $is_accepted; |
|
59 | + public $is_started; |
|
60 | + public $is_completed; |
|
61 | + public $custom_user_fields; |
|
62 | 62 | |
63 | - public $addresses = array(); |
|
63 | + public $addresses = array(); |
|
64 | 64 | |
65 | - public static function fromArray(array $params) { |
|
66 | - $order = new Order(); |
|
67 | - foreach ($params as $key => $value) { |
|
68 | - if (property_exists($order, $key)) { |
|
69 | - $order->{$key} = $value; |
|
70 | - } |
|
71 | - } |
|
65 | + public static function fromArray(array $params) { |
|
66 | + $order = new Order(); |
|
67 | + foreach ($params as $key => $value) { |
|
68 | + if (property_exists($order, $key)) { |
|
69 | + $order->{$key} = $value; |
|
70 | + } |
|
71 | + } |
|
72 | 72 | |
73 | - return $order; |
|
74 | - } |
|
73 | + return $order; |
|
74 | + } |
|
75 | 75 | |
76 | - /** |
|
77 | - * @param Order $params |
|
78 | - */ |
|
79 | - public static function addOrder($params) |
|
80 | - { |
|
81 | - $excludeFields = array('route_id', 'redirect', 'optimization_problem_id', 'order_id', |
|
82 | - 'order_ids', 'fields', 'offset', 'limit', 'query', 'created_timestamp'); |
|
76 | + /** |
|
77 | + * @param Order $params |
|
78 | + */ |
|
79 | + public static function addOrder($params) |
|
80 | + { |
|
81 | + $excludeFields = array('route_id', 'redirect', 'optimization_problem_id', 'order_id', |
|
82 | + 'order_ids', 'fields', 'offset', 'limit', 'query', 'created_timestamp'); |
|
83 | 83 | |
84 | - $allBodyFields = Route4Me::getObjectProperties(new Order(), $excludeFields); |
|
84 | + $allBodyFields = Route4Me::getObjectProperties(new Order(), $excludeFields); |
|
85 | 85 | |
86 | - $response = Route4Me::makeRequst(array( |
|
87 | - 'url' => Endpoint::ORDER_V4, |
|
88 | - 'method' => 'POST', |
|
89 | - 'body' => Route4Me::generateRequestParameters($allBodyFields, $params) |
|
90 | - )); |
|
86 | + $response = Route4Me::makeRequst(array( |
|
87 | + 'url' => Endpoint::ORDER_V4, |
|
88 | + 'method' => 'POST', |
|
89 | + 'body' => Route4Me::generateRequestParameters($allBodyFields, $params) |
|
90 | + )); |
|
91 | 91 | |
92 | - return $response; |
|
93 | - } |
|
92 | + return $response; |
|
93 | + } |
|
94 | 94 | |
95 | - public static function addOrder2Route($params) |
|
96 | - { |
|
97 | - $allQueryFields = array('route_id', 'redirect'); |
|
98 | - $allBodyFields = array('addresses'); |
|
95 | + public static function addOrder2Route($params) |
|
96 | + { |
|
97 | + $allQueryFields = array('route_id', 'redirect'); |
|
98 | + $allBodyFields = array('addresses'); |
|
99 | 99 | |
100 | - $response = Route4Me::makeRequst(array( |
|
101 | - 'url' => Endpoint::ROUTE_V4, |
|
102 | - 'method' => 'PUT', |
|
103 | - 'query' => Route4Me::generateRequestParameters($allQueryFields, $params), |
|
104 | - 'body' => Route4Me::generateRequestParameters($allBodyFields, $params) |
|
105 | - )); |
|
100 | + $response = Route4Me::makeRequst(array( |
|
101 | + 'url' => Endpoint::ROUTE_V4, |
|
102 | + 'method' => 'PUT', |
|
103 | + 'query' => Route4Me::generateRequestParameters($allQueryFields, $params), |
|
104 | + 'body' => Route4Me::generateRequestParameters($allBodyFields, $params) |
|
105 | + )); |
|
106 | 106 | |
107 | - return $response; |
|
108 | - } |
|
107 | + return $response; |
|
108 | + } |
|
109 | 109 | |
110 | - public static function addOrder2Optimization($params) |
|
111 | - { |
|
112 | - $allQueryFields = array('optimization_problem_id', 'redirect', 'device_type'); |
|
113 | - $allBodyFields = array('addresses'); |
|
110 | + public static function addOrder2Optimization($params) |
|
111 | + { |
|
112 | + $allQueryFields = array('optimization_problem_id', 'redirect', 'device_type'); |
|
113 | + $allBodyFields = array('addresses'); |
|
114 | 114 | |
115 | - $response = Route4Me::makeRequst(array( |
|
116 | - 'url' => Endpoint::OPTIMIZATION_PROBLEM, |
|
117 | - 'method' => 'PUT', |
|
118 | - 'query' => Route4Me::generateRequestParameters($allQueryFields, $params), |
|
119 | - 'body' => Route4Me::generateRequestParameters($allBodyFields, $params) |
|
120 | - )); |
|
115 | + $response = Route4Me::makeRequst(array( |
|
116 | + 'url' => Endpoint::OPTIMIZATION_PROBLEM, |
|
117 | + 'method' => 'PUT', |
|
118 | + 'query' => Route4Me::generateRequestParameters($allQueryFields, $params), |
|
119 | + 'body' => Route4Me::generateRequestParameters($allBodyFields, $params) |
|
120 | + )); |
|
121 | 121 | |
122 | - return $response; |
|
123 | - } |
|
122 | + return $response; |
|
123 | + } |
|
124 | 124 | |
125 | - public static function getOrder($params) |
|
126 | - { |
|
127 | - $allQueryFields = array('order_id', 'fields', 'day_added_YYMMDD', 'scheduled_for_YYMMDD', 'query', 'offset', 'limit'); |
|
125 | + public static function getOrder($params) |
|
126 | + { |
|
127 | + $allQueryFields = array('order_id', 'fields', 'day_added_YYMMDD', 'scheduled_for_YYMMDD', 'query', 'offset', 'limit'); |
|
128 | 128 | |
129 | - $response = Route4Me::makeRequst(array( |
|
130 | - 'url' => Endpoint::ORDER_V4, |
|
131 | - 'method' => 'GET', |
|
132 | - 'query' => Route4Me::generateRequestParameters($allQueryFields, $params) |
|
133 | - )); |
|
129 | + $response = Route4Me::makeRequst(array( |
|
130 | + 'url' => Endpoint::ORDER_V4, |
|
131 | + 'method' => 'GET', |
|
132 | + 'query' => Route4Me::generateRequestParameters($allQueryFields, $params) |
|
133 | + )); |
|
134 | 134 | |
135 | - return $response; |
|
136 | - } |
|
135 | + return $response; |
|
136 | + } |
|
137 | 137 | |
138 | - public static function getOrders($params) |
|
139 | - { |
|
140 | - $allQueryFields = array('offset', 'limit'); |
|
138 | + public static function getOrders($params) |
|
139 | + { |
|
140 | + $allQueryFields = array('offset', 'limit'); |
|
141 | 141 | |
142 | - $response = Route4Me::makeRequst(array( |
|
143 | - 'url' => Endpoint::ORDER_V4, |
|
144 | - 'method' => 'GET', |
|
145 | - 'query' => Route4Me::generateRequestParameters($allQueryFields, $params) |
|
146 | - )); |
|
142 | + $response = Route4Me::makeRequst(array( |
|
143 | + 'url' => Endpoint::ORDER_V4, |
|
144 | + 'method' => 'GET', |
|
145 | + 'query' => Route4Me::generateRequestParameters($allQueryFields, $params) |
|
146 | + )); |
|
147 | 147 | |
148 | - return $response; |
|
149 | - } |
|
148 | + return $response; |
|
149 | + } |
|
150 | 150 | |
151 | - public function getRandomOrderId($offset, $limit) |
|
152 | - { |
|
153 | - $randomOrder = $this->getRandomOrder($offset, $limit); |
|
151 | + public function getRandomOrderId($offset, $limit) |
|
152 | + { |
|
153 | + $randomOrder = $this->getRandomOrder($offset, $limit); |
|
154 | 154 | |
155 | - if (is_null($randomOrder)) { |
|
156 | - return null; |
|
157 | - } |
|
155 | + if (is_null($randomOrder)) { |
|
156 | + return null; |
|
157 | + } |
|
158 | 158 | |
159 | - if (!isset($randomOrder)) { |
|
160 | - return null; |
|
161 | - } |
|
159 | + if (!isset($randomOrder)) { |
|
160 | + return null; |
|
161 | + } |
|
162 | 162 | |
163 | - return $randomOrder['order_id']; |
|
164 | - } |
|
163 | + return $randomOrder['order_id']; |
|
164 | + } |
|
165 | 165 | |
166 | - public function getRandomOrder($offset, $limit) |
|
167 | - { |
|
168 | - $params = array('offset' => $offset, 'limit' => $limit); |
|
166 | + public function getRandomOrder($offset, $limit) |
|
167 | + { |
|
168 | + $params = array('offset' => $offset, 'limit' => $limit); |
|
169 | 169 | |
170 | - $orders = self::getOrders($params); |
|
170 | + $orders = self::getOrders($params); |
|
171 | 171 | |
172 | - if (is_null($orders)) { |
|
173 | - return null; |
|
174 | - } |
|
172 | + if (is_null($orders)) { |
|
173 | + return null; |
|
174 | + } |
|
175 | 175 | |
176 | - if (!isset($orders['results'])) { |
|
177 | - return null; |
|
178 | - } |
|
176 | + if (!isset($orders['results'])) { |
|
177 | + return null; |
|
178 | + } |
|
179 | 179 | |
180 | - $randomIndex = rand(0, sizeof($orders['results']) - 1); |
|
180 | + $randomIndex = rand(0, sizeof($orders['results']) - 1); |
|
181 | 181 | |
182 | - $order = $orders['results'][$randomIndex]; |
|
182 | + $order = $orders['results'][$randomIndex]; |
|
183 | 183 | |
184 | - return $order; |
|
185 | - } |
|
184 | + return $order; |
|
185 | + } |
|
186 | 186 | |
187 | - public static function removeOrder($params) |
|
188 | - { |
|
189 | - $allBodyFields = array('order_ids'); |
|
187 | + public static function removeOrder($params) |
|
188 | + { |
|
189 | + $allBodyFields = array('order_ids'); |
|
190 | 190 | |
191 | - $response = Route4Me::makeRequst(array( |
|
192 | - 'url' => Endpoint::ORDER_V4, |
|
193 | - 'method' => 'DELETE', |
|
194 | - 'body' => Route4Me::generateRequestParameters($allBodyFields, $params) |
|
195 | - )); |
|
191 | + $response = Route4Me::makeRequst(array( |
|
192 | + 'url' => Endpoint::ORDER_V4, |
|
193 | + 'method' => 'DELETE', |
|
194 | + 'body' => Route4Me::generateRequestParameters($allBodyFields, $params) |
|
195 | + )); |
|
196 | 196 | |
197 | - return $response; |
|
198 | - } |
|
197 | + return $response; |
|
198 | + } |
|
199 | 199 | |
200 | - public static function updateOrder($params) |
|
201 | - { |
|
202 | - $excludeFields = array('route_id', 'redirect', 'optimization_problem_id', |
|
203 | - 'order_ids', 'fields', 'offset', 'limit', 'query', 'created_timestamp'); |
|
200 | + public static function updateOrder($params) |
|
201 | + { |
|
202 | + $excludeFields = array('route_id', 'redirect', 'optimization_problem_id', |
|
203 | + 'order_ids', 'fields', 'offset', 'limit', 'query', 'created_timestamp'); |
|
204 | 204 | |
205 | - $allBodyFields = Route4Me::getObjectProperties(new Order(), $excludeFields); |
|
205 | + $allBodyFields = Route4Me::getObjectProperties(new Order(), $excludeFields); |
|
206 | 206 | |
207 | - $response = Route4Me::makeRequst(array( |
|
208 | - 'url' => Endpoint::ORDER_V4, |
|
209 | - 'method' => 'PUT', |
|
210 | - 'body' => Route4Me::generateRequestParameters($allBodyFields, $params) |
|
211 | - )); |
|
207 | + $response = Route4Me::makeRequst(array( |
|
208 | + 'url' => Endpoint::ORDER_V4, |
|
209 | + 'method' => 'PUT', |
|
210 | + 'body' => Route4Me::generateRequestParameters($allBodyFields, $params) |
|
211 | + )); |
|
212 | 212 | |
213 | - return $response; |
|
214 | - } |
|
213 | + return $response; |
|
214 | + } |
|
215 | 215 | |
216 | - public static function searchOrder($params) |
|
217 | - { |
|
218 | - $allQueryFields = array('fields', 'day_added_YYMMDD', 'scheduled_for_YYMMDD', 'query', 'offset', 'limit' ); |
|
216 | + public static function searchOrder($params) |
|
217 | + { |
|
218 | + $allQueryFields = array('fields', 'day_added_YYMMDD', 'scheduled_for_YYMMDD', 'query', 'offset', 'limit' ); |
|
219 | 219 | |
220 | - $response = Route4Me::makeRequst(array( |
|
221 | - 'url' => Endpoint::ORDER_V4, |
|
222 | - 'method' => 'GET', |
|
223 | - 'query' => Route4Me::generateRequestParameters($allQueryFields, $params) |
|
224 | - )); |
|
220 | + $response = Route4Me::makeRequst(array( |
|
221 | + 'url' => Endpoint::ORDER_V4, |
|
222 | + 'method' => 'GET', |
|
223 | + 'query' => Route4Me::generateRequestParameters($allQueryFields, $params) |
|
224 | + )); |
|
225 | 225 | |
226 | - return $response; |
|
227 | - } |
|
226 | + return $response; |
|
227 | + } |
|
228 | 228 | |
229 | - public static function validateCoordinate($coord) |
|
230 | - { |
|
231 | - $key = key($coord); |
|
229 | + public static function validateCoordinate($coord) |
|
230 | + { |
|
231 | + $key = key($coord); |
|
232 | 232 | |
233 | - if (!is_numeric($coord[$key])) { |
|
234 | - return false; |
|
235 | - } |
|
233 | + if (!is_numeric($coord[$key])) { |
|
234 | + return false; |
|
235 | + } |
|
236 | 236 | |
237 | - switch (variable) { |
|
238 | - case 'cached_lat': |
|
239 | - case 'curbside_lat': |
|
240 | - if ($lat>90 || $lat<-90) { |
|
241 | - return false; |
|
242 | - } |
|
243 | - break; |
|
244 | - case 'cached_lng': |
|
245 | - case 'curbside_lng': |
|
246 | - if ($lng>180 || $lng<-180) { |
|
247 | - return false; |
|
248 | - } |
|
249 | - break; |
|
250 | - } |
|
237 | + switch (variable) { |
|
238 | + case 'cached_lat': |
|
239 | + case 'curbside_lat': |
|
240 | + if ($lat>90 || $lat<-90) { |
|
241 | + return false; |
|
242 | + } |
|
243 | + break; |
|
244 | + case 'cached_lng': |
|
245 | + case 'curbside_lng': |
|
246 | + if ($lng>180 || $lng<-180) { |
|
247 | + return false; |
|
248 | + } |
|
249 | + break; |
|
250 | + } |
|
251 | 251 | |
252 | - return true; |
|
253 | - } |
|
252 | + return true; |
|
253 | + } |
|
254 | 254 | |
255 | - public function addOrdersFromCsvFile($csvFileHandle, $ordersFieldsMapping) |
|
256 | - { |
|
257 | - $max_line_length = 512; |
|
258 | - $delemietr = ','; |
|
255 | + public function addOrdersFromCsvFile($csvFileHandle, $ordersFieldsMapping) |
|
256 | + { |
|
257 | + $max_line_length = 512; |
|
258 | + $delemietr = ','; |
|
259 | 259 | |
260 | - $results = array(); |
|
261 | - $results['fail'] = array(); |
|
262 | - $results['success'] = array(); |
|
260 | + $results = array(); |
|
261 | + $results['fail'] = array(); |
|
262 | + $results['success'] = array(); |
|
263 | 263 | |
264 | - $columns = fgetcsv($csvFileHandle, $max_line_length, $delemietr); |
|
264 | + $columns = fgetcsv($csvFileHandle, $max_line_length, $delemietr); |
|
265 | 265 | |
266 | - $excludeFields = array('route_id', 'redirect', 'optimization_problem_id', 'order_id', |
|
267 | - 'order_ids', 'fields', 'offset', 'limit', 'query', 'created_timestamp'); |
|
266 | + $excludeFields = array('route_id', 'redirect', 'optimization_problem_id', 'order_id', |
|
267 | + 'order_ids', 'fields', 'offset', 'limit', 'query', 'created_timestamp'); |
|
268 | 268 | |
269 | - $allOrderFields = Route4Me::getObjectProperties(new Order(), $excludeFields); |
|
269 | + $allOrderFields = Route4Me::getObjectProperties(new Order(), $excludeFields); |
|
270 | 270 | |
271 | - if (!empty($columns)) { |
|
272 | - array_push($results['fail'],'Empty CSV table'); |
|
273 | - return ($results); |
|
274 | - } |
|
271 | + if (!empty($columns)) { |
|
272 | + array_push($results['fail'],'Empty CSV table'); |
|
273 | + return ($results); |
|
274 | + } |
|
275 | 275 | |
276 | - $iRow=1; |
|
276 | + $iRow=1; |
|
277 | 277 | |
278 | - while (($rows = fgetcsv($csvFileHandle, $max_line_length, $delemietr))!==false) { |
|
279 | - if ($rows[$ordersFieldsMapping['cached_lat']] && $rows[$ordersFieldsMapping['cached_lng']] && $rows[$ordersFieldsMapping['address_1']] && array(null)!==$rows) { |
|
278 | + while (($rows = fgetcsv($csvFileHandle, $max_line_length, $delemietr))!==false) { |
|
279 | + if ($rows[$ordersFieldsMapping['cached_lat']] && $rows[$ordersFieldsMapping['cached_lng']] && $rows[$ordersFieldsMapping['address_1']] && array(null)!==$rows) { |
|
280 | 280 | |
281 | - $cached_lat = 0.000; |
|
282 | - $cached_lng = 0.000; |
|
281 | + $cached_lat = 0.000; |
|
282 | + $cached_lng = 0.000; |
|
283 | 283 | |
284 | - foreach (array('cached_lat', 'cached_lng', 'curbside_lat', 'curbside_lng') as $coord) { |
|
285 | - if (!$this->validateCoordinate(array($coord => $rows[$ordersFieldsMapping[$coord]]))) { |
|
286 | - array_push($results['fail'], "$iRow --> Wrong "+$coord); |
|
287 | - $iRow++; |
|
288 | - continue; |
|
289 | - } else { |
|
290 | - switch ($coord) { |
|
291 | - case 'cached_lat': |
|
292 | - $cached_lat = doubleval($rows[$ordersFieldsMapping[$coord]]); |
|
293 | - break; |
|
294 | - case 'cached_lng': |
|
295 | - $cached_lng = doubleval($rows[$ordersFieldsMapping[$coord]]); |
|
296 | - break; |
|
297 | - } |
|
298 | - } |
|
299 | - } |
|
284 | + foreach (array('cached_lat', 'cached_lng', 'curbside_lat', 'curbside_lng') as $coord) { |
|
285 | + if (!$this->validateCoordinate(array($coord => $rows[$ordersFieldsMapping[$coord]]))) { |
|
286 | + array_push($results['fail'], "$iRow --> Wrong "+$coord); |
|
287 | + $iRow++; |
|
288 | + continue; |
|
289 | + } else { |
|
290 | + switch ($coord) { |
|
291 | + case 'cached_lat': |
|
292 | + $cached_lat = doubleval($rows[$ordersFieldsMapping[$coord]]); |
|
293 | + break; |
|
294 | + case 'cached_lng': |
|
295 | + $cached_lng = doubleval($rows[$ordersFieldsMapping[$coord]]); |
|
296 | + break; |
|
297 | + } |
|
298 | + } |
|
299 | + } |
|
300 | 300 | |
301 | - $address = $rows[$ordersFieldsMapping['address_1']]; |
|
301 | + $address = $rows[$ordersFieldsMapping['address_1']]; |
|
302 | 302 | |
303 | - foreach (array('order_city', 'order_state_id', 'order_zip_code', 'order_country_id') as $addressPart) { |
|
304 | - if (isset($ordersFieldsMapping[$addressPart])) { |
|
305 | - $address .= ', '.$rows[$ordersFieldsMapping[$addressPart]]; |
|
306 | - } |
|
307 | - } |
|
303 | + foreach (array('order_city', 'order_state_id', 'order_zip_code', 'order_country_id') as $addressPart) { |
|
304 | + if (isset($ordersFieldsMapping[$addressPart])) { |
|
305 | + $address .= ', '.$rows[$ordersFieldsMapping[$addressPart]]; |
|
306 | + } |
|
307 | + } |
|
308 | 308 | |
309 | - echo "$iRow --> ".$ordersFieldsMapping['day_scheduled_for_YYMMDD'].", ".$rows[$ordersFieldsMapping['day_scheduled_for_YYMMDD']]."<br>"; |
|
309 | + echo "$iRow --> ".$ordersFieldsMapping['day_scheduled_for_YYMMDD'].", ".$rows[$ordersFieldsMapping['day_scheduled_for_YYMMDD']]."<br>"; |
|
310 | 310 | |
311 | - $parametersArray = array(); |
|
311 | + $parametersArray = array(); |
|
312 | 312 | |
313 | - $parametersArray["cached_lat"] = $cached_lat; |
|
314 | - $parametersArray["cached_lng"] = $cached_lng; |
|
313 | + $parametersArray["cached_lat"] = $cached_lat; |
|
314 | + $parametersArray["cached_lng"] = $cached_lng; |
|
315 | 315 | |
316 | 316 | |
317 | - foreach ($allOrderFields as $orderField) { |
|
318 | - if (isset($ordersFieldsMapping[$orderField])) { |
|
319 | - $parametersArray[$orderField] = $rows[$ordersFieldsMapping[$orderField]]; |
|
320 | - } |
|
321 | - } |
|
317 | + foreach ($allOrderFields as $orderField) { |
|
318 | + if (isset($ordersFieldsMapping[$orderField])) { |
|
319 | + $parametersArray[$orderField] = $rows[$ordersFieldsMapping[$orderField]]; |
|
320 | + } |
|
321 | + } |
|
322 | 322 | |
323 | - $orderParameters = Order::fromArray($parametersArray); |
|
323 | + $orderParameters = Order::fromArray($parametersArray); |
|
324 | 324 | |
325 | - $order = new Order(); |
|
325 | + $order = new Order(); |
|
326 | 326 | |
327 | - $orderResults = $order->addOrder($orderParameters); |
|
327 | + $orderResults = $order->addOrder($orderParameters); |
|
328 | 328 | |
329 | - array_push($results['success'], "The order with order_id = ".strval($orderResults["order_id"])." added successfuly."); |
|
330 | - } |
|
331 | - else { |
|
332 | - array_push($results['fail'], "$iRow --> one of the parameters cached_lat, cached_lng, address_1 is not set"); |
|
333 | - } |
|
329 | + array_push($results['success'], "The order with order_id = ".strval($orderResults["order_id"])." added successfuly."); |
|
330 | + } |
|
331 | + else { |
|
332 | + array_push($results['fail'], "$iRow --> one of the parameters cached_lat, cached_lng, address_1 is not set"); |
|
333 | + } |
|
334 | 334 | |
335 | - $iRow++; |
|
336 | - } |
|
337 | - } |
|
335 | + $iRow++; |
|
336 | + } |
|
337 | + } |
|
338 | 338 | } |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | |
41 | 41 | public static function getTerritory($params) |
42 | 42 | { |
43 | - $allQueryFields = array('territory_id', 'addresses'); |
|
43 | + $allQueryFields = array('territory_id', 'addresses'); |
|
44 | 44 | |
45 | 45 | $territory = Route4Me::makeRequst(array( |
46 | 46 | 'url' => Endpoint::TERRITORY_V4, |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | |
54 | 54 | public static function getTerritories($params) |
55 | 55 | { |
56 | - $allQueryFields = array('offset', 'limit', 'addresses'); |
|
56 | + $allQueryFields = array('offset', 'limit', 'addresses'); |
|
57 | 57 | |
58 | 58 | $response = Route4Me::makeRequst(array( |
59 | 59 | 'url' => Endpoint::TERRITORY_V4, |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | |
67 | 67 | public static function addTerritory($params) |
68 | 68 | { |
69 | - $allBodyFields = array('territory_name', 'member_id', 'territory_color', 'territory'); |
|
69 | + $allBodyFields = array('territory_name', 'member_id', 'territory_color', 'territory'); |
|
70 | 70 | |
71 | 71 | $response = Route4Me::makeRequst(array( |
72 | 72 | 'url' => Endpoint::TERRITORY_V4, |
@@ -92,14 +92,14 @@ discard block |
||
92 | 92 | |
93 | 93 | public function updateTerritory($params) |
94 | 94 | { |
95 | - $allQueryFields = array('territory_id'); |
|
96 | - $allBodyFields = array('territory_name', 'member_id', 'territory_color', 'territory'); |
|
95 | + $allQueryFields = array('territory_id'); |
|
96 | + $allBodyFields = array('territory_name', 'member_id', 'territory_color', 'territory'); |
|
97 | 97 | |
98 | 98 | $response = Route4Me::makeRequst(array( |
99 | 99 | 'url' => Endpoint::TERRITORY_V4, |
100 | 100 | 'method' => 'PUT', |
101 | 101 | 'query' => Route4Me::generateRequestParameters($allQueryFields, $params), |
102 | - 'body' => Route4Me::generateRequestParameters($allBodyFields, $params) |
|
102 | + 'body' => Route4Me::generateRequestParameters($allBodyFields, $params) |
|
103 | 103 | )); |
104 | 104 | |
105 | 105 | return $response; |
@@ -6,157 +6,157 @@ |
||
6 | 6 | |
7 | 7 | class Vehicle extends Common |
8 | 8 | { |
9 | - public $vehicle_id; |
|
10 | - public $member_id; |
|
11 | - public $is_deleted; |
|
12 | - public $vehicle_alias; |
|
13 | - public $vehicle_vin; |
|
14 | - public $vehicle_reg_state_id; |
|
15 | - public $vehicle_reg_country_id; |
|
16 | - public $vehicle_license_plate; |
|
17 | - public $vehicle_type_id; |
|
18 | - public $vehicle_make; |
|
19 | - public $vehicle_model_year; |
|
20 | - public $vehicle_model; |
|
21 | - public $vehicle_year_acquired; |
|
22 | - public $vehicle_cost_new; |
|
23 | - public $purchased_new; |
|
24 | - public $license_start_date; |
|
25 | - public $license_end_date; |
|
26 | - public $vehicle_axle_count; |
|
27 | - public $is_operational; |
|
28 | - public $mpg_city; |
|
29 | - public $mpg_highway; |
|
30 | - public $fuel_type; |
|
31 | - public $height_inches; |
|
32 | - public $weight_lb; |
|
33 | - public $external_telematics_vehicle_id; |
|
34 | - public $has_trailer; |
|
35 | - public $heightInInches; |
|
36 | - public $lengthInInches; |
|
37 | - public $widthInInches; |
|
38 | - public $maxWeightPerAxleGroupInPounds; |
|
39 | - public $numAxles; |
|
40 | - public $weightInPounds; |
|
41 | - public $HazmatType; |
|
42 | - public $LowEmissionZonePref; |
|
43 | - public $Use53FootTrailerRouting; |
|
44 | - public $UseNationalNetwork; |
|
45 | - public $UseTruckRestrictions; |
|
46 | - public $AvoidFerries; |
|
47 | - public $DividedHighwayAvoidPreference; |
|
48 | - public $FreewayAvoidPreference; |
|
49 | - public $InternationalBordersOpen; |
|
50 | - public $TollRoadUsage; |
|
51 | - public $hwy_only; |
|
52 | - public $long_combination_vehicle; |
|
53 | - public $avoid_highways; |
|
54 | - public $side_street_adherence; |
|
55 | - public $truck_config; |
|
56 | - public $height_metric; |
|
57 | - public $length_metric; |
|
58 | - public $width_metric; |
|
59 | - public $weight_metric; |
|
60 | - public $max_weight_per_axle_group_metric; |
|
9 | + public $vehicle_id; |
|
10 | + public $member_id; |
|
11 | + public $is_deleted; |
|
12 | + public $vehicle_alias; |
|
13 | + public $vehicle_vin; |
|
14 | + public $vehicle_reg_state_id; |
|
15 | + public $vehicle_reg_country_id; |
|
16 | + public $vehicle_license_plate; |
|
17 | + public $vehicle_type_id; |
|
18 | + public $vehicle_make; |
|
19 | + public $vehicle_model_year; |
|
20 | + public $vehicle_model; |
|
21 | + public $vehicle_year_acquired; |
|
22 | + public $vehicle_cost_new; |
|
23 | + public $purchased_new; |
|
24 | + public $license_start_date; |
|
25 | + public $license_end_date; |
|
26 | + public $vehicle_axle_count; |
|
27 | + public $is_operational; |
|
28 | + public $mpg_city; |
|
29 | + public $mpg_highway; |
|
30 | + public $fuel_type; |
|
31 | + public $height_inches; |
|
32 | + public $weight_lb; |
|
33 | + public $external_telematics_vehicle_id; |
|
34 | + public $has_trailer; |
|
35 | + public $heightInInches; |
|
36 | + public $lengthInInches; |
|
37 | + public $widthInInches; |
|
38 | + public $maxWeightPerAxleGroupInPounds; |
|
39 | + public $numAxles; |
|
40 | + public $weightInPounds; |
|
41 | + public $HazmatType; |
|
42 | + public $LowEmissionZonePref; |
|
43 | + public $Use53FootTrailerRouting; |
|
44 | + public $UseNationalNetwork; |
|
45 | + public $UseTruckRestrictions; |
|
46 | + public $AvoidFerries; |
|
47 | + public $DividedHighwayAvoidPreference; |
|
48 | + public $FreewayAvoidPreference; |
|
49 | + public $InternationalBordersOpen; |
|
50 | + public $TollRoadUsage; |
|
51 | + public $hwy_only; |
|
52 | + public $long_combination_vehicle; |
|
53 | + public $avoid_highways; |
|
54 | + public $side_street_adherence; |
|
55 | + public $truck_config; |
|
56 | + public $height_metric; |
|
57 | + public $length_metric; |
|
58 | + public $width_metric; |
|
59 | + public $weight_metric; |
|
60 | + public $max_weight_per_axle_group_metric; |
|
61 | 61 | |
62 | - public function __construct () |
|
63 | - { |
|
64 | - Route4Me::setBaseUrl(Endpoint::WH_BASE_URL); |
|
65 | - } |
|
62 | + public function __construct () |
|
63 | + { |
|
64 | + Route4Me::setBaseUrl(Endpoint::WH_BASE_URL); |
|
65 | + } |
|
66 | 66 | |
67 | - public static function fromArray(array $params) { |
|
68 | - $vehicle= new Vehicle(); |
|
69 | - foreach($params as $key => $value) { |
|
70 | - if (property_exists($vehicle, $key)) { |
|
71 | - $vehicle->{$key} = $value; |
|
72 | - } |
|
73 | - } |
|
67 | + public static function fromArray(array $params) { |
|
68 | + $vehicle= new Vehicle(); |
|
69 | + foreach($params as $key => $value) { |
|
70 | + if (property_exists($vehicle, $key)) { |
|
71 | + $vehicle->{$key} = $value; |
|
72 | + } |
|
73 | + } |
|
74 | 74 | |
75 | - return $vehicle; |
|
76 | - } |
|
75 | + return $vehicle; |
|
76 | + } |
|
77 | 77 | |
78 | - public static function getVehicles($params) |
|
79 | - { |
|
80 | - $allQueryFields = array('with_pagination', 'page', 'perPage'); |
|
78 | + public static function getVehicles($params) |
|
79 | + { |
|
80 | + $allQueryFields = array('with_pagination', 'page', 'perPage'); |
|
81 | 81 | |
82 | - $response = Route4Me::makeRequst(array( |
|
83 | - 'url' => Endpoint::VEHICLE_V4, |
|
84 | - 'method' => 'GET', |
|
85 | - 'query' => Route4Me::generateRequestParameters($allQueryFields, $params) |
|
86 | - )); |
|
82 | + $response = Route4Me::makeRequst(array( |
|
83 | + 'url' => Endpoint::VEHICLE_V4, |
|
84 | + 'method' => 'GET', |
|
85 | + 'query' => Route4Me::generateRequestParameters($allQueryFields, $params) |
|
86 | + )); |
|
87 | 87 | |
88 | - return $response; |
|
89 | - } |
|
88 | + return $response; |
|
89 | + } |
|
90 | 90 | |
91 | - public function getRandomVehicleId($page,$perPage) |
|
92 | - { |
|
93 | - $params = array( |
|
94 | - 'page' => isset($page) ? $page : 1, |
|
95 | - 'perPage' => isset($perPage) ? $perPage : 10, |
|
96 | - 'with_pagination' => true |
|
97 | - ); |
|
91 | + public function getRandomVehicleId($page,$perPage) |
|
92 | + { |
|
93 | + $params = array( |
|
94 | + 'page' => isset($page) ? $page : 1, |
|
95 | + 'perPage' => isset($perPage) ? $perPage : 10, |
|
96 | + 'with_pagination' => true |
|
97 | + ); |
|
98 | 98 | |
99 | - $vehicles = $this->getVehicles($params); |
|
99 | + $vehicles = $this->getVehicles($params); |
|
100 | 100 | |
101 | - if (is_null($vehicles)) return null; |
|
102 | - if (!isset($vehicles['data'])) return null; |
|
103 | - if (sizeof($vehicles['data'])<1) return null; |
|
101 | + if (is_null($vehicles)) return null; |
|
102 | + if (!isset($vehicles['data'])) return null; |
|
103 | + if (sizeof($vehicles['data'])<1) return null; |
|
104 | 104 | |
105 | - $randomIndex = rand(0, sizeof($vehicles['data'])-1); |
|
105 | + $randomIndex = rand(0, sizeof($vehicles['data'])-1); |
|
106 | 106 | |
107 | - return $vehicles['data'][$randomIndex]['vehicle_id']; |
|
108 | - } |
|
107 | + return $vehicles['data'][$randomIndex]['vehicle_id']; |
|
108 | + } |
|
109 | 109 | |
110 | - public function getVehicleByID($vehicleID) |
|
111 | - { |
|
112 | - $response = Route4Me::makeRequst(array( |
|
113 | - 'url' => Endpoint::VEHICLE_V4 . '/' . $vehicleID, |
|
114 | - 'method' => 'GET' |
|
115 | - )); |
|
110 | + public function getVehicleByID($vehicleID) |
|
111 | + { |
|
112 | + $response = Route4Me::makeRequst(array( |
|
113 | + 'url' => Endpoint::VEHICLE_V4 . '/' . $vehicleID, |
|
114 | + 'method' => 'GET' |
|
115 | + )); |
|
116 | 116 | |
117 | - return $response; |
|
118 | - } |
|
117 | + return $response; |
|
118 | + } |
|
119 | 119 | |
120 | - public function updateVehicle($params) |
|
121 | - { |
|
122 | - $vehicleID = isset($params->vehicle_id) ? $params->vehicle_id : null; |
|
120 | + public function updateVehicle($params) |
|
121 | + { |
|
122 | + $vehicleID = isset($params->vehicle_id) ? $params->vehicle_id : null; |
|
123 | 123 | |
124 | - $allBodyFields = Route4Me::getObjectProperties(new Vehicle(), array('vehicle_id')); |
|
124 | + $allBodyFields = Route4Me::getObjectProperties(new Vehicle(), array('vehicle_id')); |
|
125 | 125 | |
126 | - $response = Route4Me::makeRequst(array( |
|
127 | - 'url' => Endpoint::VEHICLE_V4 . '/' . $vehicleID, |
|
128 | - 'method' => 'PUT', |
|
129 | - 'body' => Route4Me::generateRequestParameters($allBodyFields, $params), |
|
130 | - 'HTTPHEADER' => 'Content-Type: application/json' |
|
131 | - )); |
|
126 | + $response = Route4Me::makeRequst(array( |
|
127 | + 'url' => Endpoint::VEHICLE_V4 . '/' . $vehicleID, |
|
128 | + 'method' => 'PUT', |
|
129 | + 'body' => Route4Me::generateRequestParameters($allBodyFields, $params), |
|
130 | + 'HTTPHEADER' => 'Content-Type: application/json' |
|
131 | + )); |
|
132 | 132 | |
133 | - return $response; |
|
134 | - } |
|
133 | + return $response; |
|
134 | + } |
|
135 | 135 | |
136 | - public function createVehicle($params) |
|
137 | - { |
|
138 | - $allBodyFields = Route4Me::getObjectProperties(new Vehicle(), array('vehicle_id')); |
|
136 | + public function createVehicle($params) |
|
137 | + { |
|
138 | + $allBodyFields = Route4Me::getObjectProperties(new Vehicle(), array('vehicle_id')); |
|
139 | 139 | |
140 | - $response = Route4Me::makeRequst(array( |
|
141 | - 'url' => Endpoint::VEHICLE_V4, |
|
142 | - 'method' => 'POST', |
|
143 | - 'body' => Route4Me::generateRequestParameters($allBodyFields, $params), |
|
144 | - 'HTTPHEADER' => 'Content-Type: application/json' |
|
145 | - )); |
|
140 | + $response = Route4Me::makeRequst(array( |
|
141 | + 'url' => Endpoint::VEHICLE_V4, |
|
142 | + 'method' => 'POST', |
|
143 | + 'body' => Route4Me::generateRequestParameters($allBodyFields, $params), |
|
144 | + 'HTTPHEADER' => 'Content-Type: application/json' |
|
145 | + )); |
|
146 | 146 | |
147 | - return $response; |
|
148 | - } |
|
147 | + return $response; |
|
148 | + } |
|
149 | 149 | |
150 | - public function removeVehicle($params) |
|
151 | - { |
|
152 | - $vehicleID = isset($params->vehicle_id) ? $params->vehicle_id : null; |
|
150 | + public function removeVehicle($params) |
|
151 | + { |
|
152 | + $vehicleID = isset($params->vehicle_id) ? $params->vehicle_id : null; |
|
153 | 153 | |
154 | - $response = Route4Me::makeRequst(array( |
|
155 | - 'url' => Endpoint::VEHICLE_V4 . '/' . $vehicleID, |
|
156 | - 'method' => 'DELETE', |
|
157 | - 'HTTPHEADER' => 'Content-Type: application/json' |
|
158 | - )); |
|
154 | + $response = Route4Me::makeRequst(array( |
|
155 | + 'url' => Endpoint::VEHICLE_V4 . '/' . $vehicleID, |
|
156 | + 'method' => 'DELETE', |
|
157 | + 'HTTPHEADER' => 'Content-Type: application/json' |
|
158 | + )); |
|
159 | 159 | |
160 | - return $response; |
|
161 | - } |
|
160 | + return $response; |
|
161 | + } |
|
162 | 162 | } |
@@ -7,415 +7,415 @@ |
||
7 | 7 | |
8 | 8 | class Route4Me |
9 | 9 | { |
10 | - static public $apiKey; |
|
11 | - static public $baseUrl = Endpoint::BASE_URL; |
|
10 | + static public $apiKey; |
|
11 | + static public $baseUrl = Endpoint::BASE_URL; |
|
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 | - public static function fileUploadRequest($options) { |
|
34 | - $query = isset($options['query']) ? array_filter($options['query']) : array(); |
|
33 | + public static function fileUploadRequest($options) { |
|
34 | + $query = isset($options['query']) ? array_filter($options['query']) : array(); |
|
35 | 35 | |
36 | - if (sizeof($query)==0) { |
|
37 | - return null; |
|
36 | + if (sizeof($query)==0) { |
|
37 | + return null; |
|
38 | 38 | |
39 | - } |
|
39 | + } |
|
40 | 40 | |
41 | - $body = isset($options['body']) ? array_filter($options['body']) : null; |
|
41 | + $body = isset($options['body']) ? array_filter($options['body']) : null; |
|
42 | 42 | |
43 | - $fname = isset($body['strFilename']) ? $body['strFilename'] : ''; |
|
43 | + $fname = isset($body['strFilename']) ? $body['strFilename'] : ''; |
|
44 | 44 | |
45 | - if ($fname=='') { |
|
46 | - return null; |
|
47 | - } |
|
45 | + if ($fname=='') { |
|
46 | + return null; |
|
47 | + } |
|
48 | 48 | |
49 | - $rpath = function_exists('curl_file_create') ? curl_file_create(realpath($fname)) : '@'.realpath($fname); |
|
49 | + $rpath = function_exists('curl_file_create') ? curl_file_create(realpath($fname)) : '@'.realpath($fname); |
|
50 | 50 | |
51 | - $url = self::$baseUrl.$options['url'].'?'.http_build_query(array_merge(array('api_key' => self::getApiKey()), $query)); |
|
51 | + $url = self::$baseUrl.$options['url'].'?'.http_build_query(array_merge(array('api_key' => self::getApiKey()), $query)); |
|
52 | 52 | |
53 | - $ch = curl_init($url); |
|
53 | + $ch = curl_init($url); |
|
54 | 54 | |
55 | - $curlOpts = array( |
|
56 | - CURLOPT_POST => true, |
|
57 | - CURLOPT_RETURNTRANSFER => false, |
|
58 | - CURLOPT_TIMEOUT => 60, |
|
59 | - CURLOPT_FOLLOWLOCATION => true, |
|
60 | - CURLOPT_SSL_VERIFYHOST => FALSE, |
|
61 | - CURLOPT_SSL_VERIFYPEER => FALSE |
|
62 | - ); |
|
55 | + $curlOpts = array( |
|
56 | + CURLOPT_POST => true, |
|
57 | + CURLOPT_RETURNTRANSFER => false, |
|
58 | + CURLOPT_TIMEOUT => 60, |
|
59 | + CURLOPT_FOLLOWLOCATION => true, |
|
60 | + CURLOPT_SSL_VERIFYHOST => FALSE, |
|
61 | + CURLOPT_SSL_VERIFYPEER => FALSE |
|
62 | + ); |
|
63 | 63 | |
64 | - curl_setopt_array($ch, $curlOpts); |
|
64 | + curl_setopt_array($ch, $curlOpts); |
|
65 | 65 | |
66 | - curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); |
|
66 | + curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); |
|
67 | 67 | |
68 | - curl_setopt($ch, CURLOPT_HTTPHEADER, array( |
|
69 | - "Content-Type: multipart/form-data", |
|
70 | - 'Content-Disposition: form-data; name="strFilename"' |
|
71 | - )); |
|
72 | - curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); |
|
73 | - curl_setopt($ch, CURLOPT_POSTFIELDS, array('strFilename' => $rpath)); |
|
68 | + curl_setopt($ch, CURLOPT_HTTPHEADER, array( |
|
69 | + "Content-Type: multipart/form-data", |
|
70 | + 'Content-Disposition: form-data; name="strFilename"' |
|
71 | + )); |
|
72 | + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); |
|
73 | + curl_setopt($ch, CURLOPT_POSTFIELDS, array('strFilename' => $rpath)); |
|
74 | 74 | |
75 | - $result = curl_exec($ch); |
|
75 | + $result = curl_exec($ch); |
|
76 | 76 | |
77 | - $code = curl_getinfo($ch, CURLINFO_HTTP_CODE); |
|
78 | - curl_close($ch); |
|
77 | + $code = curl_getinfo($ch, CURLINFO_HTTP_CODE); |
|
78 | + curl_close($ch); |
|
79 | 79 | |
80 | - $json = json_decode($result, true); |
|
80 | + $json = json_decode($result, true); |
|
81 | 81 | |
82 | - if (200==$code) { |
|
83 | - return $json; |
|
84 | - } elseif (isset($json['errors'])) { |
|
85 | - throw new ApiError(implode(', ', $json['errors'])); |
|
86 | - } else { |
|
87 | - throw new ApiError('Something wrong'); |
|
88 | - } |
|
89 | - } |
|
82 | + if (200==$code) { |
|
83 | + return $json; |
|
84 | + } elseif (isset($json['errors'])) { |
|
85 | + throw new ApiError(implode(', ', $json['errors'])); |
|
86 | + } else { |
|
87 | + throw new ApiError('Something wrong'); |
|
88 | + } |
|
89 | + } |
|
90 | 90 | |
91 | - public static function makeRequst($options) { |
|
92 | - $errorHandler = new myErrorHandler(); |
|
91 | + public static function makeRequst($options) { |
|
92 | + $errorHandler = new myErrorHandler(); |
|
93 | 93 | |
94 | - $old_error_handler = set_error_handler(array($errorHandler, "proc_error")); |
|
94 | + $old_error_handler = set_error_handler(array($errorHandler, "proc_error")); |
|
95 | 95 | |
96 | - $method = isset($options['method']) ? $options['method'] : 'GET'; |
|
97 | - $query = isset($options['query']) ? array_filter($options['query'], function($x) { return !is_null($x); } ) : array(); |
|
96 | + $method = isset($options['method']) ? $options['method'] : 'GET'; |
|
97 | + $query = isset($options['query']) ? array_filter($options['query'], function($x) { return !is_null($x); } ) : array(); |
|
98 | 98 | |
99 | - $body = isset($options['body']) ? $options['body'] : null; |
|
100 | - $file = isset($options['FILE']) ? $options['FILE'] : null; |
|
101 | - $headers = array( |
|
102 | - "User-Agent: Route4Me php-sdk" |
|
103 | - ); |
|
99 | + $body = isset($options['body']) ? $options['body'] : null; |
|
100 | + $file = isset($options['FILE']) ? $options['FILE'] : null; |
|
101 | + $headers = array( |
|
102 | + "User-Agent: Route4Me php-sdk" |
|
103 | + ); |
|
104 | 104 | |
105 | - if (isset($options['HTTPHEADER'])) { |
|
106 | - $headers[] = $options['HTTPHEADER']; |
|
107 | - } |
|
105 | + if (isset($options['HTTPHEADER'])) { |
|
106 | + $headers[] = $options['HTTPHEADER']; |
|
107 | + } |
|
108 | 108 | |
109 | - if (isset($options['HTTPHEADERS'])) { |
|
110 | - foreach ($options['HTTPHEADERS'] As $header) { |
|
111 | - $headers[] = $header; |
|
112 | - } |
|
113 | - } |
|
109 | + if (isset($options['HTTPHEADERS'])) { |
|
110 | + foreach ($options['HTTPHEADERS'] As $header) { |
|
111 | + $headers[] = $header; |
|
112 | + } |
|
113 | + } |
|
114 | 114 | |
115 | - $ch = curl_init(); |
|
115 | + $ch = curl_init(); |
|
116 | 116 | |
117 | - $url = $options['url'].'?'.http_build_query(array_merge( |
|
118 | - $query, array('api_key' => self::getApiKey()) |
|
119 | - )); |
|
117 | + $url = $options['url'].'?'.http_build_query(array_merge( |
|
118 | + $query, array('api_key' => self::getApiKey()) |
|
119 | + )); |
|
120 | 120 | |
121 | - $baseUrl = self::getBaseUrl(); |
|
121 | + $baseUrl = self::getBaseUrl(); |
|
122 | 122 | |
123 | - $curlOpts = arraY( |
|
124 | - CURLOPT_URL => $baseUrl.$url, |
|
125 | - CURLOPT_RETURNTRANSFER => true, |
|
126 | - CURLOPT_TIMEOUT => 80, |
|
127 | - CURLOPT_FOLLOWLOCATION => true, |
|
128 | - CURLOPT_SSL_VERIFYHOST => FALSE, |
|
129 | - CURLOPT_SSL_VERIFYPEER => FALSE, |
|
130 | - CURLOPT_HTTPHEADER => $headers |
|
131 | - ); |
|
123 | + $curlOpts = arraY( |
|
124 | + CURLOPT_URL => $baseUrl.$url, |
|
125 | + CURLOPT_RETURNTRANSFER => true, |
|
126 | + CURLOPT_TIMEOUT => 80, |
|
127 | + CURLOPT_FOLLOWLOCATION => true, |
|
128 | + CURLOPT_SSL_VERIFYHOST => FALSE, |
|
129 | + CURLOPT_SSL_VERIFYPEER => FALSE, |
|
130 | + CURLOPT_HTTPHEADER => $headers |
|
131 | + ); |
|
132 | 132 | |
133 | - curl_setopt_array($ch, $curlOpts); |
|
133 | + curl_setopt_array($ch, $curlOpts); |
|
134 | 134 | |
135 | - if ($file!=null) { |
|
136 | - curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0); |
|
137 | - $fp=fopen($file, 'r'); |
|
138 | - curl_setopt($ch, CURLOPT_INFILE, $fp); |
|
139 | - curl_setopt($ch, CURLOPT_INFILESIZE, filesize($file)); |
|
140 | - } |
|
135 | + if ($file!=null) { |
|
136 | + curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0); |
|
137 | + $fp=fopen($file, 'r'); |
|
138 | + curl_setopt($ch, CURLOPT_INFILE, $fp); |
|
139 | + curl_setopt($ch, CURLOPT_INFILESIZE, filesize($file)); |
|
140 | + } |
|
141 | 141 | |
142 | - switch ($method) { |
|
143 | - case 'DELETE': |
|
144 | - curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE"); |
|
145 | - break; |
|
146 | - case 'DELETEARRAY': |
|
147 | - curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE"); |
|
148 | - curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($query)); |
|
149 | - break; |
|
150 | - case 'PUT': |
|
151 | - curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT"); |
|
152 | - break; |
|
153 | - case 'POST': |
|
154 | - if (isset($body)) { |
|
155 | - $bodyData = json_encode($body); |
|
156 | - if (isset($options['HTTPHEADER'])) { |
|
157 | - if (strpos($options['HTTPHEADER'], "multipart/form-data")>0) { |
|
158 | - $bodyData = $body; |
|
159 | - } |
|
160 | - } |
|
142 | + switch ($method) { |
|
143 | + case 'DELETE': |
|
144 | + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE"); |
|
145 | + break; |
|
146 | + case 'DELETEARRAY': |
|
147 | + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE"); |
|
148 | + curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($query)); |
|
149 | + break; |
|
150 | + case 'PUT': |
|
151 | + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT"); |
|
152 | + break; |
|
153 | + case 'POST': |
|
154 | + if (isset($body)) { |
|
155 | + $bodyData = json_encode($body); |
|
156 | + if (isset($options['HTTPHEADER'])) { |
|
157 | + if (strpos($options['HTTPHEADER'], "multipart/form-data")>0) { |
|
158 | + $bodyData = $body; |
|
159 | + } |
|
160 | + } |
|
161 | 161 | |
162 | - curl_setopt($ch, CURLOPT_POSTFIELDS, $bodyData); |
|
163 | - } |
|
164 | - break; |
|
165 | - case 'ADD': |
|
166 | - curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($query)); break; |
|
167 | - } |
|
162 | + curl_setopt($ch, CURLOPT_POSTFIELDS, $bodyData); |
|
163 | + } |
|
164 | + break; |
|
165 | + case 'ADD': |
|
166 | + curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($query)); break; |
|
167 | + } |
|
168 | 168 | |
169 | - if (is_numeric(array_search($method, array('DELETE', 'PUT')))) { |
|
170 | - if (isset($body)) { |
|
171 | - curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($body)); |
|
172 | - } |
|
173 | - } |
|
169 | + if (is_numeric(array_search($method, array('DELETE', 'PUT')))) { |
|
170 | + if (isset($body)) { |
|
171 | + curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($body)); |
|
172 | + } |
|
173 | + } |
|
174 | 174 | |
175 | - $result = curl_exec($ch); |
|
175 | + $result = curl_exec($ch); |
|
176 | 176 | |
177 | - $isxml = FALSE; |
|
178 | - $jxml = ""; |
|
179 | - if (strpos($result, '<?xml')>-1) { |
|
180 | - $xml = simplexml_load_string($result); |
|
181 | - //$jxml = json_encode($xml); |
|
182 | - $jxml = self::object2array($xml); |
|
183 | - $isxml = TRUE; |
|
184 | - } |
|
177 | + $isxml = FALSE; |
|
178 | + $jxml = ""; |
|
179 | + if (strpos($result, '<?xml')>-1) { |
|
180 | + $xml = simplexml_load_string($result); |
|
181 | + //$jxml = json_encode($xml); |
|
182 | + $jxml = self::object2array($xml); |
|
183 | + $isxml = TRUE; |
|
184 | + } |
|
185 | 185 | |
186 | - $code = curl_getinfo($ch, CURLINFO_HTTP_CODE); |
|
187 | - curl_close($ch); |
|
186 | + $code = curl_getinfo($ch, CURLINFO_HTTP_CODE); |
|
187 | + curl_close($ch); |
|
188 | 188 | |
189 | - if (200==$code) { |
|
190 | - if ($isxml) { |
|
191 | - $json = $jxml; |
|
192 | - } else { |
|
193 | - $json = json_decode($result, true); |
|
194 | - } |
|
189 | + if (200==$code) { |
|
190 | + if ($isxml) { |
|
191 | + $json = $jxml; |
|
192 | + } else { |
|
193 | + $json = json_decode($result, true); |
|
194 | + } |
|
195 | 195 | |
196 | - if (isset($json['errors'])) { |
|
197 | - throw new ApiError(implode(', ', $json['errors'])); |
|
198 | - } else { |
|
199 | - return $json; |
|
200 | - } |
|
201 | - } elseif (409==$code) { |
|
202 | - throw new ApiError('Wrong API key'); |
|
203 | - } else { |
|
204 | - throw new ApiError('Something wrong'); |
|
205 | - } |
|
206 | - } |
|
196 | + if (isset($json['errors'])) { |
|
197 | + throw new ApiError(implode(', ', $json['errors'])); |
|
198 | + } else { |
|
199 | + return $json; |
|
200 | + } |
|
201 | + } elseif (409==$code) { |
|
202 | + throw new ApiError('Wrong API key'); |
|
203 | + } else { |
|
204 | + throw new ApiError('Something wrong'); |
|
205 | + } |
|
206 | + } |
|
207 | 207 | |
208 | - /** |
|
209 | - * @param $object: JSON object |
|
210 | - */ |
|
211 | - public static function object2array($object) |
|
212 | - { |
|
213 | - return @json_decode(@json_encode($object), 1); |
|
214 | - } |
|
208 | + /** |
|
209 | + * @param $object: JSON object |
|
210 | + */ |
|
211 | + public static function object2array($object) |
|
212 | + { |
|
213 | + return @json_decode(@json_encode($object), 1); |
|
214 | + } |
|
215 | 215 | |
216 | - public static function makeUrlRequst($url, $options) { |
|
217 | - $method = isset($options['method']) ? $options['method'] : 'GET'; |
|
218 | - $query = isset($options['query']) ? |
|
219 | - array_filter($options['query'], function($x) { return !is_null($x); } ) : array(); |
|
220 | - $body = isset($options['body']) ? $options['body'] : null; |
|
221 | - $ch = curl_init(); |
|
216 | + public static function makeUrlRequst($url, $options) { |
|
217 | + $method = isset($options['method']) ? $options['method'] : 'GET'; |
|
218 | + $query = isset($options['query']) ? |
|
219 | + array_filter($options['query'], function($x) { return !is_null($x); } ) : array(); |
|
220 | + $body = isset($options['body']) ? $options['body'] : null; |
|
221 | + $ch = curl_init(); |
|
222 | 222 | |
223 | - $curlOpts = arraY( |
|
224 | - CURLOPT_URL => $url, |
|
225 | - CURLOPT_RETURNTRANSFER => true, |
|
226 | - CURLOPT_TIMEOUT => 60, |
|
227 | - CURLOPT_FOLLOWLOCATION => true, |
|
228 | - CURLOPT_SSL_VERIFYHOST => FALSE, |
|
229 | - CURLOPT_SSL_VERIFYPEER => FALSE, |
|
230 | - CURLOPT_HTTPHEADER => array( |
|
231 | - 'User-Agent' => 'Route4Me php-sdk' |
|
232 | - ) |
|
233 | - ); |
|
223 | + $curlOpts = arraY( |
|
224 | + CURLOPT_URL => $url, |
|
225 | + CURLOPT_RETURNTRANSFER => true, |
|
226 | + CURLOPT_TIMEOUT => 60, |
|
227 | + CURLOPT_FOLLOWLOCATION => true, |
|
228 | + CURLOPT_SSL_VERIFYHOST => FALSE, |
|
229 | + CURLOPT_SSL_VERIFYPEER => FALSE, |
|
230 | + CURLOPT_HTTPHEADER => array( |
|
231 | + 'User-Agent' => 'Route4Me php-sdk' |
|
232 | + ) |
|
233 | + ); |
|
234 | 234 | |
235 | - curl_setopt_array($ch, $curlOpts); |
|
235 | + curl_setopt_array($ch, $curlOpts); |
|
236 | 236 | |
237 | - switch ($method) { |
|
238 | - case 'DELETE': |
|
239 | - curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE"); |
|
240 | - break; |
|
241 | - case 'DELETEARRAY': |
|
242 | - curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE"); |
|
243 | - curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($query)); |
|
244 | - break; |
|
245 | - case 'PUT': |
|
246 | - curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT"); |
|
247 | - break; |
|
248 | - case 'POST': |
|
249 | - curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); |
|
250 | - break; |
|
251 | - case 'ADD': |
|
252 | - curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($query)); break; |
|
253 | - } |
|
237 | + switch ($method) { |
|
238 | + case 'DELETE': |
|
239 | + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE"); |
|
240 | + break; |
|
241 | + case 'DELETEARRAY': |
|
242 | + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE"); |
|
243 | + curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($query)); |
|
244 | + break; |
|
245 | + case 'PUT': |
|
246 | + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT"); |
|
247 | + break; |
|
248 | + case 'POST': |
|
249 | + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); |
|
250 | + break; |
|
251 | + case 'ADD': |
|
252 | + curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($query)); break; |
|
253 | + } |
|
254 | 254 | |
255 | - if (is_numeric(array_search($method, array('DELETE', 'PUT', 'POST')))) { |
|
256 | - if (isset($body)) { |
|
257 | - curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($body)); |
|
258 | - } |
|
259 | - } |
|
255 | + if (is_numeric(array_search($method, array('DELETE', 'PUT', 'POST')))) { |
|
256 | + if (isset($body)) { |
|
257 | + curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($body)); |
|
258 | + } |
|
259 | + } |
|
260 | 260 | |
261 | - $result = curl_exec($ch); |
|
261 | + $result = curl_exec($ch); |
|
262 | 262 | |
263 | - $isxml = FALSE; |
|
264 | - $jxml = ""; |
|
263 | + $isxml = FALSE; |
|
264 | + $jxml = ""; |
|
265 | 265 | |
266 | - if (strpos($result, '<?xml')>-1) { |
|
267 | - $xml = simplexml_load_string($result); |
|
268 | - $jxml = json_encode($xml); |
|
269 | - $isxml = TRUE; |
|
270 | - } |
|
266 | + if (strpos($result, '<?xml')>-1) { |
|
267 | + $xml = simplexml_load_string($result); |
|
268 | + $jxml = json_encode($xml); |
|
269 | + $isxml = TRUE; |
|
270 | + } |
|
271 | 271 | |
272 | - $code = curl_getinfo($ch, CURLINFO_HTTP_CODE); |
|
273 | - curl_close($ch); |
|
272 | + $code = curl_getinfo($ch, CURLINFO_HTTP_CODE); |
|
273 | + curl_close($ch); |
|
274 | 274 | |
275 | - if ($isxml) { |
|
276 | - $json = $jxml; |
|
277 | - } else { |
|
278 | - $json = json_decode($result, true); |
|
279 | - } |
|
275 | + if ($isxml) { |
|
276 | + $json = $jxml; |
|
277 | + } else { |
|
278 | + $json = json_decode($result, true); |
|
279 | + } |
|
280 | 280 | |
281 | - if (200==$code) { |
|
282 | - return $json; |
|
283 | - } elseif (isset($json['errors'])) { |
|
284 | - throw new ApiError(implode(', ', $json['errors'])); |
|
285 | - } else { |
|
286 | - throw new ApiError('Something wrong'); |
|
287 | - } |
|
288 | - } |
|
281 | + if (200==$code) { |
|
282 | + return $json; |
|
283 | + } elseif (isset($json['errors'])) { |
|
284 | + throw new ApiError(implode(', ', $json['errors'])); |
|
285 | + } else { |
|
286 | + throw new ApiError('Something wrong'); |
|
287 | + } |
|
288 | + } |
|
289 | 289 | |
290 | - /** |
|
291 | - * Prints on the screen main keys and values of the array |
|
292 | - * @param $results: object to be printed on the screen. |
|
293 | - * @param $deepPrinting: if true, object will be printed recursively. |
|
294 | - */ |
|
295 | - public static function simplePrint($results, $deepPrinting = null) |
|
296 | - { |
|
297 | - if (isset($results)) { |
|
298 | - if (is_array($results)) { |
|
299 | - foreach ($results as $key=>$result) { |
|
300 | - if (is_array($result)) { |
|
301 | - foreach ($result as $key1=>$result1) { |
|
302 | - if (is_array($result1)) { |
|
303 | - if ($deepPrinting) { |
|
304 | - echo "<br>$key1 ------><br>"; |
|
305 | - Route4Me::simplePrint($result1, true); |
|
306 | - echo "------<br>"; |
|
307 | - } else { |
|
308 | - echo $key1." --> "."Array() <br>"; |
|
309 | - } |
|
310 | - } else { |
|
311 | - if (is_object($result1)) { |
|
312 | - if ($deepPrinting) { |
|
313 | - echo "<br>$key1 ------><br>"; |
|
314 | - $oarray = (array)$result1; |
|
315 | - Route4Me::simplePrint($oarray, true); |
|
316 | - echo "------<br>"; |
|
317 | - } else { |
|
318 | - echo $key1." --> "."Object <br>"; |
|
319 | - } |
|
320 | - } else { |
|
321 | - if (!is_null($result1)) { |
|
322 | - echo $key1." --> ".$result1."<br>"; |
|
323 | - } |
|
324 | - } |
|
325 | - } |
|
326 | - } |
|
327 | - } else { |
|
328 | - if (is_object($result)) { |
|
329 | - if ($deepPrinting) { |
|
330 | - echo "<br>$key ------><br>"; |
|
331 | - $oarray = (array)$result; |
|
332 | - Route4Me::simplePrint($oarray, true); |
|
333 | - echo "------<br>"; |
|
334 | - } else { |
|
335 | - echo $key." --> "."Object <br>"; |
|
336 | - } |
|
337 | - } else { |
|
338 | - if (!is_null($result)) { |
|
339 | - echo $key." --> ".$result."<br>"; |
|
340 | - } |
|
341 | - } |
|
290 | + /** |
|
291 | + * Prints on the screen main keys and values of the array |
|
292 | + * @param $results: object to be printed on the screen. |
|
293 | + * @param $deepPrinting: if true, object will be printed recursively. |
|
294 | + */ |
|
295 | + public static function simplePrint($results, $deepPrinting = null) |
|
296 | + { |
|
297 | + if (isset($results)) { |
|
298 | + if (is_array($results)) { |
|
299 | + foreach ($results as $key=>$result) { |
|
300 | + if (is_array($result)) { |
|
301 | + foreach ($result as $key1=>$result1) { |
|
302 | + if (is_array($result1)) { |
|
303 | + if ($deepPrinting) { |
|
304 | + echo "<br>$key1 ------><br>"; |
|
305 | + Route4Me::simplePrint($result1, true); |
|
306 | + echo "------<br>"; |
|
307 | + } else { |
|
308 | + echo $key1." --> "."Array() <br>"; |
|
309 | + } |
|
310 | + } else { |
|
311 | + if (is_object($result1)) { |
|
312 | + if ($deepPrinting) { |
|
313 | + echo "<br>$key1 ------><br>"; |
|
314 | + $oarray = (array)$result1; |
|
315 | + Route4Me::simplePrint($oarray, true); |
|
316 | + echo "------<br>"; |
|
317 | + } else { |
|
318 | + echo $key1." --> "."Object <br>"; |
|
319 | + } |
|
320 | + } else { |
|
321 | + if (!is_null($result1)) { |
|
322 | + echo $key1." --> ".$result1."<br>"; |
|
323 | + } |
|
324 | + } |
|
325 | + } |
|
326 | + } |
|
327 | + } else { |
|
328 | + if (is_object($result)) { |
|
329 | + if ($deepPrinting) { |
|
330 | + echo "<br>$key ------><br>"; |
|
331 | + $oarray = (array)$result; |
|
332 | + Route4Me::simplePrint($oarray, true); |
|
333 | + echo "------<br>"; |
|
334 | + } else { |
|
335 | + echo $key." --> "."Object <br>"; |
|
336 | + } |
|
337 | + } else { |
|
338 | + if (!is_null($result)) { |
|
339 | + echo $key." --> ".$result."<br>"; |
|
340 | + } |
|
341 | + } |
|
342 | 342 | |
343 | - } |
|
344 | - //echo "<br>"; |
|
345 | - } |
|
346 | - } |
|
347 | - } |
|
348 | - } |
|
343 | + } |
|
344 | + //echo "<br>"; |
|
345 | + } |
|
346 | + } |
|
347 | + } |
|
348 | + } |
|
349 | 349 | |
350 | - /** |
|
351 | - * Generates query or body parameters. |
|
352 | - * @param $allFields: all known fields could be used for parameters generation. |
|
353 | - * @param $params: input parameters (array or object) |
|
354 | - */ |
|
355 | - public static function generateRequestParameters($allFields, $params) |
|
356 | - { |
|
357 | - $generatedParams = array(); |
|
350 | + /** |
|
351 | + * Generates query or body parameters. |
|
352 | + * @param $allFields: all known fields could be used for parameters generation. |
|
353 | + * @param $params: input parameters (array or object) |
|
354 | + */ |
|
355 | + public static function generateRequestParameters($allFields, $params) |
|
356 | + { |
|
357 | + $generatedParams = array(); |
|
358 | 358 | |
359 | - if (is_array($params)) { |
|
360 | - foreach ($allFields as $field) { |
|
361 | - if (isset($params[$field])) { |
|
362 | - $generatedParams[$field] = $params[$field]; |
|
363 | - } |
|
364 | - } |
|
365 | - } elseif (is_object($params)) { |
|
366 | - foreach ($allFields as $field) { |
|
367 | - if (isset($params->{$field})) { |
|
368 | - $generatedParams[$field] = $params->{$field}; |
|
369 | - } |
|
370 | - } |
|
371 | - } |
|
359 | + if (is_array($params)) { |
|
360 | + foreach ($allFields as $field) { |
|
361 | + if (isset($params[$field])) { |
|
362 | + $generatedParams[$field] = $params[$field]; |
|
363 | + } |
|
364 | + } |
|
365 | + } elseif (is_object($params)) { |
|
366 | + foreach ($allFields as $field) { |
|
367 | + if (isset($params->{$field})) { |
|
368 | + $generatedParams[$field] = $params->{$field}; |
|
369 | + } |
|
370 | + } |
|
371 | + } |
|
372 | 372 | |
373 | - return $generatedParams; |
|
374 | - } |
|
373 | + return $generatedParams; |
|
374 | + } |
|
375 | 375 | |
376 | - /** |
|
377 | - * Returns an array of the object properties |
|
378 | - * @param $object: An object. |
|
379 | - * @param $exclude: array of the object parameters to be excluded from the returned array. |
|
380 | - */ |
|
381 | - public static function getObjectProperties($object, $exclude) |
|
382 | - { |
|
383 | - $objectParameters = array(); |
|
376 | + /** |
|
377 | + * Returns an array of the object properties |
|
378 | + * @param $object: An object. |
|
379 | + * @param $exclude: array of the object parameters to be excluded from the returned array. |
|
380 | + */ |
|
381 | + public static function getObjectProperties($object, $exclude) |
|
382 | + { |
|
383 | + $objectParameters = array(); |
|
384 | 384 | |
385 | - foreach (get_object_vars($object) as $key => $value) { |
|
386 | - if (property_exists($object, $key)) { |
|
387 | - if (!is_numeric(array_search($key, $exclude))) { |
|
388 | - array_push($objectParameters, $key); |
|
389 | - } |
|
390 | - } |
|
391 | - } |
|
385 | + foreach (get_object_vars($object) as $key => $value) { |
|
386 | + if (property_exists($object, $key)) { |
|
387 | + if (!is_numeric(array_search($key, $exclude))) { |
|
388 | + array_push($objectParameters, $key); |
|
389 | + } |
|
390 | + } |
|
391 | + } |
|
392 | 392 | |
393 | - return $objectParameters; |
|
394 | - } |
|
393 | + return $objectParameters; |
|
394 | + } |
|
395 | 395 | |
396 | - /** |
|
397 | - * Returns url path generated from the array of the fields and parameters. |
|
398 | - * @param $allFields; array of the paossible fields (parameter names). |
|
399 | - * @param $params: input parameters (array or object). |
|
400 | - */ |
|
401 | - public static function generateUrlPath($allFields, $params) |
|
402 | - { |
|
403 | - $generatedPath = ""; |
|
396 | + /** |
|
397 | + * Returns url path generated from the array of the fields and parameters. |
|
398 | + * @param $allFields; array of the paossible fields (parameter names). |
|
399 | + * @param $params: input parameters (array or object). |
|
400 | + */ |
|
401 | + public static function generateUrlPath($allFields, $params) |
|
402 | + { |
|
403 | + $generatedPath = ""; |
|
404 | 404 | |
405 | - if (is_array($params)) { |
|
406 | - foreach ($allFields as $field) { |
|
407 | - if (isset($params[$field])) { |
|
408 | - $generatedPath .= $params[$field].'/'; |
|
409 | - } |
|
410 | - } |
|
411 | - } elseif (is_object($params)) { |
|
412 | - foreach ($allFields as $field) { |
|
413 | - if (isset($params->{$field})) { |
|
414 | - $generatedPath .= $params->{$field}.'/'; |
|
415 | - } |
|
416 | - } |
|
417 | - } |
|
405 | + if (is_array($params)) { |
|
406 | + foreach ($allFields as $field) { |
|
407 | + if (isset($params[$field])) { |
|
408 | + $generatedPath .= $params[$field].'/'; |
|
409 | + } |
|
410 | + } |
|
411 | + } elseif (is_object($params)) { |
|
412 | + foreach ($allFields as $field) { |
|
413 | + if (isset($params->{$field})) { |
|
414 | + $generatedPath .= $params->{$field}.'/'; |
|
415 | + } |
|
416 | + } |
|
417 | + } |
|
418 | 418 | |
419 | - return $generatedPath; |
|
420 | - } |
|
419 | + return $generatedPath; |
|
420 | + } |
|
421 | 421 | } |
@@ -6,106 +6,106 @@ |
||
6 | 6 | |
7 | 7 | class Geocoding extends Common |
8 | 8 | { |
9 | - public $strExportFormat; |
|
10 | - public $format; |
|
11 | - public $addresses; |
|
12 | - public $pk; |
|
13 | - public $offset; |
|
14 | - public $limit; |
|
15 | - public $housenumber; |
|
16 | - public $zipcode; |
|
9 | + public $strExportFormat; |
|
10 | + public $format; |
|
11 | + public $addresses; |
|
12 | + public $pk; |
|
13 | + public $offset; |
|
14 | + public $limit; |
|
15 | + public $housenumber; |
|
16 | + public $zipcode; |
|
17 | 17 | |
18 | - public static function fromArray(array $params) |
|
19 | - { |
|
20 | - $geocoding = new Geocoding(); |
|
18 | + public static function fromArray(array $params) |
|
19 | + { |
|
20 | + $geocoding = new Geocoding(); |
|
21 | 21 | |
22 | - foreach($params as $key => $value) { |
|
23 | - if (property_exists($geocoding, $key)) { |
|
24 | - $geocoding->{$key} = $value; |
|
25 | - } |
|
26 | - } |
|
22 | + foreach($params as $key => $value) { |
|
23 | + if (property_exists($geocoding, $key)) { |
|
24 | + $geocoding->{$key} = $value; |
|
25 | + } |
|
26 | + } |
|
27 | 27 | |
28 | - return $geocoding; |
|
29 | - } |
|
28 | + return $geocoding; |
|
29 | + } |
|
30 | 30 | |
31 | - public static function forwardGeocoding($params) |
|
32 | - { |
|
33 | - $allBodyFields = array('strExportFormat', 'addresses'); |
|
31 | + public static function forwardGeocoding($params) |
|
32 | + { |
|
33 | + $allBodyFields = array('strExportFormat', 'addresses'); |
|
34 | 34 | |
35 | - $fgCoding = Route4Me::makeRequst(array( |
|
36 | - 'url' => Endpoint::GEOCODER, |
|
37 | - 'method' => 'POST', |
|
38 | - 'body' => Route4Me::generateRequestParameters($allBodyFields, $params), |
|
39 | - 'HTTPHEADER' => 'Content-Type: multipart/form-data' |
|
40 | - )); |
|
35 | + $fgCoding = Route4Me::makeRequst(array( |
|
36 | + 'url' => Endpoint::GEOCODER, |
|
37 | + 'method' => 'POST', |
|
38 | + 'body' => Route4Me::generateRequestParameters($allBodyFields, $params), |
|
39 | + 'HTTPHEADER' => 'Content-Type: multipart/form-data' |
|
40 | + )); |
|
41 | 41 | |
42 | - return $fgCoding; |
|
43 | - } |
|
42 | + return $fgCoding; |
|
43 | + } |
|
44 | 44 | |
45 | - public static function reverseGeocoding($params) |
|
46 | - { |
|
47 | - $allQueryFields = array('format', 'addresses', 'detailed'); |
|
45 | + public static function reverseGeocoding($params) |
|
46 | + { |
|
47 | + $allQueryFields = array('format', 'addresses', 'detailed'); |
|
48 | 48 | |
49 | - $fgcoding = Route4Me::makeRequst(array( |
|
50 | - 'url' => Endpoint::GEOCODER, |
|
51 | - 'method' => 'POST', |
|
52 | - 'query' => Route4Me::generateRequestParameters($allQueryFields, $params) |
|
53 | - )); |
|
49 | + $fgcoding = Route4Me::makeRequst(array( |
|
50 | + 'url' => Endpoint::GEOCODER, |
|
51 | + 'method' => 'POST', |
|
52 | + 'query' => Route4Me::generateRequestParameters($allQueryFields, $params) |
|
53 | + )); |
|
54 | 54 | |
55 | - return $fgcoding; |
|
56 | - } |
|
55 | + return $fgcoding; |
|
56 | + } |
|
57 | 57 | |
58 | - public static function getStreetData($params) |
|
59 | - { |
|
60 | - $url_query = Endpoint::STREET_DATA; |
|
58 | + public static function getStreetData($params) |
|
59 | + { |
|
60 | + $url_query = Endpoint::STREET_DATA; |
|
61 | 61 | |
62 | - $allPathFields = array('pk', 'offset', 'limit'); |
|
62 | + $allPathFields = array('pk', 'offset', 'limit'); |
|
63 | 63 | |
64 | - $url_query .= Route4Me::generateUrlPath($allPathFields, $params); |
|
64 | + $url_query .= Route4Me::generateUrlPath($allPathFields, $params); |
|
65 | 65 | |
66 | - $query = array(); |
|
66 | + $query = array(); |
|
67 | 67 | |
68 | - $response = Route4Me::makeUrlRequst($url_query, array( |
|
69 | - 'method' => 'GET', |
|
70 | - 'query' => $query |
|
71 | - )); |
|
68 | + $response = Route4Me::makeUrlRequst($url_query, array( |
|
69 | + 'method' => 'GET', |
|
70 | + 'query' => $query |
|
71 | + )); |
|
72 | 72 | |
73 | - return $response; |
|
74 | - } |
|
73 | + return $response; |
|
74 | + } |
|
75 | 75 | |
76 | - public static function getZipCode($params) |
|
77 | - { |
|
78 | - $url_query = Endpoint::STREET_DATA_ZIPCODE; |
|
76 | + public static function getZipCode($params) |
|
77 | + { |
|
78 | + $url_query = Endpoint::STREET_DATA_ZIPCODE; |
|
79 | 79 | |
80 | - $allPathFields = array('zipcode', 'offset', 'limit'); |
|
80 | + $allPathFields = array('zipcode', 'offset', 'limit'); |
|
81 | 81 | |
82 | - $url_query .= Route4Me::generateUrlPath($allPathFields, $params); |
|
82 | + $url_query .= Route4Me::generateUrlPath($allPathFields, $params); |
|
83 | 83 | |
84 | - $query = array(); |
|
84 | + $query = array(); |
|
85 | 85 | |
86 | - $response = Route4Me::makeUrlRequst($url_query, array( |
|
87 | - 'method' => 'GET', |
|
88 | - 'query' => $query |
|
89 | - )); |
|
86 | + $response = Route4Me::makeUrlRequst($url_query, array( |
|
87 | + 'method' => 'GET', |
|
88 | + 'query' => $query |
|
89 | + )); |
|
90 | 90 | |
91 | - return $response; |
|
92 | - } |
|
91 | + return $response; |
|
92 | + } |
|
93 | 93 | |
94 | - public static function getService($params) |
|
95 | - { |
|
96 | - $url_query = Endpoint::STREET_DATA_SERVICE; |
|
94 | + public static function getService($params) |
|
95 | + { |
|
96 | + $url_query = Endpoint::STREET_DATA_SERVICE; |
|
97 | 97 | |
98 | - $allPathFields = array('zipcode', 'housenumber', 'offset', 'limit'); |
|
98 | + $allPathFields = array('zipcode', 'housenumber', 'offset', 'limit'); |
|
99 | 99 | |
100 | - $url_query .= Route4Me::generateUrlPath($allPathFields, $params); |
|
100 | + $url_query .= Route4Me::generateUrlPath($allPathFields, $params); |
|
101 | 101 | |
102 | - $query = array(); |
|
102 | + $query = array(); |
|
103 | 103 | |
104 | - $response = Route4Me::makeUrlRequst($url_query, array( |
|
105 | - 'method' => 'GET', |
|
106 | - 'query' => $query |
|
107 | - )); |
|
104 | + $response = Route4Me::makeUrlRequst($url_query, array( |
|
105 | + 'method' => 'GET', |
|
106 | + 'query' => $query |
|
107 | + )); |
|
108 | 108 | |
109 | - return $response; |
|
110 | - } |
|
109 | + return $response; |
|
110 | + } |
|
111 | 111 | } |