Example #1
0
 public function downloadGlossary($glossary_id)
 {
     $params = array();
     $params['ts'] = gmdate('U');
     $params['api_key'] = $this->config->get('api_key', null, true);
     $private_key = $this->config->get('private_key', null, true);
     $params['api_sig'] = Gengo_Crypto::sign($params['ts'], $private_key);
     $this->setParamsNotId($format, $params);
     $baseurl = $this->config->get('baseurl', null, true);
     $baseurl .= "v2/translate/glossary/download/{$glossary_id}";
     $this->response = $this->client->get($baseurl, $format, $params);
 }
Example #2
0
 /**
  * Set the passed parameters that are null with default
  * configuration values
  */
 protected function setParams(&$id, &$format, &$params)
 {
     if (is_null($id)) {
         $id = $this->config->get('job_id', null, true);
     }
     if (is_null($format)) {
         $format = $this->config->get('format', null, true);
     }
     if (is_null($params)) {
         $private_key = $this->config->get('private_key', null, true);
         $params = array();
         $params['ts'] = gmdate('U');
         $params['api_key'] = $this->config->get('api_key', null, true);
         $params['api_sig'] = Gengo_Crypto::sign($params['ts'], $private_key);
     }
 }
Example #3
0
 /**
  * translate/service/quote (POST)
  *
  * Submits a job or group of jobs to quote.
  *
  * @param array $jobs An array of payloads (a payload being itself an array of string)
  * of jobs to create.
  * @param array $filepath Either a key/value pair as in file_key => path/to/file or file_key => array('filename' => name, 'data' => data)
  */
 public function quote(array $jobs, array $filepath = null)
 {
     // parameters check
     if (!empty($filepath)) {
         foreach ($jobs as &$job) {
             if ($job['type'] == 'file') {
                 // make sure job has a file_key parameter
                 if (!isset($job['file_key'])) {
                     throw new Gengo_Exception(sprintf('Job %s is missing file_key parameter', print_r($job, true)));
                 }
                 // make sure the file_key parameter is a valid alphanumeric parameter
                 if (!preg_match('/^[a-z0-9_-]+$/i', $job['file_key'])) {
                     throw new Gengo_Exception(sprintf('"%s" is not a valid file_key parameter', $job['file_key']));
                 }
                 // make sure file_key parameter is a key in filepath array
                 if (!array_key_exists($job['file_key'], $filepath)) {
                     throw new Gengo_Exception(sprintf('file_key: "%s" is missing in filepath array', $job['file_key']));
                 }
                 // make sure we have valid file paths and or data
                 if (is_array($filepath[$job['file_key']])) {
                     // checking we have a valid file name
                     if (!isset($filepath[$job['file_key']]['filename']) || !is_string($filepath[$job['file_key']]['filename']) || empty($filepath[$job['file_key']]['filename'])) {
                         throw new GengoException(sprintf('file_key: %s is missing a valid file name', $job['file_key']));
                     }
                     // checking we have valid data
                     if (!isset($filepath[$job['file_key']]['data']) || empty($filepath[$job['file_key']]['data'])) {
                         throw new GengoException(sprintf('file_key: %s is missing valid data', $job['file_key']));
                     }
                 } else {
                     if (!is_file($filepath[$job['file_key']])) {
                         throw new Gengo_Exception(sprintf('Could not find file: %s', $filepath[$job['file_key']]));
                     }
                 }
             }
         }
     }
     // end parameters check
     $data = array('jobs' => $jobs);
     // create the query
     $ts = gmdate('U');
     $params = array('api_key' => $this->config->get('api_key', null, true), '_method' => 'post', 'ts' => $ts, 'data' => json_encode($data), 'api_sig' => Gengo_Crypto::sign($ts, $this->config->get('private_key', null, true)));
     $format = $this->config->get('format', null, true);
     $baseurl = $this->config->get('baseurl', null, true);
     $baseurl .= 'v2/translate/service/quote';
     if (!empty($filepath)) {
         foreach ($filepath as $file_key => $fp) {
             if (is_null($fp)) {
                 unset($filepath[$file_key]);
             }
         }
         $baseurl .= '/file';
         $this->response = $this->client->upload($baseurl, $filepath, $format, $params);
     } else {
         $this->response = $this->client->post($baseurl, $format, $params);
     }
 }
Example #4
0
 /**
  * translate/jobs/ (PUT)
  *
  * Archive jobs
  *
  * @param array $jobs (required) An array containing the job ids to archive
  * @param string $version Version of the API to use. Defaults to 'v2'.
  */
 public function archive(array $jobs, $version = 'v2')
 {
     // pack the jobs
     $data = array('action' => 'archive', 'job_ids' => $jobs);
     $ts = gmdate('U');
     // create the query
     $params = array('api_key' => $this->config->get('api_key', null, true), 'ts' => $ts, 'data' => json_encode($data), 'api_sig' => Gengo_Crypto::sign($ts, $this->config->get('private_key', null, true)));
     $format = $this->config->get('format', null, true);
     $this->setParamsNotId($format, $params);
     $baseurl = $this->config->get('baseurl', null, true);
     $baseurl .= "{$version}/translate/jobs/";
     $this->response = $this->client->put($baseurl, $format, $params);
 }
Example #5
0
 /**
  * translate/job/{id}/comment (POST)
  *
  * Submits a new comment to the job's comment thread.
  *
  * @param int $id The id of the job to comment on
  * @param string $body The comment's actual contents.
  * @param string $format The OPTIONAL response format: xml or json (default).
  * @param array|string $params (DEPRECATED) If passed should contain all the
  * necessary parameters for the request including the api_key and
  * api_sig
  */
 public function postComment($id, $body, $format = null, $params = null)
 {
     if (!(is_null($id) || is_null($body))) {
         // pack the jobs
         $data = array('body' => $body);
         $ts = gmdate('U');
         // create the query
         $params = array('api_key' => $this->config->get('api_key', null, true), '_method' => 'post', 'ts' => $ts, 'data' => json_encode($data), 'api_sig' => Gengo_Crypto::sign($ts, $this->config->get('private_key', null, true)));
     }
     if (empty($params)) {
         throw new Gengo_Exception(sprintf('In method %s: "params" must contain a valid "body" parameter as the comment', __METHOD__));
     }
     $this->setParams($id, $format, $params);
     $baseurl = $this->config->get('baseurl', null, true);
     $baseurl .= "v2/translate/job/{$id}/comment";
     $this->response = $this->client->post($baseurl, $format, $params);
 }