-
-
Notifications
You must be signed in to change notification settings - Fork 599
[WIP] Client / HttpClient decoupling for Guzzle integration #30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
847089e
Move Buzz stuff in Adapter\Buzz
romainneutron 602e4f9
Reactivate tests
romainneutron f2cd2b1
First Guzzle implementation
romainneutron 1e83e6f
Add Guzzle Response
romainneutron 992588a
Final API change
romainneutron fecbcca
Remove var_dump
romainneutron 96e00ea
Rename `Client::executeCommand` to `Client::executeRequest`
romainneutron File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
namespace Github\Exception; | ||
|
||
class InvalidJsonResponse extends RuntimeException | ||
{ | ||
private $body; | ||
|
||
public function __construct($body, $code = 0, $previous = null) | ||
{ | ||
$this->body = $body; | ||
parent::__construct('Invalid Json Response', $code, $previous); | ||
} | ||
|
||
public function getBody() | ||
{ | ||
return $this->body; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
<?php | ||
|
||
namespace Github\HttpClient; | ||
|
||
use Github\HttpClient\RequestInterface; | ||
use Github\HttpClient\ResponseInterface; | ||
|
||
abstract class AbstractAdapter implements HttpClientInterface | ||
{ | ||
/** | ||
* @var RequestInterface | ||
*/ | ||
protected $lastRequest; | ||
|
||
/** | ||
* @var ResponseInterface | ||
*/ | ||
protected $lastResponse; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
protected $options = array( | ||
'base_url' => 'https://api.github.com/', | ||
'user_agent' => 'php-github-api (http://github.com/KnpLabs/php-github-api)', | ||
'timeout' => 10, | ||
'api_version' => 'beta', | ||
'cache_dir' => null | ||
); | ||
/** | ||
* @var array | ||
*/ | ||
protected $headers; | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function setOption($name, $value) | ||
{ | ||
$this->options[$name] = $value; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function setHeaders(array $headers) | ||
{ | ||
$this->headers = array_merge($this->headers, $headers); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function clearHeaders() | ||
{ | ||
$this->headers = array( | ||
sprintf('Accept: application/vnd.github.%s+json', $this->options['api_version']) | ||
); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function getLastRequest() | ||
{ | ||
return $this->lastRequest; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function getLastResponse() | ||
{ | ||
return $this->lastResponse; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function getAPILimit() | ||
{ | ||
if (!$this->getLastRequest()) { | ||
$this->get('/rate_limit'); | ||
} | ||
|
||
return (int) $this->getLastRequest()->getHeaderAsString('X-RateLimit-Limit'); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function getAPIRemaining() | ||
{ | ||
if (!$this->getLastRequest()) { | ||
$this->get('/rate_limit'); | ||
} | ||
|
||
return (int) $this->getLastRequest()->getHeaderAsString('X-RateLimit-Remaining'); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
lib/Github/HttpClient/CachedHttpClient.php → ...pClient/Adapter/Buzz/CachedHttpClient.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
<?php | ||
|
||
namespace Github\HttpClient; | ||
namespace Github\HttpClient\Adapter\Buzz; | ||
|
||
use Buzz\Client\ClientInterface; | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably better to rename to
executeRequest