slack_chat_api/users_profile.rs
1use crate::Client;
2use crate::ClientResult;
3
4pub struct UsersProfile {
5 pub client: Client,
6}
7
8impl UsersProfile {
9 #[doc(hidden)]
10 pub fn new(client: Client) -> Self {
11 UsersProfile { client }
12 }
13
14 /**
15 * This function performs a `GET` to the `/users.profile.get` endpoint.
16 *
17 * Retrieves a user's profile information.
18 *
19 * FROM: <https://api.slack.com/methods/users.profile.get>
20 *
21 * **Parameters:**
22 *
23 * * `token: &str` -- Authentication token. Requires scope: `users.profile:read`.
24 * * `include_labels: bool` -- Include labels for each ID in custom profile fields.
25 * * `user: &str` -- User to retrieve profile info for.
26 */
27 pub async fn get(
28 &self,
29 include_labels: bool,
30 user: &str,
31 ) -> ClientResult<crate::Response<crate::types::UsersProfileGetSchema>> {
32 let mut query_args: Vec<(String, String)> = Default::default();
33 if include_labels {
34 query_args.push(("include_labels".to_string(), include_labels.to_string()));
35 }
36 if !user.is_empty() {
37 query_args.push(("user".to_string(), user.to_string()));
38 }
39 let query_ = serde_urlencoded::to_string(&query_args).unwrap();
40 let url = self
41 .client
42 .url(&format!("/users.profile.get?{}", query_), None);
43 self.client
44 .get(
45 &url,
46 crate::Message {
47 body: None,
48 content_type: None,
49 },
50 )
51 .await
52 }
53 /**
54 * This function performs a `POST` to the `/users.profile.set` endpoint.
55 *
56 * Set the profile information for a user.
57 *
58 * FROM: <https://api.slack.com/methods/users.profile.set>
59 *
60 * **Parameters:**
61 *
62 * * `token: &str` -- Authentication token. Requires scope: `users.profile:write`.
63 */
64 pub async fn set(&self) -> ClientResult<crate::Response<crate::types::UsersProfileSetSchema>> {
65 let url = self.client.url("/users.profile.set", None);
66 self.client
67 .post(
68 &url,
69 crate::Message {
70 body: None,
71 content_type: Some("application/x-www-form-urlencoded".to_string()),
72 },
73 )
74 .await
75 }
76}