✨ feat(list): implement list api to retrieve gmail messages
- add list struct to encapsulate gmail api connection - implement run function to execute the api call and handle potential errors
This commit is contained in:
committed by
Jeremiah Russell
parent
3426d3e60b
commit
5178cb6747
37
src/list.rs
37
src/list.rs
@@ -1 +1,38 @@
|
|||||||
|
use google_gmail1::{
|
||||||
|
Error, Gmail, hyper_rustls::HttpsConnector, hyper_util::client::legacy::connect::HttpConnector,
|
||||||
|
};
|
||||||
|
|
||||||
|
/// Struct to capture configuration for List API call.
|
||||||
|
pub struct List {
|
||||||
|
hub: Gmail<HttpsConnector<HttpConnector>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl List {
|
||||||
|
/// Create a new List struct and add the Gmail api connection.
|
||||||
|
pub fn new(hub: Gmail<HttpsConnector<HttpConnector>>) -> Self {
|
||||||
|
List { hub }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Run the Gmail api as configured
|
||||||
|
pub async fn run(&self) {
|
||||||
|
let result = self.hub.users().messages_list("me").doit().await;
|
||||||
|
|
||||||
|
match result {
|
||||||
|
Err(e) => match e {
|
||||||
|
// The Error enum provides details about what exactly happened.
|
||||||
|
// You can also just use its `Debug`, `Display` or `Error` traits
|
||||||
|
Error::HttpError(_)
|
||||||
|
| Error::Io(_)
|
||||||
|
| Error::MissingAPIKey
|
||||||
|
| Error::MissingToken(_)
|
||||||
|
| Error::Cancelled
|
||||||
|
| Error::UploadSizeLimitExceeded(_, _)
|
||||||
|
| Error::Failure(_)
|
||||||
|
| Error::BadRequest(_)
|
||||||
|
| Error::FieldClash(_)
|
||||||
|
| Error::JsonDecodeError(_, _) => println!("{e}"),
|
||||||
|
},
|
||||||
|
Ok(res) => println!("Success: {res:?}"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user