Skip to content

Commit

Permalink
Updating MWS client to set API version on-the-fly
Browse files Browse the repository at this point in the history
  • Loading branch information
hasbridge committed Mar 7, 2012
1 parent eb37d02 commit a333fee
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
12 changes: 11 additions & 1 deletion Mws/Command/AbstractMwsCommand.php
Expand Up @@ -23,7 +23,11 @@
*/
class AbstractMwsCommand extends AbstractCommand
{

/**
* @var string API version
*/
protected $version = '2009-01-01';

/**
* @var string MWS operation name
*/
Expand All @@ -42,6 +46,12 @@ class AbstractMwsCommand extends AbstractCommand
*/
protected function build()
{
// Hack, set API version on the fly - different sections have different API versions
$observers = $this->getClient()->getEventManager()->getAttached('Guzzle\Aws\QueryStringAuthPlugin');
foreach($observers as $observer) {
$observer->setApiVersion($this->version);
}

if (!$this->action) {
// @codeCoverageIgnoreStart
throw new \Exception('You must define an action name');
Expand Down
10 changes: 9 additions & 1 deletion Mws/Command/AbstractMwsOrderCommand.php
Expand Up @@ -7,6 +7,9 @@

namespace Guzzle\Aws\Mws\Command;

use Guzzle\Aws\QueryStringAuthPlugin;
use Guzzle\Aws\Signature\SignatureV2;

/**
* Base class order MWS Order API commands
*
Expand All @@ -17,13 +20,18 @@
*/
class AbstractMwsOrderCommand extends AbstractMwsCommand
{

/**
* @var string API version
*/
protected $version = '2011-01-01';

/**
* Build the HTTP request
*/
protected function build()
{
parent::build();

// Change path
$this->getRequest()->setPath('/Orders/2011-01-01');

Expand Down
14 changes: 14 additions & 0 deletions QueryStringAuthPlugin.php
Expand Up @@ -60,6 +60,20 @@ public function getApiVersion()
{
return $this->apiVersion;
}

/**
* Set the API version of the service
*
* @param string $version
*
* @return QueryStringAuthPlugin
*/
public function setApiVersion($version)
{
$this->apiVersion = $version;

return $this;
}

/**
* Add required query string fields to a request
Expand Down

0 comments on commit a333fee

Please sign in to comment.