1 | <?php namespace Stevenmaguire\Yelp; |
||
8 | class Client |
||
9 | { |
||
10 | /** |
||
11 | * API host url |
||
12 | * |
||
13 | * @var string |
||
14 | */ |
||
15 | protected $apiHost; |
||
16 | |||
17 | /** |
||
18 | * Consumer key |
||
19 | * |
||
20 | * @var string |
||
21 | */ |
||
22 | protected $consumerKey; |
||
23 | |||
24 | /** |
||
25 | * Consumer secret |
||
26 | * |
||
27 | * @var string |
||
28 | */ |
||
29 | protected $consumerSecret; |
||
30 | |||
31 | /** |
||
32 | * Access token |
||
33 | * |
||
34 | * @var string |
||
35 | */ |
||
36 | protected $token; |
||
37 | |||
38 | /** |
||
39 | * Access token secret |
||
40 | * |
||
41 | * @var string |
||
42 | */ |
||
43 | protected $tokenSecret; |
||
44 | |||
45 | /** |
||
46 | * Default search term |
||
47 | * |
||
48 | * @var string |
||
49 | */ |
||
50 | protected $defaultTerm = 'bar'; |
||
51 | |||
52 | /** |
||
53 | * Default location |
||
54 | * |
||
55 | * @var string |
||
56 | */ |
||
57 | protected $defaultLocation = 'Chicago, IL'; |
||
58 | |||
59 | /** |
||
60 | * Default search limit |
||
61 | * |
||
62 | * @var integer |
||
63 | */ |
||
64 | protected $searchLimit = 3; |
||
65 | |||
66 | /** |
||
67 | * Search path |
||
68 | * |
||
69 | * @var string |
||
70 | */ |
||
71 | protected $searchPath = '/v2/search/'; |
||
72 | |||
73 | /** |
||
74 | * Business path |
||
75 | * |
||
76 | * @var string |
||
77 | */ |
||
78 | protected $businessPath = '/v2/business/'; |
||
79 | |||
80 | /** |
||
81 | * Phone search path |
||
82 | * |
||
83 | * @var string |
||
84 | */ |
||
85 | protected $phoneSearchPath = '/v2/phone_search/'; |
||
86 | |||
87 | /** |
||
88 | * [$httpClient description] |
||
89 | * |
||
90 | * @var [type] |
||
91 | */ |
||
92 | protected $httpClient; |
||
93 | |||
94 | /** |
||
95 | * Create new client |
||
96 | * |
||
97 | * @param array $configuration |
||
98 | */ |
||
99 | 16 | public function __construct($configuration = []) |
|
112 | |||
113 | /** |
||
114 | * Build query string params using defaults |
||
115 | * |
||
116 | * @param array $attributes |
||
117 | * |
||
118 | * @return string |
||
119 | */ |
||
120 | 4 | public function buildQueryParams($attributes = []) |
|
131 | |||
132 | /** |
||
133 | * Build unsigned url |
||
134 | * |
||
135 | * @param string $host |
||
136 | * @param string $path |
||
137 | * |
||
138 | * @return string Unsigned url |
||
139 | */ |
||
140 | 14 | protected function buildUnsignedUrl($host, $path) |
|
144 | |||
145 | /** |
||
146 | * Builds and sets a preferred http client. |
||
147 | * |
||
148 | * @return Client |
||
149 | */ |
||
150 | 16 | protected function createHttpClient() |
|
169 | |||
170 | /** |
||
171 | * Query the Business API by business id |
||
172 | * |
||
173 | * @param string $businessId The ID of the business to query |
||
174 | * |
||
175 | * @return stdClass The JSON response from the request |
||
176 | */ |
||
177 | 8 | public function getBusiness($businessId) |
|
183 | |||
184 | /** |
||
185 | * Maps legacy configuration keys to updated keys. |
||
186 | * |
||
187 | * @param array $configuration |
||
188 | * |
||
189 | * @return array |
||
190 | */ |
||
191 | protected function mapConfiguration(array $configuration) |
||
200 | |||
201 | /** |
||
202 | * Parse configuration using defaults |
||
203 | * |
||
204 | * @param array $configuration |
||
205 | * |
||
206 | * @return array $configuration |
||
207 | */ |
||
208 | 16 | protected function parseConfiguration(&$configuration = []) |
|
225 | |||
226 | /** |
||
227 | * Makes a request to the Yelp API and returns the response |
||
228 | * |
||
229 | * @param string $path The path of the APi after the domain |
||
230 | * |
||
231 | * @return stdClass The JSON response from the request |
||
232 | * @throws Exception |
||
233 | */ |
||
234 | 14 | protected function request($path) |
|
248 | |||
249 | /** |
||
250 | * Query the Search API by a search term and location |
||
251 | * |
||
252 | * @param array $attributes Query attributes |
||
253 | * |
||
254 | * @return stdClass The JSON response from the request |
||
255 | */ |
||
256 | 4 | public function search($attributes = []) |
|
263 | |||
264 | /** |
||
265 | * Search for businesses by phone number |
||
266 | * |
||
267 | * @see https://www.yelp.com/developers/documentation/v2/phone_search |
||
268 | * |
||
269 | * @param array $attributes Query attributes |
||
270 | * |
||
271 | * @return stdClass The JSON response from the request |
||
272 | */ |
||
273 | 2 | public function searchByPhone($attributes = []) |
|
279 | |||
280 | /** |
||
281 | * Attempts to set a given value. |
||
282 | * |
||
283 | * @param mixed $value |
||
284 | * @param string $key |
||
285 | * |
||
286 | * @return Client |
||
287 | */ |
||
288 | 16 | protected function setConfig($value, $key) |
|
296 | |||
297 | /** |
||
298 | * Set default location |
||
299 | * |
||
300 | * @param string $location |
||
301 | * |
||
302 | * @return Client |
||
303 | */ |
||
304 | 2 | public function setDefaultLocation($location) |
|
309 | |||
310 | /** |
||
311 | * Set default term |
||
312 | * |
||
313 | * @param string $term |
||
314 | * |
||
315 | * @return Client |
||
316 | */ |
||
317 | 2 | public function setDefaultTerm($term) |
|
322 | |||
323 | /** |
||
324 | * Updates the yelp client's http client to the given http client. Client. |
||
325 | * |
||
326 | * @param HttpClient $client |
||
327 | * |
||
328 | * @return Client |
||
329 | */ |
||
330 | 16 | public function setHttpClient(HttpClient $client) |
|
336 | |||
337 | /** |
||
338 | * Set search limit |
||
339 | * |
||
340 | * @param integer $limit |
||
341 | * |
||
342 | * @return Client |
||
343 | */ |
||
344 | 2 | public function setSearchLimit($limit) |
|
351 | |||
352 | /** |
||
353 | * Retrives the value of a given property from the client. |
||
354 | * |
||
355 | * @param string $property |
||
356 | * |
||
357 | * @return mixed|null |
||
358 | */ |
||
359 | 2 | public function __get($property) |
|
367 | } |
||
368 |