-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #40 from akeneo/add-language-status
Add LanguageStatus API method
- Loading branch information
Showing
3 changed files
with
89 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters