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:
<?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\SmsInstance;
use Angelfon\SDK\Rest\Api\V099\User\SmsContext;
class SmsList extends ListResource
{
function __construct(Version $version)
{
parent::__construct($version);
$this->uri = '/sms';
}
public function create($to, $options = array())
{
$options = new Values($options);
$recipients = array();
$body = array(
'body' => $options['body'],
'send_at' => $options['sendAt'],
'batch_name' => $options['batchName'],
'batch_id' => $options['batchId']
);
if (is_array($to)) {
$index = 0;
foreach ($to as $recipientName => $recipient) {
$recipients["recipients[$index]"] = $recipient;
$recipients["addressee[$index]"] = $recipientName;
$index++;
}
$body += $recipients;
} else {
$body['recipients'] = $to;
$body['addressee'] = $options['recipientName'];
}
$data = Values::of($body);
$payload = $this->version->create(
'POST',
$this->uri,
array(),
$data
);
$smsData = array(
'id' => count($payload['data']) > 1 ? $payload['data'] : $payload['data'][0],
'batch_id' => $payload['batch_id']
);
return new SmsInstance($this->version, $smsData);
}
public function getContext($id)
{
return new SmsContext($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'],
'status' => $options['status'],
'scheduled_before' => $options['scheduledBefore'],
'scheduled_after' => $options['scheduledAfter'],
'batch_id' => $options['batchId'],
));
$response = $this->version->page(
'GET',
$this->uri,
$params
);
return new SmsPage($this->version, $response, $this->solution);
}
}