1 | <?php |
||
14 | trait HttpTrait |
||
15 | { |
||
16 | /** |
||
17 | * API host url |
||
18 | * |
||
19 | * @var string |
||
20 | */ |
||
21 | protected $apiHost; |
||
22 | |||
23 | /** |
||
24 | * HTTP client |
||
25 | * |
||
26 | * @var \GuzzleHttp\Client |
||
27 | */ |
||
28 | protected $httpClient; |
||
29 | |||
30 | /** |
||
31 | * HTTP scheme |
||
32 | * |
||
33 | * @var string |
||
34 | */ |
||
35 | protected $scheme; |
||
36 | |||
37 | /** |
||
38 | * Prepares and appends parameters, if provided, to the given url. |
||
39 | * |
||
40 | * @param string $url |
||
41 | * @param array $parameters |
||
42 | * @param string[] $options |
||
43 | * |
||
44 | * @return string |
||
45 | */ |
||
46 | protected function appendParametersToUrl($url, array $parameters = array(), array $options = array()) |
||
60 | |||
61 | /** |
||
62 | * Flattens given array into comma separated value. |
||
63 | * |
||
64 | * @param mixed $input |
||
65 | * |
||
66 | * @return string|mixed |
||
67 | */ |
||
68 | private function arrayToCsv($input) |
||
76 | |||
77 | /** |
||
78 | * Coerces given value into boolean and returns string representation |
||
79 | * |
||
80 | * @param boolean $value |
||
81 | * |
||
82 | * @return string |
||
83 | */ |
||
84 | private function getBoolString($value) |
||
88 | |||
89 | /** |
||
90 | * Returns the yelp client's http client to the given http client. Client. |
||
91 | * |
||
92 | * @return GuzzleHttp\Client|null |
||
93 | */ |
||
94 | public function getHttpClient() |
||
98 | |||
99 | /** |
||
100 | * Creates a PSR-7 Request instance. |
||
101 | * |
||
102 | * @param null|string $method HTTP method for the request. |
||
103 | * @param null|string $uri URI for the request. |
||
104 | * @param array $headers Headers for the message. |
||
105 | * @param string|resource|StreamInterface $body Message body. |
||
106 | * @param string $version HTTP protocol version. |
||
107 | * |
||
108 | * @return Request |
||
109 | */ |
||
110 | public function getRequest( |
||
129 | |||
130 | /** |
||
131 | * Sends a request instance and returns a response instance. |
||
132 | * |
||
133 | * WARNING: This method does not attempt to catch exceptions caused by HTTP |
||
134 | * errors! It is recommended to wrap this method in a try/catch block. |
||
135 | * |
||
136 | * @param RequestInterface $request |
||
137 | * @return ResponseInterface |
||
138 | * @throws Stevenmaguire\Yelp\Exception\HttpException |
||
139 | */ |
||
140 | public function getResponse(RequestInterface $request) |
||
150 | |||
151 | /** |
||
152 | * Updates query params array to apply yelp specific formatting rules. |
||
153 | * |
||
154 | * @param array $params |
||
155 | * @param string[] $csvParams |
||
156 | * |
||
157 | * @return string |
||
158 | */ |
||
159 | protected function prepareQueryParams($params = [], $csvParams = []) |
||
173 | |||
174 | /** |
||
175 | * Makes a request to the Yelp API and returns the response |
||
176 | * |
||
177 | * @param RequestInterface $request |
||
178 | * |
||
179 | * @return stdClass The JSON response from the request |
||
180 | * @throws Stevenmaguire\Yelp\Exception\ClientConfigurationException |
||
181 | * @throws Stevenmaguire\Yelp\Exception\HttpException |
||
182 | */ |
||
183 | protected function processRequest(RequestInterface $request) |
||
189 | |||
190 | /** |
||
191 | * Updates the yelp client's http client to the given http client. Client. |
||
192 | * |
||
193 | * @param HttpClient $client |
||
194 | * |
||
195 | * @return mixed |
||
196 | */ |
||
197 | public function setHttpClient(HttpClient $client) |
||
203 | } |
||
204 |