aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.rs
diff options
context:
space:
mode:
authorTeddy Wing2021-05-20 01:47:54 +0200
committerTeddy Wing2021-05-20 01:47:54 +0200
commitbadeb314efa44ef3dd5f7f85c5b7d923ec6484b9 (patch)
tree3a856450d31de5a20f1251c97f83d0a440f15837 /src/main.rs
parentdf7c075aeb53a2808773f87bff0c4aa2ca4e1409 (diff)
downloadgoogle-calendar-rsvp-badeb314efa44ef3dd5f7f85c5b7d923ec6484b9.tar.bz2
Accept calendar event
In order to accept the event, we need to build an `Event` value with the data that should be patched into the original. That value is then passed in the `patch()` call to update the event. The email address of the current user is required. I couldn't figure out how best to get it, so I decided to keep the event `get()` call, and grab the authenticated user's email address from there. This means it requires two requests to accept the event, which is not ideal. Not sure if there's a better way to get that information.
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs35
1 files changed, 17 insertions, 18 deletions
diff --git a/src/main.rs b/src/main.rs
index cb4a772..20b3cc9 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,3 +1,4 @@
+use google_calendar3::api::{Event, EventAttendee};
use google_calendar3::{CalendarHub, Result, Error};
use home;
use hyper;
@@ -55,35 +56,33 @@ async fn main() {
dbg!(&res.1.attendees);
- let event = res.1;
+ let mut event = Event::default();
+ let mut attendee = EventAttendee::default();
- if let Some(ref original_attendees) = event.attendees {
- let mut attendees = original_attendees.clone();
-
- for mut attendee in &mut attendees {
- if let Some(is_me) = attendee.self_ {
+ if let Some(attendees) = res.1.attendees {
+ for a in &attendees {
+ if let Some(is_me) = a.self_ {
if is_me {
- attendee.response_status = Some("accepted".to_owned());
+ attendee.email = a.email.clone();
break;
}
}
}
+ }
- let patched_attendees = serde_json::to_string(&attendees)
- .unwrap();
+ // attendee.email = Some();
+ attendee.response_status = Some("accepted".to_owned());
- dbg!(&patched_attendees);
+ event.attendees = Some(vec![attendee]);
- let res = hub.events()
- .patch(event, "primary", "1g4j1h67ndq7kddrb2bptp2cua")
- .param("attendees", &patched_attendees)
- .doit()
- .await
- .unwrap();
+ let res = hub.events()
+ .patch(event, "primary", "1g4j1h67ndq7kddrb2bptp2cua")
+ .doit()
+ .await
+ .unwrap();
- dbg!(res);
- }
+ dbg!(res);
},
}
}