mirror of
https://github.com/elyby/mojang-api.git
synced 2024-12-23 08:39:54 +05:30
Reorder methods
This commit is contained in:
parent
36cab232b6
commit
c9eed8e290
58
src/Api.php
58
src/Api.php
@ -177,6 +177,35 @@ class Api {
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $accessToken
|
||||
* @param string $accountUuid
|
||||
* @param \Psr\Http\Message\StreamInterface|resource|string $skinContents
|
||||
* @param bool $isSlim
|
||||
*
|
||||
* @throws GuzzleException
|
||||
*
|
||||
* @url https://wiki.vg/Mojang_API#Upload_Skin
|
||||
*/
|
||||
public function uploadSkin(string $accessToken, string $accountUuid, $skinContents, bool $isSlim): void {
|
||||
$this->getClient()->request('PUT', "https://api.mojang.com/user/profile/{$accountUuid}/skin", [
|
||||
'multipart' => [
|
||||
[
|
||||
'name' => 'file',
|
||||
'contents' => $skinContents,
|
||||
'filename' => 'char.png',
|
||||
],
|
||||
[
|
||||
'name' => 'model',
|
||||
'contents' => $isSlim ? 'slim' : '',
|
||||
],
|
||||
],
|
||||
'headers' => [
|
||||
'Authorization' => 'Bearer ' . $accessToken,
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $login
|
||||
* @param string $password
|
||||
@ -247,35 +276,6 @@ class Api {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $accessToken
|
||||
* @param string $accountUuid
|
||||
* @param \Psr\Http\Message\StreamInterface|resource|string $skinContents
|
||||
* @param bool $isSlim
|
||||
*
|
||||
* @throws GuzzleException
|
||||
*
|
||||
* @url https://wiki.vg/Mojang_API#Upload_Skin
|
||||
*/
|
||||
public function uploadSkin(string $accessToken, string $accountUuid, $skinContents, bool $isSlim): void {
|
||||
$this->getClient()->request('PUT', "https://api.mojang.com/user/profile/{$accountUuid}/skin", [
|
||||
'multipart' => [
|
||||
[
|
||||
'name' => 'file',
|
||||
'contents' => $skinContents,
|
||||
'filename' => 'char.png',
|
||||
],
|
||||
[
|
||||
'name' => 'model',
|
||||
'contents' => $isSlim ? 'slim' : '',
|
||||
],
|
||||
],
|
||||
'headers' => [
|
||||
'Authorization' => 'Bearer ' . $accessToken,
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $accessToken
|
||||
* @param string $accountUuid
|
||||
|
@ -231,17 +231,6 @@ class ApiTest extends TestCase {
|
||||
$this->assertTrue($result['mockusername']->isDemo());
|
||||
}
|
||||
|
||||
public function testPlayernamesToUuidsInvalidArgumentException() {
|
||||
$names = [];
|
||||
for ($i = 0; $i < 101; $i++) {
|
||||
$names[] = base64_encode(random_bytes(4));
|
||||
}
|
||||
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
$this->expectExceptionMessage('You cannot request more than 100 names per request');
|
||||
$this->api->playernamesToUuids($names);
|
||||
}
|
||||
|
||||
public function testUsernameToTextures() {
|
||||
$this->mockHandler->append($this->createResponse(200, [
|
||||
'id' => '86f6e3695b764412a29820cac1d4d0d6',
|
||||
@ -262,6 +251,34 @@ class ApiTest extends TestCase {
|
||||
$this->assertStringStartsWith('https://sessionserver.mojang.com/session/minecraft/profile/86f6e3695b764412a29820cac1d4d0d6', (string)$request2->getUri());
|
||||
}
|
||||
|
||||
public function testUploadSkinNotSlim() {
|
||||
$this->mockHandler->append(new Response(200));
|
||||
$this->api->uploadSkin('mocked access token', '86f6e3695b764412a29820cac1d4d0d6', 'skin contents', false);
|
||||
/** @var \Psr\Http\Message\RequestInterface $request */
|
||||
$request = $this->history[0]['request'];
|
||||
$this->assertSame('Bearer mocked access token', $request->getHeaderLine('Authorization'));
|
||||
$this->assertStringNotContainsString('slim', $request->getBody()->getContents());
|
||||
}
|
||||
|
||||
public function testUploadSkinSlim() {
|
||||
$this->mockHandler->append(new Response(200));
|
||||
$this->api->uploadSkin('mocked access token', '86f6e3695b764412a29820cac1d4d0d6', 'skin contents', true);
|
||||
/** @var \Psr\Http\Message\RequestInterface $request */
|
||||
$request = $this->history[0]['request'];
|
||||
$this->assertStringContainsString('slim', $request->getBody()->getContents());
|
||||
}
|
||||
|
||||
public function testPlayernamesToUuidsInvalidArgumentException() {
|
||||
$names = [];
|
||||
for ($i = 0; $i < 101; $i++) {
|
||||
$names[] = base64_encode(random_bytes(4));
|
||||
}
|
||||
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
$this->expectExceptionMessage('You cannot request more than 100 names per request');
|
||||
$this->api->playernamesToUuids($names);
|
||||
}
|
||||
|
||||
public function testAuthenticate() {
|
||||
$this->mockHandler->append($this->createResponse(200, [
|
||||
'accessToken' => 'access token value',
|
||||
@ -355,23 +372,6 @@ class ApiTest extends TestCase {
|
||||
$this->assertFalse($this->api->validate('mocked access token'));
|
||||
}
|
||||
|
||||
public function testUploadSkinNotSlim() {
|
||||
$this->mockHandler->append(new Response(200));
|
||||
$this->api->uploadSkin('mocked access token', '86f6e3695b764412a29820cac1d4d0d6', 'skin contents', false);
|
||||
/** @var \Psr\Http\Message\RequestInterface $request */
|
||||
$request = $this->history[0]['request'];
|
||||
$this->assertSame('Bearer mocked access token', $request->getHeaderLine('Authorization'));
|
||||
$this->assertStringNotContainsString('slim', $request->getBody()->getContents());
|
||||
}
|
||||
|
||||
public function testUploadSkinSlim() {
|
||||
$this->mockHandler->append(new Response(200));
|
||||
$this->api->uploadSkin('mocked access token', '86f6e3695b764412a29820cac1d4d0d6', 'skin contents', true);
|
||||
/** @var \Psr\Http\Message\RequestInterface $request */
|
||||
$request = $this->history[0]['request'];
|
||||
$this->assertStringContainsString('slim', $request->getBody()->getContents());
|
||||
}
|
||||
|
||||
public function testJoinServer() {
|
||||
$this->mockHandler->append(new Response(200));
|
||||
$this->api->joinServer('mocked access token', '86f6e3695b764412a29820cac1d4d0d6', 'ad72fe1efe364e6eb78c644a9fba1d30');
|
||||
|
Loading…
Reference in New Issue
Block a user