public function LingotekApi::addDocument in Lingotek Translation 8
Same name and namespace in other branches
- 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.1.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()
Overrides LingotekApiInterface::addDocument
File
- src/
Remote/ LingotekApi.php, line 81 - Contains \Drupal\lingotek\Remote\LingotekApi.
Class
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 $data['properties']['id'];
}
}
// TODO: log warning
return FALSE;
}