1 | <?php namespace Arcanedev\GeoLocation\Google; |
||
13 | abstract class AbstractService |
||
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 | 45 | 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 | 45 | public function setHttpClient(ClientInterface $client) |
|
59 | |||
60 | /** |
||
61 | * Set the API Key. |
||
62 | * |
||
63 | * @param string $key |
||
64 | * |
||
65 | * @return self |
||
66 | */ |
||
67 | 45 | 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 | 30 | protected function get($url, array $options) |
|
93 | |||
94 | /** |
||
95 | * Prepare the URL query. |
||
96 | * |
||
97 | * @param array $params |
||
98 | * |
||
99 | * @return string |
||
100 | */ |
||
101 | 30 | protected function prepareQuery(array $params) |
|
109 | |||
110 | /** |
||
111 | * Get the default query params. |
||
112 | * |
||
113 | * @return array |
||
114 | */ |
||
115 | abstract protected function getDefaultQueryParams(); |
||
116 | |||
117 | /** |
||
118 | * Prepare the response. |
||
119 | * |
||
120 | * @param \Psr\Http\Message\ResponseInterface $response |
||
121 | * |
||
122 | * @return \Arcanedev\GeoLocation\Google\AbstractResponse |
||
123 | */ |
||
124 | abstract protected function prepareResponse(ResponseInterface $response); |
||
125 | |||
126 | /** |
||
127 | * Parse the position object for the query. |
||
128 | * |
||
129 | * @param \Arcanedev\GeoLocation\Contracts\Entities\Coordinates\Position $position |
||
130 | * |
||
131 | * @return string |
||
132 | */ |
||
133 | 15 | protected function parsePosition(Position $position) |
|
137 | } |
||
138 |