Skip to content

Commit 7a2c8c3

Browse files
authored
Merge pull request #15 from suchmax/master
Add support for custom inventory provider
2 parents b85c24e + ee748d4 commit 7a2c8c3

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ provider = Inventory("steamsupply", "9st947vs0qmgfpeqde1gj92l0oqmhysm")
5454
# using steam as inventory provider
5555
provider = Inventory() # or Inventory("steamcommunity")
5656

57+
# using a custom api as inventory provider
58+
# requests will be sent to {url}/inventory/{steam_id}/{app_id}/{context_id}?api_key=apikey
59+
provider = Inventory("http://localhost:8000", "9st947vs0qmgfpeqde1gj92l0oqmhysm")
60+
5761
# get an inventory
5862
inventory = provider.fetch("76561198253325712")
5963
```
@@ -124,4 +128,4 @@ socket.listen()
124128
```bash
125129
# tf2-utils/
126130
python -m unittest
127-
```
131+
```

src/tf2_utils/inventory.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from .providers.steamcommunity import SteamCommunity
22
from .providers.steamsupply import SteamSupply
33
from .providers.steamapis import SteamApis
4+
from .providers.custom import Custom
45
from .sku import get_sku
56

67
import requests
@@ -45,6 +46,11 @@ def __init__(
4546
# already set
4647
return
4748

49+
# if provider_name is a url, assign it as a custom provider address
50+
if provider_name.lower().startswith("http"):
51+
self.provider = Custom(api_key, provider_name.lower())
52+
return
53+
4854
# loop through providers create object
4955
for i in self.PROVIDERS:
5056
if provider_name.lower() == i.__name__.lower():

src/tf2_utils/providers/custom.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class Custom:
2+
def __init__(self, api_key: str, url: str) -> None:
3+
self.api_key = api_key
4+
self.url = url.rstrip('/')
5+
6+
def get_url_and_params(
7+
self, steam_id: str, app_id: int, context_id: int
8+
) -> tuple[str, dict]:
9+
return (
10+
f"{self.url}/inventory/{steam_id}/{app_id}/{context_id}",
11+
{"api_key": self.api_key},
12+
)

0 commit comments

Comments
 (0)