Skip to content

Commit

Permalink
Merge pull request #170 from bc-ruth/OMNI-1024
Browse files Browse the repository at this point in the history
OMNI-1024 Expose currencies v2 resource to Client API
  • Loading branch information
aleachjr committed Apr 29, 2016
2 parents 2171bb3 + b3749b0 commit 2aac252
Show file tree
Hide file tree
Showing 4 changed files with 147 additions and 0 deletions.
69 changes: 69 additions & 0 deletions src/Bigcommerce/Api/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -1402,4 +1402,73 @@ public static function getOrderShippingAddresses($orderID, $filter = array())
$filter = Filter::create($filter);
return self::getCollection('/orders/' . $orderID . '/shipping_addresses' . $filter->toQuery(), 'Address');
}

/**
* Create a new currency.
*
* @param mixed $object fields to create
* @return mixed
*/
public static function createCurrency($object)
{
return self::createResource('/currencies', $object);
}

/**
* Returns a single currency resource by the given id.
*
* @param int $id currency id
* @return Resources\Currency|string
*/
public static function getCurrency($id)
{
return self::getResource('/currencies/' . $id, 'Currency');
}

/**
* Update the given currency.
*
* @param int $id currency id
* @param mixed $object fields to update
* @return mixed
*/
public static function updateCurrency($id, $object)
{
return self::updateResource('/currencies/' . $id, $object);
}

/**
* Delete the given currency.
*
* @param int $id currency id
* @return mixed
*/
public static function deleteCurrency($id)
{
return self::deleteResource('/currencies/' . $id);
}

/**
* Returns the default collection of currencies.
*
* @param array $filter
* @return mixed array|string list of currencies or XML string if useXml is true
*/
public static function getCurrencies($filter = array())
{
$filter = Filter::create($filter);
return self::getCollection('/currencies' . $filter->toQuery(), 'Currency');
}

/**
* Returns the total number of currencies in the collection.
*
* @param array $filter
* @return int|string number of currencies or XML string if useXml is true
*/
public static function getCurrenciesCount($filter = array())
{
$filter = Filter::create($filter);
return self::getCount('/currencies/count' . $filter->toQuery());
}
}
38 changes: 38 additions & 0 deletions src/Bigcommerce/Api/Resources/Currency.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace Bigcommerce\Api\Resources;

use Bigcommerce\Api\Resource;
use Bigcommerce\Api\Client;

/**
* Represents a single currency.
*/
class Currency extends Resource
{
protected $ignoreOnCreate = array(
'date_created',
'date_modified',
);

protected $ignoreOnUpdate = array(
'id',
'date_created',
'date_modified',
);

public function create()
{
return Client::createCurrency($this->getCreateFields());
}

public function update()
{
return Client::updateCurrency($this->id, $this->getUpdateFields());
}

public function delete()
{
return Client::deleteCurrency($this->id);
}
}
2 changes: 2 additions & 0 deletions test/Unit/Api/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ public function collections()
array('optionsets', 'getOptionSets', 'OptionSet'),
array('products/skus', 'getSkus', 'Sku'),
array('requestlogs', 'getRequestLogs', 'RequestLog'),
array('currencies', 'getCurrencies', 'Currency'),
);
}

Expand Down Expand Up @@ -313,6 +314,7 @@ public function resources()
array('options', '%sOption', 'Option'),
array('optionsets', '%sOptionSet', 'OptionSet'),
array('coupons', '%sCoupon', 'Coupon'),
array('currencies', '%sCurrency', 'Currency'),
);
}

Expand Down
38 changes: 38 additions & 0 deletions test/Unit/Api/Resources/CurrencyTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php
namespace Bigcommerce\Test\Unit\Api\Resources;

use Bigcommerce\Api\Resources\Currency;
use Bigcommerce\Api\Client;

class CurrencyTest extends ResourceTestBase
{
public function testCreatePassesThroughToConnection()
{
$currency = new Currency((object)array('id' => 1));
$this->connection->expects($this->once())
->method('post')
->with($this->basePath . '/currencies', (object)array('id' => 1));

$currency->create();
}

public function testUpdatePassesThroughToConnection()
{
$currency = new Currency((object)array('id' => 1));
$this->connection->expects($this->once())
->method('put')
->with($this->basePath . '/currencies/1', (object)array());

$currency->update();
}

public function testDeletePassesThroughToConnection()
{
$currency = new Currency((object)array('id' => 1));
$this->connection->expects($this->once())
->method('delete')
->with($this->basePath . '/currencies/1');

$currency->delete();
}
}

0 comments on commit 2aac252

Please sign in to comment.