Skip to main content

ark_rest/apis/
signer_manager_service_api.rs

1/*
2 * Ark API
3 *
4 * Combined Ark Service, Indexer, Admin, Signer Manager, and Wallet API
5 *
6 * The version of the OpenAPI document: 1.0.0
7 *
8 * Generated by: https://openapi-generator.tech
9 */
10
11use super::configuration;
12use super::ContentType;
13use super::Error;
14use crate::apis::ResponseContent;
15use crate::models;
16use reqwest;
17use serde::de::Error as _;
18use serde::Deserialize;
19use serde::Serialize;
20
21/// struct for typed errors of method [`signer_manager_service_load_signer`]
22#[derive(Debug, Clone, Serialize, Deserialize)]
23#[serde(untagged)]
24pub enum SignerManagerServiceLoadSignerError {
25    DefaultResponse(models::Status),
26    UnknownValue(serde_json::Value),
27}
28
29pub async fn signer_manager_service_load_signer(
30    configuration: &configuration::Configuration,
31    load_signer_request: models::LoadSignerRequest,
32) -> Result<serde_json::Value, Error<SignerManagerServiceLoadSignerError>> {
33    // add a prefix to parameters to efficiently prevent name collisions
34    let p_load_signer_request = load_signer_request;
35
36    let uri_str = format!("{}/v1/admin/signer", configuration.base_path);
37    let mut req_builder = configuration
38        .client
39        .request(reqwest::Method::POST, &uri_str);
40
41    if let Some(ref user_agent) = configuration.user_agent {
42        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
43    }
44    req_builder = req_builder.json(&p_load_signer_request);
45
46    let req = req_builder.build()?;
47    let resp = configuration.client.execute(req).await?;
48
49    let status = resp.status();
50    let content_type = resp
51        .headers()
52        .get("content-type")
53        .and_then(|v| v.to_str().ok())
54        .unwrap_or("application/octet-stream");
55    let content_type = super::ContentType::from(content_type);
56
57    if !status.is_client_error() && !status.is_server_error() {
58        let content = resp.text().await?;
59        match content_type {
60            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
61            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `serde_json::Value`"))),
62            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `serde_json::Value`")))),
63        }
64    } else {
65        let content = resp.text().await?;
66        let entity: Option<SignerManagerServiceLoadSignerError> =
67            serde_json::from_str(&content).ok();
68        Err(Error::ResponseError(ResponseContent {
69            status,
70            content,
71            entity,
72        }))
73    }
74}