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 | * Prepares and appends parameters, if provided, to the given url. |
||
32 | * |
||
33 | * @param string $url |
||
34 | * @param array $parameters |
||
35 | * @param string[] $options |
||
36 | * |
||
37 | * @return string |
||
38 | */ |
||
39 | protected function appendParametersToUrl($url, array $parameters = array(), array $options = array()) |
||
53 | |||
54 | /** |
||
55 | * Flattens given array into comma separated value. |
||
56 | * |
||
57 | * @param mixed $input |
||
58 | * |
||
59 | * @return string|mixed |
||
60 | */ |
||
61 | private function arrayToCsv($input) |
||
69 | |||
70 | /** |
||
71 | * Coerces given value into boolean and returns string representation |
||
72 | * |
||
73 | * @param boolean $value |
||
74 | * |
||
75 | * @return string |
||
76 | */ |
||
77 | private function getBoolString($value) |
||
81 | |||
82 | /** |
||
83 | * Returns the yelp client's http client to the given http client. Client. |
||
84 | * |
||
85 | * @return GuzzleHttp\Client|null |
||
86 | */ |
||
87 | public function getHttpClient() |
||
91 | |||
92 | /** |
||
93 | * Creates a PSR-7 Request instance. |
||
94 | * |
||
95 | * @param null|string $method HTTP method for the request. |
||
96 | * @param null|string $uri URI for the request. |
||
97 | * @param array $headers Headers for the message. |
||
98 | * @param string|resource|StreamInterface $body Message body. |
||
99 | * @param string $version HTTP protocol version. |
||
100 | * |
||
101 | * @return Request |
||
102 | */ |
||
103 | public function getRequest( |
||
122 | |||
123 | /** |
||
124 | * Sends a request instance and returns a response instance. |
||
125 | * |
||
126 | * WARNING: This method does not attempt to catch exceptions caused by HTTP |
||
127 | * errors! It is recommended to wrap this method in a try/catch block. |
||
128 | * |
||
129 | * @param RequestInterface $request |
||
130 | * @return ResponseInterface |
||
131 | * @throws Stevenmaguire\Yelp\Exception\HttpException |
||
132 | */ |
||
133 | public function getResponse(RequestInterface $request) |
||
143 | |||
144 | /** |
||
145 | * Updates query params array to apply yelp specific formatting rules. |
||
146 | * |
||
147 | * @param array $params |
||
148 | * @param string[] $csvParams |
||
149 | * |
||
150 | * @return string |
||
151 | */ |
||
152 | protected function prepareQueryParams($params = [], $csvParams = []) |
||
166 | |||
167 | /** |
||
168 | * Makes a request to the Yelp API and returns the response |
||
169 | * |
||
170 | * @param RequestInterface $request |
||
171 | * |
||
172 | * @return stdClass The JSON response from the request |
||
173 | * @throws Stevenmaguire\Yelp\Exception\ClientConfigurationException |
||
174 | * @throws Stevenmaguire\Yelp\Exception\HttpException |
||
175 | */ |
||
176 | protected function processRequest(RequestInterface $request) |
||
182 | |||
183 | /** |
||
184 | * Updates the yelp client's http client to the given http client. Client. |
||
185 | * |
||
186 | * @param HttpClient $client |
||
187 | * |
||
188 | * @return mixed |
||
189 | */ |
||
190 | public function setHttpClient(HttpClient $client) |
||
196 | } |
||
197 |