btcpay_client/apis/
api_keys_api.rs1use reqwest;
13
14use crate::apis::ResponseContent;
15use super::{Error, configuration};
16
17
18#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum ApiKeysCreateApiKeyError {
22 UnknownValue(serde_json::Value),
23}
24
25#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(untagged)]
28pub enum ApiKeysDeleteApiKeyError {
29 Status404(),
30 UnknownValue(serde_json::Value),
31}
32
33#[derive(Debug, Clone, Serialize, Deserialize)]
35#[serde(untagged)]
36pub enum ApiKeysDeleteCurrentApiKeyError {
37 UnknownValue(serde_json::Value),
38}
39
40#[derive(Debug, Clone, Serialize, Deserialize)]
42#[serde(untagged)]
43pub enum ApiKeysGetCurrentApiKeyError {
44 UnknownValue(serde_json::Value),
45}
46
47
48pub async fn api_keys_create_api_key(configuration: &configuration::Configuration, api_keys_create_api_key_request: Option<crate::models::ApiKeysCreateApiKeyRequest>) -> Result<crate::models::ApiKeyData, Error<ApiKeysCreateApiKeyError>> {
50 let local_var_configuration = configuration;
51
52 let local_var_client = &local_var_configuration.client;
53
54 let local_var_uri_str = format!("{}/api/v1/api-keys", local_var_configuration.base_path);
55 let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
56
57 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
58 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
59 }
60 if let Some(ref local_var_apikey) = local_var_configuration.api_key {
61 let local_var_key = local_var_apikey.key.clone();
62 let local_var_value = match local_var_apikey.prefix {
63 Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
64 None => local_var_key,
65 };
66 local_var_req_builder = local_var_req_builder.header("Authorization", local_var_value);
67 };
68 if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
69 local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
70 };
71 local_var_req_builder = local_var_req_builder.json(&api_keys_create_api_key_request);
72
73 let local_var_req = local_var_req_builder.build()?;
74 let local_var_resp = local_var_client.execute(local_var_req).await?;
75
76 let local_var_status = local_var_resp.status();
77 let local_var_content = local_var_resp.text().await?;
78
79 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
80 serde_json::from_str(&local_var_content).map_err(Error::from)
81 } else {
82 let local_var_entity: Option<ApiKeysCreateApiKeyError> = serde_json::from_str(&local_var_content).ok();
83 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
84 Err(Error::ResponseError(local_var_error))
85 }
86}
87
88pub async fn api_keys_delete_api_key(configuration: &configuration::Configuration, apikey: &str) -> Result<(), Error<ApiKeysDeleteApiKeyError>> {
90 let local_var_configuration = configuration;
91
92 let local_var_client = &local_var_configuration.client;
93
94 let local_var_uri_str = format!("{}/api/v1/api-keys/{apikey}", local_var_configuration.base_path, apikey=crate::apis::urlencode(apikey));
95 let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
96
97 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
98 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
99 }
100 if let Some(ref local_var_apikey) = local_var_configuration.api_key {
101 let local_var_key = local_var_apikey.key.clone();
102 let local_var_value = match local_var_apikey.prefix {
103 Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
104 None => local_var_key,
105 };
106 local_var_req_builder = local_var_req_builder.header("Authorization", local_var_value);
107 };
108 if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
109 local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
110 };
111
112 let local_var_req = local_var_req_builder.build()?;
113 let local_var_resp = local_var_client.execute(local_var_req).await?;
114
115 let local_var_status = local_var_resp.status();
116 let local_var_content = local_var_resp.text().await?;
117
118 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
119 Ok(())
120 } else {
121 let local_var_entity: Option<ApiKeysDeleteApiKeyError> = serde_json::from_str(&local_var_content).ok();
122 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
123 Err(Error::ResponseError(local_var_error))
124 }
125}
126
127pub async fn api_keys_delete_current_api_key(configuration: &configuration::Configuration, ) -> Result<crate::models::ApiKeyData, Error<ApiKeysDeleteCurrentApiKeyError>> {
129 let local_var_configuration = configuration;
130
131 let local_var_client = &local_var_configuration.client;
132
133 let local_var_uri_str = format!("{}/api/v1/api-keys/current", local_var_configuration.base_path);
134 let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
135
136 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
137 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
138 }
139 if let Some(ref local_var_apikey) = local_var_configuration.api_key {
140 let local_var_key = local_var_apikey.key.clone();
141 let local_var_value = match local_var_apikey.prefix {
142 Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
143 None => local_var_key,
144 };
145 local_var_req_builder = local_var_req_builder.header("Authorization", local_var_value);
146 };
147
148 let local_var_req = local_var_req_builder.build()?;
149 let local_var_resp = local_var_client.execute(local_var_req).await?;
150
151 let local_var_status = local_var_resp.status();
152 let local_var_content = local_var_resp.text().await?;
153
154 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
155 serde_json::from_str(&local_var_content).map_err(Error::from)
156 } else {
157 let local_var_entity: Option<ApiKeysDeleteCurrentApiKeyError> = serde_json::from_str(&local_var_content).ok();
158 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
159 Err(Error::ResponseError(local_var_error))
160 }
161}
162
163pub async fn api_keys_get_current_api_key(configuration: &configuration::Configuration, ) -> Result<crate::models::ApiKeyData, Error<ApiKeysGetCurrentApiKeyError>> {
165 let local_var_configuration = configuration;
166
167 let local_var_client = &local_var_configuration.client;
168
169 let local_var_uri_str = format!("{}/api/v1/api-keys/current", local_var_configuration.base_path);
170 let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
171
172 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
173 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
174 }
175 if let Some(ref local_var_apikey) = local_var_configuration.api_key {
176 let local_var_key = local_var_apikey.key.clone();
177 let local_var_value = match local_var_apikey.prefix {
178 Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
179 None => local_var_key,
180 };
181 local_var_req_builder = local_var_req_builder.header("Authorization", local_var_value);
182 };
183
184 let local_var_req = local_var_req_builder.build()?;
185 let local_var_resp = local_var_client.execute(local_var_req).await?;
186
187 let local_var_status = local_var_resp.status();
188 let local_var_content = local_var_resp.text().await?;
189
190 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
191 serde_json::from_str(&local_var_content).map_err(Error::from)
192 } else {
193 let local_var_entity: Option<ApiKeysGetCurrentApiKeyError> = serde_json::from_str(&local_var_content).ok();
194 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
195 Err(Error::ResponseError(local_var_error))
196 }
197}
198