btcpay_client/apis/
authorization_api.rs

1/*
2 * BTCPay Greenfield API
3 *
4 * A full API to use your BTCPay Server
5 *
6 * The version of the OpenAPI document: v1
7 * 
8 * Generated by: https://openapi-generator.tech
9 */
10
11
12use reqwest;
13
14use crate::apis::ResponseContent;
15use super::{Error, configuration};
16
17
18/// struct for typed errors of method [`api_keys_authorize`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum ApiKeysAuthorizeError {
22    UnknownValue(serde_json::Value),
23}
24
25
26/// Redirect the browser to this endpoint to request the user to generate an api-key with specific permissions
27pub async fn api_keys_authorize(configuration: &configuration::Configuration, permissions: Option<Vec<String>>, application_name: Option<&str>, strict: Option<bool>, selective_stores: Option<bool>, redirect: Option<&str>, application_identifier: Option<&str>) -> Result<(), Error<ApiKeysAuthorizeError>> {
28    let local_var_configuration = configuration;
29
30    let local_var_client = &local_var_configuration.client;
31
32    let local_var_uri_str = format!("{}/api-keys/authorize", local_var_configuration.base_path);
33    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
34
35    if let Some(ref local_var_str) = permissions {
36        local_var_req_builder = match "multi" {
37            "multi" => local_var_req_builder.query(&local_var_str.into_iter().map(|p| ("permissions".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
38            _ => local_var_req_builder.query(&[("permissions", &local_var_str.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
39        };
40    }
41    if let Some(ref local_var_str) = application_name {
42        local_var_req_builder = local_var_req_builder.query(&[("applicationName", &local_var_str.to_string())]);
43    }
44    if let Some(ref local_var_str) = strict {
45        local_var_req_builder = local_var_req_builder.query(&[("strict", &local_var_str.to_string())]);
46    }
47    if let Some(ref local_var_str) = selective_stores {
48        local_var_req_builder = local_var_req_builder.query(&[("selectiveStores", &local_var_str.to_string())]);
49    }
50    if let Some(ref local_var_str) = redirect {
51        local_var_req_builder = local_var_req_builder.query(&[("redirect", &local_var_str.to_string())]);
52    }
53    if let Some(ref local_var_str) = application_identifier {
54        local_var_req_builder = local_var_req_builder.query(&[("applicationIdentifier", &local_var_str.to_string())]);
55    }
56    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
57        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
58    }
59
60    let local_var_req = local_var_req_builder.build()?;
61    let local_var_resp = local_var_client.execute(local_var_req).await?;
62
63    let local_var_status = local_var_resp.status();
64    let local_var_content = local_var_resp.text().await?;
65
66    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
67        Ok(())
68    } else {
69        let local_var_entity: Option<ApiKeysAuthorizeError> = serde_json::from_str(&local_var_content).ok();
70        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
71        Err(Error::ResponseError(local_var_error))
72    }
73}
74