-
Notifications
You must be signed in to change notification settings - Fork 24
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 ability to respond to event invites #93
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ def __init__(self, username, password): | |
self.chat_url = None | ||
self.auth = None | ||
self.token = None | ||
self.profile = None | ||
self.groups = None | ||
self.events = None | ||
|
||
|
@@ -43,6 +44,22 @@ async def login(self): | |
self.chat_url = result["url"] | ||
self.auth = result["auth"] | ||
|
||
async def get_profile(self): | ||
""" | ||
Get the current users profile. | ||
Subject to authenticated user's access. | ||
|
||
Returns | ||
------- | ||
json response of the current user | ||
""" | ||
if not self.token: | ||
await self.login() | ||
url = f"{self.api_url}profile" | ||
async with self.clientsession.get(url, headers=self.auth_headers) as r: | ||
self.profile = await r.json() | ||
return self.profile | ||
|
||
async def get_groups(self): | ||
""" | ||
Get all groups. | ||
|
@@ -214,6 +231,7 @@ async def get_events( | |
self, | ||
group_id: Optional[str] = None, | ||
include_scheduled: bool = False, | ||
response: Optional[str] = None, | ||
max_end: Optional[datetime] = None, | ||
min_end: Optional[datetime] = None, | ||
max_start: Optional[datetime] = None, | ||
|
@@ -233,6 +251,9 @@ async def get_events( | |
(TO DO: probably events for which invites haven't been sent yet?) | ||
Defaults to False for performance reasons. | ||
Uses `scheduled` API parameter. | ||
response : str, optional | ||
Only include events which this response. Valid known options are: | ||
`unanswered`, there may be more. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this should read "Only include events with this response from the authenticated user ...", to make it clearer that this parameter (unlike the others) is not intrinsic to the event itself. |
||
max_end : datetime, optional | ||
Only include events which end before or at this datetime. | ||
Uses `maxEndTimestamp` API parameter; relates to `endTimestamp` event | ||
|
@@ -276,6 +297,8 @@ async def get_events( | |
url += f"&minStartTimestamp={min_start.strftime('%Y-%m-%dT00:00:00.000Z')}" | ||
if group_id: | ||
url += f"&groupId={group_id}" | ||
if response: | ||
url += f"&response={response}" | ||
|
||
async with self.clientsession.get(url, headers=self.auth_headers) as r: | ||
self.events = await r.json() | ||
|
@@ -380,3 +403,47 @@ async def update_event(self, uid, updates: dict): | |
async with self.clientsession.post(url, json=data, headers=headers) as r: | ||
self.events_update = await r.json() | ||
return self.events | ||
|
||
async def update_event_response( | ||
self, | ||
uid, | ||
accepted: bool = True, | ||
) -> List[dict]: | ||
""" | ||
Respond to an event invite. | ||
|
||
Parameters: | ||
---------- | ||
uid : str | ||
UID of the event. | ||
accepted : bool | ||
Accept invite to an event. | ||
|
||
Returns: | ||
---------- | ||
json results of put command, containing: | ||
`acceptedIds`, | ||
`unconfirmedIds`, | ||
`waitinglistIds`, | ||
`votes` | ||
""" | ||
if not self.token: | ||
await self.login() | ||
profile = await self.get_profile() | ||
event = await self.get_event(uid) | ||
|
||
membershipId = None | ||
members = event["recipients"]["group"]["members"] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is a similar test also needed in other functions? What do you think @elliot-100 ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Raise exception if the current user isn't a member of the event's group? It makes sense that you can't respond to an event if you're not in its group - the event isn't available for you to attend. It's needed because you may or may not be able to read it anyway, depending on visibility settings. I guess there are other 'write' cases where this should be checked but I'm not really familiar with them. Which ones do you think? |
||
for m in members: | ||
if m["profile"]["id"] == profile["id"]: | ||
membershipId = m["id"] | ||
break | ||
|
||
if membershipId == None: | ||
raise ValueError("You don't seem to be a member of the event's group") | ||
|
||
url = f"{self.api_url}sponds/{uid}/responses/{membershipId}" | ||
|
||
data = {"accepted": accepted} | ||
r = await self.clientsession.put(url, json=data, headers=self.auth_headers) | ||
return await r.json() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the function name
get_profile()
should beget_current_profile()
or similar, as the former sounds like a general purpose function to read an arbitrary item, likeget_event()
,get_group()
, etc.