diff --git a/README.md b/README.md index 96f70ac..6283c78 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ awis PHP package for making requests to Alexa Web Information Service -##Instalation +##Installation The easiest way to install Awis is via [composer](http://getcomposer.org/). Create the following `composer.json` file and run the `php composer.phar install` command to install it. diff --git a/composer.json b/composer.json index 3e7f5e7..09e13d9 100644 --- a/composer.json +++ b/composer.json @@ -13,7 +13,7 @@ "require": { "php": ">=5.3.0", "nesbot/carbon": "~1.0", - "guzzlehttp/guzzle": ">=4,<6" + "guzzlehttp/guzzle": ">=6" }, "require-dev": { "phpunit/phpunit": "~4.0" diff --git a/src/Awis.php b/src/Awis.php index 454eb9c..8e129ab 100644 --- a/src/Awis.php +++ b/src/Awis.php @@ -1,7 +1,8 @@ -dt = Carbon::now(); - $request = $this->client->createRequest('GET', $this->endPoint); - $query = $request->getQuery(); - $query->set('Action', 'UrlInfo'); - $query->set('AWSAccessKeyId', $this->accessKeyId); - $query->set('SignatureMethod', $this->signatureMethod); - $query->set('SignatureVersion', $this->signatureVersion); - $query->set('Timestamp', $this->dt->toISO8601String()); - $query->set('Url', $url); - $query->set('ResponseGroup', $responseGroup); - $query->set('Signature', $this->generateSignature($query)); - - return $this->client->send($request); + $query = [ + 'Action' => 'UrlInfo', + 'AWSAccessKeyId' => $this->accessKeyId, + 'SignatureMethod' => $this->signatureMethod, + 'SignatureVersion' => $this->signatureVersion, + 'Timestamp' => $this->dt->toISO8601String(), + 'Url' => $url, + 'ResponseGroup' => $responseGroup, + ]; + + $query['Signature'] = $this->generateSignature($query); + + $response = $this->client->get($this->endPoint, [ + 'query' => $query + ]); + + return $response; } public function getTrafficHistory($url, $range = 31, $start = "20070801") { $this->dt = Carbon::now(); - $request = $this->client->createRequest('GET', $this->endPoint); - $query = $request->getQuery(); - $query->set('Start', $start); - $query->set('Action', 'TrafficHistory'); - $query->set('AWSAccessKeyId', $this->accessKeyId); - $query->set('SignatureMethod', $this->signatureMethod); - $query->set('SignatureVersion', $this->signatureVersion); - $query->set('Timestamp', $this->dt->toISO8601String()); - $query->set('Url', $url); - $query->set('ResponseGroup', 'History'); - $query->set('Range', $range); - $query->set('Signature', $this->generateSignature($query)); - - return $this->client->send($request); + $query = [ + 'Start' => $start, + 'Action' => 'TrafficHistory', + 'AWSAccessKeyId' => $this->accessKeyId, + 'SignatureMethod' => $this->signatureMethod, + 'SignatureVersion' => $this->signatureVersion, + 'Timestamp' => $this->dt->toISO8601String(), + 'Url' => $url, + 'ResponseGroup' => 'History', + 'Range' => $range, + ]; + + $query['Signature'] = $this->generateSignature($query); + + $response = $this->client->get($this->endPoint, [ + 'query' => $query + ]); + + return $response; } public function getCategoryBrowse($url, $responseGroup = "Categories", $path, $descriptions = 'TRUE') { $this->dt = Carbon::now(); - $request = $this->client->createRequest('GET', $this->endPoint); - $query = $request->getQuery(); - $query->set('Action', 'CategoryBrowse'); - $query->set('AWSAccessKeyId', $this->accessKeyId); - $query->set('SignatureMethod', $this->signatureMethod); - $query->set('SignatureVersion', $this->signatureVersion); - $query->set('Timestamp', $this->dt->toISO8601String()); - $query->set('Url', $url); - $query->set('ResponseGroup', $responseGroup); - $query->set('Path', $path); - $query->set('Descriptions', $descriptions); - $query->set('Signature', $this->generateSignature($query)); - - return $this->client->send($request); + $query = [ + 'Action' => 'CategoryBrowse', + 'AWSAccessKeyId' => $this->accessKeyId, + 'SignatureMethod' => $this->signatureMethod, + 'SignatureVersion' => $this->signatureVersion, + 'Timestamp' => $this->dt->toISO8601String(), + 'Url' => $url, + 'ResponseGroup' => $responseGroup, + 'Path' => $path, + 'Descriptions' => $descriptions, + ]; + + $query['Signature'] = $this->generateSignature($query); + + $response = $this->client->get($this->endPoint, [ + 'query' => $query + ]); + + return $response; } public function getCategoryListings($url, $path, $sortBy, $recursive, $start, $count, $descriptions = 'TRUE') @@ -84,24 +100,29 @@ public function getCategoryListings($url, $path, $sortBy, $recursive, $start, $c $this->dt = Carbon::now(); - $request = $this->client->createRequest('GET', $this->endPoint); - $query = $request->getQuery(); - $query->set('Action', 'CategoryListings'); - $query->set('AWSAccessKeyId', $this->accessKeyId); - $query->set('SignatureMethod', $this->signatureMethod); - $query->set('SignatureVersion', $this->signatureVersion); - $query->set('Timestamp', $this->dt->toISO8601String()); - $query->set('Url', $url); - $query->set('ResponseGroup', 'Listings'); - $query->set('Path', $path); - $query->set('SortBy', $sortBy); - $query->set('Recursive', $recursive); - $query->set('Start', $start); - $query->set('Count', $count); - $query->set('Descriptions', $descriptions); - $query->set('Signature', $this->generateSignature($query)); - - return $this->client->send($request); + $query = [ + 'Action' => 'CategoryListings', + 'AWSAccessKeyId' => $this->accessKeyId, + 'SignatureMethod' => $this->signatureMethod, + 'SignatureVersion' => $this->signatureVersion, + 'Timestamp' => $this->dt->toISO8601String(), + 'Url' => $url, + 'ResponseGroup' => 'Listings', + 'Path' => $path, + 'SortBy' => $sortBy, + 'Recursive' => $recursive, + 'Start' => $start, + 'Count' => $count, + 'Descriptions' => $descriptions, + ]; + + $query['Signature'] = $this->generateSignature($query); + + $response = $this->client->get($this->endPoint, [ + 'query' => $query + ]); + + return $response; } public function getSitesLinkingIn($url, $count = 10, $start = 0) @@ -109,20 +130,25 @@ public function getSitesLinkingIn($url, $count = 10, $start = 0) $this->dt = Carbon::now(); if( $count > 20) $count = 20; - $request = $this->client->createRequest('GET', $this->endPoint); - $query = $request->getQuery(); - $query->set('Action', 'SitesLinkingIn'); - $query->set('AWSAccessKeyId', $this->accessKeyId); - $query->set('SignatureMethod', $this->signatureMethod); - $query->set('SignatureVersion', $this->signatureVersion); - $query->set('Timestamp', $this->dt->toISO8601String()); - $query->set('Url', $url); - $query->set('ResponseGroup', 'SitesLinkingIn'); - $query->set('Start', $start); - $query->set('Count', $count); - $query->set('Signature', $this->generateSignature($query)); - - return $this->client->send($request); + $query = [ + 'Action' => 'SitesLinkingIn', + 'AWSAccessKeyId' => $this->accessKeyId, + 'SignatureMethod' => $this->signatureMethod, + 'SignatureVersion' => $this->signatureVersion, + 'Timestamp' => $this->dt->toISO8601String(), + 'Url' => $url, + 'ResponseGroup' => 'SitesLinkingIn', + 'Start' => $start, + 'Count' => $count, + ]; + + $query['Signature'] = $this->generateSignature($query); + + $response = $this->client->get($this->endPoint, [ + 'query' => $query + ]); + + return $response; } protected function generateSignature($query) { @@ -132,9 +158,7 @@ protected function generateSignature($query) { } protected function buildQueryParams($query) { - $query->remove('Signature'); - $params = $query->toArray(); - ksort($params); - return new Query($params); + ksort($query); + return http_build_query($query, null, '&', PHP_QUERY_RFC3986); } } \ No newline at end of file