1 | <?php namespace Arcanedev\GeoLocation\Google; |
||
13 | abstract class AbstractWebService |
||
14 | { |
||
15 | /* ----------------------------------------------------------------- |
||
16 | | Properties |
||
17 | | ----------------------------------------------------------------- |
||
18 | */ |
||
19 | |||
20 | /** @var \GuzzleHttp\ClientInterface */ |
||
21 | protected $client; |
||
22 | |||
23 | /** @var string|null */ |
||
24 | protected $key = null; |
||
25 | |||
26 | /* ----------------------------------------------------------------- |
||
27 | | Constructor |
||
28 | | ----------------------------------------------------------------- |
||
29 | */ |
||
30 | |||
31 | /** |
||
32 | * GoogleDistanceMatrix constructor. |
||
33 | * |
||
34 | * @param \GuzzleHttp\ClientInterface $client |
||
35 | */ |
||
36 | 30 | public function __construct(ClientInterface $client) |
|
40 | |||
41 | /* ----------------------------------------------------------------- |
||
42 | | Getters & Setters |
||
43 | | ----------------------------------------------------------------- |
||
44 | */ |
||
45 | |||
46 | /** |
||
47 | * Set the HTTP Client. |
||
48 | * |
||
49 | * @param \GuzzleHttp\ClientInterface $client |
||
50 | * |
||
51 | * @return self |
||
52 | */ |
||
53 | 30 | public function setHttpClient(ClientInterface $client) |
|
59 | |||
60 | /** |
||
61 | * Set the API Key. |
||
62 | * |
||
63 | * @param string $key |
||
64 | * |
||
65 | * @return self |
||
66 | */ |
||
67 | 30 | public function setKey($key) |
|
73 | |||
74 | /* ----------------------------------------------------------------- |
||
75 | | Common Methods |
||
76 | | ----------------------------------------------------------------- |
||
77 | */ |
||
78 | |||
79 | /** |
||
80 | * Make a GET request. |
||
81 | * |
||
82 | * @param string $url |
||
83 | * @param array $options |
||
84 | * |
||
85 | * @return mixed |
||
86 | */ |
||
87 | 18 | protected function get($url, array $options) |
|
93 | |||
94 | /** |
||
95 | * Prepare the URL query. |
||
96 | * |
||
97 | * @param array $params |
||
98 | * |
||
99 | * @return string |
||
100 | */ |
||
101 | 18 | protected function prepareQuery(array $params) |
|
107 | |||
108 | /** |
||
109 | * Get the default query params. |
||
110 | * |
||
111 | * @return array |
||
112 | */ |
||
113 | abstract protected function getDefaultQueryParams(); |
||
114 | |||
115 | /** |
||
116 | * Prepare the response. |
||
117 | * |
||
118 | * @param \Psr\Http\Message\ResponseInterface $response |
||
119 | * |
||
120 | * @return mixed |
||
121 | */ |
||
122 | abstract protected function prepareResponse(ResponseInterface $response); |
||
123 | |||
124 | /** |
||
125 | * Parse the position object for the query. |
||
126 | * |
||
127 | * @param \Arcanedev\GeoLocation\Contracts\Entities\Position $position |
||
128 | * |
||
129 | * @return string |
||
130 | */ |
||
131 | 15 | protected function parsePosition(Position $position) |
|
135 | } |
||
136 |