Skip to content

Commit

Permalink
Documentation for mojang.api.base
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucino772 committed Mar 24, 2021
1 parent f0e5116 commit 1e6020f
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
15 changes: 15 additions & 0 deletions docs/PyMojang/base.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Basic API
===

::: mojang.api.base
handler: python
selection:
members:
- api_status
- name_history
- get_uuid
- get_uuids
- get_profile
rendering:
show_root_heading: true
show_source: true
51 changes: 51 additions & 0 deletions mojang/api/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@


def api_status(service: str = None) -> dict:
"""Get the status of Mojang's services
Args:
service (str, optional): The name of the service which you want to know the status
Returns:
If service is given, return only the status for this service else return a dict
with all the status for each services
"""
res = {}

data = web.request('get', STATUS_CHECK)
Expand All @@ -25,6 +34,15 @@ def api_status(service: str = None) -> dict:
return res

def name_history(uuid: str) -> list:
"""Get the user's name history
Args:
uuid (str): The user's uuid
Returns:
A list of tuples, each containing the name and the datetime at which it was
changed to
"""
names = []

data = web.request('get', NAME_HISTORY.format(uuid=uuid))
Expand All @@ -37,6 +55,17 @@ def name_history(uuid: str) -> list:
return names

def get_uuid(username: str, only_uuid: bool = True) -> dict:
"""Get uuid of username
Args:
username (str): The username which you want the uuid of
only_uuid (bool): If True only the uuid is returned (default True)
Returns:
If only_uuid is True, then only the uuid of the username is returned.
If not, a dict is returned with the following keys: `name`, `uuid`,
`legacy` and `demo`.
"""
data = web.request('get', GET_UUID.format(name=username))

if data:
Expand All @@ -52,6 +81,20 @@ def get_uuid(username: str, only_uuid: bool = True) -> dict:
return data

def get_uuids(usernames: list, only_uuid: bool = True) -> list:
"""Get uuid of username
Note: Limited Endpoint
The Mojang API only allow 10 usernames maximum, if more than 10 usernames are
given to the function, multiple request will be made.
Args:
usernames (list): The list of username which you want the uuid of
only_uuid (bool): If True only the uuid is returned for each username (default True)
Returns:
If only_uuid is True, then a list of uuid is returned. If not, a list of dict is returned.
Each dict contains the following keys: `name`, `uuid`, `legacy` and `demo`.
"""
res = [None]*len(usernames)

for i in range(0, len(usernames), 10):
Expand All @@ -71,6 +114,14 @@ def get_uuids(usernames: list, only_uuid: bool = True) -> list:
return res

def get_profile(uuid: str) -> dict:
"""Get profile information by uuid
Args:
uuid (str): The uuid of the profile
Returns:
A dict with the following keys: `uuid`, `name`, `skins` and `capes`
"""
data = web.request('get', GET_PROFILE.format(uuid=uuid), exceptions=(PayloadError,))
if data:
res = {'name': None, 'uuid': None,'skins': [], 'capes': []}
Expand Down

0 comments on commit 1e6020f

Please sign in to comment.