From 4aeb4fcd0f30e64203e6931bc49c768a36f0e754 Mon Sep 17 00:00:00 2001 From: Casper Rasmussen Date: Tue, 24 Sep 2019 09:54:02 +0200 Subject: [PATCH] update --- src/Clients/LocalizeClient.php | 40 +++++ src/Clients/LocalizeLanguagesClient.php | 55 ------- .../{UgcClient.php => PushLogClient.php} | 4 +- ...ifyClient.php => VersionControlClient.php} | 4 +- src/NStack.php | 148 +++++++++++++++++- tests/LanguageTest.php | 23 +++ tests/LocalizeLanguagesTest.php | 34 ---- tests/NStackTest.php | 17 ++ tests/NotifyTest.php | 6 +- tests/TestCase.php | 1 + tests/UgcTest.php | 2 +- 11 files changed, 233 insertions(+), 101 deletions(-) delete mode 100644 src/Clients/LocalizeLanguagesClient.php rename src/Clients/{UgcClient.php => PushLogClient.php} (95%) rename src/Clients/{NotifyClient.php => VersionControlClient.php} (96%) delete mode 100644 tests/LocalizeLanguagesTest.php create mode 100644 tests/NStackTest.php diff --git a/src/Clients/LocalizeClient.php b/src/Clients/LocalizeClient.php index c8c2b48..3ad6307 100644 --- a/src/Clients/LocalizeClient.php +++ b/src/Clients/LocalizeClient.php @@ -2,6 +2,8 @@ namespace NStack\Clients; +use NStack\Exceptions\FailedToParseException; +use NStack\Models\Language; use NStack\Models\Resource; /** @@ -56,4 +58,42 @@ public function showResource($url): array return $data; } + + /** + * indexLanguage + * + * @param string $platform + * @return array + * @throws \NStack\Exceptions\FailedToParseException + * @author Casper Rasmussen + */ + 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']); + } } \ No newline at end of file diff --git a/src/Clients/LocalizeLanguagesClient.php b/src/Clients/LocalizeLanguagesClient.php deleted file mode 100644 index 0829794..0000000 --- a/src/Clients/LocalizeLanguagesClient.php +++ /dev/null @@ -1,55 +0,0 @@ - - */ -class LocalizeLanguagesClient extends NStackClient -{ - /** @var string */ - protected $path = 'content/localize'; - - /** - * index - * - * @param string $platform - * @return array - * @throws FailedToParseException - */ - public function index(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; - } - - /** - * bestFit - * - * @param string $platform - * @return Language - * @throws FailedToParseException - */ - public function bestFit(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']); - } -} \ No newline at end of file diff --git a/src/Clients/UgcClient.php b/src/Clients/PushLogClient.php similarity index 95% rename from src/Clients/UgcClient.php rename to src/Clients/PushLogClient.php index 8bfcc31..3f414af 100644 --- a/src/Clients/UgcClient.php +++ b/src/Clients/PushLogClient.php @@ -3,12 +3,12 @@ namespace NStack\Clients; /** - * Class UgcClient + * Class PushLogClient * * @package NStack\Clients * @author Tiago Araujo */ -class UgcClient extends NStackClient +class PushLogClient extends NStackClient { /** @var string */ protected $path = 'ugc'; diff --git a/src/Clients/NotifyClient.php b/src/Clients/VersionControlClient.php similarity index 96% rename from src/Clients/NotifyClient.php rename to src/Clients/VersionControlClient.php index 5600be3..d5e7d48 100644 --- a/src/Clients/NotifyClient.php +++ b/src/Clients/VersionControlClient.php @@ -7,12 +7,12 @@ use NStack\Models\VersionControlUpdate; /** - * Class NotifyClient + * Class VersionControlClient * * @package NStack\Clients * @author Tiago Araujo */ -class NotifyClient extends NStackClient +class VersionControlClient extends NStackClient { /** @var string */ protected $path = 'notify/updates'; diff --git a/src/NStack.php b/src/NStack.php index cce03f8..271829f 100644 --- a/src/NStack.php +++ b/src/NStack.php @@ -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; /** @@ -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. * @@ -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); } /** @@ -48,7 +98,7 @@ public function getConfig(): Config /** * getContinentsClient * - * @return \NStack\Clients\ContinentsClient + * @return ContinentsClient * @author Casper Rasmussen */ public function getContinentsClient(): ContinentsClient @@ -59,7 +109,7 @@ public function getContinentsClient(): ContinentsClient /** * getCountriesClient * - * @return \NStack\Clients\CountriesClient + * @return CountriesClient * @author Casper Rasmussen */ public function getCountriesClient(): CountriesClient @@ -67,6 +117,96 @@ public function getCountriesClient(): CountriesClient return $this->countriesClient; } + /** + * @return CollectionsClient + * @author Casper Rasmussen + */ + public function getCollectionClient(): CollectionsClient + { + return $this->collectionClient; + } + + /** + * @return FilesClient + * @author Casper Rasmussen + */ + public function getFilesClient(): FilesClient + { + return $this->filesClient; + } + + /** + * @return IpAddressesClient + * @author Casper Rasmussen + */ + public function getIpAddressClient(): IpAddressesClient + { + return $this->ipAddressClient; + } + + /** + * @return LanguagesClient + * @author Casper Rasmussen + */ + public function getLanguageClient(): LanguagesClient + { + return $this->languageClient; + } + + /** + * @return LocalizeClient + * @author Casper Rasmussen + */ + public function getLocalizeClient(): LocalizeClient + { + return $this->localizeClient; + } + + /** + * @return VersionControlClient + * @author Casper Rasmussen + */ + public function getVersionControlClient(): VersionControlClient + { + return $this->versionControlClient; + } + + /** + * @return ProposalsClient + * @author Casper Rasmussen + */ + public function getProposalClient(): ProposalsClient + { + return $this->proposalClient; + } + + /** + * @return TimezoneClient + * @author Casper Rasmussen + */ + public function getTimezoneClient(): TimezoneClient + { + return $this->timezoneClient; + } + + /** + * @return PushLogClient + * @author Casper Rasmussen + */ + public function getPushLogClient(): PushLogClient + { + return $this->pushLogClient; + } + + /** + * @return ValidatorsClient + * @author Casper Rasmussen + */ + public function getValidatorClient(): ValidatorsClient + { + return $this->validatorClient; + } + /** * getDeeplink * diff --git a/tests/LanguageTest.php b/tests/LanguageTest.php index b30c292..d06cea5 100644 --- a/tests/LanguageTest.php +++ b/tests/LanguageTest.php @@ -3,6 +3,7 @@ namespace NStack\Tests; use NStack\Clients\LanguagesClient; +use NStack\Clients\LocalizeClient; use NStack\Models\Language; class LanguageTest extends TestCase @@ -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); + } } diff --git a/tests/LocalizeLanguagesTest.php b/tests/LocalizeLanguagesTest.php deleted file mode 100644 index fa51bc2..0000000 --- a/tests/LocalizeLanguagesTest.php +++ /dev/null @@ -1,34 +0,0 @@ -getClientWithMockedGet('localize-languages-index.json'); - - $client = new LocalizeLanguagesClient($this->getConfig(), $client); - $list = $client->index('mobile'); - - foreach ($list as $continent) { - $this->assertInstanceOf(Language::class, $continent); - } - } - - public function testLanguagesBestFit() - { - $client = $this->getClientWithMockedGet('localize-languages-best-fit.json'); - - $client = new LocalizeLanguagesClient($this->getConfig(), $client); - $language = $client->bestFit('mobile'); - - $this->assertInstanceOf(Language::class, $language); - } -} diff --git a/tests/NStackTest.php b/tests/NStackTest.php new file mode 100644 index 0000000..d57187a --- /dev/null +++ b/tests/NStackTest.php @@ -0,0 +1,17 @@ +getConfig(); + + $nstack = new NStack($config); + + $this->assertInstanceOf(NStack::class, $nstack); + } +} diff --git a/tests/NotifyTest.php b/tests/NotifyTest.php index 76e8703..a0d7dbf 100644 --- a/tests/NotifyTest.php +++ b/tests/NotifyTest.php @@ -5,7 +5,7 @@ use NStack\Clients\ContinentsClient; use NStack\Clients\CountriesClient; use NStack\Clients\IpAddressesClient; -use NStack\Clients\NotifyClient; +use NStack\Clients\VersionControlClient; use NStack\Models\Continent; use NStack\Models\Country; use NStack\Models\IpAddress; @@ -18,7 +18,7 @@ public function testVersionControlUpdate() { $client = $this->getClientWithMockedGet('notify-version-control-update.json'); - $client = new NotifyClient($this->getConfig(), $client); + $client = new VersionControlClient($this->getConfig(), $client); $entry = $client->versionControlIndex("mobile"); $this->assertInstanceOf(VersionControlUpdate::class, $entry); @@ -28,7 +28,7 @@ public function testVersionControlSeemUpdate() { $client = $this->getClientWithMockedPost('notify-version-control-seen-update.json'); - $client = new NotifyClient($this->getConfig(), $client); + $client = new VersionControlClient($this->getConfig(), $client); $entry = $client->markUpdateAsSeen('test', 689, 'no', 'newer_version'); $this->assertInstanceOf(SeenUpdate::class, $entry); diff --git a/tests/TestCase.php b/tests/TestCase.php index 3a7310d..40713bd 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -98,4 +98,5 @@ public function getConfig(): Config { return new Config('', ''); } + } diff --git a/tests/UgcTest.php b/tests/UgcTest.php index 27739f2..1a685bb 100644 --- a/tests/UgcTest.php +++ b/tests/UgcTest.php @@ -6,7 +6,7 @@ class UgcTest extends TestCase { public function testUgcPushlogs() { - $mock = $this->getMockBuilder('UgcClient') + $mock = $this->getMockBuilder('PushLogClient') ->setMethods(['storePushLog']) ->getMock();