bitwarden_api_api/apis/
import_ciphers_api.rs

1/*
2 * Bitwarden Internal API
3 *
4 * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
5 *
6 * The version of the OpenAPI document: latest
7 *
8 * Generated by: https://openapi-generator.tech
9 */
10
11use reqwest;
12use serde::{Deserialize, Serialize};
13
14use super::{configuration, Error};
15use crate::{apis::ResponseContent, models};
16
17/// struct for typed errors of method [`ciphers_import_organization_post`]
18#[derive(Debug, Clone, Serialize, Deserialize)]
19#[serde(untagged)]
20pub enum CiphersImportOrganizationPostError {
21    UnknownValue(serde_json::Value),
22}
23
24/// struct for typed errors of method [`ciphers_import_post`]
25#[derive(Debug, Clone, Serialize, Deserialize)]
26#[serde(untagged)]
27pub enum CiphersImportPostError {
28    UnknownValue(serde_json::Value),
29}
30
31pub async fn ciphers_import_organization_post(
32    configuration: &configuration::Configuration,
33    organization_id: Option<&str>,
34    import_organization_ciphers_request_model: Option<
35        models::ImportOrganizationCiphersRequestModel,
36    >,
37) -> Result<(), Error<CiphersImportOrganizationPostError>> {
38    let local_var_configuration = configuration;
39
40    let local_var_client = &local_var_configuration.client;
41
42    let local_var_uri_str = format!(
43        "{}/ciphers/import-organization",
44        local_var_configuration.base_path
45    );
46    let mut local_var_req_builder =
47        local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
48
49    if let Some(ref local_var_str) = organization_id {
50        local_var_req_builder =
51            local_var_req_builder.query(&[("organizationId", &local_var_str.to_string())]);
52    }
53    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
54        local_var_req_builder =
55            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
56    }
57    if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
58        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
59    };
60    local_var_req_builder = local_var_req_builder.json(&import_organization_ciphers_request_model);
61
62    let local_var_req = local_var_req_builder.build()?;
63    let local_var_resp = local_var_client.execute(local_var_req).await?;
64
65    let local_var_status = local_var_resp.status();
66    let local_var_content = local_var_resp.text().await?;
67
68    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
69        Ok(())
70    } else {
71        let local_var_entity: Option<CiphersImportOrganizationPostError> =
72            serde_json::from_str(&local_var_content).ok();
73        let local_var_error = ResponseContent {
74            status: local_var_status,
75            content: local_var_content,
76            entity: local_var_entity,
77        };
78        Err(Error::ResponseError(local_var_error))
79    }
80}
81
82pub async fn ciphers_import_post(
83    configuration: &configuration::Configuration,
84    import_ciphers_request_model: Option<models::ImportCiphersRequestModel>,
85) -> Result<(), Error<CiphersImportPostError>> {
86    let local_var_configuration = configuration;
87
88    let local_var_client = &local_var_configuration.client;
89
90    let local_var_uri_str = format!("{}/ciphers/import", local_var_configuration.base_path);
91    let mut local_var_req_builder =
92        local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
93
94    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
95        local_var_req_builder =
96            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.oauth_access_token {
99        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
100    };
101    local_var_req_builder = local_var_req_builder.json(&import_ciphers_request_model);
102
103    let local_var_req = local_var_req_builder.build()?;
104    let local_var_resp = local_var_client.execute(local_var_req).await?;
105
106    let local_var_status = local_var_resp.status();
107    let local_var_content = local_var_resp.text().await?;
108
109    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
110        Ok(())
111    } else {
112        let local_var_entity: Option<CiphersImportPostError> =
113            serde_json::from_str(&local_var_content).ok();
114        let local_var_error = ResponseContent {
115            status: local_var_status,
116            content: local_var_content,
117            entity: local_var_entity,
118        };
119        Err(Error::ResponseError(local_var_error))
120    }
121}