clerk_sdk_rust_community/apis/
clients_api.rs

1/*
2 * Clerk Backend API
3 *
4 * The Clerk REST Backend API, meant to be accessed by backend servers. Please see https://clerk.com/docs for more information.
5 *
6 * The version of the OpenAPI document: v1
7 * Contact: support@clerk.dev
8 * Generated by: https://openapi-generator.tech
9 */
10
11
12use reqwest;
13
14use crate::apis::ResponseContent;
15use super::{Error, configuration};
16
17
18/// struct for typed errors of method [`get_client`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum GetClientError {
22    Status400(crate::models::ClerkErrors),
23    Status401(crate::models::ClerkErrors),
24    Status404(crate::models::ClerkErrors),
25    UnknownValue(serde_json::Value),
26}
27
28/// struct for typed errors of method [`get_client_last_active_session`]
29#[derive(Debug, Clone, Serialize, Deserialize)]
30#[serde(untagged)]
31pub enum GetClientLastActiveSessionError {
32    Status400(crate::models::ClerkErrors),
33    Status401(crate::models::ClerkErrors),
34    Status404(crate::models::ClerkErrors),
35    UnknownValue(serde_json::Value),
36}
37
38/// struct for typed errors of method [`get_client_list`]
39#[derive(Debug, Clone, Serialize, Deserialize)]
40#[serde(untagged)]
41pub enum GetClientListError {
42    Status400(crate::models::ClerkErrors),
43    Status401(crate::models::ClerkErrors),
44    Status422(crate::models::ClerkErrors),
45    UnknownValue(serde_json::Value),
46}
47
48/// struct for typed errors of method [`verify_client`]
49#[derive(Debug, Clone, Serialize, Deserialize)]
50#[serde(untagged)]
51pub enum VerifyClientError {
52    Status400(crate::models::ClerkErrors),
53    Status401(crate::models::ClerkErrors),
54    Status404(crate::models::ClerkErrors),
55    UnknownValue(serde_json::Value),
56}
57
58
59/// Returns the details of a client.
60pub async fn get_client(configuration: &configuration::Configuration, client_id: &str) -> Result<crate::models::Client, Error<GetClientError>> {
61    let local_var_configuration = configuration;
62
63    let local_var_client = &local_var_configuration.client;
64
65    let local_var_uri_str = format!("{}/clients/{client_id}", local_var_configuration.base_path, client_id=crate::apis::urlencode(client_id));
66    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
67
68    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
69        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
70    }
71    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
72        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
73    };
74
75    let local_var_req = local_var_req_builder.build()?;
76    let local_var_resp = local_var_client.execute(local_var_req).await?;
77
78    let local_var_status = local_var_resp.status();
79    let local_var_content = local_var_resp.text().await?;
80
81    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
82        serde_json::from_str(&local_var_content).map_err(Error::from)
83    } else {
84        let local_var_entity: Option<GetClientError> = serde_json::from_str(&local_var_content).ok();
85        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
86        Err(Error::ResponseError(local_var_error))
87    }
88}
89
90/// Returns the details of the last active session of a client.
91pub async fn get_client_last_active_session(configuration: &configuration::Configuration, client_id: &str) -> Result<crate::models::Session, Error<GetClientLastActiveSessionError>> {
92    let local_var_configuration = configuration;
93
94    let local_var_client = &local_var_configuration.client;
95
96    let local_var_uri_str = format!("{}/clients/{client_id}/last_active_session", local_var_configuration.base_path, client_id=crate::apis::urlencode(client_id));
97    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
98
99    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
100        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
101    }
102    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
103        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
104    };
105
106    let local_var_req = local_var_req_builder.build()?;
107    let local_var_resp = local_var_client.execute(local_var_req).await?;
108
109    let local_var_status = local_var_resp.status();
110    let local_var_content = local_var_resp.text().await?;
111
112    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
113        serde_json::from_str(&local_var_content).map_err(Error::from)
114    } else {
115        let local_var_entity: Option<GetClientLastActiveSessionError> = serde_json::from_str(&local_var_content).ok();
116        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
117        Err(Error::ResponseError(local_var_error))
118    }
119}
120
121/// Returns a list of all clients. The clients are returned sorted by creation date, with the newest clients appearing first.
122pub async fn get_client_list(configuration: &configuration::Configuration, limit: Option<f32>, offset: Option<f32>) -> Result<Vec<crate::models::Client>, Error<GetClientListError>> {
123    let local_var_configuration = configuration;
124
125    let local_var_client = &local_var_configuration.client;
126
127    let local_var_uri_str = format!("{}/clients", local_var_configuration.base_path);
128    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
129
130    if let Some(ref local_var_str) = limit {
131        local_var_req_builder = local_var_req_builder.query(&[("limit", &local_var_str.to_string())]);
132    }
133    if let Some(ref local_var_str) = offset {
134        local_var_req_builder = local_var_req_builder.query(&[("offset", &local_var_str.to_string())]);
135    }
136    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
137        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
138    }
139    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
140        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
141    };
142
143    let local_var_req = local_var_req_builder.build()?;
144    let local_var_resp = local_var_client.execute(local_var_req).await?;
145
146    let local_var_status = local_var_resp.status();
147    let local_var_content = local_var_resp.text().await?;
148
149    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
150        serde_json::from_str(&local_var_content).map_err(Error::from)
151    } else {
152        let local_var_entity: Option<GetClientListError> = serde_json::from_str(&local_var_content).ok();
153        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
154        Err(Error::ResponseError(local_var_error))
155    }
156}
157
158/// Verifies the client in the provided token
159pub async fn verify_client(configuration: &configuration::Configuration, verify_client_request: Option<crate::models::VerifyClientRequest>) -> Result<crate::models::Client, Error<VerifyClientError>> {
160    let local_var_configuration = configuration;
161
162    let local_var_client = &local_var_configuration.client;
163
164    let local_var_uri_str = format!("{}/clients/verify", local_var_configuration.base_path);
165    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
166
167    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
168        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
169    }
170    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
171        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
172    };
173    local_var_req_builder = local_var_req_builder.json(&verify_client_request);
174
175    let local_var_req = local_var_req_builder.build()?;
176    let local_var_resp = local_var_client.execute(local_var_req).await?;
177
178    let local_var_status = local_var_resp.status();
179    let local_var_content = local_var_resp.text().await?;
180
181    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
182        serde_json::from_str(&local_var_content).map_err(Error::from)
183    } else {
184        let local_var_entity: Option<VerifyClientError> = serde_json::from_str(&local_var_content).ok();
185        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
186        Err(Error::ResponseError(local_var_error))
187    }
188}
189