-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moved mojang.api.session to mojang.account.session
- Loading branch information
Showing
5 changed files
with
139 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from .base import status, get_uuid, get_uuids, names |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from requests.auth import AuthBase | ||
|
||
class BearerAuth(AuthBase): | ||
|
||
def __init__(self, token: str): | ||
self.__token = token | ||
|
||
def __call__(self, r): | ||
r.headers['Authorization'] = 'Bearer {}'.format(self.__token) | ||
return r |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import requests | ||
|
||
from ._urls import URLs | ||
from ._structures import NameChange, Skin | ||
from ._auth import BearerAuth | ||
|
||
# TODO: Handle errors and exception | ||
|
||
def get_user_name_change(access_token: str): | ||
response = requests.get(URLs.name_change(), auth=BearerAuth(access_token)) | ||
|
||
data = response.json() | ||
data['created_at'] = dt.datetime.strptime(data.pop('createdAt'), '%Y-%m-%dT%H:%M:%SZ') | ||
data['allowed'] = data.pop('nameChangeAllowed') | ||
|
||
return NameChange(**data) | ||
|
||
def change_user_name(access_token: str, name: str): | ||
response = requests.put(URLs.change_name(name), auth=BearerAuth(access_token)) | ||
|
||
def change_user_skin(access_token: str, path: str, variant='classic'): | ||
skin = Skin(source=path, variant=variant) | ||
files = [ | ||
('variant', skin.variant), | ||
('file', ('image.png', skin.data, f'image/png')) | ||
] | ||
response = requests.post(URLs.change_skin(), auth=BearerAuth(access_token), files=files, headers={'content-type': None}) | ||
|
||
def reset_user_skin(access_token: str, uuid: str): | ||
response = requests.delete(URLs.reset_skin(uuid), auth=BearerAuth(access_token)) |