From a3e695e5ef6261decef6a859c8edf3dda437d752 Mon Sep 17 00:00:00 2001 From: awilczek Date: Fri, 16 Jul 2021 17:19:42 +0200 Subject: [PATCH] Support for Async Actions --- README.md | 18 +++++++++- src/AsyncActions.php | 46 ++++++++++++++++++++++++ src/VoucherifyClient.php | 6 ++++ test/AsyncActionsTest.php | 75 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 144 insertions(+), 1 deletion(-) create mode 100644 src/AsyncActions.php create mode 100644 test/AsyncActionsTest.php diff --git a/README.md b/README.md index c9ac83d..c03144a 100644 --- a/README.md +++ b/README.md @@ -558,6 +558,21 @@ $client->promotions->tiers->delete($promotionTierId); $client->promotions->tiers->getAvailable(); ``` +### Async Actions API +Methods are provided within `$client->asyncActions->*` namespace. +- [Get Async Action](#get-async-action) +- [List Async Actions](#list-async-actions) + +#### [Get Async Action] +```php +$client->asyncActions->get($id); +``` +#### [List Async Actions] +```php +$client->asyncActions->getList(); +$client->asyncActions->getList($params); +``` + --- ### Utils @@ -744,7 +759,8 @@ Bug reports and pull requests are welcome through [GitHub Issues](https://github - Voucher informations: *get*, *redemption* - Voucher operations: *redeem* - +[Get Async Action]: https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#get-async-actions-1 +[List Async Actions]: https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#list-async-actions [Create Voucher]: https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#create-voucher [Get Voucher]: https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#vouchers-get diff --git a/src/AsyncActions.php b/src/AsyncActions.php new file mode 100644 index 0000000..811d623 --- /dev/null +++ b/src/AsyncActions.php @@ -0,0 +1,46 @@ +client = $client; + } + + /** + * @param string $id + * + * Get Async Action details. + * + * @throws \Voucherify\ClientException + */ + public function get($id) + { + return $this->client->get("/async-actions/" . rawurlencode($id), null); + } + + /** + * @param array|stdClass $filter + * + * Get a filtered list of Async Actions. The filter can include following properties: + * - limit - number + * - end_date - date in iso format + * + * @throws \Voucherify\ClientException + */ + public function getList($filter = null) + { + return $this->client->get("/async-actions/", $filter); + } + +} \ No newline at end of file diff --git a/src/VoucherifyClient.php b/src/VoucherifyClient.php index 737c1a6..7ce6d1c 100644 --- a/src/VoucherifyClient.php +++ b/src/VoucherifyClient.php @@ -69,6 +69,11 @@ class VoucherifyClient */ public $vouchers; + /** + * @var \Voucherify\AsyncActions + */ + public $asyncActions; + /** * @param string $apiId * @param string $apiKey @@ -99,6 +104,7 @@ public function __construct($apiId, $apiKey, $apiVersion = null, $apiUrl = null) ]); $this->validationRules = new ValidationRules($this->client); $this->vouchers = new Vouchers($this->client); + $this->asyncActions = new AsyncActions($this->client); /* ********* BACKWARD COMPATIBILITY ********* */ diff --git a/test/AsyncActionsTest.php b/test/AsyncActionsTest.php new file mode 100644 index 0000000..e6e290d --- /dev/null +++ b/test/AsyncActionsTest.php @@ -0,0 +1,75 @@ +get("/async-actions/test-id") + ->reply(200, [ "status" => "ok" ]); + + $result = self::$client->asyncActions->get("test-id"); + + $this->assertEquals($result, (object)[ "status" => "ok" ]); + + CurlMock::done(); + } + + public function testGetList() + { + CurlMock::register("https://api.voucherify.io/v1", self::$headers) + ->get("/async-actions/") + ->reply(200, [ "status" => "ok" ]); + + $result = self::$client->asyncActions->getList(); + + $this->assertEquals($result, (object)[ "status" => "ok" ]); + + CurlMock::done(); + } + + public function testGetListByQuery() + { + CurlMock::register("https://api.voucherify.io/v1", self::$headers) + ->get("/async-actions/") + ->query([ "limit" => 5, "end_date" => "2021-07-16T15:12:43Z" ]) + ->reply(200, [ "status" => "ok" ]); + + $result = self::$client->asyncActions->getList([ "limit" => 5, "end_date" => "2021-07-16T15:12:43Z" ]); + + $this->assertEquals($result, (object)[ "status" => "ok" ]); + + CurlMock::done(); + } + +} \ No newline at end of file