Skip to content

Commit

Permalink
Added seperate Sync & Async Clients
Browse files Browse the repository at this point in the history
  • Loading branch information
eitozx committed Oct 2, 2022
1 parent 6f1dc98 commit 1386886
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
2 changes: 1 addition & 1 deletion animu/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@
__version__ = "0.1.0"


from animu.client import Client
from animu.client import Client, AsyncClient
32 changes: 32 additions & 0 deletions animu/client.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,40 @@
import aiohttp
import requests

from animu import model

class Client:
def __init__(self, token: str):
self._header = {"Auth": token}
self._baseurl = "https://animu.ml/api/"

def _endpoint(self, endpoint: str):
response = requests.get(f"{self._baseurl}{endpoint}", headers=self._header)
result = response.json()
return result

def fact(self):
data = self._endpoint('fact')
return model.Fact(data)

def password(self):
data = self._endpoint('password')
return model.Password(data)

def quote(self):
data = self._endpoint('quote')
return model.Quote(data)

def roleplay(self, query: str):
data = self._endpoint(query)
return model.Roleplay(data)

def waifu(self):
data = self._endpoint('waifu')
return model.Waifu(data)


class AsyncClient:
def __init__(self, token: str):
self._header = {"Auth": token}
self._baseurl = "https://animu.ml/api/"
Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
aiohttp
aiohttp
requests

0 comments on commit 1386886

Please sign in to comment.