-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add languages endpoint * fix phpcs * fix
- Loading branch information
Showing
12 changed files
with
158 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace SupportPal\ApiClient\Api\Core; | ||
|
||
use SupportPal\ApiClient\Exception\HttpResponseException; | ||
use SupportPal\ApiClient\Exception\InvalidArgumentException; | ||
use SupportPal\ApiClient\Http\CoreClient; | ||
use SupportPal\ApiClient\Model\Collection; | ||
use SupportPal\ApiClient\Model\Core\Language; | ||
|
||
use function array_map; | ||
|
||
trait Languages | ||
{ | ||
/** | ||
* @param array<mixed> $queryParameters | ||
* @throws HttpResponseException | ||
* @throws InvalidArgumentException | ||
*/ | ||
public function getLanguages(array $queryParameters = []): Collection | ||
{ | ||
$response = $this->getApiClient()->getLanguages($queryParameters); | ||
$body = $this->decodeBody($response); | ||
$models = array_map([$this, 'createLanguageModel'], $body['data']); | ||
|
||
return $this->createCollection($body['count'], $models); | ||
} | ||
|
||
/** | ||
* @param array<mixed> $data | ||
*/ | ||
private function createLanguageModel(array $data): Language | ||
{ | ||
return new Language($data); | ||
} | ||
|
||
abstract protected function getApiClient(): CoreClient; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace SupportPal\ApiClient\Http\Core; | ||
|
||
use Psr\Http\Message\ResponseInterface; | ||
use SupportPal\ApiClient\Dictionary\ApiDictionary; | ||
use SupportPal\ApiClient\Exception\HttpResponseException; | ||
use SupportPal\ApiClient\Http\ApiClientAware; | ||
|
||
trait LanguageApis | ||
{ | ||
use ApiClientAware; | ||
|
||
/** | ||
* @param array<mixed> $queryParameters | ||
* @throws HttpResponseException | ||
*/ | ||
public function getLanguages(array $queryParameters): ResponseInterface | ||
{ | ||
return $this->prepareAndSendGetRequest(ApiDictionary::CORE_LANGUAGE, $queryParameters); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace SupportPal\ApiClient\Model\Core; | ||
|
||
use SupportPal\ApiClient\Model\Model; | ||
|
||
class Language extends Model | ||
{ | ||
/** @var array<string, string> */ | ||
protected array $casts = [ | ||
'id' => 'int', | ||
'name' => 'string', | ||
'code' => 'string', | ||
'enabled' => 'bool', | ||
'upgrade_available' => 'bool', | ||
'version' => 'string', | ||
'created_at' => 'int', | ||
'updated_at' => 'int', | ||
'formatted_name' => 'string', | ||
]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace SupportPal\ApiClient\Tests\DataFixtures\Core; | ||
|
||
use SupportPal\ApiClient\Model\Core\Language; | ||
use SupportPal\ApiClient\Tests\DataFixtures\BaseModelData; | ||
|
||
class LanguageData extends BaseModelData | ||
{ | ||
public const DATA = [ | ||
'id' => 1, | ||
'name' => 'English', | ||
'code' => 'en', | ||
'enabled' => 1, | ||
'upgrade_available' => 0, | ||
'version' => '1.0', | ||
'created_at' => 1600753870, | ||
'updated_at' => 1600753870, | ||
'formatted_name' => 'English', | ||
]; | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function getModel(): string | ||
{ | ||
return Language::class; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Api\Core; | ||
|
||
use SupportPal\ApiClient\Model\Core\Language; | ||
use SupportPal\ApiClient\Tests\DataFixtures\Core\LanguageData; | ||
use SupportPal\ApiClient\Tests\Unit\Api\Core\BaseCoreApiTest; | ||
|
||
class LanguageApisTest extends BaseCoreApiTest | ||
{ | ||
public function testGetLanguages(): void | ||
{ | ||
[$output, $response] = $this->makeCommonExpectations((new LanguageData)->getAllResponse(), Language::class); | ||
|
||
$this->apiClient | ||
->getLanguages([]) | ||
->shouldBeCalled() | ||
->willReturn($response->reveal()); | ||
|
||
$returnedModels = $this->api->getLanguages(); | ||
self::assertEquals($output, $returnedModels); | ||
} | ||
} |