From bc76e6be31f2591bd6cdf924ead51703e4cfc3aa Mon Sep 17 00:00:00 2001 From: pierallard Date: Fri, 18 Nov 2016 12:09:57 +0100 Subject: [PATCH] Add LanguageStatus API method --- .../Akeneo/Crowdin/Api/LanguageStatusSpec.php | 35 +++++++++++++ src/Akeneo/Crowdin/Api/LanguageStatus.php | 51 +++++++++++++++++++ src/Akeneo/Crowdin/Client.php | 3 ++ 3 files changed, 89 insertions(+) create mode 100644 spec/Akeneo/Crowdin/Api/LanguageStatusSpec.php create mode 100644 src/Akeneo/Crowdin/Api/LanguageStatus.php diff --git a/spec/Akeneo/Crowdin/Api/LanguageStatusSpec.php b/spec/Akeneo/Crowdin/Api/LanguageStatusSpec.php new file mode 100644 index 0000000..7983577 --- /dev/null +++ b/spec/Akeneo/Crowdin/Api/LanguageStatusSpec.php @@ -0,0 +1,35 @@ +getHttpClient()->willReturn($http); + $client->getProjectIdentifier()->willReturn('akeneo'); + $client->getProjectApiKey()->willReturn('1234'); + $this->beConstructedWith($client); + } + + public function it_should_be_an_api() + { + $this->shouldBeAnInstanceOf('Akeneo\Crowdin\Api\AbstractApi'); + } + + public function it_gets_project_language_status( + HttpClient $http, + Response $response + ) { + $this->setLanguage('fr')->shouldBe($this); + $http->post('project/akeneo/language-status?key=1234', ['form_params' => ['language' => 'fr']])->willReturn($response); + $response->getBody(true)->willReturn(''); + $this->execute()->shouldBe(''); + } +} diff --git a/src/Akeneo/Crowdin/Api/LanguageStatus.php b/src/Akeneo/Crowdin/Api/LanguageStatus.php new file mode 100644 index 0000000..6a5a4dd --- /dev/null +++ b/src/Akeneo/Crowdin/Api/LanguageStatus.php @@ -0,0 +1,51 @@ + + * @see http://crowdin.net/page/api/language-status + */ +class LanguageStatus extends AbstractApi +{ + /** @var string */ + protected $language; + + /** + * @param string $language + * + * @return LanguageStatus + */ + public function setLanguage($language) + { + $this->language = $language; + + return $this; + } + + /** + * @return string + */ + public function getLanguage() + { + return $this->language; + } + + /** + * {@inheritdoc} + */ + public function execute() + { + $path = sprintf( + "project/%s/language-status?key=%s", + $this->client->getProjectIdentifier(), + $this->client->getProjectApiKey() + ); + $parameters = array_merge($this->parameters, ['form_params' => ['language' => $this->getLanguage()]]); + $response = $this->client->getHttpClient()->post($path, $parameters); + + return $response->getBody(true); + } +} diff --git a/src/Akeneo/Crowdin/Client.php b/src/Akeneo/Crowdin/Client.php index 678b0fd..91aa04d 100644 --- a/src/Akeneo/Crowdin/Client.php +++ b/src/Akeneo/Crowdin/Client.php @@ -80,6 +80,9 @@ public function api($method) case 'upload-translation': $api = new Api\UploadTranslation($this, $fileReader); break; + case 'language-status': + $api = new Api\LanguageStatus($this); + break; default: throw new InvalidArgumentException(sprintf('Undefined api method "%s"', $method)); }