Kazoo PHP SDK Documentation - Read the Docs€¦ · •Follows PSR-0 conventions and coding...

Preview:

Citation preview

Kazoo PHP SDK DocumentationRelease 0.1

2600hz Inc

May 24, 2016

Contents

1 Status 1

2 Quickstart 32.1 Create a Sub-Account . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32.2 Create a Sub-Sub-Account . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32.3 Create a SIP Device . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42.4 User / Device / Extension / VoiceMail . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42.5 Read Account CDRS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42.6 Generating Kazoo JSON . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4

3 Installation 73.1 Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73.2 Requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73.3 Autoload . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7

4 User Guide 94.1 REST API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9

5 API Documentation 115.1 Kazoo Rest Entities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115.2 Kazoo Rest Collections . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12

6 Support and Development 136.1 Running the Tests . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136.2 Making the Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13

7 Indices and tables 15

i

ii

CHAPTER 1

Status

This documentation is for version 0.1 of kazoo-php-sdk.

1

Kazoo PHP SDK Documentation, Release 0.1

2 Chapter 1. Status

CHAPTER 2

Quickstart

2.1 Create a Sub-Account

The following code will create a new Account resource:

$client = new \Kazoo\Client($username, $password, $sipRealm, $options);

$newAccount = $client->accounts()->new();$newAccount->name = "New Test Account";$newAccount->realm = "sip".rand(0,10000).".testaccount.com";$newAccount->timezone = "America/Chicago";

$client->accounts()->create($newAccount);

echo "<pre>";echo $account;echo "</pre>";

2.2 Create a Sub-Sub-Account

The following code will create a new Account resource:

$client = new \Kazoo\Client($username, $password, $sipRealm, $options);

...

...$prevAccount = $client->accounts()->retrieve($account_id);......

$client->setAccountContext($prevAccount->id);

$newSubAccount = $client->accounts()->new();$newSubAccount->name = "New Sub Test Account";$newSubAccount->realm = "sip".rand(0,10000).".subtestaccount.com";$newSubAccount->timezone = "America/Chicago";

$client->accounts()->create($newSubAccount);

echo "<pre>";

3

Kazoo PHP SDK Documentation, Release 0.1

echo $newSubAccount;echo "</pre>";

2.3 Create a SIP Device

The following code will create a new Device resource for the Account (or sub-account):

$shellDevice = $client->accounts()->devices()->new();$num = substr(number_format(time() * rand(),0,'',''),0,4);$shellDevice->name = "Test Device #" . $num;$shellDevice->sip->password = substr(number_format(time() * rand(),0,'',''),0,10);$shellDevice->sip->username = "testdevice".$num;$newDevice = $this->client->accounts()->devices()->create($shellDevice);

echo "<pre>";echo $newDevice;echo "</pre>";

2.4 User / Device / Extension / VoiceMail

The following code with create a User, a device for that User,

$start = strtotime('-30 Day') + \Kazoo\Client::GREGORIAN_OFFSET;$end = time() + \Kazoo\Client::GREGORIAN_OFFSET;$filters = array("created_from" => $start, "created_to" => $end);$cdrs = $client->accounts()->cdrs()->retrieve($filters);

echo "<pre>";echo print_r($cdrs);echo "</pre>";

2.5 Read Account CDRS

The following code will generate a list of CDRS

$start = strtotime('-30 Day') + \Kazoo\Client::GREGORIAN_OFFSET;$end = time() + \Kazoo\Client::GREGORIAN_OFFSET;$filters = array("created_from" => $start, "created_to" => $end);$cdrs = $client->accounts()->cdrs()->retrieve($filters);

echo "<pre>";echo print_r($cdrs);echo "</pre>";

2.6 Generating Kazoo JSON

Account JSON:

4 Chapter 2. Quickstart

Kazoo PHP SDK Documentation, Release 0.1

$username = 'testuser';$password = 'pAssw0rd';$sipRealm = 'sip.realm.com';$options = array();$options["base_url"] = "http://127.0.0.1:8000";$client = new \Kazoo\Client($username, $password, $sipRealm, $options);

$account = $client->accounts()->new();echo "<pre>";echo $account;echo "</pre>";

Will result in the following json:

{"name": "","realm": "","timezone": "","caller_id": {"internal": {

"name": ""},"external": {"name": ""

},"default": {

"name": ""},"emergency": {

"name": ""}

},"caller_id_options": {"reformat": ""

},"notifications": {"voicemail_to_email": {

"email_text_template": "","email_html_template": "","email_subject_template": "","support_number": "","support_email": "","service_url": "","service_name": "","service_provider": "","send_from": ""

},"deregister": {"email_text_template": "","email_html_template": "","email_subject_template": "","support_number": "","support_email": "","service_url": "","service_name": "","service_provider": "","send_from": ""

},

2.6. Generating Kazoo JSON 5

Kazoo PHP SDK Documentation, Release 0.1

"password_recovery": {"email_text_template": "","email_html_template": "","email_subject_template": "","support_number": "","support_email": "","service_url": "","service_name": "","service_provider": "","send_from": ""

},"first_occurrence": {"send_to": "","sent_initial_registration": false,"sent_initial_call": false,"email_text_template": "","email_html_template": "","email_subject_template": "","support_number": "","support_email": "","service_url": "","service_name": "","service_provider": "","send_from": ""

}},"media": {"bypass_media": "","audio": {

"codecs": []},"video": {"codecs": []

},"fax": {

"option": ""}

},"music_on_hold": {"media_id": ""

}}

View more examples of JSON generation here: usage-json

6 Chapter 2. Quickstart

CHAPTER 3

Installation

3.1 Features

• Follows PSR-0 conventions and coding standard: autoload friendly

• Light and fast thanks to lazy loading of API classes

• Extensively tested and documented

3.2 Requirements

• PHP >= 5.3.2 with cURL extension

• Guzzle library

• Monolog library

• (optional) PHPUnit to run tests.

3.3 Autoload

The new version of kazoo-php-sdk using Composer. The first step to use kazoo-php-sdk is to download composer:

$ curl -s http://getcomposer.org/installer | php

Then we have to install our dependencies using:

$ php composer.phar install

Now we can use autoloader from Composer by:

{"require": {

"2600hz/kazoo-php-sdk": "*"},"minimum-stability": "dev"

}

kazoo-php-sdk follows the PSR-0 convention names for its classes, which means you can easily integrate kazoo-php-sdk classes loading in your own autoloader.

7

Kazoo PHP SDK Documentation, Release 0.1

8 Chapter 3. Installation

CHAPTER 4

User Guide

4.1 REST API

4.1.1 Using the Kazoo REST API

Creating a REST Client

Before querying the API, you’ll need to create a KazooClient instance. The constructor takes your Kazoo user-name, password, and sip realm of your root Account.

$username = 'testuser';$password = 'pAssw0rd';$sipRealm = 'sip.realm.com';$options = array();$options["base_url"] = "http://127.0.0.1:8000";$client = new \Kazoo\Client($username, $password, $sipRealm, $options);

4.1.2 Accounts

Creating a Subaccount

$client = new \Kazoo\Client($username, $password, $sipRealm, $options);

$newAccount = $client->accounts()->new();$newAccount->name = "New Test Account";$newAccount->realm = "sip".rand(0,10000).".testaccount.com";$newAccount->timezone = "America/Chicago";

$client->accounts()->create($newAccount);

Get a list of sub accounts

$client = new \Kazoo\Client($username, $password, $sipRealm, $options);$accounts = $this->client->accounts()->retrieve();

9

Kazoo PHP SDK Documentation, Release 0.1

Get an empty Account

$client = new \Kazoo\Client($username, $password, $sipRealm, $options);$account = $this->client->accounts()->new();

4.1.3 Devices

Creating a new Device

$client = new \Kazoo\Client($username, $password, $sipRealm, $options);

$shellDevice = $client->accounts()->devices()->new();$num = substr(number_format(time() * rand(),0,'',''),0,4);$shellDevice->name = "Test Device #" . $num;$shellDevice->sip->password = substr(number_format(time() * rand(),0,'',''),0,10);$shellDevice->sip->username = "testdevice".$num;$newDevice = $this->client->accounts()->devices()->create($shellDevice);

Get a list of sub accounts

$client = new \Kazoo\Client($username, $password, $sipRealm, $options);$devices = $this->client->accounts()->devices()->retrieve();

Get a list of sub accounts

$client = new \Kazoo\Client($username, $password, $sipRealm, $options);$accounts = $this->client->accounts()->retrieve();

Get an empty Device

$client = new \Kazoo\Client($username, $password, $sipRealm, $options);$device = $this->client->accounts()->devices()->new()

10 Chapter 4. User Guide

CHAPTER 5

API Documentation

5.1 Kazoo Rest Entities

5.1.1 AbstractEntity

class AbstractEntityEntity abstraction

__construct(KazooClient $client, $uri, $data = null)@param KazooClient $client @param string $uri

updateFromResult(stdClass $result)@param stdClass $result @return KazooApiDataAbstractEntity

partialUpdateFromResult(stdClass $result)@param stdClass $result @return KazooApiDataAbstractEntity

__get($prop)@param type $prop @return type

__set($prop, $value)@param type $prop @param type $value

__toString()@return type

getData()@return type

toJSON()@return json

__call($name, $arguments)@param string $name @param null|array $arguments @return KazooApiDataAbstractEntity

5.1.2 Account

class AccountAccount Entity maps to a REST resource.

__call($name, $arguments)@param string $name @param null|array $arguments @return KazooApiDataAbstractEntity

11

Kazoo PHP SDK Documentation, Release 0.1

5.1.3 Agent

class Agent

5.1.4 Callflow

class CallflowCallflow Entity maps to a REST resource.

5.2 Kazoo Rest Collections

5.2.1 AccountCollection

class AccountCollection

5.2.2 AgentCollection

class AgentCollection

5.2.3 CallflowCollection

class CallflowCollection

5.2.4 CarrierResourceCollection

class CarrierResourceCollection

5.2.5 ClickToCallCollection

class ClickToCallCollection

5.2.6 ConferenceCollection

class ConferenceCollection

12 Chapter 5. API Documentation

CHAPTER 6

Support and Development

All development occurs on Github. To check out the source, run

git clone git@github.com:2600hz/kazoo-php-sdk.git

Report bugs using the Github issue tracker.

6.1 Running the Tests

To run the unit tests

phpunit

6.2 Making the Documentation

Our documentation is written using Sphinx. You’ll need to install Sphinx and the Sphinx PHP domain before you canbuild the docs.

make docs-install

Once you have those installed, making the docs is easy.

make docs

13

Kazoo PHP SDK Documentation, Release 0.1

14 Chapter 6. Support and Development

CHAPTER 7

Indices and tables

• genindex

• search

15

Kazoo PHP SDK Documentation, Release 0.1

16 Chapter 7. Indices and tables

Index

Symbols__call() (AbstractEntity method), 11__call() (Account method), 11__construct() (AbstractEntity method), 11__get() (AbstractEntity method), 11__set() (AbstractEntity method), 11__toString() (AbstractEntity method), 11

AAbstractEntity (class), 11Account (class), 11AccountCollection (class), 12Agent (class), 12AgentCollection (class), 12

CCallflow (class), 12CallflowCollection (class), 12CarrierResourceCollection (class), 12ClickToCallCollection (class), 12ConferenceCollection (class), 12

GgetData() (AbstractEntity method), 11

PpartialUpdateFromResult() (AbstractEntity method), 11

TtoJSON() (AbstractEntity method), 11

UupdateFromResult() (AbstractEntity method), 11

17

Recommended