Skip to content

Commit

Permalink
Merge pull request #37 from jtabet/url-parameters
Browse files Browse the repository at this point in the history
Introduced ability to add url parameters
  • Loading branch information
nidup committed Jun 6, 2016
2 parents a8e7f24 + 6bcb4f3 commit dae442d
Show file tree
Hide file tree
Showing 13 changed files with 81 additions and 23 deletions.
29 changes: 29 additions & 0 deletions src/Akeneo/Crowdin/Api/AbstractApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ abstract class AbstractApi implements ApiInterface
* @var array
*/
protected $parameters = [];

/**
* The url parameters
*
* @var array
*/
protected $urlParameters = [];

/**
* Instantiate an API
Expand All @@ -38,6 +45,28 @@ public function setParameters(array $parameters)
{
$this->parameters = $parameters;
}

/**
*
* @param string $key
* @param string $value
* @return AbstractApi
*/
public function addUrlParameter($key, $value)
{
$this->urlParameters[$key] = $value;

return $this;
}

/**
*
* @return string
*/
protected function getUrlQueryString()
{
return http_build_query($this->urlParameters);
}

/**
* {@inheritdoc}
Expand Down
6 changes: 4 additions & 2 deletions src/Akeneo/Crowdin/Api/AddDirectory.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@ public function execute()
if (null == $this->directory) {
throw new InvalidArgumentException('There is no directory to create.');
}

$this->addUrlParameter('key', $this->client->getProjectApiKey());

$path = sprintf(
"project/%s/add-directory?key=%s",
"project/%s/add-directory?%s",
$this->client->getProjectIdentifier(),
$this->client->getProjectApiKey()
$this->getUrlQueryString()
);

$parameters = ['name' => $this->directory];
Expand Down
6 changes: 4 additions & 2 deletions src/Akeneo/Crowdin/Api/AddFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,13 @@ public function execute()
if (0 === count($this->translations)) {
throw new InvalidArgumentException('There is no files to add.');
}

$this->addUrlParameter('key', $this->client->getProjectApiKey());

$path = sprintf(
"project/%s/add-file?key=%s",
"project/%s/add-file?%s",
$this->client->getProjectIdentifier(),
$this->client->getProjectApiKey()
$this->getUrlQueryString()
);

$data = $this->parameters;
Expand Down
6 changes: 4 additions & 2 deletions src/Akeneo/Crowdin/Api/ChangeDirectory.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,12 @@ public function execute()
throw new InvalidArgumentException('Argument name is required.');
}

$this->addUrlParameter('key', $this->client->getProjectApiKey());

$path = sprintf(
"project/%s/change-directory?key=%s",
"project/%s/change-directory?%s",
$this->client->getProjectIdentifier(),
$this->client->getProjectApiKey()
$this->getUrlQueryString()
);

$data = ['name' => $this->name];
Expand Down
6 changes: 4 additions & 2 deletions src/Akeneo/Crowdin/Api/DeleteDirectory.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@ public function execute()
throw new InvalidArgumentException('There is no directory to delete.');
}

$this->addUrlParameter('key', $this->client->getProjectApiKey());

$path = sprintf(
"project/%s/delete-directory?key=%s",
"project/%s/delete-directory?%s",
$this->client->getProjectIdentifier(),
$this->client->getProjectApiKey()
$this->getUrlQueryString()
);

$parameters = ['name' => $this->directory];
Expand Down
6 changes: 4 additions & 2 deletions src/Akeneo/Crowdin/Api/DeleteFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@ public function execute()
throw new InvalidArgumentException('There is no file to delete.');
}

$this->addUrlParameter('key', $this->client->getProjectApiKey());

$path = sprintf(
"project/%s/delete-file?key=%s",
"project/%s/delete-file?%s",
$this->client->getProjectIdentifier(),
$this->client->getProjectApiKey()
$this->getUrlQueryString()
);

$parameters = ['file' => $this->file];
Expand Down
6 changes: 4 additions & 2 deletions src/Akeneo/Crowdin/Api/Download.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ class Download extends AbstractApi
*/
public function execute()
{
$this->addUrlParameter('key', $this->client->getProjectApiKey());

$path = sprintf(
"project/%s/download/%s?key=%s",
"project/%s/download/%s?%s",
$this->client->getProjectIdentifier(),
$this->package,
$this->client->getProjectApiKey()
$this->getUrlQueryString()
);
if (null !== $this->branch) {
$path = sprintf('%s&branch=%s', $path, $this->branch);
Expand Down
6 changes: 4 additions & 2 deletions src/Akeneo/Crowdin/Api/Export.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ class Export extends AbstractApi
*/
public function execute()
{
$this->addUrlParameter('key', $this->client->getProjectApiKey());

$path = sprintf(
"project/%s/export?key=%s",
"project/%s/export?%s",
$this->client->getProjectIdentifier(),
$this->client->getProjectApiKey()
$this->getUrlQueryString()
);
if (null !== $this->branch) {
$path = sprintf('%s&branch=%s', $path, $this->branch);
Expand Down
6 changes: 4 additions & 2 deletions src/Akeneo/Crowdin/Api/Info.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ class Info extends AbstractApi
*/
public function execute()
{
$this->addUrlParameter('key', $this->client->getProjectApiKey());

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

Expand Down
6 changes: 4 additions & 2 deletions src/Akeneo/Crowdin/Api/Status.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ class Status extends AbstractApi
*/
public function execute()
{
$this->addUrlParameter('key', $this->client->getProjectApiKey());

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

Expand Down
8 changes: 7 additions & 1 deletion src/Akeneo/Crowdin/Api/SupportedLanguages.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,14 @@ class SupportedLanguages extends AbstractApi
*/
public function execute()
{
$path = 'supported-languages';

if (!empty($this->urlParameters)) {
$path .= sprintf('?%s', $this->getUrlQueryString());
}

$http = $this->client->getHttpClient();
$response = $http->get('supported-languages');
$response = $http->get($path);

return $response->getBody();
}
Expand Down
7 changes: 5 additions & 2 deletions src/Akeneo/Crowdin/Api/UpdateFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,13 @@ public function execute()
if (count($this->translations) === 0) {
throw new InvalidArgumentException('There is no files to update');
}

$this->addUrlParameter('key', $this->client->getProjectApiKey());

$path = sprintf(
"project/%s/update-file?key=%s",
"project/%s/update-file?%s",
$this->client->getProjectIdentifier(),
$this->client->getProjectApiKey()
$this->getUrlQueryString()
);

$data = $this->parameters;
Expand Down
6 changes: 4 additions & 2 deletions src/Akeneo/Crowdin/Api/UploadTranslation.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,12 @@ public function execute()
throw new InvalidArgumentException('Locale is not set.');
}

$this->addUrlParameter('key', $this->client->getProjectApiKey());

$path = sprintf(
"project/%s/upload-translation?key=%s",
"project/%s/upload-translation?%s",
$this->client->getProjectIdentifier(),
$this->client->getProjectApiKey()
$this->getUrlQueryString()
);

$data[] = [
Expand Down

0 comments on commit dae442d

Please sign in to comment.