slack_chat_api/pins.rs
1use crate::Client;
2use crate::ClientResult;
3
4pub struct Pins {
5 pub client: Client,
6}
7
8impl Pins {
9 #[doc(hidden)]
10 pub fn new(client: Client) -> Self {
11 Pins { client }
12 }
13
14 /**
15 * This function performs a `POST` to the `/pins.add` endpoint.
16 *
17 * Pins an item to a channel.
18 *
19 * FROM: <https://api.slack.com/methods/pins.add>
20 *
21 * **Parameters:**
22 *
23 * * `token: &str` -- Authentication token. Requires scope: `pins:write`.
24 */
25 pub async fn add(&self) -> ClientResult<crate::Response<crate::types::DndEndSchema>> {
26 let url = self.client.url("/pins.add", None);
27 self.client
28 .post(
29 &url,
30 crate::Message {
31 body: None,
32 content_type: Some("application/x-www-form-urlencoded".to_string()),
33 },
34 )
35 .await
36 }
37 /**
38 * This function performs a `GET` to the `/pins.list` endpoint.
39 *
40 * Lists items pinned to a channel.
41 *
42 * FROM: <https://api.slack.com/methods/pins.list>
43 *
44 * **Parameters:**
45 *
46 * * `token: &str` -- Authentication token. Requires scope: `pins:read`.
47 * * `channel: &str` -- Channel to get pinned items for.
48 */
49 pub async fn list(
50 &self,
51 channel: &str,
52 ) -> ClientResult<crate::Response<Vec<crate::types::PinsListResponseAnyOf>>> {
53 let mut query_args: Vec<(String, String)> = Default::default();
54 if !channel.is_empty() {
55 query_args.push(("channel".to_string(), channel.to_string()));
56 }
57 let query_ = serde_urlencoded::to_string(&query_args).unwrap();
58 let url = self.client.url(&format!("/pins.list?{}", query_), None);
59 self.client
60 .get(
61 &url,
62 crate::Message {
63 body: None,
64 content_type: None,
65 },
66 )
67 .await
68 }
69 /**
70 * This function performs a `GET` to the `/pins.list` endpoint.
71 *
72 * As opposed to `list`, this function returns all the pages of the request at once.
73 *
74 * Lists items pinned to a channel.
75 *
76 * FROM: <https://api.slack.com/methods/pins.list>
77 */
78 pub async fn list_all(
79 &self,
80 channel: &str,
81 ) -> ClientResult<crate::Response<Vec<crate::types::PinsListResponseAnyOf>>> {
82 let mut query_args: Vec<(String, String)> = Default::default();
83 if !channel.is_empty() {
84 query_args.push(("channel".to_string(), channel.to_string()));
85 }
86 let query_ = serde_urlencoded::to_string(&query_args).unwrap();
87 let url = self.client.url(&format!("/pins.list?{}", query_), None);
88 self.client
89 .get_all_pages(
90 &url,
91 crate::Message {
92 body: None,
93 content_type: None,
94 },
95 )
96 .await
97 }
98 /**
99 * This function performs a `POST` to the `/pins.remove` endpoint.
100 *
101 * Un-pins an item from a channel.
102 *
103 * FROM: <https://api.slack.com/methods/pins.remove>
104 *
105 * **Parameters:**
106 *
107 * * `token: &str` -- Authentication token. Requires scope: `pins:write`.
108 */
109 pub async fn remove(&self) -> ClientResult<crate::Response<crate::types::DndEndSchema>> {
110 let url = self.client.url("/pins.remove", None);
111 self.client
112 .post(
113 &url,
114 crate::Message {
115 body: None,
116 content_type: Some("application/x-www-form-urlencoded".to_string()),
117 },
118 )
119 .await
120 }
121}