1 | <?php |
||
15 | trait HttpTrait |
||
16 | { |
||
17 | /** |
||
18 | * API host url |
||
19 | * |
||
20 | * @var string |
||
21 | */ |
||
22 | protected $apiHost; |
||
23 | |||
24 | /** |
||
25 | * HTTP client |
||
26 | * |
||
27 | * @var \GuzzleHttp\Client |
||
28 | */ |
||
29 | protected $httpClient; |
||
30 | |||
31 | /** |
||
32 | * HTTP scheme |
||
33 | * |
||
34 | * @var string |
||
35 | */ |
||
36 | protected $scheme; |
||
37 | |||
38 | /** |
||
39 | * Prepares and appends parameters, if provided, to the given url. |
||
40 | * |
||
41 | * @param string $url |
||
42 | * @param array $parameters |
||
43 | * @param string[] $options |
||
44 | * |
||
45 | * @return string |
||
46 | */ |
||
47 | 26 | protected function appendParametersToUrl($url, array $parameters = array(), array $options = array()) |
|
61 | |||
62 | /** |
||
63 | * Flattens given array into comma separated value. |
||
64 | * |
||
65 | * @param mixed $input |
||
66 | * |
||
67 | * @return string|mixed |
||
68 | */ |
||
69 | 2 | private function arrayToCsv($input) |
|
77 | |||
78 | /** |
||
79 | * Coerces given value into boolean and returns string representation |
||
80 | * |
||
81 | * @param boolean $value |
||
82 | * |
||
83 | * @return string |
||
84 | */ |
||
85 | 4 | private function getBoolString($value) |
|
89 | |||
90 | /** |
||
91 | * Returns the yelp client's http client to the given http client. Client. |
||
92 | * |
||
93 | * @return GuzzleHttp\Client|null |
||
94 | */ |
||
95 | 42 | public function getHttpClient() |
|
99 | |||
100 | /** |
||
101 | * Creates a PSR-7 Request instance. |
||
102 | * |
||
103 | * @param null|string $method HTTP method for the request. |
||
104 | * @param null|string $uri URI for the request. |
||
105 | * @param array $headers Headers for the message. |
||
106 | * @param string|resource|StreamInterface $body Message body. |
||
107 | * @param string $version HTTP protocol version. |
||
108 | * |
||
109 | * @return Request |
||
110 | */ |
||
111 | 28 | public function getRequest( |
|
130 | |||
131 | /** |
||
132 | * Sends a request instance and returns a response instance. |
||
133 | * |
||
134 | * WARNING: This method does not attempt to catch exceptions caused by HTTP |
||
135 | * errors! It is recommended to wrap this method in a try/catch block. |
||
136 | * |
||
137 | * @param RequestInterface $request |
||
138 | * @return ResponseInterface |
||
139 | * @throws Stevenmaguire\Yelp\Exception\HttpException |
||
140 | */ |
||
141 | 14 | public function getResponse(RequestInterface $request) |
|
151 | |||
152 | /** |
||
153 | * Provides a hook that handles the response before returning to the consumer. |
||
154 | * |
||
155 | * @param ResponseInterface $response |
||
156 | * |
||
157 | * @return ResponseInterface |
||
158 | */ |
||
159 | abstract protected function handleResponse(ResponseInterface $response); |
||
160 | |||
161 | /** |
||
162 | * Updates query params array to apply yelp specific formatting rules. |
||
163 | * |
||
164 | * @param array $params |
||
165 | * @param string[] $csvParams |
||
166 | * |
||
167 | * @return string |
||
168 | */ |
||
169 | protected function prepareQueryParams($params = [], $csvParams = []) |
||
183 | |||
184 | /** |
||
185 | * Makes a request to the Yelp API and returns the response |
||
186 | * |
||
187 | * @param RequestInterface $request |
||
188 | * |
||
189 | * @return stdClass The JSON response from the request |
||
190 | * @throws Stevenmaguire\Yelp\Exception\ClientConfigurationException |
||
191 | * @throws Stevenmaguire\Yelp\Exception\HttpException |
||
192 | */ |
||
193 | 24 | protected function processRequest(RequestInterface $request) |
|
199 | |||
200 | /** |
||
201 | * Updates the yelp client's http client to the given http client. Client. |
||
202 | * |
||
203 | * @param HttpClient $client |
||
204 | * |
||
205 | * @return mixed |
||
206 | */ |
||
207 | 42 | public function setHttpClient(HttpClient $client) |
|
213 | } |
||
214 |