Skip to content

Commit 29c08bd

Browse files
authored
Merge pull request #20 from nstack-io/develop
Fixed some naming
2 parents c42cfc1 + 4aeb4fc commit 29c08bd

File tree

11 files changed

+233
-101
lines changed

11 files changed

+233
-101
lines changed

src/Clients/LocalizeClient.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace NStack\Clients;
44

5+
use NStack\Exceptions\FailedToParseException;
6+
use NStack\Models\Language;
57
use NStack\Models\Resource;
68

79
/**
@@ -56,4 +58,42 @@ public function showResource($url): array
5658

5759
return $data;
5860
}
61+
62+
/**
63+
* indexLanguage
64+
*
65+
* @param string $platform
66+
* @return array
67+
* @throws \NStack\Exceptions\FailedToParseException
68+
* @author Casper Rasmussen <cr@nodes.dk>
69+
*/
70+
public function indexLanguage(string $platform): array
71+
{
72+
$response = $this->client->get($this->buildPath($this->path . '/' . $platform . '/languages'));
73+
$contents = $response->getBody()->getContents();
74+
$data = json_decode($contents, true);
75+
76+
$array = [];
77+
foreach ($data['data'] as $object) {
78+
$array[] = new Language($object);
79+
}
80+
81+
return $array;
82+
}
83+
84+
/**
85+
* bestFitLanguage
86+
*
87+
* @param string $platform
88+
* @return Language
89+
* @throws FailedToParseException
90+
*/
91+
public function bestFitLanguage(string $platform): Language
92+
{
93+
$response = $this->client->get($this->buildPath($this->path . '/' . $platform . '/languages/best_fit'));
94+
$contents = $response->getBody()->getContents();
95+
$data = json_decode($contents, true);
96+
97+
return new Language($data['data']);
98+
}
5999
}

src/Clients/LocalizeLanguagesClient.php

Lines changed: 0 additions & 55 deletions
This file was deleted.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
namespace NStack\Clients;
44

55
/**
6-
* Class UgcClient
6+
* Class PushLogClient
77
*
88
* @package NStack\Clients
99
* @author Tiago Araujo <tiar@nodesagency.com>
1010
*/
11-
class UgcClient extends NStackClient
11+
class PushLogClient extends NStackClient
1212
{
1313
/** @var string */
1414
protected $path = 'ugc';
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
use NStack\Models\VersionControlUpdate;
88

99
/**
10-
* Class NotifyClient
10+
* Class VersionControlClient
1111
*
1212
* @package NStack\Clients
1313
* @author Tiago Araujo <tiar@nodesagency.com>
1414
*/
15-
class NotifyClient extends NStackClient
15+
class VersionControlClient extends NStackClient
1616
{
1717
/** @var string */
1818
protected $path = 'notify/updates';

src/NStack.php

Lines changed: 144 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,18 @@
22

33
namespace NStack;
44

5+
use NStack\Clients\CollectionsClient;
56
use NStack\Clients\ContinentsClient;
67
use NStack\Clients\CountriesClient;
8+
use NStack\Clients\FilesClient;
9+
use NStack\Clients\IpAddressesClient;
10+
use NStack\Clients\LanguagesClient;
11+
use NStack\Clients\LocalizeClient;
12+
use NStack\Clients\ProposalsClient;
13+
use NStack\Clients\PushLogClient;
14+
use NStack\Clients\TimezoneClient;
15+
use NStack\Clients\ValidatorsClient;
16+
use NStack\Clients\VersionControlClient;
717
use NStack\Exceptions\MissingMasterKeyException;
818

919
/**
@@ -17,12 +27,42 @@ class NStack
1727
/** @var \NStack\Config */
1828
protected $config;
1929

20-
/** @var \NStack\Clients\ContinentsClient */
30+
/** @var CollectionsClient */
31+
protected $collectionClient;
32+
33+
/** @var ContinentsClient */
2134
protected $continentsClient;
2235

23-
/** @var \NStack\Clients\CountriesClient */
36+
/** @var CountriesClient */
2437
protected $countriesClient;
2538

39+
/** @var FilesClient */
40+
protected $filesClient;
41+
42+
/** @var IpAddressesClient */
43+
protected $ipAddressClient;
44+
45+
/** @var LanguagesClient */
46+
protected $languageClient;
47+
48+
/** @var LocalizeClient */
49+
protected $localizeClient;
50+
51+
/** @var VersionControlClient */
52+
protected $versionControlClient;
53+
54+
/** @var ProposalsClient */
55+
protected $proposalClient;
56+
57+
/** @var TimezoneClient */
58+
protected $timezoneClient;
59+
60+
/** @var PushLogClient */
61+
protected $pushLogClient;
62+
63+
/** @var ValidatorsClient */
64+
protected $validatorClient;
65+
2666
/**
2767
* NStack constructor.
2868
*
@@ -34,6 +74,16 @@ public function __construct(Config $config)
3474
$this->config = $config;
3575
$this->continentsClient = new ContinentsClient($config);
3676
$this->countriesClient = new CountriesClient($config);
77+
$this->collectionClient = new CollectionsClient($config);
78+
$this->filesClient = new FilesClient($config);
79+
$this->ipAddressClient = new IpAddressesClient($config);
80+
$this->languageClient = new LanguagesClient($config);
81+
$this->localizeClient = new LocalizeClient($config);
82+
$this->versionControlClient = new VersionControlClient($config);
83+
$this->proposalClient = new ProposalsClient($config);
84+
$this->timezoneClient = new TimezoneClient($config);
85+
$this->pushLogClient = new PushLogClient($config);
86+
$this->validatorClient = new ValidatorsClient($config);
3787
}
3888

3989
/**
@@ -48,7 +98,7 @@ public function getConfig(): Config
4898
/**
4999
* getContinentsClient
50100
*
51-
* @return \NStack\Clients\ContinentsClient
101+
* @return ContinentsClient
52102
* @author Casper Rasmussen <cr@nodes.dk>
53103
*/
54104
public function getContinentsClient(): ContinentsClient
@@ -59,14 +109,104 @@ public function getContinentsClient(): ContinentsClient
59109
/**
60110
* getCountriesClient
61111
*
62-
* @return \NStack\Clients\CountriesClient
112+
* @return CountriesClient
63113
* @author Casper Rasmussen <cr@nodes.dk>
64114
*/
65115
public function getCountriesClient(): CountriesClient
66116
{
67117
return $this->countriesClient;
68118
}
69119

120+
/**
121+
* @return CollectionsClient
122+
* @author Casper Rasmussen <cr@nodes.dk>
123+
*/
124+
public function getCollectionClient(): CollectionsClient
125+
{
126+
return $this->collectionClient;
127+
}
128+
129+
/**
130+
* @return FilesClient
131+
* @author Casper Rasmussen <cr@nodes.dk>
132+
*/
133+
public function getFilesClient(): FilesClient
134+
{
135+
return $this->filesClient;
136+
}
137+
138+
/**
139+
* @return IpAddressesClient
140+
* @author Casper Rasmussen <cr@nodes.dk>
141+
*/
142+
public function getIpAddressClient(): IpAddressesClient
143+
{
144+
return $this->ipAddressClient;
145+
}
146+
147+
/**
148+
* @return LanguagesClient
149+
* @author Casper Rasmussen <cr@nodes.dk>
150+
*/
151+
public function getLanguageClient(): LanguagesClient
152+
{
153+
return $this->languageClient;
154+
}
155+
156+
/**
157+
* @return LocalizeClient
158+
* @author Casper Rasmussen <cr@nodes.dk>
159+
*/
160+
public function getLocalizeClient(): LocalizeClient
161+
{
162+
return $this->localizeClient;
163+
}
164+
165+
/**
166+
* @return VersionControlClient
167+
* @author Casper Rasmussen <cr@nodes.dk>
168+
*/
169+
public function getVersionControlClient(): VersionControlClient
170+
{
171+
return $this->versionControlClient;
172+
}
173+
174+
/**
175+
* @return ProposalsClient
176+
* @author Casper Rasmussen <cr@nodes.dk>
177+
*/
178+
public function getProposalClient(): ProposalsClient
179+
{
180+
return $this->proposalClient;
181+
}
182+
183+
/**
184+
* @return TimezoneClient
185+
* @author Casper Rasmussen <cr@nodes.dk>
186+
*/
187+
public function getTimezoneClient(): TimezoneClient
188+
{
189+
return $this->timezoneClient;
190+
}
191+
192+
/**
193+
* @return PushLogClient
194+
* @author Casper Rasmussen <cr@nodes.dk>
195+
*/
196+
public function getPushLogClient(): PushLogClient
197+
{
198+
return $this->pushLogClient;
199+
}
200+
201+
/**
202+
* @return ValidatorsClient
203+
* @author Casper Rasmussen <cr@nodes.dk>
204+
*/
205+
public function getValidatorClient(): ValidatorsClient
206+
{
207+
return $this->validatorClient;
208+
}
209+
70210
/**
71211
* getDeeplink
72212
*

tests/LanguageTest.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace NStack\Tests;
44

55
use NStack\Clients\LanguagesClient;
6+
use NStack\Clients\LocalizeClient;
67
use NStack\Models\Language;
78

89
class LanguageTest extends TestCase
@@ -30,4 +31,26 @@ public function testResourceSearch()
3031
$this->assertInstanceOf(Language::class, $language);
3132
}
3233
}
34+
35+
public function testLanguagesIndex()
36+
{
37+
$client = $this->getClientWithMockedGet('localize-languages-index.json');
38+
39+
$client = new LocalizeClient($this->getConfig(), $client);
40+
$list = $client->indexLanguage('mobile');
41+
42+
foreach ($list as $continent) {
43+
$this->assertInstanceOf(Language::class, $continent);
44+
}
45+
}
46+
47+
public function testLanguagesBestFit()
48+
{
49+
$client = $this->getClientWithMockedGet('localize-languages-best-fit.json');
50+
51+
$client = new LocalizeClient($this->getConfig(), $client);
52+
$language = $client->bestFitLanguage('mobile');
53+
54+
$this->assertInstanceOf(Language::class, $language);
55+
}
3356
}

0 commit comments

Comments
 (0)