nile_client_rs/apis/
developers_api.rs

1/*
2 * Nile API
3 *
4 * Making SaaS chill.
5 *
6 * The version of the OpenAPI document: 0.1.0-fdd7cd5
7 * Contact: support@thenile.dev
8 * Generated by: https://openapi-generator.tech
9 */
10
11use reqwest;
12use serde::{Deserialize, Serialize};
13
14use super::{configuration, Error};
15use crate::apis::ResponseContent;
16
17/// struct for typed errors of method [`create_developer`]
18#[derive(Debug, Clone, Serialize, Deserialize)]
19#[serde(untagged)]
20pub enum CreateDeveloperError {
21    UnknownValue(serde_json::Value),
22}
23
24/// struct for typed errors of method [`developer_google_o_auth_callback`]
25#[derive(Debug, Clone, Serialize, Deserialize)]
26#[serde(untagged)]
27pub enum DeveloperGoogleOAuthCallbackError {
28    UnknownValue(serde_json::Value),
29}
30
31/// struct for typed errors of method [`login_developer`]
32#[derive(Debug, Clone, Serialize, Deserialize)]
33#[serde(untagged)]
34pub enum LoginDeveloperError {
35    Status401(crate::models::Error),
36    UnknownValue(serde_json::Value),
37}
38
39/// struct for typed errors of method [`start_developer_google_o_auth`]
40#[derive(Debug, Clone, Serialize, Deserialize)]
41#[serde(untagged)]
42pub enum StartDeveloperGoogleOAuthError {
43    UnknownValue(serde_json::Value),
44}
45
46/// struct for typed errors of method [`validate_developer`]
47#[derive(Debug, Clone, Serialize, Deserialize)]
48#[serde(untagged)]
49pub enum ValidateDeveloperError {
50    Status400(crate::models::Error),
51    UnknownValue(serde_json::Value),
52}
53
54pub async fn create_developer(
55    configuration: &configuration::Configuration,
56    create_user_request: crate::models::CreateUserRequest,
57) -> Result<crate::models::User, Error<CreateDeveloperError>> {
58    let local_var_configuration = configuration;
59
60    let local_var_client = &local_var_configuration.client;
61
62    let local_var_uri_str = format!("{}/developers", local_var_configuration.base_path);
63    let mut local_var_req_builder =
64        local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
65
66    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
67        local_var_req_builder =
68            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
69    }
70    local_var_req_builder = local_var_req_builder.json(&create_user_request);
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<CreateDeveloperError> =
82            serde_json::from_str(&local_var_content).ok();
83        let local_var_error = ResponseContent {
84            status: local_var_status,
85            content: local_var_content,
86            entity: local_var_entity,
87        };
88        Err(Error::ResponseError(local_var_error))
89    }
90}
91
92/// This endpoint is called automatically by Google after the user authenticates successfully. It's here for documentation purposes only, and it shouldn't be called directly.
93pub async fn developer_google_o_auth_callback(
94    configuration: &configuration::Configuration,
95    code: Option<&str>,
96    state: Option<&str>,
97) -> Result<crate::models::DeveloperGoogleOAuthResponse, Error<DeveloperGoogleOAuthCallbackError>> {
98    let local_var_configuration = configuration;
99
100    let local_var_client = &local_var_configuration.client;
101
102    let local_var_uri_str = format!(
103        "{}/auth/oauth/google/callback",
104        local_var_configuration.base_path
105    );
106    let mut local_var_req_builder =
107        local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
108
109    if let Some(ref local_var_str) = code {
110        local_var_req_builder =
111            local_var_req_builder.query(&[("code", &local_var_str.to_string())]);
112    }
113    if let Some(ref local_var_str) = state {
114        local_var_req_builder =
115            local_var_req_builder.query(&[("state", &local_var_str.to_string())]);
116    }
117    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
118        local_var_req_builder =
119            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
120    }
121
122    let local_var_req = local_var_req_builder.build()?;
123    let local_var_resp = local_var_client.execute(local_var_req).await?;
124
125    let local_var_status = local_var_resp.status();
126    let local_var_content = local_var_resp.text().await?;
127
128    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
129        serde_json::from_str(&local_var_content).map_err(Error::from)
130    } else {
131        let local_var_entity: Option<DeveloperGoogleOAuthCallbackError> =
132            serde_json::from_str(&local_var_content).ok();
133        let local_var_error = ResponseContent {
134            status: local_var_status,
135            content: local_var_content,
136            entity: local_var_entity,
137        };
138        Err(Error::ResponseError(local_var_error))
139    }
140}
141
142pub async fn login_developer(
143    configuration: &configuration::Configuration,
144    login_info: crate::models::LoginInfo,
145) -> Result<crate::models::Token, Error<LoginDeveloperError>> {
146    let local_var_configuration = configuration;
147
148    let local_var_client = &local_var_configuration.client;
149
150    let local_var_uri_str = format!("{}/auth/login", local_var_configuration.base_path);
151    let mut local_var_req_builder =
152        local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
153
154    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
155        local_var_req_builder =
156            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
157    }
158    local_var_req_builder = local_var_req_builder.json(&login_info);
159
160    let local_var_req = local_var_req_builder.build()?;
161    let local_var_resp = local_var_client.execute(local_var_req).await?;
162
163    let local_var_status = local_var_resp.status();
164    let local_var_content = local_var_resp.text().await?;
165
166    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
167        serde_json::from_str(&local_var_content).map_err(Error::from)
168    } else {
169        let local_var_entity: Option<LoginDeveloperError> =
170            serde_json::from_str(&local_var_content).ok();
171        let local_var_error = ResponseContent {
172            status: local_var_status,
173            content: local_var_content,
174            entity: local_var_entity,
175        };
176        Err(Error::ResponseError(local_var_error))
177    }
178}
179
180pub async fn start_developer_google_o_auth(
181    configuration: &configuration::Configuration,
182    redirect_to: Option<&str>,
183) -> Result<(), Error<StartDeveloperGoogleOAuthError>> {
184    let local_var_configuration = configuration;
185
186    let local_var_client = &local_var_configuration.client;
187
188    let local_var_uri_str = format!("{}/auth/oauth/google", local_var_configuration.base_path);
189    let mut local_var_req_builder =
190        local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
191
192    if let Some(ref local_var_str) = redirect_to {
193        local_var_req_builder =
194            local_var_req_builder.query(&[("redirect_to", &local_var_str.to_string())]);
195    }
196    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
197        local_var_req_builder =
198            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
199    }
200
201    let local_var_req = local_var_req_builder.build()?;
202    let local_var_resp = local_var_client.execute(local_var_req).await?;
203
204    let local_var_status = local_var_resp.status();
205    let local_var_content = local_var_resp.text().await?;
206
207    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
208        Ok(())
209    } else {
210        let local_var_entity: Option<StartDeveloperGoogleOAuthError> =
211            serde_json::from_str(&local_var_content).ok();
212        let local_var_error = ResponseContent {
213            status: local_var_status,
214            content: local_var_content,
215            entity: local_var_entity,
216        };
217        Err(Error::ResponseError(local_var_error))
218    }
219}
220
221pub async fn validate_developer(
222    configuration: &configuration::Configuration,
223    token: crate::models::Token,
224) -> Result<(), Error<ValidateDeveloperError>> {
225    let local_var_configuration = configuration;
226
227    let local_var_client = &local_var_configuration.client;
228
229    let local_var_uri_str = format!("{}/auth/validate", local_var_configuration.base_path);
230    let mut local_var_req_builder =
231        local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
232
233    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
234        local_var_req_builder =
235            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
236    }
237    local_var_req_builder = local_var_req_builder.json(&token);
238
239    let local_var_req = local_var_req_builder.build()?;
240    let local_var_resp = local_var_client.execute(local_var_req).await?;
241
242    let local_var_status = local_var_resp.status();
243    let local_var_content = local_var_resp.text().await?;
244
245    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
246        Ok(())
247    } else {
248        let local_var_entity: Option<ValidateDeveloperError> =
249            serde_json::from_str(&local_var_content).ok();
250        let local_var_error = ResponseContent {
251            status: local_var_status,
252            content: local_var_content,
253            entity: local_var_entity,
254        };
255        Err(Error::ResponseError(local_var_error))
256    }
257}