Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions spec/Akeneo/Crowdin/Api/ExportFileSpec.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace spec\Akeneo\Crowdin\Api;

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

class ExportFileSpec 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_retrieves_translation_file(HttpClient $http, Request $request, Response $response)
{
$content = 'file-content';
$response->getBody()->willReturn($content);
$http->get('project/akeneo/export-file?key=1234')->willReturn($response);
$this->execute()->shouldBe($content);
}
}
29 changes: 29 additions & 0 deletions src/Akeneo/Crowdin/Api/ExportFile.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace Akeneo\Crowdin\Api;

/**
* This method exports single translated files from Crowdin.
*
* @author Markus Weiland <markus.weiland@mapudo.com>
* @see https://support.crowdin.com/api/export-file/
*/
class ExportFile extends AbstractApi
{
/**
* {@inheritdoc}
*/
public function execute()
{
$this->addUrlParameter('key', $this->client->getProjectApiKey());

$path = sprintf(
"project/%s/export-file?%s",
$this->client->getProjectIdentifier(),
$this->getUrlQueryString()
);
$response = $this->client->getHttpClient()->get($path);

return $response->getBody();
}
}
3 changes: 3 additions & 0 deletions src/Akeneo/Crowdin/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ public function api($method)
case 'export':
$api = new Api\Export($this);
break;
case 'export-file':
$api = new Api\ExportFile($this);
break;
case 'add-directory':
$api = new Api\AddDirectory($this);
break;
Expand Down