1use crate::Client;
2use crate::ClientResult;
3
4pub struct Oauth {
5 pub client: Client,
6}
7
8impl Oauth {
9 #[doc(hidden)]
10 pub fn new(client: Client) -> Self {
11 Oauth { client }
12 }
13
14 pub async fn access(
30 &self,
31 client_id: &str,
32 client_secret: &str,
33 code: &str,
34 redirect_uri: &str,
35 single_channel: bool,
36 ) -> ClientResult<crate::Response<crate::types::DndEndSchema>> {
37 let mut query_args: Vec<(String, String)> = Default::default();
38 if !client_id.is_empty() {
39 query_args.push(("client_id".to_string(), client_id.to_string()));
40 }
41 if !client_secret.is_empty() {
42 query_args.push(("client_secret".to_string(), client_secret.to_string()));
43 }
44 if !code.is_empty() {
45 query_args.push(("code".to_string(), code.to_string()));
46 }
47 if !redirect_uri.is_empty() {
48 query_args.push(("redirect_uri".to_string(), redirect_uri.to_string()));
49 }
50 if single_channel {
51 query_args.push(("single_channel".to_string(), single_channel.to_string()));
52 }
53 let query_ = serde_urlencoded::to_string(&query_args).unwrap();
54 let url = self.client.url(&format!("/oauth.access?{}", query_), None);
55 self.client
56 .get(
57 &url,
58 crate::Message {
59 body: None,
60 content_type: None,
61 },
62 )
63 .await
64 }
65 pub async fn token(
81 &self,
82 client_id: &str,
83 client_secret: &str,
84 code: &str,
85 redirect_uri: &str,
86 single_channel: bool,
87 ) -> ClientResult<crate::Response<crate::types::DndEndSchema>> {
88 let mut query_args: Vec<(String, String)> = Default::default();
89 if !client_id.is_empty() {
90 query_args.push(("client_id".to_string(), client_id.to_string()));
91 }
92 if !client_secret.is_empty() {
93 query_args.push(("client_secret".to_string(), client_secret.to_string()));
94 }
95 if !code.is_empty() {
96 query_args.push(("code".to_string(), code.to_string()));
97 }
98 if !redirect_uri.is_empty() {
99 query_args.push(("redirect_uri".to_string(), redirect_uri.to_string()));
100 }
101 if single_channel {
102 query_args.push(("single_channel".to_string(), single_channel.to_string()));
103 }
104 let query_ = serde_urlencoded::to_string(&query_args).unwrap();
105 let url = self.client.url(&format!("/oauth.token?{}", query_), None);
106 self.client
107 .get(
108 &url,
109 crate::Message {
110 body: None,
111 content_type: None,
112 },
113 )
114 .await
115 }
116}