options = $options; } /** * Post a file * * @param string path Path of the file to post * * @return string Json string */ public function postFile($path) { if (file_exists($path)) { $this->initProtocol(); curl_setopt($this->ch, CURLOPT_URL, $this->options['url']); curl_setopt($this->ch, CURLOPT_POST, true); curl_setopt($this->ch, CURLOPT_POSTFIELDS, array("file"=>"@".$path)); curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, true); $result = curl_exec($this->ch); curl_close($this->ch); return $result; } else throw new Exception("File ".$path." doesn't exist !"); } /** * Execute a command * * @param int id File identifier * * @param string command Command to execute * * @return string Json string */ public function command($id, $command) { $this->initProtocol(); switch ($command) { case "status" : $url = $this->options['url']."/".$id; break; case "speakers" : $url = $this->options['url']."/".$id."/speakers"; break; case "segments" : $url = $this->options['url']."/".$id."/segments"; break; default : $url = $this->options['url']."/".$id; break; } curl_setopt($this->ch, CURLOPT_URL, $url); curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, true); $result = curl_exec($this->ch); curl_close($this->ch); return $result; } /** * Set the global options for the protocol * * @param resource ch A cURL handle returned by curl_init() */ public function initProtocol() { $this->ch = curl_init(); if (isset($this->options['proxy'])) curl_setopt($this->ch, CURLOPT_PROXY, $this->options['proxy']); if (isset($this->options['proxyuserpwd'])) curl_setopt($this->ch, CURLOPT_PROXYUSERPWD, $this->options['proxyuserpwd']); if (isset($this->options['sslcert']) && isset($this->options['sslkey'])) { curl_setopt($this->ch, CURLOPT_SSLCERT, $this->options['sslcert']); curl_setopt($this->ch, CURLOPT_SSLKEY, $this->options['sslkey']); if (isset($this->options['sslkeypasswd'])) curl_setopt($this->ch, CURLOPT_SSLKEYPASSWD, $this->options['sslkeypasswd']); } } } ?>