zsgf_client/apis/
ding_talk_api.rs

1/*
2 * 全部  API 文档
3 *
4 * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
5 *
6 * The version of the OpenAPI document: v1
7 * 
8 * Generated by: https://openapi-generator.tech
9 */
10
11
12use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17
18/// struct for typed errors of method [`ding_talk_user_info`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum DingTalkUserInfoError {
22    UnknownValue(serde_json::Value),
23}
24
25
26/// 根据钉钉用户授权码获取用户的详细资料。
27pub async fn ding_talk_user_info(configuration: &configuration::Configuration, app_key: &str, code: Option<&str>) -> Result<models::StringApiResponse, Error<DingTalkUserInfoError>> {
28    // add a prefix to parameters to efficiently prevent name collisions
29    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", &param_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