Skip to content

Commit

Permalink
Added support for tagging an asset on Asset API (#24)
Browse files Browse the repository at this point in the history
* Added support for tagging an asset on Asset API

* Code style fixes
  • Loading branch information
marcortola authored and Nyholm committed Jan 16, 2018
1 parent 39109fd commit 3d39f49
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 12 deletions.
36 changes: 33 additions & 3 deletions src/Api/Asset.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,41 @@ public function create(string $projectKey, string $id)
return $response;
}

if ($response->getStatusCode() === 409) {
if (409 === $response->getStatusCode()) {
throw Exception\Domain\AssetConflictException::create($id);
}

if ($response->getStatusCode() !== 201) {
if (201 !== $response->getStatusCode()) {
$this->handleErrors($response);
}

return $this->hydrator->hydrate($response, AssetModel::class);
}

/**
* Tag an asset.
* {@link https://localise.biz/api/docs/assets/tagasset}.
*
* @param string $projectKey
* @param string $id
* @param string $tag
*
* @return AssetModel|ResponseInterface
*
* @throws Exception\DomainException
*/
public function tag(string $projectKey, string $id, string $tag)
{
$param = [
'name' => $tag,
];

$response = $this->httpPost(sprintf('/api/assets/%s/tags?key=%s', $id, $projectKey), $param);
if (!$this->hydrator) {
return $response;
}

if ($response->getStatusCode() >= 400) {
$this->handleErrors($response);
}

Expand Down Expand Up @@ -93,7 +123,7 @@ public function patch(string $projectKey, string $id, $type = null, $name = null
return $response;
}

if ($response->getStatusCode() === 409) {
if (409 === $response->getStatusCode()) {
throw Exception\Domain\AssetConflictException::create($id);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Api/Export.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function locale(string $projectKey, string $locale, string $ext, array $p
return $response;
}

if ($response->getStatusCode() !== 200) {
if (200 !== $response->getStatusCode()) {
$this->handleErrors($response);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Api/Import.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function import(string $projectKey, string $ext, string $body, array $par
return $response;
}

if ($response->getStatusCode() !== 200 && $response->getStatusCode() !== 201) {
if (200 !== $response->getStatusCode() && 201 !== $response->getStatusCode()) {
$this->handleErrors($response);
}

Expand Down
4 changes: 2 additions & 2 deletions src/Api/Translation.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function get(string $projectKey, string $id, string $locale)
return $response;
}

if ($response->getStatusCode() !== 200) {
if (200 !== $response->getStatusCode()) {
$this->handleErrors($response);
}

Expand Down Expand Up @@ -92,7 +92,7 @@ public function delete(string $projectKey, string $id, string $locale)
return $response;
}

if ($response->getStatusCode() !== 200) {
if (200 !== $response->getStatusCode()) {
$this->handleErrors($response);
}

Expand Down
6 changes: 3 additions & 3 deletions src/HttpClientConfigurator.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public function createConfiguredClient(): HttpClient
*
* @return HttpClientConfigurator
*/
public function setEndpoint(string $endpoint): HttpClientConfigurator
public function setEndpoint(string $endpoint): self
{
$this->endpoint = $endpoint;

Expand All @@ -92,7 +92,7 @@ public function setEndpoint(string $endpoint): HttpClientConfigurator
*
* @return HttpClientConfigurator
*/
public function appendPlugin(Plugin ...$plugin): HttpClientConfigurator
public function appendPlugin(Plugin ...$plugin): self
{
foreach ($plugin as $p) {
$this->appendPlugins[] = $p;
Expand All @@ -106,7 +106,7 @@ public function appendPlugin(Plugin ...$plugin): HttpClientConfigurator
*
* @return HttpClientConfigurator
*/
public function prependPlugin(Plugin ...$plugin): HttpClientConfigurator
public function prependPlugin(Plugin ...$plugin): self
{
$plugin = array_reverse($plugin);
foreach ($plugin as $p) {
Expand Down
2 changes: 1 addition & 1 deletion src/Hydrator/ArrayHydrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ final class ArrayHydrator implements Hydrator
public function hydrate(ResponseInterface $response, string $class): array
{
$body = $response->getBody()->__toString();
if (strpos($response->getHeaderLine('Content-Type'), 'application/json') !== 0) {
if (0 !== strpos($response->getHeaderLine('Content-Type'), 'application/json')) {
throw new HydrationException('The ArrayHydrator cannot hydrate response with Content-Type:'.$response->getHeaderLine('Content-Type'));
}

Expand Down
2 changes: 1 addition & 1 deletion src/Hydrator/ModelHydrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ final class ModelHydrator implements Hydrator
public function hydrate(ResponseInterface $response, string $class)
{
$body = $response->getBody()->__toString();
if (strpos($response->getHeaderLine('Content-Type'), 'application/json') !== 0) {
if (0 !== strpos($response->getHeaderLine('Content-Type'), 'application/json')) {
throw new HydrationException('The ModelHydrator cannot hydrate response with Content-Type:'.$response->getHeaderLine('Content-Type'));
}

Expand Down
7 changes: 7 additions & 0 deletions src/Model/Asset/Asset.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,30 +18,37 @@ class Asset implements CreatableFromArray
* @var string
*/
private $type;

/**
* @var string
*/
private $name;

/**
* @var string
*/
private $context;

/**
* @var string
*/
private $notes;

/**
* @var string
*/
private $modified;

/**
* @var int
*/
private $translated;

/**
* @var int
*/
private $untranslated;

/**
* @var int
*/
Expand Down
1 change: 1 addition & 0 deletions src/Model/Translation/TranslationDeleted.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
class TranslationDeleted implements CreatableFromArray
{
private $status;

private $message;

/**
Expand Down

0 comments on commit 3d39f49

Please sign in to comment.