diff --git a/README.md b/README.md
index faa9936..3566c34 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,6 @@
# WgLestaAPI
-Unofficial Python library that facilitates working with ** API Wargaming.net** and ** API Lesta Games** functionality via **Python**.
+Unofficial Python library that facilitates working with ** API Wargaming.net** and ** API Lesta Games** functionality via **Python**.
[![Downloads](https://static.pepy.tech/personalized-badge/wglestaapi?period=total&units=international_system&left_color=grey&right_color=blue&left_text=downloads)](https://pepy.tech/project/wglestaapi)
[![Downloads](https://static.pepy.tech/personalized-badge/wglestaapi?period=month&units=international_system&left_color=grey&right_color=blue&left_text=downloads/month)](https://pepy.tech/project/wglestaapi)
@@ -11,7 +11,9 @@ Unofficial Python library that facilitates working with **
+
+> By downloading this library you fully agree with all official documents **Lesta Games** and **Wargaming.net** about **Lesta Games** and **Wargaming.net** products. *The author of the library ([Alexander Podstrechnyy](https://github.com/tankalxat34)) is not responsible for your actions performed with the help of this program code.*
> [!NOTE]
> If you like this project please add it to favorite :star: \
@@ -31,89 +33,118 @@ pip install WgLestaAPI
* The presence of synchronous and asynchronous methods of working with the API;
* The ability to use any available methods of the official API through this single library;
* The ability to run a single `*.py` program in several different regions;
-* Built-in constants to designate all games and regions for ** API Wargaming.net** and ** API Lesta Games**;
+* Built-in constants to designate all games and regions for ** API Wargaming.net** and ** API Lesta Games**;
* One App class with all the necessary library methods.
## Quickstart
### 1. Get an `application_id`
-1. Choice your API provider: ** API Wargaming.net** or ** API Lesta Games**;
+1. Choice your API provider: ** API Wargaming.net** or ** API Lesta Games**;
2. Log in to the official API provider service;
3. Create a new application by clicking on the button **Add application** or use the existing;
4. Copy ID field from webpage;
-
+
+
+### 2. Make your first query to API by using dot notation
+
+To get started, you will need to initialize the applications using the received application ID from the official website of the API provider. You will also need to define the API region and the short name of the game that you want to start working with
+
+Next, you can use two approaches to application development - synchronous and asynchronous.
-### 2. Write a synchron variant of the "Hello world" example
+You can also use two approaches to making API requests. The first is to use dot notation to access the methods section and the method itself directly. The second way is to use the execute method. In both cases, the result of the execution will be the same..
+#### A synchron variant
```python
from WgLestaAPI.Application import App
from WgLestaAPI.Constants import REGION, GAMENAMES
import json
-wgApp = App("YOUR_APPLICATION_ID", REGION.EU)
+# init your app
+wgApp = App(
+ application_id = "YOUR_APPLICATION_ID",
+ region = REGION.EU,
+ game_shortname = GAMENAMES.SHORTNAMES.WOT
+)
+
+# make a query
+data = wgApp.account.info(account_id=563982544)
+# processing the response
+print(json.dumps(data, indent=2))
+```
-resp = wgApp.execute("account.info", GAMENAMES.SHORTNAMES.WOT, account_id=563982544)
-print(json.dumps(resp, indent=2))
+#### An asynchron variant
+```python
+from WgLestaAPI.Application import AsyncApp
+from WgLestaAPI.Constants import REGION, GAMENAMES
+import asyncio
+import json
-```
+# init your app
+wgApp = AsyncApp(
+ application_id = "YOUR_APPLICATION_ID",
+ region = REGION.EU,
+ game_shortname = GAMENAMES.SHORTNAMES.WOT
+)
-In the terminal you will see:
+async def getAccount(id: int):
+ return await wgApp.account.info(account_id=id)
-```json
-{
- "status": "ok",
- "meta": {
- "count": 1
- },
- "data": {
- "563982544": {
- // ...
- "nickname": "tankalxat34",
- "logout_at": 1597741881
- }
- }
-}
+# make a query
+data = asyncio.run(getAccount(563982544))
+# processing the response
+print(json.dumps(data, indent=2))
```
-### 3. Write an async variant of the "Hello world" example
+### 3. Make your query to API by using the `execute` method
+
+#### A synchron variant
```python
from WgLestaAPI.Application import App
from WgLestaAPI.Constants import REGION, GAMENAMES
import json
-import asyncio
-wgApp = App("YOUR_APPLICATION_ID", REGION.EU)
+# init your app
+wgApp = App(
+ application_id = "YOUR_APPLICATION_ID",
+ region = REGION.EU,
+ game_shortname = GAMENAMES.SHORTNAMES.WOT
+)
+
+# make a query
+data = wgApp.execute("account.info", account_id=563982544)
+# processing the response
+print(json.dumps(data, indent=2))
+```
-async def getMyAccount(myId: int):
- return await wgApp.asyncExecute("account.info", GAMENAMES.SHORTNAMES.WOT, account_id=myId)
+#### An asynchron variant
+```python
+from WgLestaAPI.Application import AsyncApp
+from WgLestaAPI.Constants import REGION, GAMENAMES
+import asyncio
+import json
-resp = asyncio.run(getMyAccount(myId=563982544))
-print(json.dumps(resp, indent=2))
-```
+# init your app
+wgApp = AsyncApp(
+ application_id = "YOUR_APPLICATION_ID",
+ region = REGION.EU,
+ game_shortname = GAMENAMES.SHORTNAMES.WOT
+)
-In the terminal you will see:
+async def getAccount(id: int):
+ return await wgApp.execute("account.info", account_id=id)
-```json
-{
- "status": "ok",
- "meta": {
- "count": 1
- },
- "data": {
- "563982544": {
- // ...
- "nickname": "tankalxat34",
- "logout_at": 1597741881
- }
- }
-}
+# make a query
+data = asyncio.run(getAccount(563982544))
+# processing the response
+print(json.dumps(data, indent=2))
```
-### 4. Get URL to login, logout and prolongate `access_token` actions into your application
+
+### 4. Get URL to `login`, `logout` and `prolongate` actions into your application
You can use the library to generate API links for user authorization in your application. This will allow your application to get an access_token, which can be passed as a parameter inside a request to any available API method
@@ -121,41 +152,30 @@ You can use the library to generate API links for user authorization in your app
from WgLestaAPI.Application import App
from WgLestaAPI.Constants import REGION, GAMENAMES
-wgApp = App("YOUR_APPLICATION_ID", REGION.EU)
+# init your app
+wgApp = App(
+ application_id = "YOUR_APPLICATION_ID",
+ region = REGION.EU,
+ game_shortname = GAMENAMES.SHORTNAMES.WOT
+)
-print(wgApp.login(redirect_uri="https://example.com/")) # url to your hosted web-application
-print(wgApp.logout())
-print(wgApp.prolongate())
+print(wgApp.urlLogin(redirect_uri="https://example.com/your-uri-here")) # url to your hosted web-application
+print(wgApp.urlLogout())
+print(wgApp.urlProlongate())
```
In the terminal you will see:
```
-https://api.worldoftanks.eu/wot/auth/login/?application_id=YOUR_APPLICATION_ID&redirect_uri=https://example.com/
+https://api.worldoftanks.eu/wot/auth/login/?application_id=YOUR_APPLICATION_ID&redirect_uri=https://example.com/your-uri-here
https://api.worldoftanks.eu/wot/auth/logout/?application_id=YOUR_APPLICATION_ID
https://api.worldoftanks.eu/wot/auth/prolongate/?application_id=YOUR_APPLICATION_ID
```
-### 5. Saving frequently called methods
-
-If you use any method very often, you can save its function to a variable. Then you can call the saved method as many times as you want without purposefully passing parameters inside each call.
-
-```python
-from WgLestaAPI.Application import App
-from WgLestaAPI.Constants import REGION, GAMENAMES
-
-wgApp = App("YOUR_APPLICATION_ID", REGION.EU)
-
-# method saving
-getMyAccount = wgApp.createMethod("account.info", GAMENAMES.SHORTNAMES.WOT, account_id=563982544)
-
-for i in range(3):
- print(i, getMyAccount())
-```
## Library functionality
-The library implements the basic functions of **API Lesta Games** and **API Wargaming.net**. All requests are made through your application, which you previously created on [ Lesta Games](https://developers.lesta.ru/applications/) or on [ Wargaming.net](https://developers.wargaming.net/applications/). Some features are listed below:
+The library implements the basic functions of **API Lesta Games** and **API Wargaming.net**. All requests are made through your application, which you previously created on [ Lesta Games](https://developers.lesta.ru/applications/) or on [ Wargaming.net](https://developers.wargaming.net/applications/). Some features are listed below:
- Getting information about the player, his equipment and medals.
- Obtaining information about the clan.
- Getting information about vehicles.
@@ -163,7 +183,7 @@ The library implements the basic functions of **API Lesta Games** and **API Warg
## Copyright Notice
-
+
- 2024 © Alexander Podstrechnyy.
- [tankalxat34@gmail.com](mailto:tankalxat34@gmail.com?subject=lestagamesapi)
diff --git a/WgLestaAPI/Application.py b/WgLestaAPI/Application.py
index 24a72e1..591e681 100644
--- a/WgLestaAPI/Application.py
+++ b/WgLestaAPI/Application.py
@@ -11,37 +11,32 @@
from . import Exceptions
-class App:
+class _AppConstructor:
"""
- A class to interact with the game APIs.
+ DO NOT USE THE RAW `_AppConstructor` TO CREATE A REAL APPLICATION. USE `App` OR `AsyncApp` TO CREATE APP
+ A class to interact with the game APIs.
+
Attributes:
application_id (str): The application ID for API access.
region (Constants.REGION): The region for the API access.
http (urllib3.PoolManager): The HTTP manager for synchronous requests.
-
- Methods:
- __str__(): Returns a string representation of the App instance.
- _getApiUrl(api_method, game_shortname, **kwargs): Constructs the API URL.
- authUrl(**kwargs): Generates the authentication URL.
- execute(api_method, game_shortname, type_request="GET", **kwargs): Executes a synchronous API request.
- asyncExecute(api_method, game_shortname, type_request="GET", **kwargs): Executes an asynchronous API request.
- createMethod(api_method, game_shortname, execution="sync", type_request="GET", **kwargs): Creates a constant method for API request
"""
-
- def __init__(self, application_id: str, region: Constants.REGION) -> None:
- """
- Initializes the App instance with application ID and region.
-
- Args:
- application_id (str): The application ID for API access.
- region (Constants.REGION): The region for the API access.
- """
+ def __init__(self,
+ application_id: str,
+ region: Constants.REGION,
+ game_shortname: Constants.GAMENAMES.SHORTNAMES,
+ method_execution: Constants.METHODEXECUTION = Constants.METHODEXECUTION.SYNC
+ ) -> None:
self.application_id = application_id
self.region = region
+ self.game_shortname = game_shortname
+ self.method_execution = method_execution
+ self.company_name = (Constants.APIHOLDERS.LESTA if self.region in Constants.REGION.CIS else Constants.APIHOLDERS.WG).split('.')[0].capitalize()
+ """May be equal `Wargaming` or `Lesta`"""
self.http = urllib3.PoolManager()
-
+
def __str__(self) -> str:
"""
Returns a string representation of the App instance.
@@ -49,28 +44,11 @@ def __str__(self) -> str:
Returns:
str: A string representing the App instance.
"""
- return f"{(Constants.APIHOLDERS.LESTA if self.region in Constants.REGION.CIS else Constants.APIHOLDERS.WG).split('.')[0].capitalize()}App('{self.application_id[:4]}...{self.application_id[-4:]}')"
-
- def _getApiUrl(self, api_method: str, game_shortname: Constants.GAMENAMES.SHORTNAMES, **kwargs) -> str:
- """
- Constructs the API URL.
-
- Args:
- api_method (str): The API method to be called.
- game_shortname (Constants.GAMENAMES.SHORTNAMES): The short name of the game.
- **kwargs: Additional query parameters.
-
- Returns:
- str: The constructed API URL.
-
- Raises:
- Exceptions.RegionDoesNotExisting: If the region does not exist for the specified game.
- """
- return Utils.constructUrl(self.application_id, self.region, api_method, game_shortname, **kwargs)
+ return f"{self.company_name}App('{Utils.maskString(self.application_id)}')"
- def login(self, **kwargs: dict[str, Any]) -> str:
+ def urlLogin(self, **kwargs: dict[str, Any]) -> str:
"""
- Generates the authentication URL.
+ Returns the authentication URL.
Args:
**kwargs: Additional query parameters, such as `display`, `expires_at`, `nofollow`, `redirect_uri` or other if needed
@@ -78,126 +56,115 @@ def login(self, **kwargs: dict[str, Any]) -> str:
Returns:
str: The authentication URL.
"""
- api_url = self._getApiUrl(api_method="auth.login", game_shortname=Constants.GAMENAMES.SHORTNAMES.TANKI if self.region in Constants.REGION.CIS else Constants.GAMENAMES.SHORTNAMES.WOT, **kwargs)
+ api_url = Utils.constructUrl(application_id=self.application_id, region=self.region, api_method="auth.login", game_shortname=Constants.GAMENAMES.SHORTNAMES.TANKI if self.region in Constants.REGION.CIS else Constants.GAMENAMES.SHORTNAMES.WOT, **kwargs)
return api_url
- def logout(self, **kwargs: dict[str, Any]) -> str:
+ def urlLogout(self, **kwargs: dict[str, Any]) -> str:
"""
- Generates the log out URL.
+ Returns the log out URL.
Args:
**kwargs: Additional query parameters, such as `access_token` or other if needed
Returns:
- str: The authentication URL.
+ str: The logout URL.
"""
- api_url = self._getApiUrl(api_method="auth.logout", game_shortname=Constants.GAMENAMES.SHORTNAMES.TANKI if self.region in Constants.REGION.CIS else Constants.GAMENAMES.SHORTNAMES.WOT, **kwargs)
+ api_url = Utils.constructUrl(application_id=self.application_id, region=self.region, api_method="auth.logout", game_shortname=Constants.GAMENAMES.SHORTNAMES.TANKI if self.region in Constants.REGION.CIS else Constants.GAMENAMES.SHORTNAMES.WOT, **kwargs)
return api_url
- def prolongate(self, **kwargs: dict[str, Any]) -> str:
+ def urlProlongate(self, **kwargs: dict[str, Any]) -> str:
"""
- Generates the URL to prolongate `access_token`.
+ Returns the URL to prolongate `access_token`.
Args:
**kwargs: Additional query parameters, such as `access_token`, `expires_at` or other if needed
Returns:
- str: The authentication URL.
+ str: The the URL to prolongate existing `access_token`.
"""
- api_url = self._getApiUrl(api_method="auth.prolongate", game_shortname=Constants.GAMENAMES.SHORTNAMES.TANKI if self.region in Constants.REGION.CIS else Constants.GAMENAMES.SHORTNAMES.WOT, **kwargs)
+ api_url = Utils.constructUrl(application_id=self.application_id, region=self.region, api_method="auth.prolongate", game_shortname=Constants.GAMENAMES.SHORTNAMES.TANKI if self.region in Constants.REGION.CIS else Constants.GAMENAMES.SHORTNAMES.WOT, **kwargs)
return api_url
-
- @Utils.validateQuery
- def execute(
- self,
- api_method: str,
- game_shortname: Constants.GAMENAMES.SHORTNAMES,
- type_request: Constants.TYPEREQUESTS = "GET",
- **kwargs: dict[str, Any]
- ) -> dict | urllib3.BaseHTTPResponse:
+
+ def execute(self) -> dict | Any:
"""
- Executes a synchronous API request.
+ Executes an API request.
Args:
api_method (str): The API method to be called.
- game_shortname (Constants.GAMENAMES.SHORTNAMES): The short name of the game.
type_request (Constants.TYPEREQUESTS, optional): The type of HTTP request (default is "GET").
**kwargs: Additional query parameters.
- Returns:
- dict | urllib3.BaseHTTPResponse: The API response, either as a dictionary or raw HTTP response.
"""
- api_url = self._getApiUrl(api_method, game_shortname, **kwargs)
- res = self.http.request(type_request, api_url.lower())
- try:
- return json.loads(res.data)
- except Exception:
- return res
-
- @Utils.validateQuery
- async def asyncExecute(
- self,
- api_method: str,
- game_shortname: Constants.GAMENAMES.SHORTNAMES,
- type_request: Constants.TYPEREQUESTS = "GET",
- **kwargs: dict[str, Any]
- ) -> dict | aiohttp.ClientResponse:
+ pass
+
+
+class App(_AppConstructor):
+ def __init__(self, application_id: str, region: Constants.REGION, game_shortname: Constants.GAMENAMES.SHORTNAMES) -> None:
"""
- Executes an asynchronous API request.
+ Initializes the synchronous App instance with application ID and region.
Args:
- api_method (str): The API method to be called.
+ application_id (str): The application ID for API access.
+ region (Constants.REGION): The region for the API access.
game_shortname (Constants.GAMENAMES.SHORTNAMES): The short name of the game.
- type_request (Constants.TYPEREQUESTS, optional): The type of HTTP request (default is "GET").
- **kwargs: Additional query parameters.
-
- Returns:
- dict | aiohttp.ClientResponse: The API response, either as a dictionary or raw HTTP response.
"""
- api_url = self._getApiUrl(api_method, game_shortname, **kwargs)
- async with aiohttp.ClientSession() as session:
- async with session.request(type_request, api_url.lower()) as response:
- try:
- return await response.json()
- except Exception:
- return response
-
- def createMethod(
+ self.method_execution = Constants.METHODEXECUTION.SYNC
+ super().__init__(application_id, region, game_shortname, self.method_execution)
+
+ def __getattr__(self, method_block: str, *args, **kwargs) -> Utils.MethodBlock:
+ return Utils.MethodBlock(
+ app_instance=self,
+ method_block=method_block,
+ *args,
+ **kwargs
+ )
+
+ def execute(
self,
api_method: str,
- game_shortname: Constants.GAMENAMES.SHORTNAMES,
- execution: Constants.METHODEXECUTION = Constants.METHODEXECUTION.SYNC,
type_request: Constants.TYPEREQUESTS = "GET",
**kwargs: dict[str, Any]
- ) -> Callable[..., dict | urllib3.BaseHTTPResponse | aiohttp.ClientResponse]:
- """Creates a constant method for API request
-
- If you use any method very often, you can save its function to a variable. Then you can call the saved method as many times as you want without purposefully passing parameters inside each call.
+ ) -> dict | urllib3.BaseHTTPResponse:
+ return Utils.methodSyncExecute(
+ app_instance=self,
+ api_method=api_method,
+ game_shortname=self.game_shortname,
+ type_request=type_request,
+ **kwargs
+ )
- Example:
- ```python
- getMyAccount = wgApp.createMethod("account.info", GAMENAMES.SHORTNAMES.WOT, account_id=563982544)
-
- for i in range(3):
- print(getMyAccount())
- ```
+
+class AsyncApp(_AppConstructor):
+ def __init__(self, application_id: str, region: Constants.REGION, game_shortname: Constants.GAMENAMES.SHORTNAMES) -> None:
+ """
+ Initializes the asynchronous App instance with application ID and region.
Args:
- api_method (str): The API method to be called.
+ application_id (str): The application ID for API access.
+ region (Constants.REGION): The region for the API access.
game_shortname (Constants.GAMENAMES.SHORTNAMES): The short name of the game.
- execution (Constants.METHODEXECUTION, optional): Type of method execution (`sync` or `async`). Defaults to Constants.METHODEXECUTION.SYNC (`sync`).
- type_request (Constants.TYPEREQUESTS, optional): The type of HTTP request (default is "GET").
- **kwargs: Additional query parameters.
+ """
+ self.method_execution = Constants.METHODEXECUTION.ASYNC
+ super().__init__(application_id, region, game_shortname, self.method_execution)
- Raises:
- ValueError: if you choose invalid execution type for method
+ def __getattr__(self, method_block: str, *args, **kwargs) -> Utils.AsyncMethodBlock:
+ return Utils.AsyncMethodBlock(
+ app_instance=self,
+ method_block=method_block,
+ *args,
+ **kwargs
+ )
- Returns:
- A function with specified parameters that can be called as many times as desired
- """
- if execution == Constants.METHODEXECUTION.SYNC:
- return lambda self=self: self.execute(api_method, game_shortname, type_request, **kwargs)
- elif execution == Constants.METHODEXECUTION.ASYNC:
- return lambda self=self: self.asyncExecute(api_method, game_shortname, type_request, **kwargs)
- else:
- raise ValueError(f"Invalid value for type of method execution: '{execution}'")
\ No newline at end of file
+ async def execute(
+ self,
+ api_method: str,
+ type_request: Constants.TYPEREQUESTS = "GET",
+ **kwargs: dict[str, Any]
+ ) -> dict | aiohttp.ClientResponse:
+ return await Utils.methodAsyncExecute(
+ app_instance=self,
+ api_method=api_method,
+ game_shortname=self.game_shortname,
+ type_request=type_request,
+ **kwargs
+ )
diff --git a/WgLestaAPI/Utils.py b/WgLestaAPI/Utils.py
index d5f0d49..fba8b9e 100644
--- a/WgLestaAPI/Utils.py
+++ b/WgLestaAPI/Utils.py
@@ -1,14 +1,22 @@
-from typing import Callable
+from typing import Any, Callable
+import aiohttp
+import urllib3
+import json
from . import Constants
from . import Exceptions
+def maskString(s: str) -> str:
+ l = int(len(s) // 6)
+ return f'{s[:l]}...{s[-l:]}'
+
+
def validateQuery(f: Callable):
def wrapper(*args, **kwargs):
- appInstance = args[0]
- region = appInstance.region
- game_shortname = kwargs.get("game_shortname") if kwargs.get("game_shortname") else args[2]
+ app_instance = kwargs.get("app_instance") if kwargs.get("app_instance") else args[0]
+ region = app_instance.region
+ game_shortname = app_instance.game_shortname
api_method: str = kwargs.get("api_method") if kwargs.get("api_method") else args[1]
if game_shortname not in Constants.GAMENAMES.SHORTNAMES.ALL:
@@ -54,3 +62,117 @@ def constructUrl(application_id: str, region: str, api_method: str, game_shortna
) + f"{method_block}/{method_name}/{query_url}"
+@validateQuery
+def methodSyncExecute(
+ app_instance: Any,
+ api_method: str,
+ game_shortname: Constants.GAMENAMES.SHORTNAMES,
+ type_request: Constants.TYPEREQUESTS = "GET",
+ **kwargs: dict[str, Any]
+ ) -> dict | urllib3.BaseHTTPResponse:
+ api_url = constructUrl(app_instance.application_id, app_instance.region, api_method, game_shortname, **kwargs)
+ res = app_instance.http.request(type_request, api_url.lower())
+ try:
+ return json.loads(res.data)
+ except Exception:
+ return res
+
+
+@validateQuery
+async def methodAsyncExecute(
+ app_instance: Any,
+ api_method: str,
+ game_shortname: Constants.GAMENAMES.SHORTNAMES,
+ type_request: Constants.TYPEREQUESTS = "GET",
+ **kwargs: dict[str, Any]
+ ) -> dict | aiohttp.ClientResponse:
+ api_url = constructUrl(app_instance.application_id, app_instance.region, api_method, game_shortname, **kwargs)
+ async with aiohttp.ClientSession() as session:
+ async with session.request(type_request, api_url.lower()) as response:
+ try:
+ return await response.json()
+ except Exception:
+ return response
+
+
+class MethodBlock:
+ def __init__(self,
+ app_instance: Any,
+ method_block: str
+ ) -> None:
+ self.app_instance = app_instance
+ self.method_block = method_block
+
+ def __str__(self) -> str:
+ return f"MethodBlock('{self.method_block}')"
+
+ def __getattr__(self, method_name: str):
+ """Applies dot-notation for methods like `appInstance.methodBlock.methodName(*args, **kwargs)`
+
+ Args:
+ method_name (str): Method name from the official documentation
+ """
+ def dynamicMethod(
+ type_request: Constants.TYPEREQUESTS = "GET",
+ **kwargs: Any
+ ) -> dict | urllib3.BaseHTTPResponse:
+ """
+ Executes selected method from the official API.
+
+ Args:
+ type_request (Constants.TYPEREQUESTS, optional): The type of HTTP request (default is "GET").
+ **kwargs (Any): Additional query parameters.
+
+ Returns:
+ dict | urllib3.BaseHTTPResponse: The API response, either as a dictionary or raw HTTP response.
+ """
+ return methodSyncExecute(
+ app_instance=self.app_instance,
+ api_method=f'{self.method_block}.{method_name}',
+ game_shortname=self.app_instance.game_shortname,
+ type_request=type_request,
+ **kwargs
+ )
+ return dynamicMethod
+
+
+class AsyncMethodBlock:
+ def __init__(self,
+ app_instance: Any,
+ method_block: str
+ ) -> None:
+ self.app_instance = app_instance
+ self.method_block = method_block
+
+ def __str__(self) -> str:
+ return f"AsyncMethodBlock('{self.method_block}')"
+
+ def __getattr__(self, method_name: str):
+ """Applies dot-notation for methods like `appInstance.methodBlock.methodName(*args, **kwargs)`
+
+ Args:
+ method_name (str): Method name from the official documentation
+ """
+ async def dynamicMethod(
+ type_request: Constants.TYPEREQUESTS = "GET",
+ **kwargs: Any
+ ) -> dict | aiohttp.ClientResponse:
+ """
+ Executes selected method from the official API.
+
+ Args:
+ type_request (Constants.TYPEREQUESTS, optional): The type of HTTP request (default is "GET").
+ **kwargs (Any): Additional query parameters.
+
+ Returns:
+ dict | aiohttp.ClientResponse: The API response, either as a dictionary or raw HTTP response.
+ """
+ return await methodAsyncExecute(
+ app_instance=self.app_instance,
+ api_method=f'{self.method_block}.{method_name}',
+ game_shortname=self.app_instance.game_shortname,
+ type_request=type_request,
+ **kwargs
+ )
+ return dynamicMethod
+
diff --git a/WgLestaAPI/__init__.py b/WgLestaAPI/__init__.py
index a974ac3..5a50d95 100644
--- a/WgLestaAPI/__init__.py
+++ b/WgLestaAPI/__init__.py
@@ -32,6 +32,8 @@
## Quickstart
+More examples you can find on the [GitHub](https://github.com/tankalxat34/WgLestaAPI)
+
### 1. Get an `application_id`
1. Choice your API provider;
2. Log in to the official API provider service;
@@ -45,43 +47,17 @@
from WgLestaAPI.Constants import REGION, GAMENAMES
import json
-wgApp = App("YOUR_APPLICATION_ID", REGION.EU)
-
-resp = wgApp.execute("account.info", GAMENAMES.SHORTNAMES.WOT, account_id=563982544)
-print(json.dumps(resp, indent=2))
-
-```
-
-### 3. Write an async variant of the "Hello world" example
-
-```python
-from WgLestaAPI.Application import App
-from WgLestaAPI.Constants import REGION, GAMENAMES
-import json
-import asyncio
-
-wgApp = App("YOUR_APPLICATION_ID", REGION.EU)
-
-async def getMyAccount(myId: int):
- return await wgApp.asyncExecute("account.info", GAMENAMES.SHORTNAMES.WOT, account_id=myId)
-
-resp = asyncio.run(getMyAccount(myId=563982544))
-print(json.dumps(resp, indent=2))
-```
-
-### 4. Get URL to login, logout and prolongate `access_token` actions into your application
-
-You can use the library to generate API links for user authorization in your application. This will allow your application to get an access_token, which can be passed as a parameter inside a request to any available API method
-
-```python
-from WgLestaAPI.Application import App
-from WgLestaAPI.Constants import REGION, GAMENAMES
-
-wgApp = App("YOUR_APPLICATION_ID", REGION.EU)
-
-print(wgApp.login(redirect_uri="https://example.com/")) # url to your hosted web-application
-print(wgApp.logout())
-print(wgApp.prolongate())
+# init your app
+wgApp = App(
+ application_id = "YOUR_APPLICATION_ID",
+ region = REGION.EU,
+ game_shortname = GAMENAMES.SHORTNAMES.WOT
+)
+
+# make a query
+data = wgApp.account.info(account_id=563982544)
+# processing the response
+print(json.dumps(data, indent=2))
```
## Copyright Notice
diff --git a/pyproject.toml b/pyproject.toml
index 46cdd1c..9f39dff 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -1,6 +1,6 @@
[tool.poetry]
name = "WgLestaAPI"
-version = "1.0.1"
+version = "1.1.0"
description = "Unofficial Python library that implements the Wargaming.net API and Lesta Games API functionality"
authors = ["Alexander Podstrechnyy "]
repository = "https://github.com/tankalxat34/WgLestaAPI"