bitwarden_api_api/apis/
phishing_domains_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::{de::Error as _, Deserialize, Serialize};
13
14use super::{configuration, ContentType, Error};
15use crate::{apis::ResponseContent, models};
16
17/// struct for typed errors of method [`phishing_domains_checksum_get`]
18#[derive(Debug, Clone, Serialize, Deserialize)]
19#[serde(untagged)]
20pub enum PhishingDomainsChecksumGetError {
21    UnknownValue(serde_json::Value),
22}
23
24/// struct for typed errors of method [`phishing_domains_get`]
25#[derive(Debug, Clone, Serialize, Deserialize)]
26#[serde(untagged)]
27pub enum PhishingDomainsGetError {
28    UnknownValue(serde_json::Value),
29}
30
31pub async fn phishing_domains_checksum_get(
32    configuration: &configuration::Configuration,
33) -> Result<String, Error<PhishingDomainsChecksumGetError>> {
34    let uri_str = format!("{}/phishing-domains/checksum", configuration.base_path);
35    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
36
37    if let Some(ref user_agent) = configuration.user_agent {
38        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
39    }
40    if let Some(ref token) = configuration.oauth_access_token {
41        req_builder = req_builder.bearer_auth(token.to_owned());
42    };
43
44    let req = req_builder.build()?;
45    let resp = configuration.client.execute(req).await?;
46
47    let status = resp.status();
48    let content_type = resp
49        .headers()
50        .get("content-type")
51        .and_then(|v| v.to_str().ok())
52        .unwrap_or("application/octet-stream");
53    let content_type = super::ContentType::from(content_type);
54
55    if !status.is_client_error() && !status.is_server_error() {
56        let content = resp.text().await?;
57        match content_type {
58            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
59            ContentType::Text => return Ok(content),
60            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `String`")))),
61        }
62    } else {
63        let content = resp.text().await?;
64        let entity: Option<PhishingDomainsChecksumGetError> = serde_json::from_str(&content).ok();
65        Err(Error::ResponseError(ResponseContent {
66            status,
67            content,
68            entity,
69        }))
70    }
71}
72
73pub async fn phishing_domains_get(
74    configuration: &configuration::Configuration,
75) -> Result<Vec<String>, Error<PhishingDomainsGetError>> {
76    let uri_str = format!("{}/phishing-domains", configuration.base_path);
77    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
78
79    if let Some(ref user_agent) = configuration.user_agent {
80        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
81    }
82    if let Some(ref token) = configuration.oauth_access_token {
83        req_builder = req_builder.bearer_auth(token.to_owned());
84    };
85
86    let req = req_builder.build()?;
87    let resp = configuration.client.execute(req).await?;
88
89    let status = resp.status();
90    let content_type = resp
91        .headers()
92        .get("content-type")
93        .and_then(|v| v.to_str().ok())
94        .unwrap_or("application/octet-stream");
95    let content_type = super::ContentType::from(content_type);
96
97    if !status.is_client_error() && !status.is_server_error() {
98        let content = resp.text().await?;
99        match content_type {
100            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
101            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec&lt;String&gt;`"))),
102            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `Vec&lt;String&gt;`")))),
103        }
104    } else {
105        let content = resp.text().await?;
106        let entity: Option<PhishingDomainsGetError> = serde_json::from_str(&content).ok();
107        Err(Error::ResponseError(ResponseContent {
108            status,
109            content,
110            entity,
111        }))
112    }
113}