From 0b56a8c4bbf7caf71622718f2cd2d9aa4a7371a9 Mon Sep 17 00:00:00 2001 From: Michael Babker Date: Sun, 27 Sep 2015 17:08:39 -0400 Subject: [PATCH 1/6] 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/6] 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/6] 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); From 5625e5947da68384f7eef46d574f038f6631a512 Mon Sep 17 00:00:00 2001 From: Michael Babker Date: Mon, 23 Nov 2015 12:37:44 -0500 Subject: [PATCH 4/6] Update documented return, use method to get status code. --- src/AbstractGithubObject.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/AbstractGithubObject.php b/src/AbstractGithubObject.php index 3b6eaf17..3cc6debc 100644 --- a/src/AbstractGithubObject.php +++ b/src/AbstractGithubObject.php @@ -113,7 +113,7 @@ protected function fetchUrl($path, $page = 0, $limit = 0) * @param Response $response The response. * @param integer $expectedCode The expected "good" code. * - * @return mixed + * @return Response * * @since 1.0 * @throws UnexpectedResponseException @@ -129,7 +129,7 @@ protected function processResponse(Response $response, $expectedCode = 200) // 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 UnexpectedResponseException($response, $message, $response->code); + throw new UnexpectedResponseException($response, $message, $response->getStatusCode()); } return $response; From f3ba0d7db2698c1ba269565a830fd106e02be3f5 Mon Sep 17 00:00:00 2001 From: George Wilson Date: Sun, 27 Sep 2015 22:43:32 +0100 Subject: [PATCH 5/6] 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 c5a7e580..852f9807 100644 --- a/src/AbstractGithubObject.php +++ b/src/AbstractGithubObject.php @@ -167,7 +167,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); From e4bfa62300a12cfcaaea708682c408d814176266 Mon Sep 17 00:00:00 2001 From: Michael Babker Date: Mon, 23 Nov 2015 12:37:44 -0500 Subject: [PATCH 6/6] Update documented return, use method to get status code. --- src/AbstractGithubObject.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/AbstractGithubObject.php b/src/AbstractGithubObject.php index 852f9807..674c959e 100644 --- a/src/AbstractGithubObject.php +++ b/src/AbstractGithubObject.php @@ -159,7 +159,7 @@ protected function fetchUrl($path, $page = 0, $limit = 0) * @param Response $response The response. * @param integer $expectedCode The expected "good" code. * - * @return mixed + * @return Response * * @since 1.0 * @throws UnexpectedResponseException @@ -173,7 +173,7 @@ protected function processResponse(Response $response, $expectedCode = 200) $error = json_decode($response->body); $message = isset($error->message) ? $error->message : 'Invalid response received from GitHub.'; - throw new UnexpectedResponseException($response, $message, $response->code); + throw new UnexpectedResponseException($response, $message, $response->getStatusCode()); } return json_decode($response->body);