Add lib
This commit is contained in:
18
lib/ShazamIO/shazamio/client.py
Normal file
18
lib/ShazamIO/shazamio/client.py
Normal file
@@ -0,0 +1,18 @@
|
||||
import aiohttp
|
||||
|
||||
from shazamio.exceptions import BadMethod
|
||||
from shazamio.utils import validate_json
|
||||
|
||||
|
||||
class HTTPClient:
|
||||
@staticmethod
|
||||
async def request(method: str, url: str, *args, **kwargs) -> dict:
|
||||
async with aiohttp.ClientSession() as session:
|
||||
if method.upper() == "GET":
|
||||
async with session.get(url, **kwargs) as resp:
|
||||
return await validate_json(resp, *args)
|
||||
elif method.upper() == "POST":
|
||||
async with session.post(url, **kwargs) as resp:
|
||||
return await validate_json(resp, *args)
|
||||
else:
|
||||
raise BadMethod("Accept only GET/POST")
|
||||
Reference in New Issue
Block a user