| @@ 30-45 (lines=16) @@ | ||
| 27 | * |
|
| 28 | * @return mixed|ResponseInterface |
|
| 29 | */ |
|
| 30 | public function create(string $projectKey, string $name, array $params = []) |
|
| 31 | { |
|
| 32 | $params['name'] = $name; |
|
| 33 | ||
| 34 | $response = $this->httpPost(sprintf('/api/v2/projects/%s/keys', $projectKey), $params); |
|
| 35 | ||
| 36 | if (!$this->hydrator) { |
|
| 37 | return $response; |
|
| 38 | } |
|
| 39 | ||
| 40 | if ($response->getStatusCode() !== 200 && $response->getStatusCode() !== 201) { |
|
| 41 | $this->handleErrors($response); |
|
| 42 | } |
|
| 43 | ||
| 44 | return $this->hydrator->hydrate($response, KeyCreated::class); |
|
| 45 | } |
|
| 46 | ||
| 47 | /** |
|
| 48 | * Search keys. |
|
| @@ 32-47 (lines=16) @@ | ||
| 29 | * |
|
| 30 | * @return string|ResponseInterface |
|
| 31 | */ |
|
| 32 | public function download(string $projectKey, string $localeId, string $ext, array $params = []) |
|
| 33 | { |
|
| 34 | $params['file_format'] = $ext; |
|
| 35 | ||
| 36 | $response = $this->httpGet(sprintf('/api/v2/projects/%s/locales/%s/download', $projectKey, $localeId), $params); |
|
| 37 | ||
| 38 | if (!$this->hydrator) { |
|
| 39 | return $response; |
|
| 40 | } |
|
| 41 | ||
| 42 | if ($response->getStatusCode() !== 200) { |
|
| 43 | $this->handleErrors($response); |
|
| 44 | } |
|
| 45 | ||
| 46 | return (string) $response->getBody(); |
|
| 47 | } |
|
| 48 | } |
|
| 49 | ||
| @@ 31-44 (lines=14) @@ | ||
| 28 | * |
|
| 29 | * @return mixed|ResponseInterface |
|
| 30 | */ |
|
| 31 | public function indexLocale(string $projectKey, string $localeId, array $params = []) |
|
| 32 | { |
|
| 33 | $response = $this->httpGet(sprintf('/api/v2/projects/%s/locales/%s/translations', $projectKey, $localeId), $params); |
|
| 34 | ||
| 35 | if (!$this->hydrator) { |
|
| 36 | return $response; |
|
| 37 | } |
|
| 38 | ||
| 39 | if ($response->getStatusCode() !== 200 && $response->getStatusCode() !== 201) { |
|
| 40 | $this->handleErrors($response); |
|
| 41 | } |
|
| 42 | ||
| 43 | return $this->hydrator->hydrate($response, Index::class); |
|
| 44 | } |
|
| 45 | ||
| 46 | /** |
|
| 47 | * Create a translation. |
|
| @@ 85-100 (lines=16) @@ | ||
| 82 | * |
|
| 83 | * @return mixed|ResponseInterface |
|
| 84 | */ |
|
| 85 | public function update(string $projectKey, string $translationId, string $content, array $params = []) |
|
| 86 | { |
|
| 87 | $params['content'] = $content; |
|
| 88 | ||
| 89 | $response = $this->httpPatch(sprintf('/api/v2/projects/%s/translations/%s', $projectKey, $translationId), $params); |
|
| 90 | ||
| 91 | if (!$this->hydrator) { |
|
| 92 | return $response; |
|
| 93 | } |
|
| 94 | ||
| 95 | if ($response->getStatusCode() !== 200 && $response->getStatusCode() !== 201) { |
|
| 96 | $this->handleErrors($response); |
|
| 97 | } |
|
| 98 | ||
| 99 | return $this->hydrator->hydrate($response, TranslationUpdated::class); |
|
| 100 | } |
|
| 101 | ||
| 102 | /** |
|
| 103 | * List translations for a specific key. |
|