Skip to content

Commit

Permalink
Documentation for mojang.main
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucino772 committed Mar 25, 2021
1 parent 6241513 commit 26a39bd
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 24 deletions.
15 changes: 15 additions & 0 deletions docs/PyMojang/main.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Mojang - Main
===

::: mojang.main
handler: python
selection:
members:
- api_status
- name_history
- get_uuid
- get_uuids
- get_username
rendering:
show_root_heading: true
show_source: true
10 changes: 5 additions & 5 deletions docs/basic.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ PyMojang - Basic Usage

## API Status

To get the status of each Mojang services, use the function [`api_status`]()
To get the status of each Mojang services, use the function `api_status`

```python
import mojang
Expand Down Expand Up @@ -38,7 +38,7 @@ green

## UUID by Username

To get the UUID of a username, use the function [`get_uuid`]()
To get the UUID of a username, use the function `get_uuid`

```python
import mojang
Expand All @@ -53,7 +53,7 @@ uuid = mojang.get_uuid('Notch')

## UUIDs by Usernames

To get the UUID for multiple usernames, use the function [`get_uuids`]()
To get the UUID for multiple usernames, use the function `get_uuids`

!!! note
The Mojang API endpoint only allow 10 usernames, if more than 10 usernames are given to the function, multiple request will be made.
Expand All @@ -70,7 +70,7 @@ uuids = mojang.get_uuids(['Notch','jeb_'])

## Username by UUID

To get the username for a UUID, use the function [`get_username`]()
To get the username for a UUID, use the function `get_username`

```python
import mojang
Expand All @@ -84,7 +84,7 @@ Notch

## Name History

To get the name history for a specific user, use the function [`name_history`]()
To get the name history for a specific user, use the function `name_history`

```python
import mojang
Expand Down
20 changes: 11 additions & 9 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,19 @@ extra_css:

nav:
- Quisk Start:
- 'Installation': 'index.md'
- 'About': 'index.md'
- 'Basic Usage': 'basic.md'

- Advanced:
- 'Profile and Authentication': 'advanced.md'

- PyMojang:
- 'mojang.api.auth.yggdrasil': 'PyMojang/yggdrasil.md'
- 'mojang.api.auth.security': 'PyMojang/security.md'
- 'mojang.api.base': 'PyMojang/base.md'
- 'mojang.api.session': 'PyMojang/session.md'
- 'mojang.profile.UserProfile': 'PyMojang/UserProfile.md'
- 'mojang.session.UserSession': 'PyMojang/UserSession.md'
- 'Exceptions': 'PyMojang/exceptions.md'
- Reference:
- mojang:
- 'mojang.main': 'PyMojang/main.md'
- 'mojang.api.base': 'PyMojang/base.md'
- 'mojang.api.session': 'PyMojang/session.md'
- 'mojang.api.auth.yggdrasil': 'PyMojang/yggdrasil.md'
- 'mojang.api.auth.security': 'PyMojang/security.md'
- 'mojang.profile.UserProfile': 'PyMojang/UserProfile.md'
- 'mojang.session.UserSession': 'PyMojang/UserSession.md'
- 'Exceptions': 'PyMojang/exceptions.md'
8 changes: 4 additions & 4 deletions mojang/api/auth/yggdrasil.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from ..urls import AUTHENTICATE, INVALIDATE, REFRESH, SIGNOUT, VALIDATE


def authenticate_user(username: str, password: str, client_token=None) -> dict:
def authenticate_user(username: str, password: str, client_token: str = None) -> dict:
"""Authenticate user with name and password
Args:
Expand Down Expand Up @@ -49,7 +49,7 @@ def refresh_token(access_token: str, client_token: str) -> dict:
Args:
access_token (str): The access token to refresh
clien_token (str): The client token used to generate the access token
client_token (str): The client token used to generate the access token
Returns:
A dict with the following keys: `access_token`, `client_token`, `uuid`, `name`,
Expand Down Expand Up @@ -80,7 +80,7 @@ def validate_token(access_token: str, client_token: str):
Args:
access_token (str): The access token to validate
clien_token (str): The client token used to generate the access token
client_token (str): The client token used to generate the access token
Raises:
TokenError: If client token is not the one used to generate the access token
Expand Down Expand Up @@ -116,7 +116,7 @@ def invalidate_token(access_token: str, client_token: str):
Args:
access_token (str): The access token to invalidate
clien_token (str): The client token used to generate the access token
client_token (str): The client token used to generate the access token
Raises:
TokenError: If client token is not the one used to generate the access token
Expand Down
2 changes: 1 addition & 1 deletion mojang/api/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ 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
"""Get uuid of multiple username
Note: Limited Endpoint
The Mojang API only allow 10 usernames maximum, if more than 10 usernames are
Expand Down
58 changes: 53 additions & 5 deletions mojang/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,74 @@
api_status = base.api_status
name_history = base.name_history

def get_uuid(username: str):
def get_uuid(username: str) -> str:
"""Get uuid of username
Args:
username (str): The username which you want the uuid of
Returns:
The uuid of the username
"""
return base.get_uuid(username)

def get_uuids(usernames: list):
def get_uuids(usernames: list) -> list:
"""Get uuid of multiple 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
Returns:
A list of uuid
"""
return base.get_uuids(usernames)

def get_username(uuid: str):
def get_username(uuid: str) -> str:
"""Get the username of a uuid
Args:
uuid (str): The uuid you want the username of
Returns:
The username of the uuid
"""
profile = base.get_profile(uuid)
if profile:
return profile['name']


# Connect
def connect(username: str, password: str, client_token=None):
def connect(username: str, password: str, client_token: str = None) -> 'UserSession':
"""Connect a user with name and password
Args:
username (str): The username or email if account is not legacy
password (str): The user password
client_token (str, optional): The client token to use in the authentication (default to None)
Returns:
A `UserSession` object
"""
auth_data = yggdrasil.authenticate_user(username, password, client_token=client_token)
return UserSession(auth_data['access_token'], auth_data['client_token'])


# Complete profile
def user(username: str = None, uuid: str = None):
def user(username: str = None, uuid: str = None) -> 'UserProfile':
"""Fetch the complete profile by `uuid` or `username`. If both are given
the `username` is used
Args:
username (str, optional): The username to fetch the profile for
uuid (str, optional): The uuid to fetch the profile for
Returns:
A UserProfile object
"""
if username is not None:
user_data = base.get_uuid(username, only_uuid=False)
if user_data:
Expand Down

0 comments on commit 26a39bd

Please sign in to comment.