1 | <?php |
||
14 | class Client implements HttpContract |
||
15 | { |
||
16 | use ConfigurationTrait, |
||
17 | HttpTrait; |
||
18 | |||
19 | /** |
||
20 | * Consumer key |
||
21 | * |
||
22 | * @var string |
||
23 | */ |
||
24 | protected $consumerKey; |
||
25 | |||
26 | /** |
||
27 | * Consumer secret |
||
28 | * |
||
29 | * @var string |
||
30 | */ |
||
31 | protected $consumerSecret; |
||
32 | |||
33 | /** |
||
34 | * Access token |
||
35 | * |
||
36 | * @var string |
||
37 | */ |
||
38 | protected $token; |
||
39 | |||
40 | /** |
||
41 | * Access token secret |
||
42 | * |
||
43 | * @var string |
||
44 | */ |
||
45 | protected $tokenSecret; |
||
46 | |||
47 | /** |
||
48 | * Default search term |
||
49 | * |
||
50 | * @var string |
||
51 | */ |
||
52 | protected $defaultTerm = 'bar'; |
||
53 | |||
54 | /** |
||
55 | * Default location |
||
56 | * |
||
57 | * @var string |
||
58 | */ |
||
59 | protected $defaultLocation = 'Chicago, IL'; |
||
60 | |||
61 | /** |
||
62 | * Default search limit |
||
63 | * |
||
64 | * @var integer |
||
65 | */ |
||
66 | protected $searchLimit = 3; |
||
67 | |||
68 | /** |
||
69 | * Search path |
||
70 | * |
||
71 | * @var string |
||
72 | */ |
||
73 | protected $searchPath = '/v2/search/'; |
||
74 | |||
75 | /** |
||
76 | * Business path |
||
77 | * |
||
78 | * @var string |
||
79 | */ |
||
80 | protected $businessPath = '/v2/business/'; |
||
81 | |||
82 | /** |
||
83 | * Phone search path |
||
84 | * |
||
85 | * @var string |
||
86 | */ |
||
87 | protected $phoneSearchPath = '/v2/phone_search/'; |
||
88 | |||
89 | /** |
||
90 | * Create new client |
||
91 | * |
||
92 | * @param array $options |
||
93 | */ |
||
94 | public function __construct(array $options = array()) |
||
107 | |||
108 | /** |
||
109 | * Build query string params using defaults |
||
110 | * |
||
111 | * @param array $attributes |
||
112 | * |
||
113 | * @return string |
||
114 | */ |
||
115 | public function buildQueryParams($attributes = []) |
||
126 | |||
127 | /** |
||
128 | * Build unsigned url |
||
129 | * |
||
130 | * @param string $host |
||
131 | * @param string $path |
||
132 | * |
||
133 | * @return string Unsigned url |
||
134 | */ |
||
135 | protected function buildUnsignedUrl($host, $path) |
||
139 | |||
140 | /** |
||
141 | * Builds and sets a preferred http client. |
||
142 | * |
||
143 | * @return Client |
||
144 | */ |
||
145 | protected function createHttpClient() |
||
164 | |||
165 | /** |
||
166 | * Query the Business API by business id |
||
167 | * |
||
168 | * @param string $businessId The ID of the business to query |
||
169 | * @param array $attributes Optional attributes to include in query string |
||
170 | * |
||
171 | * @return stdClass The JSON response from the request |
||
172 | */ |
||
173 | public function getBusiness($businessId, $attributes = []) |
||
179 | |||
180 | /** |
||
181 | * Makes a request to the Yelp API and returns the response |
||
182 | * |
||
183 | * @param string $path The path of the APi after the domain |
||
184 | * |
||
185 | * @return stdClass The JSON response from the request |
||
186 | * @throws Stevenmaguire\Yelp\Exception\HttpException |
||
187 | */ |
||
188 | protected function request($path) |
||
202 | |||
203 | /** |
||
204 | * Query the Search API by a search term and location |
||
205 | * |
||
206 | * @param array $attributes Query attributes |
||
207 | * |
||
208 | * @return stdClass The JSON response from the request |
||
209 | */ |
||
210 | public function search($attributes = []) |
||
217 | |||
218 | /** |
||
219 | * Search for businesses by phone number |
||
220 | * |
||
221 | * @see https://www.yelp.com/developers/documentation/v2/phone_search |
||
222 | * |
||
223 | * @param array $attributes Query attributes |
||
224 | * |
||
225 | * @return stdClass The JSON response from the request |
||
226 | */ |
||
227 | public function searchByPhone($attributes = []) |
||
233 | |||
234 | /** |
||
235 | * Set default location |
||
236 | * |
||
237 | * @param string $location |
||
238 | * |
||
239 | * @return Client |
||
240 | */ |
||
241 | public function setDefaultLocation($location) |
||
246 | |||
247 | /** |
||
248 | * Set default term |
||
249 | * |
||
250 | * @param string $term |
||
251 | * |
||
252 | * @return Client |
||
253 | */ |
||
254 | public function setDefaultTerm($term) |
||
259 | |||
260 | /** |
||
261 | * Set search limit |
||
262 | * |
||
263 | * @param integer $limit |
||
264 | * |
||
265 | * @return Client |
||
266 | */ |
||
267 | public function setSearchLimit($limit) |
||
274 | } |
||
275 |