|
13 | 13 | /**
|
14 | 14 | * Class MailChimpAPI
|
15 | 15 | * @package MailChimp
|
| 16 | + * |
| 17 | + * @method mixed get($resource, array $options = []) |
| 18 | + * @method mixed head($resource, array $options = []) |
| 19 | + * @method mixed put($resource, array $options = []) |
| 20 | + * @method mixed post($resource, array $options = []) |
| 21 | + * @method mixed patch($resource, array $options = []) |
| 22 | + * @method mixed delete($resource, array $options = []) |
16 | 23 | */
|
17 | 24 | class MailChimpAPI {
|
18 | 25 |
|
@@ -147,28 +154,42 @@ private function makeRequest($resource, $arguments, $method) {
|
147 | 154 | try {
|
148 | 155 |
|
149 | 156 | $options = $this->getOptions($method, $arguments);
|
150 |
| - $response = $this->client->{$method}($this->endpoint . $resource, $options); |
| 157 | + $response = $this->client->{$method}( |
| 158 | + ( $this->endpoint . $resource ), |
| 159 | + $options |
| 160 | + ); |
151 | 161 |
|
152 | 162 | //plain old json_decode
|
153 | 163 | $data = json_decode( $response->getBody() );
|
154 | 164 |
|
155 | 165 | if( $de = json_last_error() )
|
156 |
| - throw new MailChimpAPIException("Could not decode API response... ."); |
| 166 | + throw new MailChimpAPIException( |
| 167 | + "Could not decode API response... . |
| 168 | + JSON error #{$de}: " . json_last_error_msg() |
| 169 | + ); |
157 | 170 |
|
158 | 171 | return $data;
|
159 | 172 |
|
160 | 173 | } catch (ClientException $e) {
|
161 |
| - throw new MailChimpAPIException($e->getResponse()->getBody(), $e->getResponse()->getStatusCode(), $e); |
| 174 | + throw new MailChimpAPIException( |
| 175 | + $e->getResponse()->getBody(), |
| 176 | + $e->getResponse()->getStatusCode(), |
| 177 | + $e |
| 178 | + ); |
162 | 179 |
|
163 | 180 | } catch (RequestException $e) {
|
164 | 181 |
|
165 | 182 | $response = $e->getResponse();
|
166 | 183 |
|
167 |
| - if ($response instanceof ResponseInterface) { |
168 |
| - throw new MailChimpAPIException($e->getResponse()->getBody(), $e->getResponse()->getStatusCode(), $e); |
169 |
| - } |
| 184 | + if ( $response instanceof ResponseInterface ) |
| 185 | + throw new MailChimpAPIException( |
| 186 | + $e->getResponse()->getBody(), |
| 187 | + $e->getResponse()->getStatusCode(), |
| 188 | + $e |
| 189 | + ); |
170 | 190 |
|
171 |
| - throw new MailChimpAPIException($e->getMessage()); |
| 191 | + |
| 192 | + throw new MailChimpAPIException( $e->getMessage() ); |
172 | 193 |
|
173 | 194 | }
|
174 | 195 |
|
@@ -204,16 +225,18 @@ private function getOptions($method, $arguments) {
|
204 | 225 | */
|
205 | 226 | public function __call($method, $arguments) {
|
206 | 227 |
|
207 |
| - if (count($arguments) < 1) { |
208 |
| - throw new InvalidArgumentException('Magic request methods require a URI and optional options array'); |
209 |
| - } |
| 228 | + if ( count($arguments) < 1 ) |
| 229 | + throw new InvalidArgumentException( |
| 230 | + 'Magic request methods require a URI and optional options array' |
| 231 | + ); |
210 | 232 |
|
211 |
| - if ( ! in_array($method, $this->allowedMethods)) { |
212 |
| - throw new BadMethodCallException('Method "' . $method . '" is not supported.'); |
213 |
| - } |
| 233 | + if ( ! in_array($method, $this->allowedMethods) ) |
| 234 | + throw new BadMethodCallException( |
| 235 | + 'Method "' . $method . '" is not supported.' |
| 236 | + ); |
214 | 237 |
|
215 | 238 | $resource = $arguments[0];
|
216 |
| - $options = isset($arguments[1]) ? $arguments[1] : []; |
| 239 | + $options = isset($arguments[1]) ? $arguments[1] : []; |
217 | 240 |
|
218 | 241 | return $this->request($resource, $options, $method);
|
219 | 242 |
|
|
0 commit comments