Skip to content
This repository has been archived by the owner on Oct 16, 2019. It is now read-only.

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
Preparing release 2.3.0
  • Loading branch information
Jefersson Nathan committed Jun 22, 2017
2 parents a653306 + bc9aee8 commit 95347a5
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 10 deletions.
22 changes: 21 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

All notable changes to this project will be documented in this file, in reverse chronological order by release.

## 2.2.1 - TBD
## 2.4.0 - TBD

### Added

Expand All @@ -20,6 +20,26 @@ All notable changes to this project will be documented in this file, in reverse

- Nothing.

## 2.3.0 - 2017-06-22

### Added

- [#70](https://github.com/zendframework/ZendService_Amazon/pull/70) added
support for IT, ES, CN, BR amazon endpoints and added new $useHttps constructor
parameter to `ZendService\Amazon\Amazon`

### Deprecated

- Nothing.

### Removed

- Nothing.

### Fixed

- Nothing.

## 2.2.0 - 2017-03-15

### Added
Expand Down
34 changes: 25 additions & 9 deletions src/Amazon.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,20 @@ class Amazon
*
* @var array
*/
protected $_baseUriList = ['US' => 'http://webservices.amazon.com',
'UK' => 'http://webservices.amazon.co.uk',
'DE' => 'http://webservices.amazon.de',
'JP' => 'http://webservices.amazon.co.jp',
'FR' => 'http://webservices.amazon.fr',
'CA' => 'http://webservices.amazon.ca'];
protected $_baseUriList = [
'BR' => 'http://webservices.amazon.com.br',
'CA' => 'http://webservices.amazon.ca',
'CN' => 'http://webservices.amazon.cn',
'DE' => 'http://webservices.amazon.de',
'ES' => 'http://webservices.amazon.es',
'FR' => 'http://webservices.amazon.fr',
'IN' => 'http://webservices.amazon.in',
'IT' => 'http://webservices.amazon.it',
'JP' => 'http://webservices.amazon.co.jp',
'MX' => 'http://webservices.amazon.com.mx',
'UK' => 'http://webservices.amazon.co.uk',
'US' => 'http://webservices.amazon.com',
];

/**
* Reference to REST client object
Expand All @@ -74,11 +82,17 @@ class Amazon
* @param string $countryCode Country code for Amazon service; may be US, UK, DE, JP, FR, CA
* @param string $secretKey API Secret Key
* @param string $version API Version to use
* @param bool $useHttps Use HTTPS instead of HTTP?
* @throws Exception\InvalidArgumentException
* @return Amazon
*/
public function __construct($appId, $countryCode = 'US', $secretKey = null, $version = null)
{
public function __construct(
$appId,
$countryCode = 'US',
$secretKey = null,
$version = null,
$useHttps = false
) {
$this->appId = (string) $appId;
$this->_secretKey = $secretKey;

Expand All @@ -91,7 +105,9 @@ public function __construct($appId, $countryCode = 'US', $secretKey = null, $ver
throw new Exception\InvalidArgumentException("Unknown country code: $countryCode");
}

$this->_baseUri = $this->_baseUriList[$countryCode];
$this->_baseUri = $useHttps
? str_replace('http:', 'https:', $this->_baseUriList[$countryCode])
: $this->_baseUriList[$countryCode];
}


Expand Down
64 changes: 64 additions & 0 deletions test/OfflineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -356,4 +356,68 @@ public function testNoticeErrorDoesNotHappenInTotalPages()

$this->assertEquals(0, $result->totalPages());
}

/**
* Get a mock REST client for testing an expected URL.
*
* @param string $expectedUrl URL to check for.
*
* @return
*/
protected function getMockRestClient($expectedUrl)
{
// We have to do a lot of mocking to avoid causing errors, but the only
// part of this that is significant to the tests below is the expectation
// set up on the $restClient's setUri method.
$httpClient = $this->getMockBuilder('Zend\Http\Client')->getMock();
$response = $this->getMockBuilder('Zend\Http\Response')->setMethods(['getBody'])->getMock();
$response->expects($this->any())->method('getBody')->will($this->returnValue('<foo />'));
$restClient = $this->getMockBuilder('ZendRest\Client\RestClient')
->disableOriginalConstructor()->setMethods(['setUri', 'getHttpClient', 'restGet'])->getMock();
$restClient->expects($this->once())->method('setUri')
->with($this->equalTo($expectedUrl));
$restClient->expects($this->any())->method('getHttpClient')->will($this->returnValue($httpClient));
$restClient->expects($this->any())->method('restGet')->will($this->returnValue($response));
return $restClient;
}

/**
* Test that default URL is selected appropriately.
*/
public function testDefaultUrl()
{
$amazon = new Amazon\Amazon(constant('TESTS_ZEND_SERVICE_AMAZON_ONLINE_ACCESSKEYID'));
$amazon->setRestClient($this->getMockRestClient('http://webservices.amazon.com'))->itemLookup('foo');
}

/**
* Test that secure URLs are selected appropriately.
*/
public function testSecureUrls()
{
$urls = [
'BR' => 'https://webservices.amazon.com.br',
'CA' => 'https://webservices.amazon.ca',
'CN' => 'https://webservices.amazon.cn',
'DE' => 'https://webservices.amazon.de',
'ES' => 'https://webservices.amazon.es',
'FR' => 'https://webservices.amazon.fr',
'IN' => 'https://webservices.amazon.in',
'IT' => 'https://webservices.amazon.it',
'JP' => 'https://webservices.amazon.co.jp',
'MX' => 'https://webservices.amazon.com.mx',
'UK' => 'https://webservices.amazon.co.uk',
'US' => 'https://webservices.amazon.com',
];
foreach ($urls as $country => $expected) {
$amazon = new Amazon\Amazon(
constant('TESTS_ZEND_SERVICE_AMAZON_ONLINE_ACCESSKEYID'),
$country,
null,
null,
true
);
$amazon->setRestClient($this->getMockRestClient($expected))->itemLookup('foo');
}
}
}

0 comments on commit 95347a5

Please sign in to comment.