Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add: subgroup_id parameter to get_events() API call #114

Merged
merged 2 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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