Esempio n. 1
0
 function _post($type)
 {
     $result = FALSE;
     $headers = array();
     $rest_endpoint = $this->_options['RESTEndPoint'];
     $rest_key_private = $this->_options['RESTKeyPrivate'];
     $job_id = empty($this->_options['JobID']) ? '' : $this->_options['JobID'];
     // make sure we have an endpoint to post to
     if (!$rest_endpoint) {
         throw new UnexpectedValueException('Configuration option RESTEndPoint required');
     }
     // generate the job xml
     $xml_req = $this->_xmlBody($type);
     if (!empty($rest_key_private)) {
         // generate headers with signature
         $gmd = gmdate('D, d M Y H:i:s O');
         $sig = array();
         $params = $this->_jobParameters($type);
         ksort($params);
         foreach ($params as $k => $v) {
             $sig[] = "{$k}={$v}";
         }
         $sig = $gmd . join('&', $sig);
         $sig = private_signature($rest_key_private, $sig);
         if (!$sig) {
             throw new RuntimeException('Could not sign request');
         }
         $headers[] = 'X-Moviemasher-Date: ' . $gmd;
         $headers[] = 'Authorization: ' . $sig;
     }
     $url = end_with_slash($rest_endpoint) . 'mm.' . $this->getVersion() . '/rest/' . $type . '/';
     if (!empty($this->_options['LogRequests'])) {
         $this->log('SENDING REST Request: ' . $xml_req);
     }
     $xml_string = http_post_xml($url, $xml_req, $headers);
     // make sure we got a response, log it and parse into SimpleXML object
     if (!$xml_string) {
         throw new RuntimeException('Could not post xml to: ' . $url . ' ' . $xml_req);
     }
     if (!empty($this->_options['LogResponses'])) {
         $this->log('RECEIVING REST Response ' . $xml_string);
     }
     $xml = $this->_parseResponse($xml_string);
     // determine job ID and return
     if (!empty($xml->JobID)) {
         $result = (string) $xml->JobID;
     } else {
         if (!empty($job_id)) {
             $result = $job_id;
         }
     }
     return $result;
 }
Esempio n. 2
0
 function __sendDone($err = '')
 {
     if ($url = $this->_options['Coder' . ($err ? 'Error' : 'Done') . 'URL']) {
         if ($this->_options['Verbose']) {
             $this->log('Posting to: ' . $url);
         }
         $progress_path = $this->_options['DirCache'] . $this->__jobID . '/media.xml';
         // include latest progress
         $data = file_get($progress_path);
         if ($data) {
             if (http_post_xml($url, $data) === FALSE) {
                 if (!$err) {
                     throw new RuntimeException('Could not post to CoderDoneURL');
                 }
             }
         }
     }
     return $err;
 }