/**
  * TODO: type endpoint description here
  * @return mixed response from the API call*/
 public function getAccount()
 {
     //the base uri for api requests
     $queryBuilder = Configuration::$BASEURI;
     //prepare query string for API call
     $queryBuilder = $queryBuilder . '/me';
     //validate and preprocess url
     $queryUrl = APIHelper::cleanUrl($queryBuilder);
     //prepare headers
     $headers = array('user-agent' => 'APIMATIC 2.0', 'Accept' => 'application/json', 'Authorization' => sprintf('Bearer %1$s', Configuration::$oAuthAccessToken));
     //prepare API request
     $request = Unirest::get($queryUrl, $headers);
     //and invoke the API call request to fetch the response
     $response = Unirest::getResponse($request);
     //Error handling using HTTP status codes
     if ($response->code == 404) {
         throw new APIException('UserNotFound', 404, $response->body);
     } else {
         if ($response->code < 200 || $response->code > 206) {
             //[200,206] = HTTP OK
             throw new APIException("HTTP Response Not OK", $response->code, $response->body);
         }
     }
     return $response->body;
 }
 /**
  * Download the latest translation package. If a language is provided, only the translation package of that language is returned. You must have given a /package call beforehand and wait until the packaging status is 'completed'.
  * @param  int        $id           Required parameter: Project ID
  * @param  string     $language     Required parameter: Optional language code. If you need, you can download the translation of only a specific language.
  * @return string response from the API call*/
 public function download($id, $language = null)
 {
     //the base uri for api requests
     $queryBuilder = Configuration::$BASEURI;
     //prepare query string for API call
     $queryBuilder = $queryBuilder . '/projects/{id}/download/{language}';
     //process optional query parameters
     APIHelper::appendUrlWithTemplateParameters($queryBuilder, array('id' => $id, 'language' => $language));
     //validate and preprocess url
     $queryUrl = APIHelper::cleanUrl($queryBuilder);
     //prepare headers
     $headers = array('user-agent' => 'APIMATIC 2.0', 'Authorization' => sprintf('Bearer %1$s', Configuration::$oAuthAccessToken));
     //prepare API request
     $request = Unirest::get($queryUrl, $headers);
     //and invoke the API call request to fetch the response
     $response = Unirest::getResponse($request);
     //Error handling using HTTP status codes
     if ($response->code == 402) {
         throw new APIException('ProjectNotLaunchedYet', 402, $response->body);
     } else {
         if ($response->code == 404) {
             throw new APIException('TranslationPackageNotFound', 404, $response->body);
         } else {
             if ($response->code < 200 || $response->code > 206) {
                 //[200,206] = HTTP OK
                 throw new APIException("HTTP Response Not OK", $response->code, $response->body);
             }
         }
     }
     return $response->body;
 }
Exemple #3
0
 public static function generateAccessToken()
 {
     //the base uri for api requests
     $queryBuilder = Configuration::$BASEURI;
     //prepare query string for API call
     $queryBuilder = $queryBuilder . '/token';
     //validate and preprocess url
     $queryUrl = APIHelper::cleanUrl($queryBuilder);
     //prepare headers
     $headers = array('user-agent' => 'APIMATIC 2.0', 'Accept' => 'application/json', 'Authorization' => sprintf('Basic %1$s', base64_encode(Configuration::$clientID . ':' . Configuration::$clientSecret)));
     //prepare parameters
     $parameters = array('grant_type' => 'client_credentials');
     //prepare API request
     $request = Unirest::post($queryUrl, $headers, $parameters);
     //and invoke the API call request to fetch the response
     $response = Unirest::getResponse($request);
     //Error handling using HTTP status codes
     if ($response->code == 500) {
         throw new APIException('Authentication error', 500, $response->body);
     } else {
         if ($response->code < 200 || $response->code > 206) {
             //[200,206] = HTTP OK
             throw new APIException("HTTP Response Not OK", $response->code, $response->body);
         }
     }
     if (isset($response->body->error)) {
         throw new APIException($response->body->error->code, $response->body->error->http_code, $response->body->error->message);
     }
     if (!isset($response->body->access_token)) {
         throw new OAuthException('Access token is missing.');
     }
     Configuration::$oAuthAccessToken = $response->body->access_token;
     return $response->body->access_token;
 }
 /**
  * Get a list of comments belonging to this activity.
  * @param  int     $activityId     Required parameter: Activity ID
  * @param  int     $projectId      Required parameter: Project ID
  * @return mixed response from the API call*/
 public function getActivityComments($activityId, $projectId)
 {
     //the base uri for api requests
     $queryBuilder = Configuration::$BASEURI;
     //prepare query string for API call
     $queryBuilder = $queryBuilder . '/projects/{projectId}/activities/{activityId}/comments';
     //process optional query parameters
     APIHelper::appendUrlWithTemplateParameters($queryBuilder, array('activityId' => $activityId, 'projectId' => $projectId));
     //validate and preprocess url
     $queryUrl = APIHelper::cleanUrl($queryBuilder);
     //prepare headers
     $headers = array('user-agent' => 'APIMATIC 2.0', 'Accept' => 'application/json', 'Authorization' => sprintf('Bearer %1$s', Configuration::$oAuthAccessToken));
     //prepare API request
     $request = Unirest::get($queryUrl, $headers);
     //and invoke the API call request to fetch the response
     $response = Unirest::getResponse($request);
     //Error handling using HTTP status codes
     if ($response->code == 404) {
         throw new APIException('ProjectActivityNotFound', 404, $response->body);
     } else {
         if ($response->code < 200 || $response->code > 206) {
             //[200,206] = HTTP OK
             throw new APIException("HTTP Response Not OK", $response->code, $response->body);
         }
     }
     return $response->body;
 }