pub struct GCalClient { /* private fields */ }
Expand description
Client is a Google Calendar client. The access key must have already been fetched and the oauth negotiation should have already been completed. The client itself only implements HTTP verbs that accept Sendable implementations. You must use the decorated clients such as EventClient and CalendarListClient to do transactional work.
Implementations§
Source§impl GCalClient
impl GCalClient
Sourcepub fn new(token: OToken, oauth: Option<Arc<OAuth>>) -> ClientResult<Self>
pub fn new(token: OToken, oauth: Option<Arc<OAuth>>) -> ClientResult<Self>
Create a new client. Requires an access key.
Examples found in repository?
examples/calendars.rs (line 26)
16async fn main() {
17 let client_id = std::env::var("GOOGLE_CLIENT_ID")
18 .expect("[ERR] Missing the GOOGLE_CLIENT_ID environment variable.");
19 let client_secret = std::env::var("GOOGLE_CLIENT_SECRET")
20 .expect("[ERR] Missing the GOOGLE_CLIENT_SECRET environment variable.");
21 let token = OAuth::new(client_id, client_secret, "http://localhost:5000/auth")
22 .naive()
23 .await
24 .expect("[ERR] Failed to get access key.");
25
26 let calendar_client = GCalClient::new(token, None).unwrap().calendar_client();
27 let list = calendar_client
28 .list(true, CalendarAccessRole::Reader)
29 .await
30 .unwrap();
31
32 println!("Calendars:");
33 for cal in &list {
34 eprintln!(" - {} {}", cal.summary, cal.id);
35 }
36}
More examples
examples/events.rs (line 37)
17async fn main() {
18 let client_id = std::env::var("GOOGLE_CLIENT_ID")
19 .expect("[ERR] Missing the GOOGLE_CLIENT_ID environment variable.");
20 let client_secret = std::env::var("GOOGLE_CLIENT_SECRET")
21 .expect("[ERR] Missing the GOOGLE_CLIENT_SECRET environment variable.");
22
23 let token = OAuth::new(client_id, client_secret, "http://localhost:5000/auth")
24 .naive()
25 .await
26 .expect("[ERR] Failed to get access key.");
27 println!("Refresh: {:?}", token.refresh);
28
29 // # Mini example showing how to refresh the access token.
30 //
31 // println!("Ref: {}", token.refresh.unwrap());
32 // let token = OAuth::new(client_id, client_secret, "http://localhost:5000".to_string())
33 // .exhange_refresh("REF TOKEN HERE".to_string())
34 // .await
35 // .unwrap();
36
37 let (calendar_client, event_client) = GCalClient::new(token, None).unwrap().clients();
38
39 let list = calendar_client
40 .list(true, CalendarAccessRole::Reader)
41 .await
42 .unwrap();
43
44 let start = Local::now();
45 let end = Local::now().checked_add_signed(Duration::days(7)).unwrap();
46
47 let mut event_list = Vec::new();
48 for calendar in list {
49 event_list.extend(
50 event_client
51 .list(calendar.id.clone(), start, end)
52 .await
53 .unwrap(),
54 );
55 }
56
57 println!("Events: ");
58 for event in &event_list {
59 println!(" - {} : {}", event.summary, event.calendar_id);
60 }
61}
Sourcepub fn calendar_client(&self) -> CalendarListClient
pub fn calendar_client(&self) -> CalendarListClient
Examples found in repository?
examples/calendars.rs (line 26)
16async fn main() {
17 let client_id = std::env::var("GOOGLE_CLIENT_ID")
18 .expect("[ERR] Missing the GOOGLE_CLIENT_ID environment variable.");
19 let client_secret = std::env::var("GOOGLE_CLIENT_SECRET")
20 .expect("[ERR] Missing the GOOGLE_CLIENT_SECRET environment variable.");
21 let token = OAuth::new(client_id, client_secret, "http://localhost:5000/auth")
22 .naive()
23 .await
24 .expect("[ERR] Failed to get access key.");
25
26 let calendar_client = GCalClient::new(token, None).unwrap().calendar_client();
27 let list = calendar_client
28 .list(true, CalendarAccessRole::Reader)
29 .await
30 .unwrap();
31
32 println!("Calendars:");
33 for cal in &list {
34 eprintln!(" - {} {}", cal.summary, cal.id);
35 }
36}
pub fn event_client(&self) -> EventClient
Sourcepub fn clients(self) -> (CalendarListClient, EventClient)
pub fn clients(self) -> (CalendarListClient, EventClient)
Examples found in repository?
examples/events.rs (line 37)
17async fn main() {
18 let client_id = std::env::var("GOOGLE_CLIENT_ID")
19 .expect("[ERR] Missing the GOOGLE_CLIENT_ID environment variable.");
20 let client_secret = std::env::var("GOOGLE_CLIENT_SECRET")
21 .expect("[ERR] Missing the GOOGLE_CLIENT_SECRET environment variable.");
22
23 let token = OAuth::new(client_id, client_secret, "http://localhost:5000/auth")
24 .naive()
25 .await
26 .expect("[ERR] Failed to get access key.");
27 println!("Refresh: {:?}", token.refresh);
28
29 // # Mini example showing how to refresh the access token.
30 //
31 // println!("Ref: {}", token.refresh.unwrap());
32 // let token = OAuth::new(client_id, client_secret, "http://localhost:5000".to_string())
33 // .exhange_refresh("REF TOKEN HERE".to_string())
34 // .await
35 // .unwrap();
36
37 let (calendar_client, event_client) = GCalClient::new(token, None).unwrap().clients();
38
39 let list = calendar_client
40 .list(true, CalendarAccessRole::Reader)
41 .await
42 .unwrap();
43
44 let start = Local::now();
45 let end = Local::now().checked_add_signed(Duration::days(7)).unwrap();
46
47 let mut event_list = Vec::new();
48 for calendar in list {
49 event_list.extend(
50 event_client
51 .list(calendar.id.clone(), start, end)
52 .await
53 .unwrap(),
54 );
55 }
56
57 println!("Events: ");
58 for event in &event_list {
59 println!(" - {} : {}", event.summary, event.calendar_id);
60 }
61}
pub fn set_debug(&mut self)
Sourcepub async fn get(
&self,
action: Option<String>,
target: impl Sendable,
) -> ClientResult<Response>
pub async fn get( &self, action: Option<String>, target: impl Sendable, ) -> ClientResult<Response>
Perform a GET request.
Sourcepub async fn post(
&self,
action: Option<String>,
target: impl Sendable,
) -> ClientResult<Response>
pub async fn post( &self, action: Option<String>, target: impl Sendable, ) -> ClientResult<Response>
Perform a POST request.
Sourcepub async fn put(
&self,
action: Option<String>,
target: impl Sendable,
) -> ClientResult<Response>
pub async fn put( &self, action: Option<String>, target: impl Sendable, ) -> ClientResult<Response>
Perform a PUT request.
Trait Implementations§
Source§impl Clone for GCalClient
impl Clone for GCalClient
Source§fn clone(&self) -> GCalClient
fn clone(&self) -> GCalClient
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreAuto Trait Implementations§
impl Freeze for GCalClient
impl !RefUnwindSafe for GCalClient
impl Send for GCalClient
impl Sync for GCalClient
impl Unpin for GCalClient
impl !UnwindSafe for GCalClient
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more