Skip to content

Commit

Permalink
Merge pull request #114 from elliot-100/14-get-events-within-subgroup
Browse files Browse the repository at this point in the history
Add: `subgroup_id` parameter to `get_events()` API call
  • Loading branch information
elliot-100 authored May 23, 2024
2 parents ce54bf6 + 22d7298 commit ab0694b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 13 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ asyncio.run(main())

Get details of all your group memberships and all members of those groups.

### get_events([group_id, include_scheduled, max_end, min_end, max_start, min_start, max_events])
### get_events([group_id, subgroup_id, include_scheduled, max_end, min_end, max_start, min_start, max_events])

Get details of events, limited to 100 by default.
Optional parameters allow filtering by start and end datetimes, group; more events to be returned; inclusion of 'scheduled' events.
Optional parameters allow filtering by start and end datetimes, group and subgroup; more events to be returned; inclusion of 'scheduled' events.

### get_person()
Get a member's details.
Expand Down
32 changes: 21 additions & 11 deletions spond/spond.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ class AuthenticationError(Exception):


class Spond:

DT_FORMAT = "%Y-%m-%dT00:00:00.000Z"

def __init__(self, username, password):
self.username = username
self.password = password
Expand Down Expand Up @@ -234,6 +237,7 @@ async def send_message(self, text, user=None, group_uid=None, chat_id=None):
async def get_events(
self,
group_id: Optional[str] = None,
subgroup_id: Optional[str] = None,
include_scheduled: bool = False,
max_end: Optional[datetime] = None,
min_end: Optional[datetime] = None,
Expand All @@ -249,6 +253,8 @@ async def get_events(
----------
group_id : str, optional
Uses `GroupId` API parameter.
subgroup_id : str, optional
Uses `subgroupId` API parameter.
include_scheduled : bool, optional
Include scheduled events.
(TO DO: probably events for which invites haven't been sent yet?)
Expand Down Expand Up @@ -280,23 +286,27 @@ async def get_events(
list of dict
Events; each event is a dict.
"""
url = (
f"{self.api_url}sponds/?"
f"max={max_events}"
f"&scheduled={include_scheduled}"
)
url = f"{self.api_url}sponds/"
params = {
"max": str(max_events),
"scheduled": str(include_scheduled),
}
if max_end:
url += f"&maxEndTimestamp={max_end.strftime('%Y-%m-%dT00:00:00.000Z')}"
params["maxEndTimestamp"] = max_end.strftime(self.DT_FORMAT)
if max_start:
url += f"&maxStartTimestamp={max_start.strftime('%Y-%m-%dT00:00:00.000Z')}"
params["maxStartTimestamp"] = max_start.strftime(self.DT_FORMAT)
if min_end:
url += f"&minEndTimestamp={min_end.strftime('%Y-%m-%dT00:00:00.000Z')}"
params["minEndTimestamp"] = min_end.strftime(self.DT_FORMAT)
if min_start:
url += f"&minStartTimestamp={min_start.strftime('%Y-%m-%dT00:00:00.000Z')}"
params["minStartTimestamp"] = min_start.strftime(self.DT_FORMAT)
if group_id:
url += f"&groupId={group_id}"
params["groupId"] = group_id
if subgroup_id:
params["subgroupId"] = subgroup_id

async with self.clientsession.get(url, headers=self.auth_headers) as r:
async with self.clientsession.get(
url, headers=self.auth_headers, params=params
) as r:
self.events = await r.json()
return self.events

Expand Down

0 comments on commit ab0694b

Please sign in to comment.