You are here

public function LingotekApi::getDocumentTranslationStatuses in Lingotek Translation 3.8.x

Same name and namespace in other branches
  1. 8 src/Remote/LingotekApi.php \Drupal\lingotek\Remote\LingotekApi::getDocumentTranslationStatuses()
  2. 8.2 src/Remote/LingotekApi.php \Drupal\lingotek\Remote\LingotekApi::getDocumentTranslationStatuses()
  3. 4.0.x src/Remote/LingotekApi.php \Drupal\lingotek\Remote\LingotekApi::getDocumentTranslationStatuses()
  4. 3.0.x src/Remote/LingotekApi.php \Drupal\lingotek\Remote\LingotekApi::getDocumentTranslationStatuses()
  5. 3.1.x src/Remote/LingotekApi.php \Drupal\lingotek\Remote\LingotekApi::getDocumentTranslationStatuses()
  6. 3.2.x src/Remote/LingotekApi.php \Drupal\lingotek\Remote\LingotekApi::getDocumentTranslationStatuses()
  7. 3.3.x src/Remote/LingotekApi.php \Drupal\lingotek\Remote\LingotekApi::getDocumentTranslationStatuses()
  8. 3.4.x src/Remote/LingotekApi.php \Drupal\lingotek\Remote\LingotekApi::getDocumentTranslationStatuses()
  9. 3.5.x src/Remote/LingotekApi.php \Drupal\lingotek\Remote\LingotekApi::getDocumentTranslationStatuses()
  10. 3.6.x src/Remote/LingotekApi.php \Drupal\lingotek\Remote\LingotekApi::getDocumentTranslationStatuses()
  11. 3.7.x src/Remote/LingotekApi.php \Drupal\lingotek\Remote\LingotekApi::getDocumentTranslationStatuses()

Gets the document target translation statuses from the Lingotek service.

Parameters

string $id: The document id.

Return value

\Psr\Http\Message\ResponseInterface A response.

Overrides LingotekApiInterface::getDocumentTranslationStatuses

File

src/Remote/LingotekApi.php, line 273

Class

LingotekApi
A simple connector to the Lingotek Translation API.

Namespace

Drupal\lingotek\Remote

Code

public function getDocumentTranslationStatuses($id) {
  try {
    $this->logger
      ->debug('Lingotek::getDocumentTranslationStatuses called with %id', [
      '%id' => $id,
    ]);
    $response = $this->lingotekClient
      ->get('/api/document/' . $id . '/translation');
  } catch (ClientException $e) {
    if ($e
      ->getCode() === Response::HTTP_NOT_FOUND) {
      $responseBody = json_decode($e
        ->getResponse()
        ->getBody(), TRUE);
      $message = $responseBody['messages'][0];
      throw new LingotekDocumentNotFoundException($message, Response::HTTP_NOT_FOUND);
    }
    throw new LingotekApiException('Failed to get document translation status: ' . $e
      ->getMessage(), $e
      ->getCode(), $e);
  } catch (\Exception $e) {
    $this->logger
      ->error('Error getting document translation status (%id): %message.', [
      '%id' => $id,
      '%message' => $e
        ->getMessage(),
    ]);
    throw new LingotekApiException('Failed to get document translation status: ' . $e
      ->getMessage());
  }
  $this->logger
    ->debug('getDocumentTranslationStatuses response received, code %code and body %body', [
    '%code' => $response
      ->getStatusCode(),
    '%body' => (string) $response
      ->getBody(TRUE),
  ]);
  return $response;
}