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 | 16 | protected function mapConfiguration(array $configuration) |
|
208 | |||
209 | /** |
||
210 | * Parse configuration using defaults |
||
211 | * |
||
212 | * @param array $configuration |
||
213 | * |
||
214 | * @return array $configuration |
||
215 | */ |
||
216 | 16 | protected function parseConfiguration(&$configuration = []) |
|
233 | |||
234 | /** |
||
235 | * Makes a request to the Yelp API and returns the response |
||
236 | * |
||
237 | * @param string $path The path of the APi after the domain |
||
238 | * |
||
239 | * @return stdClass The JSON response from the request |
||
240 | * @throws Exception |
||
241 | */ |
||
242 | 14 | protected function request($path) |
|
256 | |||
257 | /** |
||
258 | * Query the Search API by a search term and location |
||
259 | * |
||
260 | * @param array $attributes Query attributes |
||
261 | * |
||
262 | * @return stdClass The JSON response from the request |
||
263 | */ |
||
264 | 4 | public function search($attributes = []) |
|
271 | |||
272 | /** |
||
273 | * Search for businesses by phone number |
||
274 | * |
||
275 | * @see https://www.yelp.com/developers/documentation/v2/phone_search |
||
276 | * |
||
277 | * @param array $attributes Query attributes |
||
278 | * |
||
279 | * @return stdClass The JSON response from the request |
||
280 | */ |
||
281 | 2 | public function searchByPhone($attributes = []) |
|
287 | |||
288 | /** |
||
289 | * Attempts to set a given value. |
||
290 | * |
||
291 | * @param mixed $value |
||
292 | * @param string $key |
||
293 | * |
||
294 | * @return Client |
||
295 | */ |
||
296 | 16 | protected function setConfig($value, $key) |
|
304 | |||
305 | /** |
||
306 | * Set default location |
||
307 | * |
||
308 | * @param string $location |
||
309 | * |
||
310 | * @return Client |
||
311 | */ |
||
312 | 2 | public function setDefaultLocation($location) |
|
317 | |||
318 | /** |
||
319 | * Set default term |
||
320 | * |
||
321 | * @param string $term |
||
322 | * |
||
323 | * @return Client |
||
324 | */ |
||
325 | 2 | public function setDefaultTerm($term) |
|
330 | |||
331 | /** |
||
332 | * Updates the yelp client's http client to the given http client. Client. |
||
333 | * |
||
334 | * @param HttpClient $client |
||
335 | * |
||
336 | * @return Client |
||
337 | */ |
||
338 | 16 | public function setHttpClient(HttpClient $client) |
|
344 | |||
345 | /** |
||
346 | * Set search limit |
||
347 | * |
||
348 | * @param integer $limit |
||
349 | * |
||
350 | * @return Client |
||
351 | */ |
||
352 | 2 | public function setSearchLimit($limit) |
|
359 | |||
360 | /** |
||
361 | * Retrives the value of a given property from the client. |
||
362 | * |
||
363 | * @param string $property |
||
364 | * |
||
365 | * @return mixed|null |
||
366 | */ |
||
367 | 2 | public function __get($property) |
|
375 | } |
||
376 |