From 721be6dc4659836598cb8eff6af4ce28c9647f34 Mon Sep 17 00:00:00 2001 From: bc-ruth Date: Wed, 27 Apr 2016 16:38:56 -0700 Subject: [PATCH 1/3] OMNI-1024 Expose currencies v2 resource to Client API --- src/Bigcommerce/Api/Client.php | 57 ++++++++++++++++++++++ src/Bigcommerce/Api/Resources/Currency.php | 38 +++++++++++++++ test/Unit/Api/ClientTest.php | 1 + test/Unit/Api/Resources/CurrencyTest.php | 38 +++++++++++++++ 4 files changed, 134 insertions(+) create mode 100644 src/Bigcommerce/Api/Resources/Currency.php create mode 100644 test/Unit/Api/Resources/CurrencyTest.php diff --git a/src/Bigcommerce/Api/Client.php b/src/Bigcommerce/Api/Client.php index 306b6671..08acca9b 100644 --- a/src/Bigcommerce/Api/Client.php +++ b/src/Bigcommerce/Api/Client.php @@ -1402,4 +1402,61 @@ 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'); + } } diff --git a/src/Bigcommerce/Api/Resources/Currency.php b/src/Bigcommerce/Api/Resources/Currency.php new file mode 100644 index 00000000..365aa9f1 --- /dev/null +++ b/src/Bigcommerce/Api/Resources/Currency.php @@ -0,0 +1,38 @@ +getCreateFields()); + } + + public function update() + { + return Client::updateCurrency($this->id, $this->getUpdateFields()); + } + + public function delete() + { + return Client::deleteCurrency($this->id); + } +} diff --git a/test/Unit/Api/ClientTest.php b/test/Unit/Api/ClientTest.php index 0d26b247..a297f823 100644 --- a/test/Unit/Api/ClientTest.php +++ b/test/Unit/Api/ClientTest.php @@ -313,6 +313,7 @@ public function resources() array('options', '%sOption', 'Option'), array('optionsets', '%sOptionSet', 'OptionSet'), array('coupons', '%sCoupon', 'Coupon'), + array('currencies', '%sCurrency', 'Currency'), ); } diff --git a/test/Unit/Api/Resources/CurrencyTest.php b/test/Unit/Api/Resources/CurrencyTest.php new file mode 100644 index 00000000..274dabf5 --- /dev/null +++ b/test/Unit/Api/Resources/CurrencyTest.php @@ -0,0 +1,38 @@ + 1)); + $this->connection->expects($this->once()) + ->method('post') + ->with($this->basePath . '/currencies', (object)array('id' => 1)); + + $currency->create(); + } + + public function testUpdatePassesThroughToConnection() + { + $product = new Currency((object)array('id' => 1)); + $this->connection->expects($this->once()) + ->method('put') + ->with($this->basePath . '/currencies/1', (object)array()); + + $product->update(); + } + + public function testDeletePassesThroughToConnection() + { + $product = new Currency((object)array('id' => 1)); + $this->connection->expects($this->once()) + ->method('delete') + ->with($this->basePath . '/currencies/1'); + + $product->delete(); + } +} From 006152623ae655a25f6c3d87fefc3dff0ea083a3 Mon Sep 17 00:00:00 2001 From: bc-ruth Date: Thu, 28 Apr 2016 16:40:17 -0700 Subject: [PATCH 2/3] Rename variables --- test/Unit/Api/Resources/CurrencyTest.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/Unit/Api/Resources/CurrencyTest.php b/test/Unit/Api/Resources/CurrencyTest.php index 274dabf5..05421da0 100644 --- a/test/Unit/Api/Resources/CurrencyTest.php +++ b/test/Unit/Api/Resources/CurrencyTest.php @@ -18,21 +18,21 @@ public function testCreatePassesThroughToConnection() public function testUpdatePassesThroughToConnection() { - $product = new Currency((object)array('id' => 1)); + $currency = new Currency((object)array('id' => 1)); $this->connection->expects($this->once()) ->method('put') ->with($this->basePath . '/currencies/1', (object)array()); - $product->update(); + $currency->update(); } public function testDeletePassesThroughToConnection() { - $product = new Currency((object)array('id' => 1)); + $currency = new Currency((object)array('id' => 1)); $this->connection->expects($this->once()) ->method('delete') ->with($this->basePath . '/currencies/1'); - $product->delete(); + $currency->delete(); } } From b3749b01d1e47a76267588c9861d393c33eb1448 Mon Sep 17 00:00:00 2001 From: bc-ruth Date: Thu, 28 Apr 2016 17:15:16 -0700 Subject: [PATCH 3/3] Implement getCurrenciesCount --- src/Bigcommerce/Api/Client.php | 12 ++++++++++++ test/Unit/Api/ClientTest.php | 1 + 2 files changed, 13 insertions(+) diff --git a/src/Bigcommerce/Api/Client.php b/src/Bigcommerce/Api/Client.php index 08acca9b..bae46f78 100644 --- a/src/Bigcommerce/Api/Client.php +++ b/src/Bigcommerce/Api/Client.php @@ -1459,4 +1459,16 @@ 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()); + } } diff --git a/test/Unit/Api/ClientTest.php b/test/Unit/Api/ClientTest.php index a297f823..dbe7c6cd 100644 --- a/test/Unit/Api/ClientTest.php +++ b/test/Unit/Api/ClientTest.php @@ -261,6 +261,7 @@ public function collections() array('optionsets', 'getOptionSets', 'OptionSet'), array('products/skus', 'getSkus', 'Sku'), array('requestlogs', 'getRequestLogs', 'RequestLog'), + array('currencies', 'getCurrencies', 'Currency'), ); }