<commit_before><?php
/**
 * myGengo API Client
 *
 * LICENSE
 *
 * This source file is subject to the new BSD license that came
 * with this package in the file LICENSE.txt. It is also available
 * through the world-wide-web at this URL:
 * http://mygengo.com/services/api/dev-docs/mygengo-code-license
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to <EMAIL> so we can send you a copy immediately.
 *
 * @category   myGengo
 * @package    API Client Library
 * @copyright  Copyright (c) 2009-2010 myGengo, Inc. (http://mygengo.com)
 * @license    http://mygengo.com/services/api/dev-docs/mygengo-code-license   New BSD License
 */

class myGengo_Api_Job extends myGengo_Api
{
    /**
     * @param string $api_key the public API key.
     * @param string $private_key the private API key.
     */
    public function __construct($api_key = null, $private_key = null)
    {
        parent::__construct($api_key, $private_key);
    }

    /**
     * translate/job/{id} (GET)
     *
     * Retrieves a specific job
     *
     * @param int $id The id of the job to retrieve
     * @param string $format The response format, xml or json
     * @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 getJob($id = null, $format = null, $params = null)
    {
        $this->setParams($id, $format, $params);
        $baseurl = $this->config->get('baseurl', null, true);
        $baseurl .= "translate/job/{$id}";
        $this->response = $this->client->get($baseurl, $format, $params);
    }

    /**
     * translate/job/{id}/comments (GET)
     *
     * Retrieves the comment thread for a job
     *
     * @param int $id The id of the job to retrieve
     * @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 getComments($id, $format = null, $params = null)
    {
        $this->setParams($id, $format, $params);
        $baseurl = $this->config->get('baseurl', null, true);
        $baseurl .= "translate/job/{$id}/comments";
        $this->response = $this->client->get($baseurl, $format, $params);
    }

    /**
     * translate/job/{id}/feedback (GET)
     *
     * Retrieves the feedback
     *
     * @param int $id The id of the job to retrieve
     * @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 getFeedback($id, $format = null, $params = null)
    {
        $this->setParams($id, $format, $params);
        $baseurl = $this->config->get('baseurl', null, true);
        $baseurl .= "translate/job/{$id}/feedback";
        $this->response = $this->client->get($baseurl, $format, $params);
    }

    /**
     * translate/job/{id}/revisions (GET)
     *
     * Gets list of revision resources for a job.
     *
     * @param int $id The id of the job to retrieve
     * @param string $format The OPTIONAL response format: xml or json
     * @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 getRevisions($id, $format = null, $params = null)
    {
        $this->setParams($id, $format, $params);
        $baseurl = $this->config->get('baseurl', null, true);
        $baseurl .= "translate/job/{$id}/revisions";
        $this->response = $this->client->get($baseurl, $format, $params);
    }

    /**
     * translate/job/{id}/revision/{rev_id}
     *
     * Gets specific revision for a job.
     *
     * @param int $id The id of the job to retrieve
     * @param int $rev_id The id of the revision to retrieve
     * @param string $format The OPTIONAL response format: xml or json
     * @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 getRevision($id, $rev_id, $format = null, $params = null)
    {
        $this->setParams($id, $format, $params);
        if (is_null($rev_id))
        {
            $rev_id = $this->config->get('rev_id', null, true);
        }
        $baseurl = $this->config->get('baseurl', null, true);
        $baseurl .= "translate/job/{$id}/revision/{$rev_id}";
        $this->response = $this->client->get($baseurl, $format, $params);
    }

    /**
     * translate/job/{id} (PUT)
     *
     * Updates a job to translate. returns this job back to the translator for revisions.
     *
     * @param int $id The id of the job to revise
     * @param string $comment (required) the reason to the translator for sending the job back for revisions.
     */
    public function revise($id, $comment)
    {
        if (!(empty($id) || empty($comment)))
        {
            // pack the jobs
            $data = array('action' => 'revise', 'comment' => $comment);

            // create the query
            $params = array('api_key' => $this->config->get('api_key', null, true),
                    'ts' => gmdate('U'),
                    'data' => json_encode($data));
            // sort and sign
            ksort($params);
            $enc_params = json_encode($params);
            $params['api_sig'] = myGengo_Crypto::sign($enc_params, $this->config->get('private_key', null, true));
        }
        else 
        {
            throw new myGengo_Exception(
                    sprintf('In method %s: "id" and "comment" are required', __METHOD__)
                    );
        }

        $format = $this->config->get('format', null, true);
        $this->setParams($id, $format, $params);
        $baseurl = $this->config->get('baseurl', null, true);
        $baseurl .= "translate/job/{$id}";
        $this->response = $this->client->put($baseurl, $format, $params);
    }

    /**
     * translate/job/{id} (PUT)
     *
     * Updates a job to translate. Approves job.
     *
     * @param int $id The id of the job to approve
     * @param array|string $args contains the parameters for the approval:
     *  rating (optional) - 1 (poor) to 5 (fantastic)
     *  for_translator (optional) - comments for the translator
     *  for_mygengo (optional) - comments for myGengo staff (private)
     *  public (optional) - 1 (true) / 0 (false, default); whether myGengo can share this feedback publicly
     */
    public function approve($id, $args)
    {
        if (!is_null($id))
        {
            if (isset($args['rating']) &&
                !(is_numeric($args['rating']) && $args['rating'] >= 1 && $args['rating'] <= 5))
            {
                throw new myGengo_Exception(
                        sprintf('In method %s: "params" must contain a valid rating', __METHOD__)
                        );
            }

            // pack the jobs
            $data = array('action' => 'approve', 'public' => (isset($args['public']) && !empty($public))? 1 : 0);
            if (isset($args['rating']))
            {
                $data['rating'] = $args['rating'];
            }
            if (isset($args['for_translator']))
            {
                $data['for_translator'] = $args['for_translator'];
            }
            if (isset($args['for_mygengo']))
            {
                $data['for_mygengo'] = $args['for_mygengo'];
            }

            // create the query
            $params = array('api_key' => $this->config->get('api_key', null, true),
                    'ts' => gmdate('U'),<commit_msg>- Arguments on approve (job PUT) function are optional.<commit_after><?php
/**
 * myGengo API Client
 *
 * LICENSE
 *
 * This source file is subject to the new BSD license that came
 * with this package in the file LICENSE.txt. It is also available
 * through the world-wide-web at this URL:
 * http://mygengo.com/services/api/dev-docs/mygengo-code-license
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to <EMAIL> so we can send you a copy immediately.
 *
 * @category   myGengo
 * @package    API Client Library
 * @copyright  Copyright (c) 2009-2010 myGengo, Inc. (http://mygengo.com)
 * @license    http://mygengo.com/services/api/dev-docs/mygengo-code-license   New BSD License
 */

class myGengo_Api_Job extends myGengo_Api
{
    /**
     * @param string $api_key the public API key.
     * @param string $private_key the private API key.
     */
    public function __construct($api_key = null, $private_key = null)
    {
        parent::__construct($api_key, $private_key);
    }

    /**
     * translate/job/{id} (GET)
     *
     * Retrieves a specific job
     *
     * @param int $id The id of the job to retrieve
     * @param string $format The response format, xml or json
     * @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 getJob($id = null, $format = null, $params = null)
    {
        $this->setParams($id, $format, $params);
        $baseurl = $this->config->get('baseurl', null, true);
        $baseurl .= "translate/job/{$id}";
        $this->response = $this->client->get($baseurl, $format, $params);
    }

    /**
     * translate/job/{id}/comments (GET)
     *
     * Retrieves the comment thread for a job
     *
     * @param int $id The id of the job to retrieve
     * @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 getComments($id, $format = null, $params = null)
    {
        $this->setParams($id, $format, $params);
        $baseurl = $this->config->get('baseurl', null, true);
        $baseurl .= "translate/job/{$id}/comments";
        $this->response = $this->client->get($baseurl, $format, $params);
    }

    /**
     * translate/job/{id}/feedback (GET)
     *
     * Retrieves the feedback
     *
     * @param int $id The id of the job to retrieve
     * @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 getFeedback($id, $format = null, $params = null)
    {
        $this->setParams($id, $format, $params);
        $baseurl = $this->config->get('baseurl', null, true);
        $baseurl .= "translate/job/{$id}/feedback";
        $this->response = $this->client->get($baseurl, $format, $params);
    }

    /**
     * translate/job/{id}/revisions (GET)
     *
     * Gets list of revision resources for a job.
     *
     * @param int $id The id of the job to retrieve
     * @param string $format The OPTIONAL response format: xml or json
     * @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 getRevisions($id, $format = null, $params = null)
    {
        $this->setParams($id, $format, $params);
        $baseurl = $this->config->get('baseurl', null, true);
        $baseurl .= "translate/job/{$id}/revisions";
        $this->response = $this->client->get($baseurl, $format, $params);
    }

    /**
     * translate/job/{id}/revision/{rev_id}
     *
     * Gets specific revision for a job.
     *
     * @param int $id The id of the job to retrieve
     * @param int $rev_id The id of the revision to retrieve
     * @param string $format The OPTIONAL response format: xml or json
     * @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 getRevision($id, $rev_id, $format = null, $params = null)
    {
        $this->setParams($id, $format, $params);
        if (is_null($rev_id))
        {
            $rev_id = $this->config->get('rev_id', null, true);
        }
        $baseurl = $this->config->get('baseurl', null, true);
        $baseurl .= "translate/job/{$id}/revision/{$rev_id}";
        $this->response = $this->client->get($baseurl, $format, $params);
    }

    /**
     * translate/job/{id} (PUT)
     *
     * Updates a job to translate. returns this job back to the translator for revisions.
     *
     * @param int $id The id of the job to revise
     * @param string $comment (required) the reason to the translator for sending the job back for revisions.
     */
    public function revise($id, $comment)
    {
        if (!(empty($id) || empty($comment)))
        {
            // pack the jobs
            $data = array('action' => 'revise', 'comment' => $comment);

            // create the query
            $params = array('api_key' => $this->config->get('api_key', null, true),
                    'ts' => gmdate('U'),
                    'data' => json_encode($data));
            // sort and sign
            ksort($params);
            $enc_params = json_encode($params);
            $params['api_sig'] = myGengo_Crypto::sign($enc_params, $this->config->get('private_key', null, true));
        }
        else 
        {
            throw new myGengo_Exception(
                    sprintf('In method %s: "id" and "comment" are required', __METHOD__)
                    );
        }

        $format = $this->config->get('format', null, true);
        $this->setParams($id, $format, $params);
        $baseurl = $this->config->get('baseurl', null, true);
        $baseurl .= "translate/job/{$id}";
        $this->response = $this->client->put($baseurl, $format, $params);
    }

    /**
     * translate/job/{id} (PUT)
     *
     * Updates a job to translate. Approves job.
     *
     * @param int $id The id of the job to approve
     * @param array|string $args contains the parameters for the approval:
     *  rating (optional) - 1 (poor) to 5 (fantastic)
     *  for_translator (optional) - comments for the translator
     *  for_mygengo (optional) - comments for myGengo staff (private)
     *  public (optional) - 1 (true) / 0 (false, default); whether myGengo can share this feedback publicly
     */
    public function approve($id, $args = array())
    {
        if (!is_null($id))
        {
            if (isset($args['rating']) &&
                !(is_numeric($args['rating']) && $args['rating'] >= 1 && $args['rating'] <= 5))
            {
                throw new myGengo_Exception(
                        sprintf('In method %s: "params" must contain a valid rating', __METHOD__)
                        );
            }

            // pack the jobs
            $data = array('action' => 'approve', 'public' => (isset($args['public']) && !empty($public))? 1 : 0);
            if (isset($args['rating']))
            {
                $data['rating'] = $args['rating'];
            }
            if (isset($args['for_translator']))
            {
                $data['for_translator'] = $args['for_translator'];
            }
            if (isset($args['for_mygengo']))
            {
                $data['for_mygengo'] = $args['for_mygengo'];
            }

            // create the query
            $params = array('api_key' => $this->config->get('api_key', null, true),
                    'ts' => gmdate('U'),
{'fraction_non_alphanumeric': 0.13930191532258066, 'fraction_numerical': 0.0020161290322580645, 'mean_word_length': 2.2613519621943703, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 117, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 10}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5361860', 'n_tokens_mistral': 4782, 'n_tokens_neox': 4629, 'n_words': 1406}