Bandwidth PHP SDK
  • Namespace
  • Class

Namespaces

  • Catapult
  • None

Classes

  • Catapult\Account
  • Catapult\AnswerCallEvent
  • Catapult\Application
  • Catapult\ApplicationCollection
  • Catapult\AudioMixin
  • Catapult\BaML
  • Catapult\BaMLAssert
  • Catapult\BaMLAttribute
  • Catapult\BaMLContainer
  • Catapult\BaMLGather
  • Catapult\BaMLGeneric
  • Catapult\BaMLHangup
  • Catapult\BaMLPlayAudio
  • Catapult\BaMLRedirect
  • Catapult\BaMLResource
  • Catapult\BaMLSendMessage
  • Catapult\BaMLSpeakSentence
  • Catapult\BaMLText
  • Catapult\BaMLTransfer
  • Catapult\BaMLVerb
  • Catapult\BaMLVerbGather
  • Catapult\BaMLVerbHangup
  • Catapult\BaMLVerbPlayAudio
  • Catapult\BaMLVerbRecord
  • Catapult\BaMLVerbRedirect
  • Catapult\BaMLVerbSendMessage
  • Catapult\BaMLVerbSpeakSentence
  • Catapult\BaMLVerbTransfer
  • Catapult\BaseResource
  • Catapult\BaseUtilities
  • Catapult\Bridge
  • Catapult\BridgeCollection
  • Catapult\Call
  • Catapult\Callback
  • Catapult\CallCollection
  • Catapult\CallCombo
  • Catapult\CallEvent
  • Catapult\CallEvents
  • Catapult\CallEventsCollection
  • Catapult\Cleaner
  • Catapult\Client
  • Catapult\ClientResource
  • Catapult\CollectionIterator
  • Catapult\CollectionObject
  • Catapult\CollectionSequence
  • Catapult\Conference
  • Catapult\ConferenceEventMixin
  • Catapult\ConferenceMember
  • Catapult\ConferenceMemberEvent
  • Catapult\ConferencePlaybackEvent
  • Catapult\Constructor
  • Catapult\Converter
  • Catapult\Credentials
  • Catapult\CredentialsUser
  • Catapult\DataPacket
  • Catapult\DataPacketCollection
  • Catapult\Date
  • Catapult\DependsObject
  • Catapult\DependsResource
  • Catapult\Domains
  • Catapult\DomainsCollection
  • Catapult\DTMF
  • Catapult\DtmfCallEvent
  • Catapult\Endpoints
  • Catapult\EndpointsCollection
  • Catapult\EndpointsCredentials
  • Catapult\EndpointsMulti
  • Catapult\EndpointsToken
  • Catapult\Ensure
  • Catapult\EnsureResource
  • Catapult\ErrorCallEvent
  • Catapult\Event
  • Catapult\EventAssert
  • Catapult\EventCollection
  • Catapult\EventResource
  • Catapult\EventType
  • Catapult\FileHandler
  • Catapult\Gather
  • Catapult\GatherCallEvent
  • Catapult\GatherCollection
  • Catapult\GenericResource
  • Catapult\HangupCallEvent
  • Catapult\Id
  • Catapult\IncomingCallEvent
  • Catapult\LoadsResource
  • Catapult\Locator
  • Catapult\Log
  • Catapult\Media
  • Catapult\MediaCollection
  • Catapult\MediaURL
  • Catapult\Message
  • Catapult\MessageCollection
  • Catapult\MessageEvent
  • Catapult\MessageMulti
  • Catapult\MetaResource
  • Catapult\Multi
  • Catapult\NumberInfo
  • Catapult\Page
  • Catapult\Parameters
  • Catapult\PathResource
  • Catapult\PhoneCombo
  • Catapult\PhoneNumber
  • Catapult\PhoneNumbers
  • Catapult\PhoneNumbersCollection
  • Catapult\PlaybackCallEvent
  • Catapult\PrototypeUtility
  • Catapult\Recording
  • Catapult\RecordingCallEvent
  • Catapult\RecordingCollection
  • Catapult\RejectCallEvent
  • Catapult\RemoveResource
  • Catapult\Resolver
  • Catapult\ResolverResource
  • Catapult\RESTClient
  • Catapult\SchemaResource
  • Catapult\Sentence
  • Catapult\SIP
  • Catapult\SIPRealm
  • Catapult\Size
  • Catapult\SpeakCallEvent
  • Catapult\StringifyResource
  • Catapult\SubfunctionObject
  • Catapult\SubFunctionResource
  • Catapult\TextMessage
  • Catapult\Timeout
  • Catapult\TimeoutCallEvent
  • Catapult\TitleUtility
  • Catapult\Transaction
  • Catapult\TransactionCollection
  • Catapult\Transcription
  • Catapult\TranscriptionCallEvent
  • Catapult\TranscriptionCollection
  • Catapult\Types
  • Catapult\URIResource
  • Catapult\UserError
  • Catapult\UserErrorCollection
  • Catapult\VerifyResource
  • Catapult\Voice
  • Catapult\XMLUtility
  • CatapultApiWarning

Interfaces

  • Catapult\API
  • Catapult\API_MODE
  • Catapult\BAML_SETTINGS
  • Catapult\BAML_VERBS
  • Catapult\BAML_XML_HANDLERS
  • Catapult\BAML_XML_METHODS
  • Catapult\BAML_XML_OPTIONS
  • Catapult\CALL_ERROR
  • Catapult\CALL_STATES
  • Catapult\CONFERENCE_MEMBER_STATES
  • Catapult\CONFERENCE_SPEAK_STATES
  • Catapult\CONFERENCE_STATES
  • Catapult\DEFAULTS
  • Catapult\EXCEPTIONS
  • Catapult\GATHER_REASONS
  • Catapult\GATHER_STATES
  • Catapult\MESSAGE_DIRECTIONS
  • Catapult\MESSAGE_STATES
  • Catapult\NUMBER_STATES
  • Catapult\PATHS
  • Catapult\PLAYBACK_STATES
  • Catapult\RECORDING_STATES
  • Catapult\RECORDING_STATUSES
  • Catapult\SPEAK_STATES
  • Catapult\TRANSCRIPTION_STATES
  • Catapult\WARNINGS

Exceptions

  • CatapultApiException

Functions

  • includeDir
  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 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 
<?php

namespace Catapult;

/**
 * Object based credentials
 * object. Use in place of JSON
 * file if needed. Provide
 * seamless crossover from json object
 */
final class CredentialsUser {
    /* the order we normally get arguments in */
    public static $order = array(
      API::API_BANDWIDTH_USER_ID,
      API::API_BANDWIDTH_TOKEN,
      API::API_BANDWIDTH_SECRET,
      API::API_BANDWIDTH_APPLICATION_ID,
      API::API_BANDWIDTH_VALID_NUMBERS
    );

    /**
    * Accept a connection with connections
    * without a JSON object. This can
    * be used alternatively.
    * ex: $cred = new Catapult\Credentials("USER_ID","API_KEY","API_SECRET"); 
    * this will initilaize CredentialsUser as a property of Credentials
    */
    public function __construct(/* polymorphic accept any arg with 'BANDWIDTH' prefix */)
    {
      $cnt = 0;
      $args = func_get_args();
      $found = array();

      foreach ($args as $arg) {
        $found[] = $k = self::$order[$cnt];
        $this->$k = $arg;

        $cnt ++;
      }

      foreach (self::$order as $key) {
        if (!(in_array($key, $found)))
          $this->$key = "";

      }
    }
}

/**
 * Get and set the credential in the JSON file
 * if we cant find credentials.json
 * @object Credentials can also
 * be loaded by associative an array or 
 * from the envorinment variables
 */
final class Credentials {

     private $secure = array(
       API::API_BANDWIDTH_SECRET,
       API::API_BANDWIDTH_TOKEN
     );

    /** 
     * credentials should initially be set to 'credentials.json' 
     * which will be found in the parent directory 
     *
     */
    public static $credentials_opts = array(
      "file" => "credentials.json"
     );

    /** set the credentials incase we need JSON **/
    private $credentials = null;

    /**
     * All string parameters
     * if provided use these in place of json credentials
     *
     * @param user_token: Bandwidth user id
     * @param api_token: API token
     * @param api_secret: API secret
     */
    public function __construct($user_token='',
              $api_token='',
              $api_secret='') 
    { 
      $file = self::$credentials_opts['file'];

      /* only consider parameter init if all provided */
      if (isset(self::$credentials_opts['path'])) {
        /** do not load path twice **/
        if (!preg_match("/credentials\.json/", self::$credentials_opts['path'])) {
          self::$credentials_opts['path'] = self::$credentials_opts['path'] . DIRECTORY_SEPARATOR . self::$credentials_opts['file'];
        }
      } else {
        self::$credentials_opts['path'] = realpath(getcwd()) . DIRECTORY_SEPARATOR . self::$credentials_opts['file'];
      }

      if ($user_token && $api_token && $api_secret) {
        $this->credentials = new CredentialsUser($user_token, $api_token, $api_secret);
      } else {
        if (!is_file(self::$credentials_opts['path'])) {
          throw new \CatapultApiException("$file was not found in directory " . self::$credentials_opts['path']);
        }
        $this->credentials = file_get_contents(self::$credentials_opts['path']);
      }
    } 


    /* get a key or all the config in the config */
    public function get($key=null)
    {

      if ($key == null) {
        return json_decode(file_get_contents(self::$credentials_opts['path']));
      }

      return $this->getVal($key);
    }

    /**
     * Returns the area we've
     * initialized the credentials
     * object with. Possibilities
     *
     * @return
     * \stdClass [JSON Object]
     * \stdClass [CredentialsUser]
     *
     */
    protected function getParamInstance()
    { }


    /**
     * Gets either a singular
     * or array based value by
     * key. Where all keys are 
     * elements in the credentials.json
     * file. 
     * @param key: key for element
     * @param show: omit with asterisks
     */
    protected function getVal($key, $show=TRUE)
    {
      if (!($this->credentials instanceof CredentialsUser)) {
        $content = json_decode(file_get_contents(self::$credentials_opts['path']));
      } else {
        $content = $this->credentials;
      }

      if (!array_key_exists($key, get_object_vars($content))) {
        return false;
      }

      if (is_array($content->{$key})) {
        return implode(",", $content->{$key});
      }
            
      return $content->{$key};
    }

   /**
    * Gets a number from the provided
    * set in credentials.json. This
    * will not have any affect towards
    * the PhoneNumber service.
    * 
    * @param idx: index of number
    */
    public function getNumber($idx)
    {
      return $content->BANDWIDTH_VALID_NUMBERS[$idx];
    }

    /**
     * Shortcut. Get the first app
     * id. Usage
     *
     * @param idx: index of app
     */
    public function getApplicationId($idx=0)
    {
      return $content->BANDWIDTH_APPLICATION_ID;
    }

    /**
     * Set a value at runtime
     *
     * @param key: key to set
     * @param val: value
     */
    public function set($key, $val)
    {
      $this->credentials->$key = $val;
    }

    /**
     * Sets the path of credentials.json
     *
     * @param path: path
     */
    public static function setPath($path)
    {
      $rf = realpath($path);
      if (is_file($rf))
        throw new \CatapultApiException("Provided folder does not exist");  

      self::$credentials_opts['path'] = realpath($path);
    }

    /**
     * Sets the file 
     * to find credentials
     * suitable when the term credentials is not
     * being used for the credentials file
     *
     * @param file: file
     */
    public static function setFile($file)
    {
      $rf = realpath($file);
      if (is_file($rf))
        throw new \CatapultApiException("File provided does not exist..");  

      self::$credentials_opts['file'] = realpath($file);
    }

}
Bandwidth PHP SDK API documentation generated by ApiGen