Overview

Namespaces

  • Angelfon
    • SDK
      • Exceptions
      • Http
      • Rest
        • Api
          • V099
            • User

Classes

  • Angelfon\SDK\Domain
  • Angelfon\SDK\Http\GuzzleClient
  • Angelfon\SDK\Http\Response
  • Angelfon\SDK\InstanceContext
  • Angelfon\SDK\InstanceResource
  • Angelfon\SDK\ListResource
  • Angelfon\SDK\Options
  • Angelfon\SDK\Page
  • Angelfon\SDK\Rest\Api
  • Angelfon\SDK\Rest\Api\V099
  • Angelfon\SDK\Rest\Api\V099\User\CallContext
  • Angelfon\SDK\Rest\Api\V099\User\CallInstance
  • Angelfon\SDK\Rest\Api\V099\User\CallList
  • Angelfon\SDK\Rest\Api\V099\User\CallOptions
  • Angelfon\SDK\Rest\Api\V099\User\CallPage
  • Angelfon\SDK\Rest\Api\V099\User\CreateCallOptions
  • Angelfon\SDK\Rest\Api\V099\User\CreateSmsOptions
  • Angelfon\SDK\Rest\Api\V099\User\ReadCallOptions
  • Angelfon\SDK\Rest\Api\V099\User\ReadSmsOptions
  • Angelfon\SDK\Rest\Api\V099\User\SmsContext
  • Angelfon\SDK\Rest\Api\V099\User\SmsInstance
  • Angelfon\SDK\Rest\Api\V099\User\SmsList
  • Angelfon\SDK\Rest\Api\V099\User\SmsOptions
  • Angelfon\SDK\Rest\Api\V099\User\SmsPage
  • Angelfon\SDK\Rest\Api\V099\UserContext
  • Angelfon\SDK\Rest\Api\V099\UserInstance
  • Angelfon\SDK\Rest\Client
  • Angelfon\SDK\Serialize
  • Angelfon\SDK\Values
  • Angelfon\SDK\Version
  • Angelfon\SDK\VersionInfo

Interfaces

  • Angelfon\SDK\Http\Client

Exceptions

  • Angelfon\SDK\Exceptions\AngelfonException
  • Angelfon\SDK\Exceptions\ConfigurationException
  • Angelfon\SDK\Exceptions\RestException
  • Overview
  • Namespace
  • Class
  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';
    }

    /**
     * Create a new Sms instance
     */
    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
    );

    //when multiple recipients, id is array instead of integer, use batchId instead
    $smsData = array(
      'id' => count($payload['data']) > 1 ? $payload['data'] : $payload['data'][0],
      'batch_id' => $payload['batch_id']
    );

    return new SmsInstance($this->version, $smsData);
    }

  /**
   * Construct a SMS context
   * 
   * @param  int $id The SMS ID
   * @return \Angelfon\SDK\Rest\Api\V099\User\SmsContext
   */
  public function getContext($id)
  {
    return new SmsContext($this->version, $id);    
  }

  /**
   * Reads SmsInstance records from the API as a list.
   * Unlike stream(), this operation is eager and will load `limit` records into
   * memory before returning.
   * 
   * @param array|Options $options Optional Arguments
   * @param int $limit Upper limit for the number of records to return. read()
   *                   guarantees to never return more than limit.  Default is no
   *                   limit
   * @param mixed $pageSize Number of records to fetch per request, when not set
   *                        will use the default value of 50 records.  If no
   *                        page_size is defined but a limit is defined, read()
   *                        will attempt to read the limit with the most
   *                        efficient page size, i.e. min(limit, 1000)
   * @return SmsInstance[] Array of results
   */
  public function read($options = array(), $limit = null, $pageSize = null) {
    return iterator_to_array($this->page($options), false);
  }

  /**
   * Retrieve a single page of SmsInstance records from the API.
   * Request is executed immediately
   * 
   * @param array|Options $options Optional Arguments
   * @param mixed $pageSize Number of records to return, defaults to 50
   * @param string $pageToken PageToken provided by the API
   * @param mixed $pageNumber Page Number, this value is simply for client state
   * @return \Angelfon\SDK\SmsPage Page of SmsInstance
   */
  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);
  }
}
API documentation generated by ApiGen