mirror of
https://github.com/elyby/mojang-api.git
synced 2024-12-22 16:19:48 +05:30
Implemented Change Skin endpoint
This commit is contained in:
parent
8a9e6ca41d
commit
46c0215add
@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
- [API Status](https://wiki.vg/Mojang_API#API_Status) endpoint.
|
- [API Status](https://wiki.vg/Mojang_API#API_Status) endpoint.
|
||||||
- [UUID to Name history](https://wiki.vg/Mojang_API#UUID_-.3E_Name_history) endpoint.
|
- [UUID to Name history](https://wiki.vg/Mojang_API#UUID_-.3E_Name_history) endpoint.
|
||||||
- [Playernames -> UUIDs](https://wiki.vg/Mojang_API#Playernames_-.3E_UUIDs) endpoint.
|
- [Playernames -> UUIDs](https://wiki.vg/Mojang_API#Playernames_-.3E_UUIDs) endpoint.
|
||||||
|
- [Change Skin](https://wiki.vg/Mojang_API#Change_Skin) endpoint.
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
- The constructor no longer has arguments.
|
- The constructor no longer has arguments.
|
||||||
|
23
src/Api.php
23
src/Api.php
@ -177,6 +177,29 @@ class Api {
|
|||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $accessToken
|
||||||
|
* @param string $accountUuid
|
||||||
|
* @param string $skinUrl
|
||||||
|
* @param bool $isSlim
|
||||||
|
*
|
||||||
|
* @throws \Ely\Mojang\Exception\MojangApiException
|
||||||
|
* @throws GuzzleException
|
||||||
|
*
|
||||||
|
* @url https://wiki.vg/Mojang_API#Change_Skin
|
||||||
|
*/
|
||||||
|
public function changeSkin(string $accessToken, string $accountUuid, string $skinUrl, bool $isSlim): void {
|
||||||
|
$this->getClient()->request('POST', "https://api.mojang.com/user/profile/{$accountUuid}/skin", [
|
||||||
|
'form_params' => [
|
||||||
|
'model' => $isSlim ? 'slim' : '',
|
||||||
|
'url' => $skinUrl,
|
||||||
|
],
|
||||||
|
'headers' => [
|
||||||
|
'Authorization' => 'Bearer ' . $accessToken,
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $accessToken
|
* @param string $accessToken
|
||||||
* @param string $accountUuid
|
* @param string $accountUuid
|
||||||
|
@ -251,11 +251,32 @@ class ApiTest extends TestCase {
|
|||||||
$this->assertStringStartsWith('https://sessionserver.mojang.com/session/minecraft/profile/86f6e3695b764412a29820cac1d4d0d6', (string)$request2->getUri());
|
$this->assertStringStartsWith('https://sessionserver.mojang.com/session/minecraft/profile/86f6e3695b764412a29820cac1d4d0d6', (string)$request2->getUri());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testChangeSkinNotSlim() {
|
||||||
|
$this->mockHandler->append(new Response(200));
|
||||||
|
$this->api->changeSkin('mocked access token', '86f6e3695b764412a29820cac1d4d0d6', 'http://localhost/skin.png', false);
|
||||||
|
/** @var \Psr\Http\Message\RequestInterface $request */
|
||||||
|
$request = $this->history[0]['request'];
|
||||||
|
$this->assertSame('https://api.mojang.com/user/profile/86f6e3695b764412a29820cac1d4d0d6/skin', (string)$request->getUri());
|
||||||
|
$this->assertSame('Bearer mocked access token', $request->getHeaderLine('Authorization'));
|
||||||
|
$body = urldecode($request->getBody()->getContents());
|
||||||
|
$this->assertStringContainsString('url=http://localhost/skin.png', $body);
|
||||||
|
$this->assertStringNotContainsString('model=slim', $body);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testChangeSkinSlim() {
|
||||||
|
$this->mockHandler->append(new Response(200));
|
||||||
|
$this->api->changeSkin('mocked access token', '86f6e3695b764412a29820cac1d4d0d6', 'http://localhost/skin.png', true);
|
||||||
|
/** @var \Psr\Http\Message\RequestInterface $request */
|
||||||
|
$request = $this->history[0]['request'];
|
||||||
|
$this->assertStringContainsString('model=slim', $request->getBody()->getContents());
|
||||||
|
}
|
||||||
|
|
||||||
public function testUploadSkinNotSlim() {
|
public function testUploadSkinNotSlim() {
|
||||||
$this->mockHandler->append(new Response(200));
|
$this->mockHandler->append(new Response(200));
|
||||||
$this->api->uploadSkin('mocked access token', '86f6e3695b764412a29820cac1d4d0d6', 'skin contents', false);
|
$this->api->uploadSkin('mocked access token', '86f6e3695b764412a29820cac1d4d0d6', 'skin contents', false);
|
||||||
/** @var \Psr\Http\Message\RequestInterface $request */
|
/** @var \Psr\Http\Message\RequestInterface $request */
|
||||||
$request = $this->history[0]['request'];
|
$request = $this->history[0]['request'];
|
||||||
|
$this->assertSame('https://api.mojang.com/user/profile/86f6e3695b764412a29820cac1d4d0d6/skin', (string)$request->getUri());
|
||||||
$this->assertSame('Bearer mocked access token', $request->getHeaderLine('Authorization'));
|
$this->assertSame('Bearer mocked access token', $request->getHeaderLine('Authorization'));
|
||||||
$this->assertStringNotContainsString('slim', $request->getBody()->getContents());
|
$this->assertStringNotContainsString('slim', $request->getBody()->getContents());
|
||||||
}
|
}
|
||||||
@ -265,6 +286,7 @@ class ApiTest extends TestCase {
|
|||||||
$this->api->uploadSkin('mocked access token', '86f6e3695b764412a29820cac1d4d0d6', 'skin contents', true);
|
$this->api->uploadSkin('mocked access token', '86f6e3695b764412a29820cac1d4d0d6', 'skin contents', true);
|
||||||
/** @var \Psr\Http\Message\RequestInterface $request */
|
/** @var \Psr\Http\Message\RequestInterface $request */
|
||||||
$request = $this->history[0]['request'];
|
$request = $this->history[0]['request'];
|
||||||
|
$this->assertSame('https://api.mojang.com/user/profile/86f6e3695b764412a29820cac1d4d0d6/skin', (string)$request->getUri());
|
||||||
$this->assertStringContainsString('slim', $request->getBody()->getContents());
|
$this->assertStringContainsString('slim', $request->getBody()->getContents());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user