1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140:
<?php
namespace Angelfon\SDK\Rest\Api\V099\User;
use Angelfon\SDK\ListResource;
use Angelfon\SDK\Values;
use Angelfon\SDK\Version;
use Angelfon\SDK\Serialize;
use Angelfon\SDK\Rest\Api\V099\User\CallInstance;
use Angelfon\SDK\Rest\Api\V099\User\CallContext;
class CallList extends ListResource
{
function __construct(Version $version)
{
parent::__construct($version);
$this->uri = '/calls';
}
public function create($to, $options = array())
{
$options = new Values($options);
$recipients = array();
$body = array(
'callerid' => Serialize::booleanToString($options['callerId']),
'call_from' => $options['callFrom'],
'batch_name' => $options['batchName'],
'batch_id' => $options['batchId'],
'calltime' => $options['callAt'],
'type' => $options['type'],
'audio' => $options['audioId1'],
'audio1' => $options['audioId2'],
'audio2' => $options['audioId3'],
'tts' => $options['tts1'],
'tts1' => $options['tts2'],
'force_schedule' => Serialize::booleanToString($options['forceSchedule']),
'adjust_schedule' => Serialize::booleanToString($options['adjustSchedule']),
);
if (is_array($to)) {
$index = 0;
foreach ($to as $recipientName => $recipient) {
$recipients["recipients[$index]"] = $recipient;
$recipients["abrid[$index]"] = $recipientName;
$index++;
}
$body += $recipients;
} else {
$body['recipients'] = $to;
$body['abrid'] = $options['recipientName'];
}
$data = Values::of($body);
$payload = $this->version->create(
'POST',
$this->uri,
array(),
$data
);
$callData = array(
'id' => count($payload['data']) > 1 ? $payload['data'] : $payload['data'][0],
'batch_id' => $payload['batch_id']
);
return new CallInstance($this->version, $callData);
}
public function getContext($id)
{
return new CallContext($this->version, $id);
}
public function read($options = array(), $limit = null, $pageSize = null) {
return iterator_to_array($this->page($options), false);
}
public function page($options = array()) {
$options = new Values($options);
$params = Values::of(array(
'recipient' => $options['recipient'],
'batch_id' => $options['batchId'],
'started_before' => $options['startedBefore'],
'started_after' => $options['startedAfter'],
'scheduled_before' => $options['scheduledBefore'],
'scheduled_after' => $options['scheduledAfter'],
'call_from' => $options['callFrom'],
'status' => $options['status'],
'answer' => $options['answer'],
));
$response = $this->version->page(
'GET',
$this->uri,
$params
);
return new CallPage($this->version, $response, $this->solution);
}
}