bitwarden_api_api/apis/
mod.rs

1use std::{error, fmt};
2
3#[derive(Debug, Clone)]
4pub struct ResponseContent<T> {
5    pub status: reqwest::StatusCode,
6    pub content: String,
7    pub entity: Option<T>,
8}
9
10#[derive(Debug)]
11pub enum Error<T> {
12    Reqwest(reqwest::Error),
13    Serde(serde_json::Error),
14    Io(std::io::Error),
15    ResponseError(ResponseContent<T>),
16}
17
18impl<T> fmt::Display for Error<T> {
19    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
20        let (module, e) = match self {
21            Error::Reqwest(e) => ("reqwest", e.to_string()),
22            Error::Serde(e) => ("serde", e.to_string()),
23            Error::Io(e) => ("IO", e.to_string()),
24            Error::ResponseError(e) => ("response", format!("status code {}", e.status)),
25        };
26        write!(f, "error in {}: {}", module, e)
27    }
28}
29
30impl<T: fmt::Debug> error::Error for Error<T> {
31    fn source(&self) -> Option<&(dyn error::Error + 'static)> {
32        Some(match self {
33            Error::Reqwest(e) => e,
34            Error::Serde(e) => e,
35            Error::Io(e) => e,
36            Error::ResponseError(_) => return None,
37        })
38    }
39}
40
41impl<T> From<reqwest::Error> for Error<T> {
42    fn from(e: reqwest::Error) -> Self {
43        Error::Reqwest(e)
44    }
45}
46
47impl<T> From<serde_json::Error> for Error<T> {
48    fn from(e: serde_json::Error) -> Self {
49        Error::Serde(e)
50    }
51}
52
53impl<T> From<std::io::Error> for Error<T> {
54    fn from(e: std::io::Error) -> Self {
55        Error::Io(e)
56    }
57}
58
59pub fn urlencode<T: AsRef<str>>(s: T) -> String {
60    ::url::form_urlencoded::byte_serialize(s.as_ref().as_bytes()).collect()
61}
62
63pub fn parse_deep_object(prefix: &str, value: &serde_json::Value) -> Vec<(String, String)> {
64    if let serde_json::Value::Object(object) = value {
65        let mut params = vec![];
66
67        for (key, value) in object {
68            match value {
69                serde_json::Value::Object(_) => params.append(&mut parse_deep_object(
70                    &format!("{}[{}]", prefix, key),
71                    value,
72                )),
73                serde_json::Value::Array(array) => {
74                    for (i, value) in array.iter().enumerate() {
75                        params.append(&mut parse_deep_object(
76                            &format!("{}[{}][{}]", prefix, key, i),
77                            value,
78                        ));
79                    }
80                }
81                serde_json::Value::String(s) => {
82                    params.push((format!("{}[{}]", prefix, key), s.clone()))
83                }
84                _ => params.push((format!("{}[{}]", prefix, key), value.to_string())),
85            }
86        }
87
88        return params;
89    }
90
91    unimplemented!("Only objects are supported with style=deepObject")
92}
93
94pub mod access_policies_api;
95pub mod accounts_api;
96pub mod accounts_billing_api;
97pub mod accounts_key_management_api;
98pub mod auth_requests_api;
99pub mod ciphers_api;
100pub mod collections_api;
101pub mod config_api;
102pub mod counts_api;
103pub mod devices_api;
104pub mod emergency_access_api;
105pub mod events_api;
106pub mod folders_api;
107pub mod groups_api;
108pub mod hibp_api;
109pub mod import_ciphers_api;
110pub mod info_api;
111pub mod installations_api;
112pub mod invoices_api;
113pub mod licenses_api;
114pub mod misc_api;
115pub mod notifications_api;
116pub mod organization_auth_requests_api;
117pub mod organization_billing_api;
118pub mod organization_connections_api;
119pub mod organization_domain_api;
120pub mod organization_export_api;
121pub mod organization_sponsorships_api;
122pub mod organization_users_api;
123pub mod organizations_api;
124pub mod plans_api;
125pub mod policies_api;
126pub mod projects_api;
127pub mod provider_billing_api;
128pub mod provider_clients_api;
129pub mod provider_organizations_api;
130pub mod provider_users_api;
131pub mod providers_api;
132pub mod push_api;
133pub mod reports_api;
134pub mod request_sm_access_api;
135pub mod secrets_api;
136pub mod secrets_manager_events_api;
137pub mod secrets_manager_porting_api;
138pub mod security_task_api;
139pub mod self_hosted_organization_licenses_api;
140pub mod self_hosted_organization_sponsorships_api;
141pub mod sends_api;
142pub mod service_accounts_api;
143pub mod settings_api;
144pub mod stripe_api;
145pub mod sync_api;
146pub mod trash_api;
147pub mod two_factor_api;
148pub mod users_api;
149pub mod web_authn_api;
150
151pub mod configuration;