Skip to content

Commit 2aac252

Browse files
committed
Merge pull request #170 from bc-ruth/OMNI-1024
OMNI-1024 Expose currencies v2 resource to Client API
2 parents 2171bb3 + b3749b0 commit 2aac252

File tree

4 files changed

+147
-0
lines changed

4 files changed

+147
-0
lines changed

src/Bigcommerce/Api/Client.php

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1402,4 +1402,73 @@ public static function getOrderShippingAddresses($orderID, $filter = array())
14021402
$filter = Filter::create($filter);
14031403
return self::getCollection('/orders/' . $orderID . '/shipping_addresses' . $filter->toQuery(), 'Address');
14041404
}
1405+
1406+
/**
1407+
* Create a new currency.
1408+
*
1409+
* @param mixed $object fields to create
1410+
* @return mixed
1411+
*/
1412+
public static function createCurrency($object)
1413+
{
1414+
return self::createResource('/currencies', $object);
1415+
}
1416+
1417+
/**
1418+
* Returns a single currency resource by the given id.
1419+
*
1420+
* @param int $id currency id
1421+
* @return Resources\Currency|string
1422+
*/
1423+
public static function getCurrency($id)
1424+
{
1425+
return self::getResource('/currencies/' . $id, 'Currency');
1426+
}
1427+
1428+
/**
1429+
* Update the given currency.
1430+
*
1431+
* @param int $id currency id
1432+
* @param mixed $object fields to update
1433+
* @return mixed
1434+
*/
1435+
public static function updateCurrency($id, $object)
1436+
{
1437+
return self::updateResource('/currencies/' . $id, $object);
1438+
}
1439+
1440+
/**
1441+
* Delete the given currency.
1442+
*
1443+
* @param int $id currency id
1444+
* @return mixed
1445+
*/
1446+
public static function deleteCurrency($id)
1447+
{
1448+
return self::deleteResource('/currencies/' . $id);
1449+
}
1450+
1451+
/**
1452+
* Returns the default collection of currencies.
1453+
*
1454+
* @param array $filter
1455+
* @return mixed array|string list of currencies or XML string if useXml is true
1456+
*/
1457+
public static function getCurrencies($filter = array())
1458+
{
1459+
$filter = Filter::create($filter);
1460+
return self::getCollection('/currencies' . $filter->toQuery(), 'Currency');
1461+
}
1462+
1463+
/**
1464+
* Returns the total number of currencies in the collection.
1465+
*
1466+
* @param array $filter
1467+
* @return int|string number of currencies or XML string if useXml is true
1468+
*/
1469+
public static function getCurrenciesCount($filter = array())
1470+
{
1471+
$filter = Filter::create($filter);
1472+
return self::getCount('/currencies/count' . $filter->toQuery());
1473+
}
14051474
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
namespace Bigcommerce\Api\Resources;
4+
5+
use Bigcommerce\Api\Resource;
6+
use Bigcommerce\Api\Client;
7+
8+
/**
9+
* Represents a single currency.
10+
*/
11+
class Currency extends Resource
12+
{
13+
protected $ignoreOnCreate = array(
14+
'date_created',
15+
'date_modified',
16+
);
17+
18+
protected $ignoreOnUpdate = array(
19+
'id',
20+
'date_created',
21+
'date_modified',
22+
);
23+
24+
public function create()
25+
{
26+
return Client::createCurrency($this->getCreateFields());
27+
}
28+
29+
public function update()
30+
{
31+
return Client::updateCurrency($this->id, $this->getUpdateFields());
32+
}
33+
34+
public function delete()
35+
{
36+
return Client::deleteCurrency($this->id);
37+
}
38+
}

test/Unit/Api/ClientTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ public function collections()
261261
array('optionsets', 'getOptionSets', 'OptionSet'),
262262
array('products/skus', 'getSkus', 'Sku'),
263263
array('requestlogs', 'getRequestLogs', 'RequestLog'),
264+
array('currencies', 'getCurrencies', 'Currency'),
264265
);
265266
}
266267

@@ -313,6 +314,7 @@ public function resources()
313314
array('options', '%sOption', 'Option'),
314315
array('optionsets', '%sOptionSet', 'OptionSet'),
315316
array('coupons', '%sCoupon', 'Coupon'),
317+
array('currencies', '%sCurrency', 'Currency'),
316318
);
317319
}
318320

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
namespace Bigcommerce\Test\Unit\Api\Resources;
3+
4+
use Bigcommerce\Api\Resources\Currency;
5+
use Bigcommerce\Api\Client;
6+
7+
class CurrencyTest extends ResourceTestBase
8+
{
9+
public function testCreatePassesThroughToConnection()
10+
{
11+
$currency = new Currency((object)array('id' => 1));
12+
$this->connection->expects($this->once())
13+
->method('post')
14+
->with($this->basePath . '/currencies', (object)array('id' => 1));
15+
16+
$currency->create();
17+
}
18+
19+
public function testUpdatePassesThroughToConnection()
20+
{
21+
$currency = new Currency((object)array('id' => 1));
22+
$this->connection->expects($this->once())
23+
->method('put')
24+
->with($this->basePath . '/currencies/1', (object)array());
25+
26+
$currency->update();
27+
}
28+
29+
public function testDeletePassesThroughToConnection()
30+
{
31+
$currency = new Currency((object)array('id' => 1));
32+
$this->connection->expects($this->once())
33+
->method('delete')
34+
->with($this->basePath . '/currencies/1');
35+
36+
$currency->delete();
37+
}
38+
}

0 commit comments

Comments
 (0)