print_nanny_client/apis/
users_api.rs

1/*
2 * print-nanny-client
3 *
4 * Official API client library for print-nanny.com
5 *
6 * The version of the OpenAPI document: 0.0.0
7 * Contact: leigh@print-nanny.com
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 [`users_list`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum UsersListError {
22    UnknownValue(serde_json::Value),
23}
24
25/// struct for typed errors of method [`users_me_retrieve`]
26#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(untagged)]
28pub enum UsersMeRetrieveError {
29    UnknownValue(serde_json::Value),
30}
31
32/// struct for typed errors of method [`users_partial_update`]
33#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum UsersPartialUpdateError {
36    UnknownValue(serde_json::Value),
37}
38
39/// struct for typed errors of method [`users_retrieve`]
40#[derive(Debug, Clone, Serialize, Deserialize)]
41#[serde(untagged)]
42pub enum UsersRetrieveError {
43    UnknownValue(serde_json::Value),
44}
45
46/// struct for typed errors of method [`users_update`]
47#[derive(Debug, Clone, Serialize, Deserialize)]
48#[serde(untagged)]
49pub enum UsersUpdateError {
50    UnknownValue(serde_json::Value),
51}
52
53
54pub async fn users_list(configuration: &configuration::Configuration, page: Option<i32>) -> Result<crate::models::PaginatedUserList, Error<UsersListError>> {
55    let local_var_configuration = configuration;
56
57    let local_var_client = &local_var_configuration.client;
58
59    let local_var_uri_str = format!("{}/api/users/", local_var_configuration.base_path);
60    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
61
62    if let Some(ref local_var_str) = page {
63        local_var_req_builder = local_var_req_builder.query(&[("page", &local_var_str.to_string())]);
64    }
65    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
66        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
67    }
68    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
69        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
70    };
71
72    let local_var_req = local_var_req_builder.build()?;
73    let local_var_resp = local_var_client.execute(local_var_req).await?;
74
75    let local_var_status = local_var_resp.status();
76    let local_var_content = local_var_resp.text().await?;
77
78    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
79        serde_json::from_str(&local_var_content).map_err(Error::from)
80    } else {
81        let local_var_entity: Option<UsersListError> = serde_json::from_str(&local_var_content).ok();
82        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
83        Err(Error::ResponseError(local_var_error))
84    }
85}
86
87pub async fn users_me_retrieve(configuration: &configuration::Configuration, ) -> Result<crate::models::User, Error<UsersMeRetrieveError>> {
88    let local_var_configuration = configuration;
89
90    let local_var_client = &local_var_configuration.client;
91
92    let local_var_uri_str = format!("{}/api/users/me/", local_var_configuration.base_path);
93    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
94
95    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
96        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
97    }
98    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
99        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
100    };
101
102    let local_var_req = local_var_req_builder.build()?;
103    let local_var_resp = local_var_client.execute(local_var_req).await?;
104
105    let local_var_status = local_var_resp.status();
106    let local_var_content = local_var_resp.text().await?;
107
108    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
109        serde_json::from_str(&local_var_content).map_err(Error::from)
110    } else {
111        let local_var_entity: Option<UsersMeRetrieveError> = serde_json::from_str(&local_var_content).ok();
112        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
113        Err(Error::ResponseError(local_var_error))
114    }
115}
116
117pub async fn users_partial_update(configuration: &configuration::Configuration, id: i32, patched_user_request: Option<crate::models::PatchedUserRequest>) -> Result<crate::models::User, Error<UsersPartialUpdateError>> {
118    let local_var_configuration = configuration;
119
120    let local_var_client = &local_var_configuration.client;
121
122    let local_var_uri_str = format!("{}/api/users/{id}/", local_var_configuration.base_path, id=id);
123    let mut local_var_req_builder = local_var_client.request(reqwest::Method::PATCH, local_var_uri_str.as_str());
124
125    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
126        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
127    }
128    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
129        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
130    };
131    local_var_req_builder = local_var_req_builder.json(&patched_user_request);
132
133    let local_var_req = local_var_req_builder.build()?;
134    let local_var_resp = local_var_client.execute(local_var_req).await?;
135
136    let local_var_status = local_var_resp.status();
137    let local_var_content = local_var_resp.text().await?;
138
139    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
140        serde_json::from_str(&local_var_content).map_err(Error::from)
141    } else {
142        let local_var_entity: Option<UsersPartialUpdateError> = serde_json::from_str(&local_var_content).ok();
143        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
144        Err(Error::ResponseError(local_var_error))
145    }
146}
147
148pub async fn users_retrieve(configuration: &configuration::Configuration, id: i32) -> Result<crate::models::User, Error<UsersRetrieveError>> {
149    let local_var_configuration = configuration;
150
151    let local_var_client = &local_var_configuration.client;
152
153    let local_var_uri_str = format!("{}/api/users/{id}/", local_var_configuration.base_path, id=id);
154    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
155
156    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
157        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
158    }
159    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
160        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
161    };
162
163    let local_var_req = local_var_req_builder.build()?;
164    let local_var_resp = local_var_client.execute(local_var_req).await?;
165
166    let local_var_status = local_var_resp.status();
167    let local_var_content = local_var_resp.text().await?;
168
169    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
170        serde_json::from_str(&local_var_content).map_err(Error::from)
171    } else {
172        let local_var_entity: Option<UsersRetrieveError> = serde_json::from_str(&local_var_content).ok();
173        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
174        Err(Error::ResponseError(local_var_error))
175    }
176}
177
178pub async fn users_update(configuration: &configuration::Configuration, id: i32, user_request: crate::models::UserRequest) -> Result<crate::models::User, Error<UsersUpdateError>> {
179    let local_var_configuration = configuration;
180
181    let local_var_client = &local_var_configuration.client;
182
183    let local_var_uri_str = format!("{}/api/users/{id}/", local_var_configuration.base_path, id=id);
184    let mut local_var_req_builder = local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
185
186    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
187        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
188    }
189    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
190        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
191    };
192    local_var_req_builder = local_var_req_builder.json(&user_request);
193
194    let local_var_req = local_var_req_builder.build()?;
195    let local_var_resp = local_var_client.execute(local_var_req).await?;
196
197    let local_var_status = local_var_resp.status();
198    let local_var_content = local_var_resp.text().await?;
199
200    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
201        serde_json::from_str(&local_var_content).map_err(Error::from)
202    } else {
203        let local_var_entity: Option<UsersUpdateError> = serde_json::from_str(&local_var_content).ok();
204        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
205        Err(Error::ResponseError(local_var_error))
206    }
207}
208