1 | <?php namespace Arcanedev\GeoLocation\Google; |
||
14 | abstract class AbstractService |
||
15 | { |
||
16 | /* ----------------------------------------------------------------- |
||
17 | | Properties |
||
18 | | ----------------------------------------------------------------- |
||
19 | */ |
||
20 | |||
21 | /** @var \GuzzleHttp\ClientInterface */ |
||
22 | protected $client; |
||
23 | |||
24 | /** @var string|null */ |
||
25 | protected $key = null; |
||
26 | |||
27 | /* ----------------------------------------------------------------- |
||
28 | | Constructor |
||
29 | | ----------------------------------------------------------------- |
||
30 | */ |
||
31 | |||
32 | /** |
||
33 | * GoogleDistanceMatrix constructor. |
||
34 | * |
||
35 | * @param \GuzzleHttp\ClientInterface $client |
||
36 | * @param array $options |
||
37 | */ |
||
38 | 57 | public function __construct(ClientInterface $client, array $options = []) |
|
43 | |||
44 | /* ----------------------------------------------------------------- |
||
45 | | Getters & Setters |
||
46 | | ----------------------------------------------------------------- |
||
47 | */ |
||
48 | |||
49 | /** |
||
50 | * Set the HTTP Client. |
||
51 | * |
||
52 | * @param \GuzzleHttp\ClientInterface $client |
||
53 | * |
||
54 | * @return self |
||
55 | */ |
||
56 | 57 | public function setHttpClient(ClientInterface $client) |
|
62 | |||
63 | /** |
||
64 | * Set the options. |
||
65 | * |
||
66 | * @param array $options |
||
67 | */ |
||
68 | 57 | protected function setOptions(array $options): void |
|
72 | |||
73 | /** |
||
74 | * Set the API Key. |
||
75 | * |
||
76 | * @param string $key |
||
77 | * |
||
78 | * @return self |
||
79 | */ |
||
80 | 57 | public function setKey($key) |
|
86 | |||
87 | /* ----------------------------------------------------------------- |
||
88 | | Common Methods |
||
89 | | ----------------------------------------------------------------- |
||
90 | */ |
||
91 | |||
92 | /** |
||
93 | * Make a GET request. |
||
94 | * |
||
95 | * @param string $url |
||
96 | * @param array $options |
||
97 | * |
||
98 | * @return mixed |
||
99 | */ |
||
100 | 39 | protected function get($url, array $options) |
|
106 | |||
107 | /** |
||
108 | * Prepare the URL query. |
||
109 | * |
||
110 | * @param array $params |
||
111 | * |
||
112 | * @return string |
||
113 | */ |
||
114 | 39 | protected function prepareQuery(array $params) |
|
122 | |||
123 | /** |
||
124 | * Get the default query params. |
||
125 | * |
||
126 | * @return array |
||
127 | */ |
||
128 | 39 | protected function getDefaultQueryParams() |
|
134 | |||
135 | /** |
||
136 | * Prepare the response. |
||
137 | * |
||
138 | * @param \Psr\Http\Message\ResponseInterface $response |
||
139 | * |
||
140 | * @return \Arcanedev\GeoLocation\Google\AbstractResponse |
||
141 | */ |
||
142 | abstract protected function prepareResponse(ResponseInterface $response); |
||
143 | |||
144 | /** |
||
145 | * Parse the position object for the query. |
||
146 | * |
||
147 | * @param \Arcanedev\GeoLocation\Contracts\Entities\Coordinates\Position $position |
||
148 | * |
||
149 | * @return string |
||
150 | */ |
||
151 | 24 | protected function parsePosition(Position $position) |
|
155 | } |
||
156 |