Fixes ACCOUNTS-5FF. Handle 204 response from Chrly.

This commit is contained in:
ErickSkrauch
2019-05-13 19:39:11 +03:00
parent 02a7d3815d
commit 194a7acd2a
5 changed files with 47 additions and 25 deletions

View File

@@ -1,34 +1,48 @@
<?php
declare(strict_types=1);
namespace common\components\SkinSystem;
use GuzzleHttp\Client as GuzzleClient;
use GuzzleHttp\ClientInterface;
use Yii;
// TODO: convert to complete Chrly client library
class Api {
private const BASE_DOMAIN = 'http://skinsystem.ely.by';
/** @var ClientInterface */
private $client;
/**
* @param string $username
* @throws \GuzzleHttp\Exception\GuzzleException
*
* @return array
*/
public function textures(string $username): array {
$response = $this->getClient()->get($this->getBuildUrl('/textures/' . $username));
public function textures(string $username): ?array {
$response = $this->getClient()->request('GET', $this->buildUrl('/textures/' . $username));
if ($response->getStatusCode() !== 204) {
return null;
}
return json_decode($response->getBody(), true);
}
protected function getBuildUrl(string $url): string {
public function setClient(ClientInterface $client): void {
$this->client = $client;
}
private function buildUrl(string $url): string {
return self::BASE_DOMAIN . $url;
}
/**
* @return GuzzleClient
*/
protected function getClient(): GuzzleClient {
return Yii::$app->guzzle;
private function getClient(): ClientInterface {
if ($this->client === null) {
$this->client = Yii::$container->get(ClientInterface::class);
}
return $this->client;
}
}