simpleweb/saasrunner-client-php

Name: saasrunner-client-php

Owner: Simpleweb

Description: PHP client library for the Saas Runner REST API

Created: 2014-02-12 09:55:51.0

Updated: 2014-09-11 16:25:19.0

Pushed: 2014-09-12 08:13:43.0

Homepage: http://saasrunner.com/

Size: 314

Language: PHP

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

Saas Runner PHP client library

PHP client library for the Saas Runner REST API

NB. Requires PHP 5.4+

Installation

Use Composer to install saasrunner-client-php

Add simpleweb/saasrunner-client-php to your composer.json file


equire": {
"simpleweb/saasrunner": "~0.1",


and then run

$ composer install
Usage

Refer to the Saas Runner API docs for more information on the API.

First create a client object with your Saas Runner API key

ent = new SaasRunner\Client('5201bad4-014a-4eb6-b18c-35b18c6b4249');

And then call the relevant resource

Subscribers

Create a new subscriber

ams = [
ubscriber_uid' => 'SB#013473',
eta' => [
'name' => 'J Bloggs'



ent->subscribers->create($params);
Transactions

Create a new transaction charge

ams = [
ubscriber_uid' => 'SB#013473',
ransaction_uid' => 'TX#827473',


ent->transactions->charge($params);

Create a new transaction refund

ams = [
ubscriber_uid' => 'SB#013473',
ransaction_uid' => 'TX#827474',


ent->transactions->refund($params);
Events

List all events

ent->events->index();

List an individual event

ent->events->show(3732);

Delete an event

ent->events->destroy(3732);
Error handling

Any response from the Saas Runner API with a 4xx status code will throw the following exception

Runner\Exception\ResponseError

For example:

sr-repl > $client->subscribers->create();
Fatal error:  Uncaught exception 'SaasRunner\Exception\ResponseError' with message 'Client error response
tus code] 400
son phrase] Bad Request
] http://api.saasrunner.com/subscribers' in src/SaasRunner/Client.php:88

You can catch this exception and programatically inspect the response

{
$client->subscribers->create();
tch(\SaasRunner\Exception\ResponseError $exception) {
echo $ex->getMessage();
// Client error response
// [status code] 400
// [reason phrase] Bad Request
// [url] http://api.saasrunner.com/subscribers

$response = $ex->getResponse();
echo $response->getStatusCode();
// 400

Built-in Saas Runner REPL

A REPL for experimenting and debugging is provided, powered by boris.

To start it, run the following command (replacing API_KEY with your API key)

$ bin/sr-repl API_KEY
[1] sr-repl > $client;
// object(SaasRunner\Client)(
//   'client' => object(Guzzle\Http\Client)(
//
//   ),
//   'apiKey' => '5e0130d4-034a-4eb6-b1cc-31b1876ba249',
//   ...
// )

The $client object is preloaded for you, using the API key you gave.

Running the tests
$ bin/phpspec run

This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.