Skip to content

Commit

Permalink
Add support for http proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenmaguire committed Sep 23, 2016
1 parent 4ccd842 commit 7cd461e
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 4 deletions.
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,23 @@
#Changelog
All Notable changes to `trello-php` will be documented in this file

## 0.4.0 - 2016-09-23

### Added
- Add support for HTTP proxy configuration.

### Deprecated
- Nothing

### Fixed
- Nothing

### Removed
- Nothing

### Security
- Nothing

## 0.3.6 - 2015-10-26

### Added
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ Setting | Description
`callbackUrl` | Required when using package to help get access tokens.
`expiration` | Required when using package to help get access tokens.
`scope` | Required when using package to help get access tokens.
`proxy` | Optional setting to declare a host to use for proxy; [Read more on the Guzzle Docs](http://docs.guzzlephp.org/en/latest/request-options.html#proxy).

#### Set configuration when creating client

Expand Down
1 change: 1 addition & 0 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class Client
protected static $defaultOptions = [
'domain' => 'https://trello.com',
'key' => null,
'proxy' => null,
'version' => '1',
'secret' => null,
];
Expand Down
3 changes: 2 additions & 1 deletion src/Http.php
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,8 @@ protected function sendRequest(RequestInterface $request)
{
try {
$response = $this->httpClient->send($request, [
'multipart' => $this->multipartResources
'multipart' => $this->multipartResources,
'proxy' => Configuration::get('proxy')
]);

$this->multipartResources = [];
Expand Down
1 change: 0 additions & 1 deletion tests/ApiTestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -3888,5 +3888,4 @@ public function testUpdateWebhookIdModel()

$this->assertExpectedEqualsResult($payload, $result);
}

}
22 changes: 20 additions & 2 deletions tests/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ protected function getTestString()
return uniqid();
}

protected function prepareFor($method, $path, $query = "", $payload = [], $status = 200)
protected function prepareFor($method, $path, $query = "", $payload = [], $status = 200, $proxy = null)
{
$path = $this->getFullPathFromPath($path);
$domain = $this->getDomain();
Expand All @@ -95,7 +95,10 @@ protected function prepareFor($method, $path, $query = "", $payload = [], $statu
&& strpos($uri->getQuery(), $authorizedQuery) > -1;
});

$requestOptions = m::on(function ($options) {
$requestOptions = m::on(function ($options) use ($proxy) {
if ($proxy && (!isset($options['proxy']) || $options['proxy'] != $proxy)) {
return false;
}
return is_array($options);
});

Expand Down Expand Up @@ -200,4 +203,19 @@ public function testBadMethodCallThrowsException()

$result = $this->client->$method();
}

public function testGetCurrentUserWithProxy()
{
$proxy = $this->getTestString();
$payload = $this->getSuccessPayload();
$this->prepareFor("GET", "/members/me", "", $payload, 200, $proxy);

$this->client->addConfig('proxy', $proxy);

$result = $this->client->getCurrentUser();

$this->client->addConfig('proxy', null);

$this->assertExpectedEqualsResult($payload, $result);
}
}

0 comments on commit 7cd461e

Please sign in to comment.