From 0b56a8c4bbf7caf71622718f2cd2d9aa4a7371a9 Mon Sep 17 00:00:00 2001 From: Michael Babker Date: Sun, 27 Sep 2015 17:08:39 -0400 Subject: [PATCH 1/3] Return Response objects from the API methods --- composer.json | 4 ++-- src/AbstractGithubObject.php | 10 +++++++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/composer.json b/composer.json index 520d7d9d..39e5c1d2 100644 --- a/composer.json +++ b/composer.json @@ -6,9 +6,9 @@ "homepage": "https://github.com/joomla-framework/github-api", "license": "GPL-2.0+", "require": { - "php": ">=5.3.10", + "php": ">=5.4", "joomla/date": "~1.0", - "joomla/http": "~1.0", + "joomla/http": "2.0.*@dev", "joomla/registry": "2.0.*@dev", "joomla/uri": "~1.0" }, diff --git a/src/AbstractGithubObject.php b/src/AbstractGithubObject.php index 93e6e39a..2042993b 100644 --- a/src/AbstractGithubObject.php +++ b/src/AbstractGithubObject.php @@ -8,6 +8,7 @@ namespace Joomla\Github; +use Joomla\Http\Exception\UnexpectedResponseException; use Joomla\Http\Response; use Joomla\Uri\Uri; use Joomla\Registry\Registry; @@ -115,7 +116,7 @@ protected function fetchUrl($path, $page = 0, $limit = 0) * @return mixed * * @since 1.0 - * @throws \DomainException + * @throws UnexpectedResponseException */ protected function processResponse(Response $response, $expectedCode = 200) { @@ -124,10 +125,13 @@ protected function processResponse(Response $response, $expectedCode = 200) { // Decode the error response and throw an exception. $error = json_decode($response->body); + + // Check if the error message is set; send a generic one if not $message = isset($error->message) ? $error->message : 'Invalid response received from GitHub.'; - throw new \DomainException($message, $response->code); + + throw new UnexpectedResponseException($response, $message, $response->code); } - return json_decode($response->body); + return $response; } } From ca91589898d38c645683176edeaa580bb0dd1ec7 Mon Sep 17 00:00:00 2001 From: George Wilson Date: Sun, 27 Sep 2015 22:23:36 +0100 Subject: [PATCH 2/3] Remove 5.3 from unit tests --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 75969c0b..13ac73eb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,6 @@ language: php php: - - 5.3 - 5.4 - 5.5 - 5.6 From 7baf2d281d6ee332709505ba646a48e1fe2b5485 Mon Sep 17 00:00:00 2001 From: George Wilson Date: Sun, 27 Sep 2015 22:43:32 +0100 Subject: [PATCH 3/3] Use PSR-7 for status code check --- src/AbstractGithubObject.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/AbstractGithubObject.php b/src/AbstractGithubObject.php index 2042993b..3b6eaf17 100644 --- a/src/AbstractGithubObject.php +++ b/src/AbstractGithubObject.php @@ -121,7 +121,7 @@ protected function fetchUrl($path, $page = 0, $limit = 0) protected function processResponse(Response $response, $expectedCode = 200) { // Validate the response code. - if ($response->code != $expectedCode) + if ($response->getStatusCode() != $expectedCode) { // Decode the error response and throw an exception. $error = json_decode($response->body);