diff --git a/composer.json b/composer.json index 34a2f3a..5bf3895 100644 --- a/composer.json +++ b/composer.json @@ -7,7 +7,12 @@ ], "require": { "php": ">=5.4.0", - "guzzlehttp/guzzle": "~6.0" + "guzzlehttp/guzzle": "~7.0", + "ext-json": "*" + } + , + "require-dev": { + "roave/security-advisories": "dev-latest" }, "autoload": { "psr-4": { diff --git a/src/Base.php b/src/Base.php index 447cf72..98ff9e2 100644 --- a/src/Base.php +++ b/src/Base.php @@ -1,4 +1,5 @@ setNetworkId($networkId); - $this->setHttpClient(new GuzzleClient([ - 'defaults' => [ - 'headers' => $this->getHeaders(), - ], - ])); + $this->setHttpClient( + new GuzzleClient( + [ + 'defaults' => [ + 'headers' => $this->getHeaders(), + ], + ] + ) + ); } /** @@ -101,13 +107,14 @@ public function api($class) * @param array $parameters * * @return object + * @throws Exception */ public function get($apiMethod, $parameters = []) { $requestUrl = $this->buildUrl($apiMethod, $parameters); $requestUrl = urldecode($requestUrl); - $response = $this->getHttpClient()->get($requestUrl); + $response = $this->getHttpClient()->get($requestUrl); return $this->handleResponse($response); } @@ -116,20 +123,34 @@ public function get($apiMethod, $parameters = []) * Build the request url. * * @param string $apiMethod - * @param array $parameter + * @param $parameters * * @return string */ private function buildUrl($apiMethod, $parameters) { + $url = null; switch ($this->getApiType()) { case 'Brand': - $url = sprintf($this->apiUrlBrand, $this->getNetworkId(), $this->getApiNamespace(), $apiMethod, $this->getApiKey()); - break; + $url = sprintf( + $this->apiUrlBrand, + $this->getNetworkId(), + $this->getApiNamespace(), + $apiMethod, + $this->getApiKey() + ); + break; case 'Affiliate': - $url = sprintf($this->apiUrlAffiliate, $this->getNetworkId(), $this->getApiType(), $this->getApiNamespace(), $apiMethod, $this->getApiKey()); - break; + $url = sprintf( + $this->apiUrlAffiliate, + $this->getNetworkId(), + $this->getApiType(), + $this->getApiNamespace(), + $apiMethod, + $this->getApiKey() + ); + break; } return $url.'&'.http_build_query($parameters); @@ -141,17 +162,18 @@ private function buildUrl($apiMethod, $parameters) * @param object $response * * @return object + * @throws Exception */ private function handleResponse($response) { $statusCode = $response->getStatusCode(); - $body = json_decode($response->getBody()); + $body = json_decode($response->getBody(), true); if ($statusCode >= 200 && $statusCode < 300) { return $body; } - throw new \Exception($response->getBody(), $statusCode); + throw new Exception($response->getBody(), $statusCode); } /**