Init
This commit is contained in:
6
coc/__init__.py
Normal file
6
coc/__init__.py
Normal file
@@ -0,0 +1,6 @@
|
||||
import imp
|
||||
from .user import Player
|
||||
from .clan import Clan
|
||||
|
||||
class ClashOfClans(Player, Clan):
|
||||
pass
|
26
coc/base.py
Normal file
26
coc/base.py
Normal file
@@ -0,0 +1,26 @@
|
||||
import json
|
||||
import requests
|
||||
from abc import ABC
|
||||
|
||||
class Base(ABC):
|
||||
def __init__(self, api_token:str, clan_tag:str = None) -> None:
|
||||
self.headers = {
|
||||
"Content-Type": "application/json",
|
||||
"Authorization": "Bearer {api_token}".format(api_token=api_token)
|
||||
}
|
||||
self.clan_tag = clan_tag
|
||||
|
||||
def get(self, url: str, tag: str):
|
||||
request = requests.get(
|
||||
url.format(tag.replace("#", "")),
|
||||
headers=self.headers
|
||||
)
|
||||
return json.loads(request.text)
|
||||
|
||||
def post(self, url: str, tag: str, payload: dict):
|
||||
request = requests.post(
|
||||
url=url.format(tag.replace("#", "")),
|
||||
headers=self.headers,
|
||||
data=json.dumps(payload)
|
||||
)
|
||||
return json.loads(request.text)
|
17
coc/clan.py
Normal file
17
coc/clan.py
Normal file
@@ -0,0 +1,17 @@
|
||||
from .base import Base
|
||||
|
||||
class Clan(Base):
|
||||
|
||||
def clan_members(self, clan_tag:str = None):
|
||||
if self.clan_tag is not None:
|
||||
clan_tag = self.clan_tag
|
||||
|
||||
url = "https://api.clashofclans.com/v1/clans/%23{}/members"
|
||||
return self.get(url, tag=clan_tag)
|
||||
|
||||
def get_clan(self, clan_tag:str = None):
|
||||
if self.clan_tag is not None:
|
||||
clan_tag = self.clan_tag
|
||||
|
||||
url = "https://api.clashofclans.com/v1/clans/%23{}"
|
||||
return self.get(url, tag=clan_tag)
|
12
coc/user.py
Normal file
12
coc/user.py
Normal file
@@ -0,0 +1,12 @@
|
||||
from .base import Base
|
||||
|
||||
class Player(Base):
|
||||
|
||||
def get_player(self, tag: str):
|
||||
url = "https://api.clashofclans.com/v1/players/%23{}"
|
||||
return self.get(url, tag)
|
||||
|
||||
def verify_token(self, tag: str, token: str):
|
||||
payload = {"token":token}
|
||||
url = "https://api.clashofclans.com/v1/players/%23{}/verifytoken"
|
||||
return self.post(url, tag, payload)
|
Reference in New Issue
Block a user