diff --git a/docs/example.rst b/docs/example.rst index bac945d..25fef4f 100644 --- a/docs/example.rst +++ b/docs/example.rst @@ -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 + } + diff --git a/docs/index.rst b/docs/index.rst index 0b1bcc5..bbefcca 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -31,8 +31,6 @@ Getting started Manuals ------- -.. toctree:: - :maxdepth: 2 - - api +- :doc:`api` +- If you're looking for something specific, try the :ref:`index ` or :ref:`searching `. diff --git a/pymyku/requests.py b/pymyku/requests.py index 4b7c3f7..afbf534 100644 --- a/pymyku/requests.py +++ b/pymyku/requests.py @@ -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] = '', diff --git a/pymyku/utils.py b/pymyku/utils.py index 8cbe510..6f0e145 100644 --- a/pymyku/utils.py +++ b/pymyku/utils.py @@ -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) @@ -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') @@ -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,