1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
use anyhow::Result;
use crate::Client;
pub struct Views {
pub client: Client,
}
impl Views {
#[doc(hidden)]
pub fn new(client: Client) -> Self {
Views { client }
}
/**
* This function performs a `GET` to the `/views.open` endpoint.
*
* Open a view for a user.
*
* FROM: <https://api.slack.com/methods/views.open>
*
* **Parameters:**
*
* * `token: &str` -- Authentication token. Requires scope: `none`.
* * `trigger_id: &str` -- Exchange a trigger to post to the user.
* * `view: &str` -- A [view payload](/reference/surfaces/views). This must be a JSON-encoded string.
*/
pub async fn open(&self, trigger_id: &str, view: &str) -> Result<crate::types::DndEndSchema> {
let mut query_args: Vec<(String, String)> = Default::default();
if !trigger_id.is_empty() {
query_args.push(("trigger_id".to_string(), trigger_id.to_string()));
}
if !view.is_empty() {
query_args.push(("view".to_string(), view.to_string()));
}
let query_ = serde_urlencoded::to_string(&query_args).unwrap();
let url = format!("/views.open?{}", query_);
self.client.get(&url, None).await
}
/**
* This function performs a `GET` to the `/views.publish` endpoint.
*
* Publish a static view for a User.
*
* FROM: <https://api.slack.com/methods/views.publish>
*
* **Parameters:**
*
* * `token: &str` -- Authentication token. Requires scope: `none`.
* * `user_id: &str` -- `id` of the user you want publish a view to.
* * `view: &str` -- A [view payload](/reference/surfaces/views). This must be a JSON-encoded string.
* * `hash: &str` -- A string that represents view state to protect against possible race conditions.
*/
pub async fn publish(
&self,
user_id: &str,
view: &str,
hash: &str,
) -> Result<crate::types::DndEndSchema> {
let mut query_args: Vec<(String, String)> = Default::default();
if !hash.is_empty() {
query_args.push(("hash".to_string(), hash.to_string()));
}
if !user_id.is_empty() {
query_args.push(("user_id".to_string(), user_id.to_string()));
}
if !view.is_empty() {
query_args.push(("view".to_string(), view.to_string()));
}
let query_ = serde_urlencoded::to_string(&query_args).unwrap();
let url = format!("/views.publish?{}", query_);
self.client.get(&url, None).await
}
/**
* This function performs a `GET` to the `/views.push` endpoint.
*
* Push a view onto the stack of a root view.
*
* FROM: <https://api.slack.com/methods/views.push>
*
* **Parameters:**
*
* * `token: &str` -- Authentication token. Requires scope: `none`.
* * `trigger_id: &str` -- Exchange a trigger to post to the user.
* * `view: &str` -- A [view payload](/reference/surfaces/views). This must be a JSON-encoded string.
*/
pub async fn push(&self, trigger_id: &str, view: &str) -> Result<crate::types::DndEndSchema> {
let mut query_args: Vec<(String, String)> = Default::default();
if !trigger_id.is_empty() {
query_args.push(("trigger_id".to_string(), trigger_id.to_string()));
}
if !view.is_empty() {
query_args.push(("view".to_string(), view.to_string()));
}
let query_ = serde_urlencoded::to_string(&query_args).unwrap();
let url = format!("/views.push?{}", query_);
self.client.get(&url, None).await
}
/**
* This function performs a `GET` to the `/views.update` endpoint.
*
* Update an existing view.
*
* FROM: <https://api.slack.com/methods/views.update>
*
* **Parameters:**
*
* * `token: &str` -- Authentication token. Requires scope: `none`.
* * `view_id: &str` -- A unique identifier of the view to be updated. Either `view_id` or `external_id` is required.
* * `external_id: &str` -- A unique identifier of the view set by the developer. Must be unique for all views on a team. Max length of 255 characters. Either `view_id` or `external_id` is required.
* * `view: &str` -- A [view object](/reference/surfaces/views). This must be a JSON-encoded string.
* * `hash: &str` -- A string that represents view state to protect against possible race conditions.
*/
pub async fn update(
&self,
view_id: &str,
external_id: &str,
view: &str,
hash: &str,
) -> Result<crate::types::DndEndSchema> {
let mut query_args: Vec<(String, String)> = Default::default();
if !external_id.is_empty() {
query_args.push(("external_id".to_string(), external_id.to_string()));
}
if !hash.is_empty() {
query_args.push(("hash".to_string(), hash.to_string()));
}
if !view.is_empty() {
query_args.push(("view".to_string(), view.to_string()));
}
if !view_id.is_empty() {
query_args.push(("view_id".to_string(), view_id.to_string()));
}
let query_ = serde_urlencoded::to_string(&query_args).unwrap();
let url = format!("/views.update?{}", query_);
self.client.get(&url, None).await
}
}