Struct GCalClient

Source
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

Source

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
Hide additional 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}
Source

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}
Source

pub fn event_client(&self) -> EventClient

Source

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}
Source

pub fn set_debug(&mut self)

Source

pub async fn get( &self, action: Option<String>, target: impl Sendable, ) -> ClientResult<Response>

Perform a GET request.

Source

pub async fn post( &self, action: Option<String>, target: impl Sendable, ) -> ClientResult<Response>

Perform a POST request.

Source

pub async fn put( &self, action: Option<String>, target: impl Sendable, ) -> ClientResult<Response>

Perform a PUT request.

Source

pub async fn patch( &self, action: Option<String>, target: impl Sendable, ) -> ClientResult<Response>

Perform a PATCH request.

Source

pub async fn delete( &self, action: Option<String>, target: impl Sendable, ) -> ClientResult<Response>

Perform a DELETE request.

Trait Implementations§

Source§

impl Clone for GCalClient

Source§

fn clone(&self) -> GCalClient

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for GCalClient

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,