Skip to content
Merged
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
40 changes: 40 additions & 0 deletions src/Clients/LocalizeClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace NStack\Clients;

use NStack\Exceptions\FailedToParseException;
use NStack\Models\Language;
use NStack\Models\Resource;

/**
Expand Down Expand Up @@ -56,4 +58,42 @@ public function showResource($url): array

return $data;
}

/**
* indexLanguage
*
* @param string $platform
* @return array
* @throws \NStack\Exceptions\FailedToParseException
* @author Casper Rasmussen <cr@nodes.dk>
*/
public function indexLanguage(string $platform): array
{
$response = $this->client->get($this->buildPath($this->path . '/' . $platform . '/languages'));
$contents = $response->getBody()->getContents();
$data = json_decode($contents, true);

$array = [];
foreach ($data['data'] as $object) {
$array[] = new Language($object);
}

return $array;
}

/**
* bestFitLanguage
*
* @param string $platform
* @return Language
* @throws FailedToParseException
*/
public function bestFitLanguage(string $platform): Language
{
$response = $this->client->get($this->buildPath($this->path . '/' . $platform . '/languages/best_fit'));
$contents = $response->getBody()->getContents();
$data = json_decode($contents, true);

return new Language($data['data']);
}
}
55 changes: 0 additions & 55 deletions src/Clients/LocalizeLanguagesClient.php

This file was deleted.

4 changes: 2 additions & 2 deletions src/Clients/UgcClient.php → src/Clients/PushLogClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
namespace NStack\Clients;

/**
* Class UgcClient
* Class PushLogClient
*
* @package NStack\Clients
* @author Tiago Araujo <tiar@nodesagency.com>
*/
class UgcClient extends NStackClient
class PushLogClient extends NStackClient
{
/** @var string */
protected $path = 'ugc';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
use NStack\Models\VersionControlUpdate;

/**
* Class NotifyClient
* Class VersionControlClient
*
* @package NStack\Clients
* @author Tiago Araujo <tiar@nodesagency.com>
*/
class NotifyClient extends NStackClient
class VersionControlClient extends NStackClient
{
/** @var string */
protected $path = 'notify/updates';
Expand Down
148 changes: 144 additions & 4 deletions src/NStack.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,18 @@

namespace NStack;

use NStack\Clients\CollectionsClient;
use NStack\Clients\ContinentsClient;
use NStack\Clients\CountriesClient;
use NStack\Clients\FilesClient;
use NStack\Clients\IpAddressesClient;
use NStack\Clients\LanguagesClient;
use NStack\Clients\LocalizeClient;
use NStack\Clients\ProposalsClient;
use NStack\Clients\PushLogClient;
use NStack\Clients\TimezoneClient;
use NStack\Clients\ValidatorsClient;
use NStack\Clients\VersionControlClient;
use NStack\Exceptions\MissingMasterKeyException;

/**
Expand All @@ -17,12 +27,42 @@ class NStack
/** @var \NStack\Config */
protected $config;

/** @var \NStack\Clients\ContinentsClient */
/** @var CollectionsClient */
protected $collectionClient;

/** @var ContinentsClient */
protected $continentsClient;

/** @var \NStack\Clients\CountriesClient */
/** @var CountriesClient */
protected $countriesClient;

/** @var FilesClient */
protected $filesClient;

/** @var IpAddressesClient */
protected $ipAddressClient;

/** @var LanguagesClient */
protected $languageClient;

/** @var LocalizeClient */
protected $localizeClient;

/** @var VersionControlClient */
protected $versionControlClient;

/** @var ProposalsClient */
protected $proposalClient;

/** @var TimezoneClient */
protected $timezoneClient;

/** @var PushLogClient */
protected $pushLogClient;

/** @var ValidatorsClient */
protected $validatorClient;

/**
* NStack constructor.
*
Expand All @@ -34,6 +74,16 @@ public function __construct(Config $config)
$this->config = $config;
$this->continentsClient = new ContinentsClient($config);
$this->countriesClient = new CountriesClient($config);
$this->collectionClient = new CollectionsClient($config);
$this->filesClient = new FilesClient($config);
$this->ipAddressClient = new IpAddressesClient($config);
$this->languageClient = new LanguagesClient($config);
$this->localizeClient = new LocalizeClient($config);
$this->versionControlClient = new VersionControlClient($config);
$this->proposalClient = new ProposalsClient($config);
$this->timezoneClient = new TimezoneClient($config);
$this->pushLogClient = new PushLogClient($config);
$this->validatorClient = new ValidatorsClient($config);
}

/**
Expand All @@ -48,7 +98,7 @@ public function getConfig(): Config
/**
* getContinentsClient
*
* @return \NStack\Clients\ContinentsClient
* @return ContinentsClient
* @author Casper Rasmussen <cr@nodes.dk>
*/
public function getContinentsClient(): ContinentsClient
Expand All @@ -59,14 +109,104 @@ public function getContinentsClient(): ContinentsClient
/**
* getCountriesClient
*
* @return \NStack\Clients\CountriesClient
* @return CountriesClient
* @author Casper Rasmussen <cr@nodes.dk>
*/
public function getCountriesClient(): CountriesClient
{
return $this->countriesClient;
}

/**
* @return CollectionsClient
* @author Casper Rasmussen <cr@nodes.dk>
*/
public function getCollectionClient(): CollectionsClient
{
return $this->collectionClient;
}

/**
* @return FilesClient
* @author Casper Rasmussen <cr@nodes.dk>
*/
public function getFilesClient(): FilesClient
{
return $this->filesClient;
}

/**
* @return IpAddressesClient
* @author Casper Rasmussen <cr@nodes.dk>
*/
public function getIpAddressClient(): IpAddressesClient
{
return $this->ipAddressClient;
}

/**
* @return LanguagesClient
* @author Casper Rasmussen <cr@nodes.dk>
*/
public function getLanguageClient(): LanguagesClient
{
return $this->languageClient;
}

/**
* @return LocalizeClient
* @author Casper Rasmussen <cr@nodes.dk>
*/
public function getLocalizeClient(): LocalizeClient
{
return $this->localizeClient;
}

/**
* @return VersionControlClient
* @author Casper Rasmussen <cr@nodes.dk>
*/
public function getVersionControlClient(): VersionControlClient
{
return $this->versionControlClient;
}

/**
* @return ProposalsClient
* @author Casper Rasmussen <cr@nodes.dk>
*/
public function getProposalClient(): ProposalsClient
{
return $this->proposalClient;
}

/**
* @return TimezoneClient
* @author Casper Rasmussen <cr@nodes.dk>
*/
public function getTimezoneClient(): TimezoneClient
{
return $this->timezoneClient;
}

/**
* @return PushLogClient
* @author Casper Rasmussen <cr@nodes.dk>
*/
public function getPushLogClient(): PushLogClient
{
return $this->pushLogClient;
}

/**
* @return ValidatorsClient
* @author Casper Rasmussen <cr@nodes.dk>
*/
public function getValidatorClient(): ValidatorsClient
{
return $this->validatorClient;
}

/**
* getDeeplink
*
Expand Down
23 changes: 23 additions & 0 deletions tests/LanguageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace NStack\Tests;

use NStack\Clients\LanguagesClient;
use NStack\Clients\LocalizeClient;
use NStack\Models\Language;

class LanguageTest extends TestCase
Expand Down Expand Up @@ -30,4 +31,26 @@ public function testResourceSearch()
$this->assertInstanceOf(Language::class, $language);
}
}

public function testLanguagesIndex()
{
$client = $this->getClientWithMockedGet('localize-languages-index.json');

$client = new LocalizeClient($this->getConfig(), $client);
$list = $client->indexLanguage('mobile');

foreach ($list as $continent) {
$this->assertInstanceOf(Language::class, $continent);
}
}

public function testLanguagesBestFit()
{
$client = $this->getClientWithMockedGet('localize-languages-best-fit.json');

$client = new LocalizeClient($this->getConfig(), $client);
$language = $client->bestFitLanguage('mobile');

$this->assertInstanceOf(Language::class, $language);
}
}
Loading