zsgf_client/apis/
ding_talk_api.rs1use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17
18#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum DingTalkUserInfoError {
22 UnknownValue(serde_json::Value),
23}
24
25
26pub async fn ding_talk_user_info(configuration: &configuration::Configuration, app_key: &str, code: Option<&str>) -> Result<models::StringApiResponse, Error<DingTalkUserInfoError>> {
28 let p_app_key = app_key;
30 let p_code = code;
31
32 let uri_str = format!("{}/DingTalk/{appKey}/UserInfo", configuration.base_path, appKey=crate::apis::urlencode(p_app_key));
33 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
34
35 if let Some(ref param_value) = p_code {
36 req_builder = req_builder.query(&[("code", ¶m_value.to_string())]);
37 }
38 if let Some(ref user_agent) = configuration.user_agent {
39 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
40 }
41 if let Some(ref token) = configuration.bearer_access_token {
42 req_builder = req_builder.bearer_auth(token.to_owned());
43 };
44
45 let req = req_builder.build()?;
46 let resp = configuration.client.execute(req).await?;
47
48 let status = resp.status();
49 let content_type = resp
50 .headers()
51 .get("content-type")
52 .and_then(|v| v.to_str().ok())
53 .unwrap_or("application/octet-stream");
54 let content_type = super::ContentType::from(content_type);
55
56 if !status.is_client_error() && !status.is_server_error() {
57 let content = resp.text().await?;
58 match content_type {
59 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
60 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::StringApiResponse`"))),
61 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::StringApiResponse`")))),
62 }
63 } else {
64 let content = resp.text().await?;
65 let entity: Option<DingTalkUserInfoError> = serde_json::from_str(&content).ok();
66 Err(Error::ResponseError(ResponseContent { status, content, entity }))
67 }
68}
69