-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Updated docs for the __init__.py - Added the ability to execute queries using dot notation - Synchronous and asynchronous methods of operation are now separated into two types of applications - The short name for the game is now set during application initialization - Methods for getting authorization related url have been changed
- Loading branch information
1 parent
3ef5305
commit 8f27086
Showing
5 changed files
with
320 additions
and
235 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
# WgLestaAPI | ||
|
||
Unofficial Python library that facilitates working with **<a href="https://developers.wargaming.net"><img src="docs/icons/wg.ico" width=15px> API Wargaming.net</a>** and **<a href="https://developers.lesta.ru"><img src="docs/icons/lesta.ico" width=15px> API Lesta Games</a>** functionality via **Python**. | ||
Unofficial Python library that facilitates working with **<a href="https://developers.wargaming.net"><img src="https://raw.githubusercontent.com/tankalxat34/WgLestaAPI/main/docs/icons/wg.ico" width=15px> API Wargaming.net</a>** and **<a href="https://developers.lesta.ru"><img src="https://raw.githubusercontent.com/tankalxat34/WgLestaAPI/main/docs/icons/lesta.ico" width=15px> API Lesta Games</a>** 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 **<a href="https://devel | |
[![](https://img.shields.io/pypi/wheel/wglestaapi)](https://pypi.org/project/wglestaapi) | ||
[![GitHub Repo stars](https://img.shields.io/github/stars/tankalxat34/wglestaapi?style=social)](https://github.com/tankalxat34/wglestaapi) | ||
|
||
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 Podstrechny](https://github.com/tankalxat34)) is not responsible for your actions performed with the help of this program code.* | ||
<a href="https://developers.lesta.ru/"><img src="https://raw.githubusercontent.com/tankalxat34/WgLestaAPI/main/docs/icons/lesta_logo.png" width="178px" style="margin: 20px;"></a> <a href="https://developers.wargaming.net/"><img src="https://raw.githubusercontent.com/tankalxat34/WgLestaAPI/main/docs/icons/wg_logo.png" width="150px" style="margin: 20px;"></a> | ||
|
||
> 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,139 +33,157 @@ 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 **<a href="https://developers.wargaming.net"><img src="docs/icons/wg.ico" width=15px> API Wargaming.net</a>** and **<a href="https://developers.lesta.ru"><img src="docs/icons/lesta.ico" width=15px> API Lesta Games</a>**; | ||
* Built-in constants to designate all games and regions for **<a href="https://developers.wargaming.net"><img src="https://raw.githubusercontent.com/tankalxat34/WgLestaAPI/main/docs/icons/wg.ico" width=15px> API Wargaming.net</a>** and **<a href="https://developers.lesta.ru"><img src="https://raw.githubusercontent.com/tankalxat34/WgLestaAPI/main/docs/icons/lesta.ico" width=15px> API Lesta Games</a>**; | ||
* One App class with all the necessary library methods. | ||
|
||
## Quickstart | ||
|
||
### 1. Get an `application_id` | ||
1. Choice your API provider: **<a href="https://developers.wargaming.net"><img src="docs/icons/wg.ico" width=15px> API Wargaming.net</a>** or **<a href="https://developers.lesta.ru"><img src="docs/icons/lesta.ico" width=15px> API Lesta Games</a>**; | ||
1. Choice your API provider: **<a href="https://developers.wargaming.net"><img src="https://raw.githubusercontent.com/tankalxat34/WgLestaAPI/main/docs/icons/wg.ico" width=15px> API Wargaming.net</a>** or **<a href="https://developers.lesta.ru"><img src="https://raw.githubusercontent.com/tankalxat34/WgLestaAPI/main/docs/icons/lesta.ico" width=15px> API Lesta Games</a>**; | ||
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; | ||
|
||
|
||
<img src="docs/picture1.png" width=900px> | ||
<img src="https://raw.githubusercontent.com/tankalxat34/WgLestaAPI/main/docs/picture1.png" width=900px> | ||
|
||
### 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 | ||
|
||
```python | ||
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 [<img src="docs/icons/lesta.ico" width=14px> Lesta Games](https://developers.lesta.ru/applications/) or on [<img src="docs/icons/wg.ico" width=14px> 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 [<img src="https://raw.githubusercontent.com/tankalxat34/WgLestaAPI/main/docs/icons/lesta.ico" width=14px> Lesta Games](https://developers.lesta.ru/applications/) or on [<img src="https://raw.githubusercontent.com/tankalxat34/WgLestaAPI/main/docs/icons/wg.ico" width=14px> 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. | ||
- *And other methods.* | ||
|
||
## Copyright Notice | ||
|
||
<a href="https://developers.lesta.ru/"><img src="docs/icons/lesta_logo.png" width="178px" style="margin: 20px;"></a> <a href="https://developers.wargaming.net/"><img src="docs/icons/wg_logo.png" width="150px" style="margin: 20px;"></a> | ||
<a href="https://developers.lesta.ru/"><img src="https://raw.githubusercontent.com/tankalxat34/WgLestaAPI/main/docs/icons/lesta_logo.png" width="178px" style="margin: 20px;"></a> <a href="https://developers.wargaming.net/"><img src="https://raw.githubusercontent.com/tankalxat34/WgLestaAPI/main/docs/icons/wg_logo.png" width="150px" style="margin: 20px;"></a> | ||
|
||
- 2024 © Alexander Podstrechnyy. | ||
- [[email protected]](mailto:[email protected]?subject=lestagamesapi) | ||
|
Oops, something went wrong.