public function LingotekApi::addDocument in Lingotek Translation 3.1.x
Same name and namespace in other branches
- 8 src/Remote/LingotekApi.php \Drupal\lingotek\Remote\LingotekApi::addDocument()
- 8.2 src/Remote/LingotekApi.php \Drupal\lingotek\Remote\LingotekApi::addDocument()
- 4.0.x src/Remote/LingotekApi.php \Drupal\lingotek\Remote\LingotekApi::addDocument()
- 3.0.x src/Remote/LingotekApi.php \Drupal\lingotek\Remote\LingotekApi::addDocument()
- 3.2.x src/Remote/LingotekApi.php \Drupal\lingotek\Remote\LingotekApi::addDocument()
- 3.3.x src/Remote/LingotekApi.php \Drupal\lingotek\Remote\LingotekApi::addDocument()
- 3.4.x src/Remote/LingotekApi.php \Drupal\lingotek\Remote\LingotekApi::addDocument()
- 3.5.x src/Remote/LingotekApi.php \Drupal\lingotek\Remote\LingotekApi::addDocument()
- 3.6.x src/Remote/LingotekApi.php \Drupal\lingotek\Remote\LingotekApi::addDocument()
- 3.7.x src/Remote/LingotekApi.php \Drupal\lingotek\Remote\LingotekApi::addDocument()
- 3.8.x src/Remote/LingotekApi.php \Drupal\lingotek\Remote\LingotekApi::addDocument()
Adds a document to Lingotek.
Parameters
array $args: The document data.
Return value
\Psr\Http\Message\ResponseInterface A response.
Throws
\Drupal\lingotek\Exception\LingotekApiException
Overrides LingotekApiInterface::addDocument
See also
File
- src/
Remote/ LingotekApi.php, line 93
Class
- LingotekApi
- A simple connector to the Lingotek Translation API.
Namespace
Drupal\lingotek\RemoteCode
public function addDocument($args) {
try {
$this->logger
->debug('Lingotek::addDocument (POST /api/document) called with ' . var_export($args, TRUE));
$response = $this->lingotekClient
->post('/api/document', $args, TRUE);
} catch (\Exception $e) {
$this->logger
->error('Error adding document: %message.', [
'%message' => $e
->getMessage(),
]);
throw new LingotekApiException('Error adding document: ' . $e
->getMessage());
}
if ($response
->getStatusCode() == Response::HTTP_ACCEPTED) {
$data = json_decode($response
->getBody(), TRUE);
$this->logger
->debug('addDocument response received, code %code and body %body', [
'%code' => $response
->getStatusCode(),
'%body' => (string) $response
->getBody(TRUE),
]);
if (!empty($data['properties']['id'])) {
return $response;
}
}
// TODO: log warning
return $response;
}