-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #77 from voucherifyio/aw/async-actions
Support for Async Actions
- Loading branch information
Showing
4 changed files
with
144 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
namespace Voucherify; | ||
|
||
class AsyncActions | ||
{ | ||
/** | ||
* @var \Voucherify\ApiClient | ||
*/ | ||
private $client; | ||
|
||
/** | ||
* @param \Voucherify\ApiClient $client | ||
*/ | ||
public function __construct($client) | ||
{ | ||
$this->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); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<?php | ||
|
||
use Voucherify\Test\Helpers\CurlMock; | ||
|
||
use Voucherify\VoucherifyClient; | ||
use Voucherify\ClientException; | ||
|
||
class AsyncActionsTest extends PHPUnit_Framework_TestCase | ||
{ | ||
protected static $headers; | ||
protected static $apiId; | ||
protected static $apiKey; | ||
protected static $client; | ||
|
||
public static function setUpBeforeClass() | ||
{ | ||
self::$apiId = "c70a6f00-cf91-4756-9df5-47628850002b"; | ||
self::$apiKey = "3266b9f8-e246-4f79-bdf0-833929b1380c"; | ||
self::$headers = [ | ||
"Content-Type: application/json", | ||
"X-App-Id: " . self::$apiId, | ||
"X-App-Token: " . self::$apiKey, | ||
"X-Voucherify-Channel: PHP-SDK" | ||
]; | ||
self::$client = new VoucherifyClient(self::$apiId, self::$apiKey); | ||
|
||
CurlMock::enable(); | ||
} | ||
|
||
public static function tearDownAfterClass() | ||
{ | ||
CurlMock::disable(); | ||
} | ||
|
||
public function testGet() | ||
{ | ||
CurlMock::register("https://api.voucherify.io/v1", self::$headers) | ||
->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(); | ||
} | ||
|
||
} |