/** * point to a * member and update * * @param params: set of arguments with * with memberId */ public function updateMember($params) { $args = Ensure::Input($params); $url = URIResource::Make($this->path, array($this->id, "members", $args->val("memberId"))); $member = $this->client->post($url, $args->get()); return $this->member($member['id']); }
/** * Patch the given * application with new information * same as update/1 * * @param data: set of application data */ public function patch($data) { $data = Ensure::Input($data); $this->client->post($this->path . "/" . $this->id, $data->get()); // reload after recreating return Constructor::make($this, array("id" => $this->id), TRUE); }
/** * Speak a sentence. * where voice in args has to be a * valid voice * * @param args [assoc array] */ public function speakSentence($args) { $args = Ensure::Input($args); $url = new URIResource($this->getAudioUrl()); $data = $args->get(); $this->client->post((string) $url, $data); }
/** * Create musn't preserve the domainId * as this will be our path. We will pass * it in the parameter, use PathResource * then remove it * * @param: args Endpoint create data */ public function create() { $data = Ensure::Input(func_get_args()); $data = $data->get(); if (isset($data['domainId'])) { new PathResource($this, array("domains" => $data['domainId'], "endpoints" => "")); } return parent::create($data); }
/** * * treat transcriptions * create/0 different * as we need the path */ public function create() { $data = Ensure::Input(func_get_args()); $data = $data->get(); if (!isset($data['recordingId'])) { $data['recordingId'] = ""; } return parent::create($data, new RemoveResource($this, array("recordingId"), new PathResource($this, array("recordings" => $data['recordingId'], "transcriptions" => "")))); }
/** * Make an HTTP request. * * @param string $url * @param string|array $content * @param array $headers * @param string $method * * @return string */ public function makeRequest($url, $content = null, $headers = [], $method = 'GET') { $context_options = array_replace_recursive($this->contextOptionDefaults, ['http' => ['method' => $method, 'header' => $headers, 'content' => $content]]); $this->app->debug('Sending report to {url}: {context_options}', compact('url', 'context_options')); $response = file_get_contents($url, false, stream_context_create($context_options)); $this->app->debug('Response from {url}: {response} [headers: {headers}]', ['url' => $url, 'response' => $response, 'headers' => $http_response_header]); $http_header = $http_response_header[0]; Ensure::matches('#HTTP/\\d+\\.\\d+\\s+2\\d{2}#Ai', $http_header, sprintf('Bad response from server: "%s"', $http_header)); return $response; }
/** * Send message with additional parameters * important rewrite in place of * more polymorphic style. * i.e send(from, to, message, calback) * * @param args: list of valid parameters */ public function send($args) { $data = Ensure::Input($args); $url = URIResource::Make($this->path); if ($data->has("media")) { $data->add("media", (string) new MediaURL($data->val("media", $this))); } $message_id = Locator::Find($this->client->post($url, $data->get())); $data->add("id", $message_id); return Constructor::Make($this, $data->get(), array("messageId" => "id")); }
/** * push a message to * the queue * @all params -> string to objects according to api. */ public function pushMessage() { $args = func_get_args(); $args = $args[0]; $out = array(); $cnt = 0; foreach ($args as $arg) { $out[self::$args[$cnt]] = $arg; $cnt++; } $message = Ensure::Input($out); $this->messages[] = $message->get(); }
public function __construct($data = null) { if (!in_array($_SERVER['HTTP_METHOD'], array("GET", "POST"))) { throw new \CatapultApiException("Catapult events only accept GET and POST"); } if ($data != null) { // mocking tests only $data = Ensure::Input($data); } else { $data = Ensure::Input(json_decode(file_get_contents("php://input"))); } return new EventType(new EventResource($this, $data)); }
/** * Main function figure out whether * to create or get this object. * * @param object: Catapult Model Object * @param data: EnsuredInput */ public static function Find(&$object, $data) { $data = Ensure::Input($data); $is_str = $data->is_string(); if ($data->data == null || sizeof($data) == 0) { return $object; } /** * certain objects cannot * be resolved without there parents * this is 'only' the case when arity is 1 * otherwise we follow normal flow */ if ($object->loads->silent && $is_str) { return $object; } /** * if we have a singleton * treat as primary key then * invoke create call with * in some cases the primary method can be * create in others get */ if ($is_str && !$object->loads->silent) { if ($object->loads->primary == 'create' || !isset($object->loads->primary)) { return $object->create(array($object->loads->primary => $data)); } else { return $object->get($data->get()); } } $input = Ensure::Input($data); $data = $input->get(); if (in_array("id", array_keys($data))) { $object->get($data['id']); } else { $object->create($data); } }
/** * EventResource type can be one of the following * * - Calls * - Conferences * - Messages * - Recordings * */ public function __construct(&$object, $data) { $data = Ensure::Input($data); $args = Cleaner::Omit($data->get()); $type = $args['eventType']; $splits = explode("-", $type); $class = __CLASS__; $object->eventType = $type; /** * when we're called directly as * a sub class we should get our input first. * * i.e * call_event = new CallEvent; * * this is only when the user knows which * event should be triggered in his program. */ /** conferences use hyphens **/ /** i.e speak-conference **/ if (sizeof($splits) > 1) { $g = ""; foreach ($splits as $s) { $g .= ucwords($g); } $class = "Catapult\\" . "Conference" . $g . "Event"; return $object->model = new Conference($args['id']); } /** sms is singular and does not use any other term, use Message here **/ if ($type == "sms") { return $object->model = new Message($args['id']); } if (in_array($type, array("incoming", "hangup", "answer", "speak", "recording", "dtmf", "gather"))) { $cl = "Catapult\\" . ucwords($type) . "CallEvent"; return $object->model = new Call($args['id']); } throw new \CatapultApiException("EventType was not found in list of events"); }
/** * Bridge call CTor accept calls * as main argument * * Init forms * GET * Bridge('bridge-id') * Bridge() * * POST * Bridge(array) */ public function __construct($data = null) { $data = Ensure::Input($data); parent::_init($data, new DependsResource(), new LoadsResource(array("primary" => "get", "id" => "id", "init" => "", "silent" => false)), new SchemaResource(array("fields" => array('audio', 'completedTime', 'createdTime', 'activatedTime', 'callIds'), "needs" => array("id"))), new SubFunctionResource(array(array("type" => "get", "term" => "calls")))); }
/** * CTor for gather resource. * Init Forms * * GET * Gather('call-id') * Gather('call-id', 'gather-id') * * POST * Gather('call-id', array) * Gather(array) */ public function __construct() { $data = Ensure::Input(func_get_args()); parent::_init($data, new DependsResource(array(array("term" => "calls", "plural" => true))), new LoadsResource(array("parent" => false, "primary" => "create", "id" => "id", "init" => array("callId"), "silent" => true)), new SchemaResource(array("fields" => array("maxDigits", "interDigitTimeout", "terinatingDigits", "tag", "prompt.sentance", "prompt.gender", "prompt.fileUrl", "prompt.loopEnabled", "prompt.bargeable"), "needs" => array("id")))); }
/** * similar to public api * functions. create takes * accepted input as per (ensureResource) * and will form the object from it * @param data */ public function create($arg) { $data = Ensure::Input($arg); $args = $data->get(); foreach ($args as $k => $arg) { if (is_string($arg)) { $this->addAttribute($k, $arg); } if ($arg instanceof BaMLVerb) { $this->addVerb($arg); } if ($arg instanceof BaMLAttribute) { $this->addAttribute($arg); } if ($arg instanceof BaMLText) { $this->addText($arg); } } }
/** * Upload new media. * * * In remaking we need the url. As this is * a PUT request no 'location' header would * be present [spec] * * we will need both the mediaName and url * * @param args * must contain fileName and file(path to file) */ public function upload($args) { $args = Ensure::Input($args); $data = $args->get(); $url = URIResource::Make($this->path, array($data["mediaName"])); if (isset($data['file'])) { $file = FileHandler::Read($data['file']); } else { $file = $this->data; } $this->client->put($url, $file); return Constructor::Make($this, array_merge(array("url" => $this->client->join($url)), $data)); }
/** * push an endpoint * by the assoc array or params object * * @param data: Parameters or array */ public function pushEndpoint() { $data = Ensure::Input(func_get_args()); $this->data[] = $data->get(); $this->queued++; }
/** * CTor for NumberInfo * Init Forms: * * GET * NumberInfo('cname-number') * */ public function __construct() { $data = Ensure::Input(func_get_args()); parent::_init($data, new DependsResource(array(array("term" => "phoneNumbers", "plural" => true))), new LoadsResource(array("primary" => "GET", "init" => array(), "id" => "number", "silent" => false)), new SchemaResource(array("needs" => array('name', 'number', 'created', 'updated'), "fields" => array('name', 'number')))); }
/** * handles a two arity * where the split becomes * * [0] => array 1 * [1] => array 2 * * Input should not be insured yet.. */ public static function InputTwo($args) { $one = Ensure::Input($args[0]); $two = Ensure::Input($args[1]); return array(0 => $one, 1 => $two); }
public function __construct() { $data = Ensure::Input(func_get_args, Converter::toArray(json_decode(file_get_contents("php://input")))); return new ConferenceMember($data); }
/** * CTor for conference memebrs * * Init forms: * GET * ConferenceMember('member-id') * ConferenceMember() * * POST * ConferenceMember('conference-id', array) * ConferenceMember(array) */ public function __construct() { $data = Ensure::Input(func_get_args()); parent::_init($data, new DependsResource(array(array("term" => "conference", "plural" => true, "silent" => false))), new LoadsResource(array("primary" => "GET", "init" => array("conferenceId"), "id" => "id")), new SchemaResource(array("fields" => array('id', 'state', 'added_time', 'hold', 'mute', 'join_tone', 'leaving_tone'), "needs" => array("id", "state", "from")))); }
/** * * CallEvents do not directly provide * GET or POST functions they can be accessed * by calls only. * * Init Forms: * * GET: * CallEvents() * CallEvents('event-id') */ public function __construct() { $data = Ensure::Input(func_get_args()); parent::_init($data, new DependsResource(array(array("term" => "calls", "plural" => false))), new LoadsResource(array("silent" => false, "primary" => "GET", "id" => "id", "init" => array("callId"))), new SchemaResource(array("fields" => array("id", "time", "name"), "needs" => "id"))); }
/** * Sends a string of characters as DTMF on the given call_id * Valid chars are '0123456789*#ABCD' * * @param dtmf: dtmf characters */ public function sendDtmf($dtmf) { $args = Ensure::Input($dtmf); $dtmf = $args->get(); $url = URIResource::Make($this->path, array($this->id, "dtmf")); $data = new DataPacket(array("dtmfOut" => (string) $dtmf)); $this->client->post($url, $data->get()); }
/** * load the object with static properties * usually done client side -- or by collections * already holding information on an object * * @param props -> set of properties to load */ public function load() { $args = Ensure::Input(func_get_args()); $props = $args->get(); foreach ($props as $k => $prop) { $this->{$k} = $prop; } }
/** * CTor for recordings * * Init Forms: * GET * Recording('recording-id') * * POST * Recording(array) */ public function __construct($args = null) { $data = Ensure::Input($args); parent::_init($data, new DependsResource(), new LoadsResource(array("primary" => "GET", "id" => "id", "init" => "", "silent" => false)), new SchemaResource(array("fields" => array("id", "call", "endTime", "media", "startTime", "state", "page", "size"), "needs" => array("id"))), new SubFunctionResource(array(array("term" => "transcriptions", "type" => "get", "plural" => true)))); }
/** * TollFree version batch allocation * * @param params */ public function batchAllocateTollFree($params) { $url = URIResource::Make($this->availablePath, array("tollFree")); $args = Ensure::Input($params); $data = $this->client->post($url, $args->get(), true, false, true); return new PhoneNumbersCollection(new DataPacketCollection($data)); }
/** * iterator over the listing * object * @return a CollectionIterator */ public function listIterator() { $args = Ensure::input(func_get_args()); /** * collection * iterator should point * to our collection */ return new CollectionIterator($this, $args->get()); }
public function __construct() { $data = Ensure::Input(func_get_args(), Converter::toArray(json_decode(file_get_contents("php://input")))); parent::_init($data, new Call()); }
public function __construct() { $data = Ensure::Input(func_get_args()); return $this->setup($data->get()); }
/** * construct the domains as initiated * or new. Domains should have functions * to access their endpoints as well * * init forms * GET: * Domains('domain-id') * Domains() * * POST * Domains(array) */ public function __construct() { $data = Ensure::Input(func_get_args()); return parent::_init($data, new DependsResource(), new LoadsResource(array("primary" => "GET", "id" => "id", "init" => TRUE, "silent" => FALSE)), new SchemaResource(array("fields" => array('name', 'description'), "needs" => array('id', 'name'))), new SubFunctionResource()); }
/** * Init forms * GET * UserError('user-error-id') * UserError() */ public function __construct() { $data = Ensure::Input(func_get_args()); parent::_init($data, new DependsResource(), new LoadsResource(array("primary" => "get", "id" => "id", "init" => "", "silent" => false)), new SchemaResource(array("fields" => array('id', 'time', 'category', 'code', 'message', 'details', 'version', 'user'), "needs" => array("id")))); }