diff --git a/src/Common/Service/AbstractService.php b/src/Common/Service/AbstractService.php index bd9e703..66a461c 100644 --- a/src/Common/Service/AbstractService.php +++ b/src/Common/Service/AbstractService.php @@ -162,7 +162,7 @@ public function getHTTPTransporter() /** * {@inheritdoc} */ - public function requestJSON($uri, array $body = [], $method = 'GET', array $extraHeaders = []) + public function requestJSON($uri, $body = [], $method = 'GET', array $extraHeaders = []) { return json_decode($this->request($uri, $body, $method, $extraHeaders), TRUE); } @@ -170,11 +170,18 @@ public function requestJSON($uri, array $body = [], $method = 'GET', array $extr /** * {@inheritdoc} */ - public function httpRequest($uri, array $body = [], array $headers = [], $method = 'POST') + public function httpRequest($uri, $body = [], array $headers = [], $method = 'POST') { try { - $response = $this->httpTransporter->submit($uri, $body, $method, $headers); + if (is_array($body)) + { + $response = $this->httpTransporter->submit($uri, $body, $method, $headers); + } else + { + $response = $this->httpTransporter->call($uri, $method, $headers, $body); + } + } catch (RequestException $e) { throw new TokenResponseException($e->getMessage() ? $e->getMessage() : 'Failed to request resource.'); diff --git a/src/Common/Service/ServiceInterface.php b/src/Common/Service/ServiceInterface.php index be6955e..f4b617c 100644 --- a/src/Common/Service/ServiceInterface.php +++ b/src/Common/Service/ServiceInterface.php @@ -17,38 +17,37 @@ interface ServiceInterface { * If the path provided is not an absolute URI, the base API Uri (service-specific) will be used. * * @param string|Url $path - * @param array $body Request body if applicable (an associative array will + * @param array|string $body Request body if applicable (an associative array will automatically be converted into a urlencoded body) * @param string $method HTTP method - * automatically be converted into a urlencoded body) - * @param array $extraHeaders Extra headers if applicable. These will override service-specific - * any defaults. + * + * @param array $extraHeaders Extra headers if applicable. These will override service-specific defaults. * @return string */ - public function request($path, array $body = [], $method = 'GET', array $extraHeaders = []); + public function request($path, $body = [], $method = 'GET', array $extraHeaders = []); /** * Shortcut for json_decode($this->request(... * * @param $uri - * @param array $body + * @param array|string $body * @param string $method * @param array $extraHeaders * @return array */ - public function requestJSON($uri, array $body = [], $method = 'GET', array $extraHeaders = []); + public function requestJSON($uri, $body = [], $method = 'GET', array $extraHeaders = []); /** * Sends an authenticated API request to the path provided. * If the path provided is not an absolute URI, the base API Uri (must be passed into constructor) will be used. * * @param Url|string $uri - * @param array $body Request body if applicable (key/value pairs) + * @param array|string $body Request body if applicable * @param array $headers Extra headers if applicable. * @param string $method HTTP method * @throws TokenResponseException * @return string */ - public function httpRequest($uri, array $body = [], array $headers = [], $method = 'POST'); + public function httpRequest($uri, $body = [], array $headers = [], $method = 'POST'); /** * Returns the url to redirect to for authorization purposes. diff --git a/src/OAuth1/Service/AbstractService.php b/src/OAuth1/Service/AbstractService.php index 8542f75..579e44b 100644 --- a/src/OAuth1/Service/AbstractService.php +++ b/src/OAuth1/Service/AbstractService.php @@ -130,7 +130,7 @@ public function requestAccessToken($token, $verifier, $tokenSecret = NULL) /** * {@inheritdoc} */ - public function request($path, array $body = [], $method = 'GET', array $extraHeaders = []) + public function request($path, $body = [], $method = 'GET', array $extraHeaders = []) { $uri = $this->determineRequestUriFromPath($path, $this->baseApiUri); diff --git a/src/OAuth1/Service/Flickr.php b/src/OAuth1/Service/Flickr.php index 2956e37..6d8da49 100644 --- a/src/OAuth1/Service/Flickr.php +++ b/src/OAuth1/Service/Flickr.php @@ -74,7 +74,7 @@ protected function parseAccessTokenResponse($responseBody) return $token; } - public function request($path, array $body = [], $method = 'GET', array $extraHeaders = []) + public function request($path, $body = [], $method = 'GET', array $extraHeaders = []) { $uri = $this->determineRequestUriFromPath('/'); $uri->getQuery()->modify(['method' => $path]); diff --git a/src/OAuth2/Service/AbstractService.php b/src/OAuth2/Service/AbstractService.php index a49b320..d053c99 100644 --- a/src/OAuth2/Service/AbstractService.php +++ b/src/OAuth2/Service/AbstractService.php @@ -134,7 +134,7 @@ public function getAuthorizationUri(array $additionalParameters = []) * @throws ExpiredTokenException * @throws Exception */ - public function request($path, array $body = [], $method = 'GET', array $extraHeaders = []) + public function request($path, $body = [], $method = 'GET', array $extraHeaders = []) { $uri = $this->determineRequestUriFromPath($path); $token = $this->storage->retrieveAccessToken($this->service()); diff --git a/src/OAuth2/Service/Foursquare.php b/src/OAuth2/Service/Foursquare.php index 7916de1..23830e9 100644 --- a/src/OAuth2/Service/Foursquare.php +++ b/src/OAuth2/Service/Foursquare.php @@ -43,7 +43,7 @@ protected function parseAccessTokenResponse($responseBody) /** * {@inheritdoc} */ - public function request($path, array $body = [], $method = 'GET', array $extraHeaders = []) + public function request($path, $body = [], $method = 'GET', array $extraHeaders = []) { $uri = $this->determineRequestUriFromPath($path); $uri->getQuery()->modify(['v' => $this->apiVersionDate]); diff --git a/src/OAuth2/Service/Mailchimp.php b/src/OAuth2/Service/Mailchimp.php index 21a80e9..b8f8c2f 100644 --- a/src/OAuth2/Service/Mailchimp.php +++ b/src/OAuth2/Service/Mailchimp.php @@ -55,7 +55,7 @@ protected function parseAccessTokenResponse($responseBody) /** * {@inheritdoc} */ - public function request($path, array $body = [], $method = 'GET', array $extraHeaders = []) + public function request($path, $body = [], $method = 'GET', array $extraHeaders = []) { if (is_null($this->baseApiUri)) { diff --git a/tests/Mocks/Common/Service/Mock.php b/tests/Mocks/Common/Service/Mock.php index ca46a46..71a4105 100644 --- a/tests/Mocks/Common/Service/Mock.php +++ b/tests/Mocks/Common/Service/Mock.php @@ -23,7 +23,7 @@ public function __construct( /** * {@inheritdoc} */ - public function request($path, array $body = [], $method = 'GET', array $extraHeaders = []) + public function request($path, $body = [], $method = 'GET', array $extraHeaders = []) { } diff --git a/tests/Mocks/OAuth1/Service/Mock.php b/tests/Mocks/OAuth1/Service/Mock.php index 30dbd71..4c2af63 100644 --- a/tests/Mocks/OAuth1/Service/Mock.php +++ b/tests/Mocks/OAuth1/Service/Mock.php @@ -12,7 +12,7 @@ class Mock extends AbstractService protected $authorizationEndpoint = 'http://pieterhordijk.com/auth'; protected $accessTokenEndpoint = 'http://pieterhordijk.com/access'; - public function httpRequest($uri, array $body = [], array $headers = [], $method = 'POST') + public function httpRequest($uri, $body = [], array $headers = [], $method = 'POST') { return [ 'uri' => $uri, diff --git a/tests/Mocks/OAuth2/Service/Mock.php b/tests/Mocks/OAuth2/Service/Mock.php index fda8125..dae68db 100644 --- a/tests/Mocks/OAuth2/Service/Mock.php +++ b/tests/Mocks/OAuth2/Service/Mock.php @@ -25,7 +25,7 @@ public function setAuthorizationMethod($method) $this->authorizationMethod = $method; } - public function httpRequest($uri, array $body = [], array $headers = [], $method = 'POST') + public function httpRequest($uri, $body = [], array $headers = [], $method = 'POST') { return [ 'uri' => $uri,