mirror of
https://github.com/elyby/accounts.git
synced 2024-11-30 02:32:26 +05:30
Написал простецкую обёртку над Mojang API (пока только метод запроса uuid по нику).
Зафиксировал минорные версии для библиотек Composer
This commit is contained in:
parent
d8a2cc21b8
commit
8b06adb7e8
49
common/components/Mojang/Api.php
Normal file
49
common/components/Mojang/Api.php
Normal file
@ -0,0 +1,49 @@
|
||||
<?php
|
||||
namespace common\components\Mojang;
|
||||
|
||||
use common\components\Mojang\exceptions\MojangApiException;
|
||||
use common\components\Mojang\exceptions\NoContentException;
|
||||
use common\components\Mojang\response\UsernameToUUIDResponse;
|
||||
use GuzzleHttp\Client as GuzzleClient;
|
||||
|
||||
class Api {
|
||||
|
||||
/**
|
||||
* @param string $username
|
||||
* @param int $atTime
|
||||
*
|
||||
* @return UsernameToUUIDResponse
|
||||
* @throws MojangApiException
|
||||
* @throws NoContentException
|
||||
*/
|
||||
public function usernameToUUID($username, $atTime = null) {
|
||||
$client = $this->createClient();
|
||||
$request = $client->createRequest('GET', 'https://api.mojang.com/users/profiles/minecraft/' . $username);
|
||||
$queryParams = [];
|
||||
if ($atTime !== null) {
|
||||
$queryParams['atTime'] = $atTime;
|
||||
}
|
||||
|
||||
$request->setQuery($queryParams);
|
||||
$response = $client->send($request);
|
||||
if ($response->getStatusCode() === 204) {
|
||||
throw new NoContentException('Username not found');
|
||||
} elseif ($response->getStatusCode()) {
|
||||
throw new MojangApiException('Unexpected request result');
|
||||
}
|
||||
|
||||
$data = $response->json(['object' => false]);
|
||||
$responseObj = new UsernameToUUIDResponse();
|
||||
$responseObj->id = $data['id'];
|
||||
$responseObj->name = $data['name'];
|
||||
$responseObj->legacy = isset($data['legacy']);
|
||||
$responseObj->demo = isset($data['demo']);
|
||||
|
||||
return $responseObj;
|
||||
}
|
||||
|
||||
protected function createClient() {
|
||||
return new GuzzleClient();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
<?php
|
||||
namespace common\components\Mojang\exceptions;
|
||||
|
||||
use Exception;
|
||||
|
||||
class MojangApiException extends Exception {
|
||||
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
<?php
|
||||
namespace common\components\Mojang\exceptions;
|
||||
|
||||
class NoContentException extends MojangApiException {
|
||||
|
||||
}
|
29
common/components/Mojang/response/UsernameToUUIDResponse.php
Normal file
29
common/components/Mojang/response/UsernameToUUIDResponse.php
Normal file
@ -0,0 +1,29 @@
|
||||
<?php
|
||||
namespace common\components\Mojang\response;
|
||||
|
||||
/**
|
||||
* http://wiki.vg/Mojang_API#Username_-.3E_UUID_at_time
|
||||
*/
|
||||
class UsernameToUUIDResponse {
|
||||
|
||||
/**
|
||||
* @var string uuid пользователя без разделения на дефисы
|
||||
*/
|
||||
public $id;
|
||||
|
||||
/**
|
||||
* @var string ник пользователя в настоящем времени
|
||||
*/
|
||||
public $name;
|
||||
|
||||
/**
|
||||
* @var bool если имеет значение true, то значит аккаунт не мигрирован в Mojang аккаунт
|
||||
*/
|
||||
public $legacy = false;
|
||||
|
||||
/**
|
||||
* @var bool будет иметь значение true, если аккаунт находится в демо-режиме (не приобретена лицензия)
|
||||
*/
|
||||
public $demo = false;
|
||||
|
||||
}
|
@ -15,13 +15,14 @@
|
||||
"minimum-stability": "stable",
|
||||
"require": {
|
||||
"php": ">=5.6.0",
|
||||
"yiisoft/yii2": ">=2.0.6",
|
||||
"yiisoft/yii2": "~2.0.6",
|
||||
"yiisoft/yii2-bootstrap": "*",
|
||||
"yiisoft/yii2-swiftmailer": "*",
|
||||
"ramsey/uuid": "^3.1",
|
||||
"ramsey/uuid": "~3.1",
|
||||
"league/oauth2-server": "~4.1.5",
|
||||
"yiisoft/yii2-redis": "~2.0.0",
|
||||
"damirka/yii2-jwt": "dev-master#be29a5b5d7e7d146c13d4374788e02c54cc04138"
|
||||
"damirka/yii2-jwt": "dev-master#be29a5b5d7e7d146c13d4374788e02c54cc04138",
|
||||
"guzzlehttp/guzzle": "~5.3.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"yiisoft/yii2-codeception": "*",
|
||||
|
Loading…
Reference in New Issue
Block a user