use std::collections::HashMap; use std::cell::RefCell; use std::borrow::BorrowMut; use std::default::Default; use std::collections::BTreeMap; use serde_json as json; use std::io; use std::fs; use std::mem; use std::thread::sleep; use crate::client; // ############## // UTILITIES ### // ############ // ######## // HUB ### // ###### /// Central instance to access all HangoutsChat related resource activities /// /// # Examples /// /// Instantiate a new hub /// /// ```test_harness,no_run /// extern crate hyper; /// extern crate hyper_rustls; /// extern crate yup_oauth2 as oauth2; /// extern crate google_chat1 as chat1; /// use chat1::api::Message; /// use chat1::{Result, Error}; /// # async fn dox() { /// use std::default::Default; /// use oauth2; /// use chat1::HangoutsChat; /// /// // Get an ApplicationSecret instance by some means. It contains the `client_id` and /// // `client_secret`, among other things. /// let secret: oauth2::ApplicationSecret = Default::default(); /// // Instantiate the authenticator. It will choose a suitable authentication flow for you, /// // unless you replace `None` with the desired Flow. /// // Provide your own `AuthenticatorDelegate` to adjust the way it operates and get feedback about /// // what's going on. You probably want to bring in your own `TokenStorage` to persist tokens and /// // retrieve them from storage. /// let auth = yup_oauth2::InstalledFlowAuthenticator::builder( /// secret, /// yup_oauth2::InstalledFlowReturnMethod::HTTPRedirect, /// ).build().await.unwrap(); /// let mut hub = HangoutsChat::new(hyper::Client::builder().build(hyper_rustls::HttpsConnector::with_native_roots()), auth); /// // As the method needs a request, you would usually fill it with the desired information /// // into the respective structure. Some of the parts shown here might not be applicable ! /// // Values shown here are possibly random and not representative ! /// let mut req = Message::default(); /// /// // You can configure optional parameters by calling the respective setters at will, and /// // execute the final call using `doit()`. /// // Values shown here are possibly random and not representative ! /// let result = hub.dms().conversations_messages(req, "parent") /// .thread_key("At") /// .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), /// } /// # } /// ``` pub struct HangoutsChat { client: RefCell, auth: RefCell>>, _user_agent: String, _base_url: String, _root_url: String, } impl<'a, C> client::Hub for HangoutsChat {} impl<'a, C> HangoutsChat where C: BorrowMut, hyper::body::Body>> { pub fn new(client: C, authenticator: oauth2::authenticator::Authenticator>) -> HangoutsChat { HangoutsChat { client: RefCell::new(client), auth: RefCell::new(authenticator), _user_agent: "google-api-rust-client/2.0.0".to_string(), _base_url: "https://chat.googleapis.com/".to_string(), _root_url: "https://chat.googleapis.com/".to_string(), } } pub fn dms(&'a self) -> DmMethods<'a, C> { DmMethods { hub: &self } } pub fn media(&'a self) -> MediaMethods<'a, C> { MediaMethods { hub: &self } } pub fn rooms(&'a self) -> RoomMethods<'a, C> { RoomMethods { hub: &self } } pub fn spaces(&'a self) -> SpaceMethods<'a, C> { SpaceMethods { hub: &self } } /// Set the user-agent header field to use in all requests to the server. /// It defaults to `google-api-rust-client/2.0.0`. /// /// Returns the previously set user-agent. pub fn user_agent(&mut self, agent_name: String) -> String { mem::replace(&mut self._user_agent, agent_name) } /// Set the base url to use in all requests to the server. /// It defaults to `https://chat.googleapis.com/`. /// /// Returns the previously set base url. pub fn base_url(&mut self, new_base_url: String) -> String { mem::replace(&mut self._base_url, new_base_url) } /// Set the root url to use in all requests to the server. /// It defaults to `https://chat.googleapis.com/`. /// /// Returns the previously set root url. pub fn root_url(&mut self, new_root_url: String) -> String { mem::replace(&mut self._root_url, new_root_url) } } // ############ // SCHEMAS ### // ########## /// List of string parameters to supply when the action method is invoked. For example, consider three snooze buttons: snooze now, snooze 1 day, snooze next week. You might use action method = snooze(), passing the snooze type and snooze time in the list of string parameters. /// /// This type is not used in any activity, and only used as *part* of another schema. /// #[derive(Default, Clone, Debug, Serialize, Deserialize)] pub struct ActionParameter { /// The name of the parameter for the action script. pub key: Option, /// The value of the parameter. pub value: Option, } impl client::Part for ActionParameter {} /// Parameters that a bot can use to configure how it's response is posted. /// /// This type is not used in any activity, and only used as *part* of another schema. /// #[derive(Default, Clone, Debug, Serialize, Deserialize)] pub struct ActionResponse { /// The type of bot response. #[serde(rename="type")] pub type_: Option, /// URL for users to auth or config. (Only for REQUEST_CONFIG response types.) pub url: Option, } impl client::Part for ActionResponse {} /// Annotations associated with the plain-text body of the message. Example plain-text message body: ``` Hello @FooBot how are you!" ``` The corresponding annotations metadata: ``` "annotations":[{ "type":"USER_MENTION", "startIndex":6, "length":7, "userMention": { "user": { "name":"users/107946847022116401880", "displayName":"FooBot", "avatarUrl":"https://goo.gl/aeDtrS", "type":"BOT" }, "type":"MENTION" } }] ``` /// /// This type is not used in any activity, and only used as *part* of another schema. /// #[derive(Default, Clone, Debug, Serialize, Deserialize)] pub struct Annotation { /// Length of the substring in the plain-text message body this annotation corresponds to. pub length: Option, /// The metadata for a slash command. #[serde(rename="slashCommand")] pub slash_command: Option, /// Start index (0-based, inclusive) in the plain-text message body this annotation corresponds to. #[serde(rename="startIndex")] pub start_index: Option, /// The type of this annotation. #[serde(rename="type")] pub type_: Option, /// The metadata of user mention. #[serde(rename="userMention")] pub user_mention: Option, } impl client::Part for Annotation {} /// An attachment in Hangouts Chat. /// /// # Activities /// /// This type is used in activities, which are methods you may call on this type or where this type is involved in. /// The list links the activity name, along with information about where it is used (one of *request* and *response*). /// /// * [messages attachments get spaces](SpaceMessageAttachmentGetCall) (response) /// #[derive(Default, Clone, Debug, Serialize, Deserialize)] pub struct Attachment { /// A reference to the attachment data. This is used with the media API to download the attachment data. #[serde(rename="attachmentDataRef")] pub attachment_data_ref: Option, /// The original file name for the content, not the full path. #[serde(rename="contentName")] pub content_name: Option, /// The content type (MIME type) of the file. #[serde(rename="contentType")] pub content_type: Option, /// Output only. The download URL which should be used to allow a human user to download the attachment. Bots should not use this URL to download attachment content. #[serde(rename="downloadUri")] pub download_uri: Option, /// A reference to the drive attachment. This is used with the Drive API. #[serde(rename="driveDataRef")] pub drive_data_ref: Option, /// Resource name of the attachment, in the form "spaces/*/messages/*/attachments/*". pub name: Option, /// The source of the attachment. pub source: Option, /// Output only. The thumbnail URL which should be used to preview the attachment to a human user. Bots should not use this URL to download attachment content. #[serde(rename="thumbnailUri")] pub thumbnail_uri: Option, } impl client::ResponseResult for Attachment {} /// A reference to the data of an attachment. /// /// This type is not used in any activity, and only used as *part* of another schema. /// #[derive(Default, Clone, Debug, Serialize, Deserialize)] pub struct AttachmentDataRef { /// The resource name of the attachment data. This is used with the media API to download the attachment data. #[serde(rename="resourceName")] pub resource_name: Option, } impl client::Part for AttachmentDataRef {} /// A button. Can be a text button or an image button. /// /// This type is not used in any activity, and only used as *part* of another schema. /// #[derive(Default, Clone, Debug, Serialize, Deserialize)] pub struct Button { /// A button with image and onclick action. #[serde(rename="imageButton")] pub image_button: Option, /// A button with text and onclick action. #[serde(rename="textButton")] pub text_button: Option, } impl client::Part for Button {} /// A card is a UI element that can contain UI widgets such as texts, images. /// /// This type is not used in any activity, and only used as *part* of another schema. /// #[derive(Default, Clone, Debug, Serialize, Deserialize)] pub struct Card { /// The actions of this card. #[serde(rename="cardActions")] pub card_actions: Option>, /// The header of the card. A header usually contains a title and an image. pub header: Option, /// Name of the card. pub name: Option, /// Sections are separated by a line divider. pub sections: Option>, } impl client::Part for Card {} /// A card action is the action associated with the card. For an invoice card, a typical action would be: delete invoice, email invoice or open the invoice in browser. /// /// This type is not used in any activity, and only used as *part* of another schema. /// #[derive(Default, Clone, Debug, Serialize, Deserialize)] pub struct CardAction { /// The label used to be displayed in the action menu item. #[serde(rename="actionLabel")] pub action_label: Option, /// The onclick action for this action item. #[serde(rename="onClick")] pub on_click: Option, } impl client::Part for CardAction {} /// There is no detailed description. /// /// This type is not used in any activity, and only used as *part* of another schema. /// #[derive(Default, Clone, Debug, Serialize, Deserialize)] pub struct CardHeader { /// The image's type (e.g. square border or circular border). #[serde(rename="imageStyle")] pub image_style: Option, /// The URL of the image in the card header. #[serde(rename="imageUrl")] pub image_url: Option, /// The subtitle of the card header. pub subtitle: Option, /// The title must be specified. The header has a fixed height: if both a title and subtitle is specified, each will take up 1 line. If only the title is specified, it will take up both lines. pub title: Option, } impl client::Part for CardHeader {} /// A reference to the data of a drive attachment. /// /// This type is not used in any activity, and only used as *part* of another schema. /// #[derive(Default, Clone, Debug, Serialize, Deserialize)] pub struct DriveDataRef { /// The id for the drive file, for use with the Drive API. #[serde(rename="driveFileId")] pub drive_file_id: Option, } impl client::Part for DriveDataRef {} /// A generic empty message that you can re-use to avoid defining duplicated empty messages in your APIs. A typical example is to use it as the request or the response type of an API method. For instance: service Foo { rpc Bar(google.protobuf.Empty) returns (google.protobuf.Empty); } The JSON representation for `Empty` is empty JSON object `{}`. /// /// # Activities /// /// This type is used in activities, which are methods you may call on this type or where this type is involved in. /// The list links the activity name, along with information about where it is used (one of *request* and *response*). /// /// * [messages delete spaces](SpaceMessageDeleteCall) (response) /// #[derive(Default, Clone, Debug, Serialize, Deserialize)] pub struct Empty { _never_set: Option } impl client::ResponseResult for Empty {} /// A form action describes the behavior when the form is submitted. For example, an Apps Script can be invoked to handle the form. /// /// This type is not used in any activity, and only used as *part* of another schema. /// #[derive(Default, Clone, Debug, Serialize, Deserialize)] pub struct FormAction { /// The method name is used to identify which part of the form triggered the form submission. This information is echoed back to the bot as part of the card click event. The same method name can be used for several elements that trigger a common behavior if desired. #[serde(rename="actionMethodName")] pub action_method_name: Option, /// List of action parameters. pub parameters: Option>, } impl client::Part for FormAction {} /// An image that is specified by a URL and can have an onclick action. /// /// This type is not used in any activity, and only used as *part* of another schema. /// #[derive(Default, Clone, Debug, Serialize, Deserialize)] pub struct Image { /// The aspect ratio of this image (width/height). This field allows clients to reserve the right height for the image while waiting for it to load. It's not meant to override the native aspect ratio of the image. If unset, the server fills it by prefetching the image. #[serde(rename="aspectRatio")] pub aspect_ratio: Option, /// The URL of the image. #[serde(rename="imageUrl")] pub image_url: Option, /// The onclick action. #[serde(rename="onClick")] pub on_click: Option, } impl client::Part for Image {} /// An image button with an onclick action. /// /// This type is not used in any activity, and only used as *part* of another schema. /// #[derive(Default, Clone, Debug, Serialize, Deserialize)] pub struct ImageButton { /// The icon specified by an enum that indices to an icon provided by Chat API. pub icon: Option, /// The icon specified by a URL. #[serde(rename="iconUrl")] pub icon_url: Option, /// The name of this image_button which will be used for accessibility. Default value will be provided if developers don't specify. pub name: Option, /// The onclick action. #[serde(rename="onClick")] pub on_click: Option, } impl client::Part for ImageButton {} /// A UI element contains a key (label) and a value (content). And this element may also contain some actions such as onclick button. /// /// This type is not used in any activity, and only used as *part* of another schema. /// #[derive(Default, Clone, Debug, Serialize, Deserialize)] pub struct KeyValue { /// The text of the bottom label. Formatted text supported. #[serde(rename="bottomLabel")] pub bottom_label: Option, /// A button that can be clicked to trigger an action. pub button: Option