dev-devel
dev-devel https://github.com/Arrowsphere/ClientPHP clients for the Arrowsphere API
MIT
The Requires
- php >=5.5.0
- guzzlehttp/guzzle 6.1.*
- monolog/monolog 1.17.2
by Olivier Lépine
PHP clients for the Arrowsphere API
The Arrowsphere API Client Suite is the best way to consume services offered by the Arrowsphere xAC API., (*1)
Written in PHP and Framework-agnostic, the Client is available as a composer package., (*2)
xAC Client is a complete PHP semantic client able to perform queries on the xAC API., (*3)
Client configuration is quite simple. Set your API secret key, the API URL and the desired API version., (*4)
use Arrowsphere\Client\xAC as Client; Client::setApiKey('MySecretApiKeyThatNobodyKnowsAbout'); Client::setBaseUrl('https://xac.arrowsphereconnect.com/api/'); Client::setVersion(2); // 1 and 2 (default) are valid versions
Get the last response from the service with the getLastRespons() static method. The content is an array representing the latest received json payload., (*5)
var_dump(Client::getLastResponse()); array(6) { ["status"]=> int(0) ["message"]=> string(7) "Success" ["ACUserID"]=> int(1) ["ACTransactionID"]=> string(36) "7d985f56-011f-436e-bf38-4afec9467cc6" ["language"]=> string(5) "en_UK" ["body"]=> array(4) { ["parameters"]=> array(0) { } ["data"]=> ...
Get an array of available services for the whole API and for the user identified by the API key or for a given Entity() instance., (*6)
// Get all services for user ahtentified with API key var_dump(Client::getServices()); array(15) { ["transactions"]=> array(3) { ["type"]=> string(10) "collection" ["description"]=> string(16) "Get Transactions" ["endpoint"]=> string(12) "transactions" } ["customers"]=> array(3) { ["type"]=> string(10) "collection" ["description"]=> string(39) "Get Customers of authenticated reseller" ["endpoint"]=> string(9) "customers" } ... var_dump(Client::getServices(Client::customer()));
$cursor = Client::customers(); // get first customers batch as an array of xAC\Entity() instances $collection = $cursor->get(); // or walk through collection $cursor->rewind(); foreach ($cursor->getOne() as $entity) { // do something on $entity instance }
// get next batch $data = $cursor->next(); // get previous page $data = $cursor->prev();
// add filter on-the-fly $cursor->filter('name', 'Acme')->get();
Entities are elements like customer, subscription or order. Each element can be accessed as an xAC\Entity() instance., (*7)
// Get a customer instance $customer = Client::customer('myRef'); // Get a property echo $customer->company_name;
An entity instance can contain collections. To access data, get a cursor and proceed as described in the Cursors section., (*8)
// Get a cursor for the subscriptions collection $cursor = $customer->subscriptions(); // get first batch $batch = $cursor->get();
To execute operations on a given Entity() instance, either populated or empty, get an Action() handler instance., (*9)
// create an empty customer instance $customer = Client::customer(); // get a create action handler $action = $customer->create(); // or do the same in one pass $action = Client::customer()->create();
Action() instances can receive a data array with the setData() method., (*10)
$action->setData(['someKey' => 'someValue']);
Action() can then be executed with the execute() method., (*11)
// $result will contain a boolean $result = $action->execute();
// create an empty customer instance $customer = Client::customer(); // get a provision action $action = $customer->provision(); $action->setData([ 'customer_ref' => 'newRef', 'customer_name' => 'Acme Limited', ... ]); $res = $action->execute(); // send a create request to the API with customer data $result = $customer->create([ 'customer_ref' => 'newRef', 'customer_name' => 'Acme Limited', ... ]);
PHP clients for the Arrowsphere API
MIT