/** * Send an event into a running Tropo session. * * @param string $session_id * @param string $event * * @return bool * @throws \Exception * */ public function sendEvent($session_id, $event) { $url = $this->base . '%session_id%/signals?action=signal&value=%value%'; $url = str_replace(array('%session_id%', '%value%'), array($session_id, $event), $url); curl_setopt($this->ch, CURLOPT_URL, $url); curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, 1); $result = curl_exec($this->ch); $error = curl_error($this->ch); parent::__destruct(); if ($result === false) { throw new Exception('An error occurred: ' . $error); } else { if (strpos($result, self::EventResponse) === false) { throw new Exception('An error occurred: Tropo event injection failed.'); } return true; } }
/** * Launch a new Tropo session. * * @param string $token * @param array $params * * @return bool * * @throws \Exception */ public function createSession($token, array $params = null) { $querystring = ''; if (isset($params)) { foreach ($params as $key => $value) { @($querystring .= '&' . urlencode($key) . '=' . urlencode($value)); } } curl_setopt($this->ch, CURLOPT_URL, $this->base . 'sessions?action=create&token=' . $token . $querystring); curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, 1); $result = curl_exec($this->ch); $error = curl_error($this->ch); parent::__destruct(); //check result and parse if ($result === false or !($xml = new SimpleXMLElement($result))) { throw new Exception('An error occurred: ' . $error); } else { if (!($xml->success == 'true')) { throw new Exception('An error occurred: Tropo session launch failed.'); } return trim((string) $xml->id); } }
public function __destruct() { parent::__destruct(); }