Skip to content

Commit

Permalink
Merge pull request #40 from akeneo/add-language-status
Browse files Browse the repository at this point in the history
Add LanguageStatus API method
  • Loading branch information
nidup authored Nov 18, 2016
2 parents 984c33b + bc76e6b commit a19d7b3
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 0 deletions.
35 changes: 35 additions & 0 deletions spec/Akeneo/Crowdin/Api/LanguageStatusSpec.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace spec\Akeneo\Crowdin\Api;

use Akeneo\Crowdin\Client;
use GuzzleHttp\Client as HttpClient;
use GuzzleHttp\Psr7\Response;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;

class LanguageStatusSpec extends ObjectBehavior
{
public function let(Client $client, HttpClient $http)
{
$client->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('<xml></xml>');
$this->execute()->shouldBe('<xml></xml>');
}
}
51 changes: 51 additions & 0 deletions src/Akeneo/Crowdin/Api/LanguageStatus.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

namespace Akeneo\Crowdin\Api;

/**
* Project translation progress by language
*
* @author Pierre Allard <[email protected]>
* @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);
}
}
3 changes: 3 additions & 0 deletions src/Akeneo/Crowdin/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down

0 comments on commit a19d7b3

Please sign in to comment.