1 | <?php |
||
18 | class Geo6 |
||
19 | { |
||
20 | // URL for the api |
||
21 | const API_URL = 'https://taxipost.geo6.be/Locator'; |
||
22 | |||
23 | // current version |
||
24 | const VERSION = '3'; |
||
25 | |||
26 | /** |
||
27 | * @see getPointType |
||
28 | * @see getServicePointPageUrl |
||
29 | */ |
||
30 | const POINT_TYPE_POST_OFFICE = 1; |
||
31 | const POINT_TYPE_POST_POINT = 2; |
||
32 | const POINT_TYPE_BPACK_247 = 4; |
||
33 | const POINT_TYPE_CLICK_COLLECT_SHOP = 8; |
||
34 | |||
35 | /** @var ApiCaller */ |
||
36 | private $apiCaller; |
||
37 | |||
38 | /** |
||
39 | * @var string |
||
40 | */ |
||
41 | private $appId; |
||
42 | |||
43 | /** |
||
44 | * @var string |
||
45 | */ |
||
46 | private $partner; |
||
47 | |||
48 | /** |
||
49 | * The timeout |
||
50 | * |
||
51 | * @var int |
||
52 | */ |
||
53 | private $timeOut = 10; |
||
54 | |||
55 | /** |
||
56 | * The user agent |
||
57 | * |
||
58 | * @var string |
||
59 | */ |
||
60 | private $userAgent; |
||
61 | |||
62 | /** |
||
63 | * Constructor |
||
64 | * @param string $partner Static parameter used for protection/statistics |
||
65 | * @param string $appId Static parameter used for protection/statistics |
||
66 | */ |
||
67 | public function __construct($partner, $appId) |
||
72 | |||
73 | /** |
||
74 | * @return ApiCaller |
||
75 | */ |
||
76 | public function getApiCaller() |
||
77 | { |
||
78 | if ($this->apiCaller === null) { |
||
79 | $this->apiCaller = new ApiCaller(new Logger()); |
||
80 | } |
||
81 | return $this->apiCaller; |
||
82 | } |
||
83 | |||
84 | /** |
||
85 | * @param ApiCaller $apiCaller |
||
86 | */ |
||
87 | public function setApiCaller(ApiCaller $apiCaller) |
||
91 | |||
92 | /** |
||
93 | * Build the url to be called |
||
94 | * |
||
95 | * @param string $method |
||
96 | * @param array $parameters |
||
97 | * @return string |
||
98 | */ |
||
99 | private function buildUrl($method, array $parameters = array()) |
||
103 | |||
104 | /** |
||
105 | * Build the parameters to send (URL-encoded string) |
||
106 | * |
||
107 | * @param string $method |
||
108 | * @param array $parameters |
||
109 | * @return string |
||
110 | */ |
||
111 | private function buildParameters($method, array $parameters = array()) |
||
121 | |||
122 | /** |
||
123 | * Make the real call |
||
124 | * |
||
125 | * @param string $method |
||
126 | * @param array $parameters |
||
127 | * @return \SimpleXMLElement |
||
128 | * @throws BpostCurlException |
||
129 | * @throws BpostInvalidXmlResponseException |
||
130 | * @throws BpostTaxipostLocatorException |
||
131 | */ |
||
132 | private function doCall($method, array $parameters = array()) |
||
165 | |||
166 | /** |
||
167 | * @param string $appId |
||
168 | */ |
||
169 | public function setAppId($appId) |
||
170 | { |
||
171 | $this->appId = $appId; |
||
172 | } |
||
173 | |||
174 | /** |
||
175 | * @return string |
||
176 | */ |
||
177 | public function getAppId() |
||
178 | { |
||
179 | return $this->appId; |
||
180 | } |
||
181 | |||
182 | /** |
||
183 | * @param string $partner |
||
184 | */ |
||
185 | public function setPartner($partner) |
||
186 | { |
||
187 | $this->partner = $partner; |
||
188 | } |
||
189 | |||
190 | /** |
||
191 | * @return string |
||
192 | */ |
||
193 | public function getPartner() |
||
194 | { |
||
195 | return $this->partner; |
||
196 | } |
||
197 | |||
198 | /** |
||
199 | * Set the timeout |
||
200 | * After this time the request will stop. You should handle any errors triggered by this. |
||
201 | * |
||
202 | * @param int $seconds The timeout in seconds. |
||
203 | */ |
||
204 | public function setTimeOut($seconds) |
||
205 | { |
||
206 | $this->timeOut = (int)$seconds; |
||
207 | } |
||
208 | |||
209 | /** |
||
210 | * Get the timeout that will be used |
||
211 | * |
||
212 | * @return int |
||
213 | */ |
||
214 | public function getTimeOut() |
||
215 | { |
||
216 | return (int)$this->timeOut; |
||
217 | } |
||
218 | |||
219 | /** |
||
220 | * Get the useragent that will be used. |
||
221 | * Our version will be prepended to yours. |
||
222 | * It will look like: "PHP Bpost/<version> <your-user-agent>" |
||
223 | * |
||
224 | * @return string |
||
225 | */ |
||
226 | public function getUserAgent() |
||
227 | { |
||
228 | return (string)'PHP Bpost Geo6/' . self::VERSION . ' ' . $this->userAgent; |
||
229 | } |
||
230 | |||
231 | /** |
||
232 | * Set the user-agent for you application |
||
233 | * It will be appended to ours, the result will look like: "PHP Bpost/<version> <your-user-agent>" |
||
234 | * |
||
235 | * @param string $userAgent Your user-agent, it should look like <app-name>/<app-version>. |
||
236 | */ |
||
237 | public function setUserAgent($userAgent) |
||
238 | { |
||
239 | $this->userAgent = (string)$userAgent; |
||
240 | } |
||
241 | |||
242 | // webservice methods |
||
243 | /** |
||
244 | * The GetNearestServicePoints web service delivers the nearest bpost pick-up points to a location |
||
245 | * |
||
246 | * @param string $street Street name |
||
247 | * @param string $number Street number |
||
248 | * @param string $zone Postal code and/or city |
||
249 | * @param string $language Language, possible values are: nl, fr |
||
250 | * @param int $type Requested point type, possible values are: |
||
251 | * - 1: Post Office |
||
252 | * - 2: Post Point |
||
253 | * - 3: (1+2, Post Office + Post Point) |
||
254 | * - 4: bpack 24/7 |
||
255 | * - 7: (1+2+4, Post Office + Post Point + bpack 24/7) |
||
256 | * @param int $limit |
||
257 | * @return array |
||
258 | * @throws BpostCurlException |
||
259 | * @throws BpostInvalidXmlResponseException |
||
260 | * @throws BpostTaxipostLocatorException |
||
261 | */ |
||
262 | public function getNearestServicePoint($street, $number, $zone, $language = 'nl', $type = 3, $limit = 10) |
||
289 | |||
290 | /** |
||
291 | * The GetServicePointDetails web service delivers the details for a bpost |
||
292 | * pick up point referred to by its identifier. |
||
293 | * |
||
294 | * @param string $id Requested point identifier |
||
295 | * @param string $language Language, possible values: nl, fr |
||
296 | * @param int $type Requested point type, possible values are: |
||
297 | * - 1: Post Office |
||
298 | * - 2: Post Point |
||
299 | * - 4: bpack 24/7 |
||
300 | * |
||
301 | * @return Poi |
||
302 | * @throws BpostCurlException |
||
303 | * @throws BpostInvalidXmlResponseException |
||
304 | * @throws BpostTaxipostLocatorException |
||
305 | */ |
||
306 | public function getServicePointDetails($id, $language = 'nl', $type = 3) |
||
322 | |||
323 | /** |
||
324 | * @param int $id |
||
325 | * @param string $language |
||
326 | * @param int $type |
||
327 | * @return string |
||
328 | * |
||
329 | * @see getPointType to feed the param $type |
||
330 | */ |
||
331 | public function getServicePointPageUrl($id, $language = 'nl', $type = 3) |
||
341 | |||
342 | /** |
||
343 | * @param int $id |
||
344 | * @param string $language |
||
345 | * @param int $type |
||
346 | * @return string |
||
347 | * |
||
348 | * @deprecated Renamed |
||
349 | * @see getServicePointPageUrl |
||
350 | */ |
||
351 | public function getServicePointPage($id, $language = 'nl', $type = 3) |
||
355 | |||
356 | /** |
||
357 | * @param bool $withPostOffice |
||
358 | * @param bool $withPostPoint |
||
359 | * @param bool $withBpack247 |
||
360 | * @param bool $withClickAndCollectShop |
||
361 | * @return int |
||
362 | */ |
||
363 | public function getPointType( |
||
375 | } |
||
376 |