Skip to content

Commit

Permalink
refactor: Extract Spond.API_BASE_URL class constant
Browse files Browse the repository at this point in the history
  • Loading branch information
elliot-100 committed May 23, 2024
1 parent d3c08fc commit 9391ef2
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions spond/spond.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ class AuthenticationError(Exception):

class Spond:

API_BASE_URL = "https://api.spond.com/core/v1/"
DT_FORMAT = "%Y-%m-%dT00:00:00.000Z"

def __init__(self, username, password):
self.username = username
self.password = password
self.api_url = "https://api.spond.com/core/v1/"
self.clientsession = aiohttp.ClientSession(cookie_jar=aiohttp.CookieJar())
self.chat_url = None
self.auth = None
Expand All @@ -34,7 +34,7 @@ def auth_headers(self):
}

async def login(self):
login_url = f"{self.api_url}login"
login_url = f"{self.API_BASE_URL}login"
data = {"email": self.username, "password": self.password}
async with self.clientsession.post(login_url, json=data) as r:
login_result = await r.json()
Expand All @@ -43,7 +43,7 @@ async def login(self):
err_msg = f"Login failed. Response received: {login_result}"
raise AuthenticationError(err_msg)

api_chat_url = f"{self.api_url}chat"
api_chat_url = f"{self.API_BASE_URL}chat"
headers = {
"content-type": "application/json",
"Authorization": f"Bearer {self.token}",
Expand Down Expand Up @@ -76,7 +76,7 @@ async def get_groups(self):
list of dict
Groups; each group is a dict.
"""
url = f"{self.api_url}groups/"
url = f"{self.API_BASE_URL}groups/"
async with self.clientsession.get(url, headers=self.auth_headers) as r:
self.groups = await r.json()
return self.groups
Expand Down Expand Up @@ -286,7 +286,7 @@ async def get_events(
list of dict
Events; each event is a dict.
"""
url = f"{self.api_url}sponds/"
url = f"{self.API_BASE_URL}sponds/"
params = {
"max": str(max_events),
"scheduled": str(include_scheduled),
Expand Down Expand Up @@ -361,7 +361,7 @@ async def update_event(self, uid, updates: dict):
if event["id"] == uid:
break

url = f"{self.api_url}sponds/{uid}"
url = f"{self.API_BASE_URL}sponds/{uid}"

base_event = {
"heading": None,
Expand Down

0 comments on commit 9391ef2

Please sign in to comment.