Skip to content

Commit

Permalink
Merge pull request #17 from frissyn/async
Browse files Browse the repository at this point in the history
v0.4.0
  • Loading branch information
frissyn authored Mar 18, 2021
2 parents d4e1921 + 15907d9 commit 2395407
Show file tree
Hide file tree
Showing 4 changed files with 219 additions and 81 deletions.
86 changes: 45 additions & 41 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,69 +9,73 @@

`valorant.py` is an unofficial API wrapper for Riot Games' Valorant API endpoints. It's modern, easy to use, feature-rich, and intuitive! Implemented with object oriented designs and explicit reloads to prevent `429`s, valorant.py is the best Valorant API wrapper out there!

**Update Notice:**
## Updates

Riot recently released a new endpoint along Episode 2: Leaderboards! Leaderboards in `valorant.py` support pagination and attribute finding. Take a look at the following snippet:
Most recent version: `0.4.0`

```python
import valorant
Changes:
+ Added `AsyncClient`
+ Added `asyncio.run` to namespace
+ Updated some docstrings and type-hinting

KEY = "RGAPI-Key-Goes-Here"
client = valorant.Client(kEY)
## Installation

page1 = client.get_leaderboard(size=25, page=0)
page2 = client.get_leaderboard(size=25, page=1)
|Manager|Command|
|:-:|:--|
|PIP|`pip install valorant`|
|Poetry|`python -m poetry add valorant`|
|Easy Install|`easy_install valorant`|

print(page1.players.find(3, "leaderboardRank"))
print(page2.players.find("haley", "gameName"))
```
## Usage

# Overview
Quickstart:

### Installation
```py
import valorant

|Manager |Command |
|:----------------|:---------------------------------|
|**pip** |`pip install valorant` |
|**poetry** |`python -m poetry add valorant` |
|**easy_install** |`easy_install valorant` |
KEY = "RGAPI-Key-Here"
client = valorant.Client(KEY)

agents = client.get_characters()

### Usage
for agent in agents:
print(agent.name)
```

Quickstart Guide:
```python
Asynchronous Client:

```py
import valorant

KEY = "RGAPI-Key-Goes-Here"
client = valorant.Client(KEY, locale=None)
KEY = "RGAPI-Key-Here"
client = valorant.AsyncClient(KEY)

maps = client.get_maps()
agents = client.get_characters()
async def _main():
agents = await client.get_characters()

print(agents.get("Viper"))
print(maps.get("Ascent"))
```
for agent in agents:
print(agent.name)

### Documentation
valorant.run(_main())
```

[**valorant.py Documentation**](https://github.com/frissyn/valorant.py/tree/master/docs)
## Documentation

### Contributing
You can find all of `valorant.py`'s documentation [`here`](https://github.com/frissyn/valorant.py/tree/master/docs). I plan on generating package docs with Sphinx eventually...

Bug reports, additional endopint coverage, and other fun stuff is always welcome in [issues](https://github.com/frissyn/valorant.py/issues)!
## Contributing

1. Clone the repository with `git`:
1. Fork the repository: [`Fork`](https://github.com/frissyn/valorant.py/fork)
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create a new Pull Request! 🎉

- `git clone https://github.com/frissyn/valorant.py.git`
- `cd valorant`
You can also re-create these steps with GitHub Desktop, Visual Studio Code, or whatever `git` version control UI you prefer.

2. Make your changes
3. Create a pull request describing what you changed.
4. Squash your commits with a reference to your pull request.
You don't have to, but I use prefixes for all my commits (i.e `✨: add asyncio run to package namespace`). I have a personal style guide that I use, which you can find [`here`](https://github.com/frissyn/commit-prefixes).

### Other Notes

As of January 26, 2021, this repository will follow my personal commit prefix guide. Please refer to it when contributing! :) [github.com/frissyn/commit-prefixes](https://github.com/frissyn/commit-prefixes)
## Final Note

**What am I working on now?**: Making an asynchronous `Client`!
**Thanks for taking the time to check out `valorant.py`! 🎉**
82 changes: 44 additions & 38 deletions docs/about.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,64 +9,70 @@

`valorant.py` is an unofficial API wrapper for Riot Games' Valorant API endpoints. It's modern, easy to use, feature-rich, and intuitive! Implemented with object oriented designs and explicit reloads to prevent `429`s, valorant.py is the best Valorant API wrapper out there!

**Update Notice:**
## Updates

Riot recently released a new endpoint along Episode 2: Leaderboards! Leaderboards in `valorant.py` support pagination and attribute finding. Take a look at the following snippet:
Most recent version: `0.4.0`

```python
import valorant
Changes:
+ Added `AsyncClient`
+ Added `asyncio.run` to namespace
+ Updated some docstrings and type-hinting

KEY = "RGAPI-Key-Goes-Here"
client = valorant.Client(kEY)
## Installation

page1 = client.get_leaderboard(size=25, page=0)
page2 = client.get_leaderboard(size=25, page=1)
|Manager|Command|
|:-:|:--|
|PIP|`pip install valorant`|
|Poetry|`python -m poetry add valorant`|
|Easy Install|`easy_install valorant`|

print(page1.players.find(3, "leaderboardRank"))
print(page2.players.find("haley", "gameName"))
```
## Usage

# Overview
Quickstart:

### Installation
```py
import valorant

|Manager |Command |
|:----------------|:---------------------------------|
|**pip** |`pip install valorant` |
|**poetry** |`python -m poetry add valorant` |
|**easy_install** |`easy_install valorant` |
KEY = "RGAPI-Key-Here"
client = valorant.Client(KEY)

agents = client.get_characters()

### Usage
for agent in agents:
print(agent.name)
```

Quickstart Guide:
```python
Asynchronous Client:

```py
import valorant

KEY = "RGAPI-Key-Goes-Here"
client = valorant.Client(KEY, locale=None)
KEY = "RGAPI-Key-Here"
client = valorant.AsyncClient(KEY)

maps = client.get_maps()
agents = client.get_characters()
async def _main():
agents = await client.get_characters()

print(agents.get("Viper"))
print(maps.get("Ascent"))
```
for agent in agents:
print(agent.name)

### Documentation
valorant.run(_main())
```

[**valorant.py Documentation**](https://github.com/frissyn/valorant.py/tree/master/docs)
## Documentation

### Contributing
You can find all of `valorant.py`'s documentation [`here`](https://github.com/frissyn/valorant.py/tree/master/docs). I plan on generating package docs with Sphinx eventually...

Bug reports, additional endopint coverage, and other fun stuff is always welcome in [issues](https://github.com/frissyn/valorant.py/issues)!
## Contributing

1. Clone the repository with `git`:
1. Fork the repository: [`Fork`](https://github.com/frissyn/valorant.py/fork)
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create a new Pull Request! 🎉

- `git clone https://github.com/frissyn/valorant.py.git`
- `cd valorant`
You can also re-create these steps with GitHub Desktop, Visual Studio Code, or whatever version control UI you prefer.

2. Make your changes
3. Create a pull request describing what you changed.
4. Squash your commits with a reference to your pull request.
## Final Note

**Thanks for taking the time to check out `valorant.py`! 🎉**
6 changes: 4 additions & 2 deletions valorant/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from .client import Client
from .threads import run
from .threads import AsyncClient

__all__ = ["Client"]
__all__ = ["Client", "AsyncClient", "run"]
__author__ = "frissyn"
__version__ = "0.3.1"
__version__ = "0.4.0"
126 changes: 126 additions & 0 deletions valorant/threads.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
import asyncio
import requests

from .client import Client

from .objects import ActDTO
from .objects import AccountDTO
# from .objects import ContentItemDTO
# from .objects import LeaderboardDTO
from .objects import PlatformDataDTO

from .objects import ContentList

# from .values import SAFES
# from .values import ROUTES
from .values import LOCALE
from .values import LOCALES
# from .values import REGIONS
# from .values import HEADERS
# from .values import WEB_API
# from .values import ENDPOINTS
# from .values import CLIENT_API


run = asyncio.run

class AsyncClient(Client):
def __init__(self, key, locale=LOCALE, region="na", route="americas", reload=True):
self.key = key
self.route = route
self.region = region
self.fetch = requests.get

if locale not in LOCALES:
raise ValueError(
f"The given locale '{locale}' is invalid. See "
+ "`valorant.values.LOCALES` for a list of valid locales."
)
else:
self.locale = locale

if reload:
run(self.reload())
else:
pass

def __getattribute__(self, name):
return super(AsyncClient, self).__getattribute__(name)

async def reload(self) -> None:
"""Reload the current cached response for the VAL-CONTENT endpoints."""
return super().reload()

async def get_user_by_puuid(self, puuid: str) -> AccountDTO:
"""Get a Riot account by the given puuid."""
return super().get_user_by_puuid()

async def get_user_by_name(self, name: str, delim: str = "#") -> AccountDTO:
"""Get a Riot account by a given name split by a delimiter."""
return super().get_user_by_name()

async def get_platform_status(self) -> PlatformDataDTO:
"""Get the current platform status for Valorant."""
return super().get_platform_status()

async def get_acts(self) -> ContentList:
"""Get a ContentList of Acts from Valorant."""
return super().get_acts()

async def get_characters(self) -> ContentList:
"""Get a ContentList of Agents from Valorant."""
return super().get_characters()

async def get_current_act(self) -> ActDTO:
"""Get the current Act (indiscriminate of episode)."""
return super().get_current_act()

async def get_charms(self) -> ContentList:
"""Get a ContentList of Gun Buddies from Valorant."""
return super().get_charms()

async def get_charm_levels(self) -> ContentList:
"""Get a ContentList of Gun Buddy Levels from Valorant."""
return super().get_charm_levels()

async def get_chromas(self) -> ContentList:
return super().get_chromas()

async def get_equips(self) -> ContentList:
return super().get_equips()

async def get_leaderboard(self, size: int = 100, page: int = 0, actID: str = ""):
"""Get the top user's in your client's region during a given Act."""
return super().get_leaderboard()

async def get_maps(self) -> ContentList:
"""Get a ContentList of Maps from Valorant."""
return super().get_maps()

async def get_skins(self) -> ContentList:
"""Get a ContentList of Weapon Skins from Valorant."""
return super().get_skins()

async def get_skin_levels(self) -> ContentList:
"""Get a ContentList of Weapon Skin Levels from Valorant."""
return super().get_skin_levels()

async def get_game_modes(self) -> ContentList:
"""Get a ContentList of Game Modes from Valorant."""
return super().get_game_modes()

async def get_sprays(self) -> ContentList:
"""Get a ContentList of Sprays from Valorant."""
return super().get_sprays()

async def get_spray_levels(self) -> ContentList:
"""Get a ContentList of Spray Levels from Valorant."""
return super().get_spray_levels()

async def get_player_cards(self) -> ContentList:
"""Get a ContentList of Player Cards from Valorant."""
return super().get_player_cards()

async def get_player_titles(self) -> ContentList:
"""Get a ContentList of Player Titles from Valorant."""
return super().get_player_titles()

0 comments on commit 2395407

Please sign in to comment.