Skip to content
This repository has been archived by the owner on May 31, 2024. It is now read-only.

Commit

Permalink
Update docs and fix utils
Browse files Browse the repository at this point in the history
  • Loading branch information
lazykern committed May 10, 2022
1 parent a6ea9fd commit 4a6ef80
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 10 deletions.
116 changes: 116 additions & 0 deletions docs/example.rst
Original file line number Diff line number Diff line change
@@ -1,2 +1,118 @@
:orphan:

.. currentmodule:: pymyku

Examples
========

This page is a collection of examples that demonstrate the use of pymyku.

Using Client
------------

Importing :class:`Client` from pymyku and initializing it with your credentials:

.. code-block:: python
from pymyku import Client
client = Client("USERNAME", "PASSWORD")
The initialization method of the :class:`Client` will automatically call
:meth:`Client.login` and :meth:`Client.initialize` methods to get the data required to work with the API.

Fetching
^^^^^^^^
The word :code:`fetch` for this module means getting a response from the API by sending a GET or POST request to the API.

The following examples show all methods of pymyku that fetch data from the APIs.

:meth:`Client.fetch_schedule`
"""""""""""""""""""""""""""""

.. code-block:: python
print(client.fetch_schedule())
.. code-block:: bash
API Responses
-------------

POST
^^^^

:attr:`url.LOGIN`
"""""""""""""""""
.. code-block:: json
{
"accesstoken": "x",
"renewtoken": "x",
"user": {
"loginName": "x",
"userType": "x",
"idCode": "x",
"titleTh": "x",
"titleEn": "x",
"firstNameTh": "x",
"firstNameEn": "x",
"middleNameTh": "x",
"middleNameEn": "x",
"lastNameTh": "x",
"lastNameEn": "x",
"avatar": "x",
"gender": "x",
"student": {
"loginName": "x",
"stdId": "x",
"stdCode": "x",
"titleTh": "x",
"titleEn": "x",
"firstNameTh": "x",
"middleNameTh": "x",
"lastNameTh": "x",
"firstNameEn": "x",
"middleNameEn": "x",
"lastNameEn": "x",
"copenId": "x",
"copenNameTh": "x",
"copenNameEn": "x",
"campusCode": "x",
"campusNameTh": "x",
"campusNameEn": "x",
"facultyCode": "x",
"facultyNameTh": "x",
"facultyNameEn": "x",
"departmentCode": "x",
"departmentNameTh": "x",
"departmentNameEn": "x",
"majorCode": "x",
"majorNameTh": "x",
"majorNameEn": "x",
"nationCode": "x",
"nationalityNameTh": "x",
"nationalityNameEn": "x",
"studentStatusCode": "x",
"studentStatusNameTh": "x",
"studentStatusNameEn": "x",
"studentTypeCode": "x",
"studentTypeNameTh": "x",
"studentTypeNameEn": "x",
"edulevelCode": "x",
"edulevelNameTh": "x",
"edulevelNameEn": "x",
"studentYear": "x",
"advisorId": "x",
"advisorNameTh": "x",
"advisorNameEn": "x",
"positionTh": "x",
"email": "x",
"mobileNo": "x"
},
"roleMenus": [{ "...": "..." }]
},
"cache": false
}
6 changes: 2 additions & 4 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ Getting started
Manuals
-------

.. toctree::
:maxdepth: 2

api
- :doc:`api`
- If you're looking for something specific, try the :ref:`index <genindex>` or :ref:`searching <search>`.

4 changes: 2 additions & 2 deletions pymyku/requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ def request_logout(access_token: Optional[str] = '',
Required parameters are missing.
'''

params = utils.gen_request_args_f(logout, **locals())
params = utils.gen_request_args_f(request_logout, **locals())

return r_get(**params)
return r_post(**params)


def get_schedule(access_token: Optional[str] = '',
Expand Down
8 changes: 4 additions & 4 deletions pymyku/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from . import constant, url
from .attribute import Schedule, Student, Token, User
from .attribute import FetchedResponses, Schedule, Student, Token, User
from .type import (Any, ClientType, Dict, Enum, EnumMeta, Optional, Response,
Union)

Expand Down Expand Up @@ -392,9 +392,9 @@ def gen_request_args_f(function: callable,

if kwargs.get('client'):
client = kwargs['client']
kwargs['login_response'] = client.get(attribute.FetchedResponses.LOGIN_RESPONSE)
kwargs['login_response'] = client.get(FetchedResponses.LOGIN_RESPONSE)
kwargs['schedule_response'] = client.get(
attribute.FetchedResponses.SCHEDULE_RESPONSE)
FetchedResponses.SCHEDULE_RESPONSE)

if kwargs.get('login_response'):
login_response = kwargs.get('login_response')
Expand Down Expand Up @@ -430,7 +430,7 @@ def gen_request_args_f(function: callable,

headers = gen_request_headers(kwargs.get('access_token'))

if name == 'logout':
if name == 'request_logout':

return {
'url': url.LOGOUT,
Expand Down

0 comments on commit 4a6ef80

Please sign in to comment.