2016-09-06 15:26:39 +05:30
|
|
|
<?php
|
2019-05-13 22:09:11 +05:30
|
|
|
declare(strict_types=1);
|
|
|
|
|
2016-09-06 15:26:39 +05:30
|
|
|
namespace common\components\SkinSystem;
|
|
|
|
|
2019-05-13 22:09:11 +05:30
|
|
|
use GuzzleHttp\ClientInterface;
|
2016-09-06 15:26:39 +05:30
|
|
|
use Yii;
|
|
|
|
|
2019-05-13 22:09:11 +05:30
|
|
|
// TODO: convert to complete Chrly client library
|
2016-09-06 15:26:39 +05:30
|
|
|
class Api {
|
|
|
|
|
2018-04-18 02:17:25 +05:30
|
|
|
private const BASE_DOMAIN = 'http://skinsystem.ely.by';
|
2016-09-06 15:26:39 +05:30
|
|
|
|
2019-05-13 22:09:11 +05:30
|
|
|
/** @var ClientInterface */
|
|
|
|
private $client;
|
|
|
|
|
2016-12-23 04:20:34 +05:30
|
|
|
/**
|
|
|
|
* @param string $username
|
|
|
|
* @throws \GuzzleHttp\Exception\GuzzleException
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
2019-05-13 22:09:11 +05:30
|
|
|
public function textures(string $username): ?array {
|
|
|
|
$response = $this->getClient()->request('GET', $this->buildUrl('/textures/' . $username));
|
|
|
|
if ($response->getStatusCode() !== 204) {
|
|
|
|
return null;
|
|
|
|
}
|
2016-09-06 15:26:39 +05:30
|
|
|
|
2019-05-13 23:30:17 +05:30
|
|
|
return json_decode($response->getBody()->getContents(), true);
|
2016-09-06 15:26:39 +05:30
|
|
|
}
|
|
|
|
|
2019-05-13 22:09:11 +05:30
|
|
|
public function setClient(ClientInterface $client): void {
|
|
|
|
$this->client = $client;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function buildUrl(string $url): string {
|
2016-09-06 15:26:39 +05:30
|
|
|
return self::BASE_DOMAIN . $url;
|
|
|
|
}
|
|
|
|
|
2019-05-13 22:09:11 +05:30
|
|
|
private function getClient(): ClientInterface {
|
|
|
|
if ($this->client === null) {
|
|
|
|
$this->client = Yii::$container->get(ClientInterface::class);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->client;
|
2016-09-06 15:26:39 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
}
|