1 | <?php |
||
11 | class Client implements HttpContract |
||
12 | { |
||
13 | use ConfigurationTrait, |
||
14 | HttpTrait; |
||
15 | |||
16 | /** |
||
17 | * Access token |
||
18 | * |
||
19 | * @var string |
||
20 | */ |
||
21 | protected $accessToken; |
||
22 | |||
23 | /** |
||
24 | * Api key |
||
25 | * |
||
26 | * @var string |
||
27 | */ |
||
28 | protected $apiKey; |
||
29 | |||
30 | /** |
||
31 | * Rate limit |
||
32 | * |
||
33 | * @var RateLimit|null |
||
34 | */ |
||
35 | protected $rateLimit; |
||
36 | |||
37 | /** |
||
38 | * Creates new client |
||
39 | * |
||
40 | * @param array $options |
||
41 | */ |
||
42 | 26 | public function __construct(array $options = array()) |
|
56 | |||
57 | /** |
||
58 | * Creates default http client with appropriate authorization configuration. |
||
59 | * |
||
60 | * @return \GuzzleHttp\Client |
||
61 | */ |
||
62 | 26 | public function createDefaultHttpClient() |
|
68 | |||
69 | /** |
||
70 | * Fetches results from the Autocomplete API. |
||
71 | * |
||
72 | * @param array $parameters |
||
73 | * |
||
74 | * @return stdClass |
||
75 | * @throws Stevenmaguire\Yelp\Exception\HttpException |
||
76 | * @link https://www.yelp.com/developers/documentation/v3/autocomplete |
||
77 | */ |
||
78 | 2 | public function getAutocompleteResults($parameters = []) |
|
85 | |||
86 | /** |
||
87 | * Returns the api key, if available, otherwise returns access token. |
||
88 | * |
||
89 | * @return string|null |
||
90 | * @link https://www.yelp.com/developers/documentation/v3/authentication#where-is-my-client-secret-going |
||
91 | */ |
||
92 | 26 | private function getBearerToken() |
|
100 | |||
101 | /** |
||
102 | * Fetches a specific business by id. |
||
103 | * |
||
104 | * @param string $businessId |
||
105 | * @param array $parameters |
||
106 | * |
||
107 | * @return stdClass |
||
108 | * @throws Stevenmaguire\Yelp\Exception\HttpException |
||
109 | * @link https://www.yelp.com/developers/documentation/v3/business |
||
110 | */ |
||
111 | 4 | public function getBusiness($businessId, $parameters = []) |
|
118 | |||
119 | /** |
||
120 | * Fetches reviews for a specific business by id. |
||
121 | * |
||
122 | * @param string $businessId |
||
123 | * @param array $parameters |
||
124 | * |
||
125 | * @return stdClass |
||
126 | * @throws Stevenmaguire\Yelp\Exception\HttpException |
||
127 | * @link https://www.yelp.com/developers/documentation/v3/business_reviews |
||
128 | */ |
||
129 | 2 | public function getBusinessReviews($businessId, $parameters = []) |
|
136 | |||
137 | /** |
||
138 | * Fetches results from the Business Search API. |
||
139 | * |
||
140 | * @param array $parameters |
||
141 | * |
||
142 | * @return stdClass |
||
143 | * @throws Stevenmaguire\Yelp\Exception\HttpException |
||
144 | * @link https://www.yelp.com/developers/documentation/v3/business_search |
||
145 | */ |
||
146 | 2 | public function getBusinessesSearchResults($parameters = []) |
|
155 | |||
156 | /** |
||
157 | * Fetches results from the Business Search API by Phone. |
||
158 | * |
||
159 | * @param string $phoneNumber |
||
160 | * |
||
161 | * @return stdClass |
||
162 | * @throws Stevenmaguire\Yelp\Exception\HttpException |
||
163 | * @link https://www.yelp.com/developers/documentation/v3/business_search_phone |
||
164 | */ |
||
165 | 2 | public function getBusinessesSearchResultsByPhone($phoneNumber) |
|
176 | |||
177 | /** |
||
178 | * Builds and returns default headers, specifically including the Authorization |
||
179 | * header used for authenticating HTTP requests to Yelp. |
||
180 | * |
||
181 | * @return array |
||
182 | */ |
||
183 | 26 | protected function getDefaultHeaders() |
|
189 | |||
190 | /** |
||
191 | * Returns the latest rate limit metrics, absorbed from the HTTP headers of |
||
192 | * the most recent HTTP request to the Yelp v3 service. |
||
193 | * |
||
194 | * @return RateLimit|null |
||
195 | * |
||
196 | * @see https://www.yelp.com/developers/documentation/v3/rate_limiting |
||
197 | */ |
||
198 | 2 | public function getRateLimit() |
|
202 | |||
203 | /** |
||
204 | * Fetches results from the Business Search API by Type. |
||
205 | * |
||
206 | * @param string $type |
||
207 | * @param array $parameters |
||
208 | * |
||
209 | * @return stdClass |
||
210 | * @throws Stevenmaguire\Yelp\Exception\HttpException |
||
211 | * @link https://www.yelp.com/developers/documentation/v3/transactions_search |
||
212 | */ |
||
213 | 2 | public function getTransactionsSearchResultsByType($type, $parameters = []) |
|
220 | |||
221 | /** |
||
222 | * Provides a hook that handles the response before returning to the consumer. |
||
223 | * |
||
224 | * @param ResponseInterface $response |
||
225 | * |
||
226 | * @return ResponseInterface |
||
227 | */ |
||
228 | 12 | protected function handleResponse(ResponseInterface $response) |
|
237 | } |
||
238 |