btcpay_client/apis/
stores_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 [`stores_create_store`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum StoresCreateStoreError {
22    Status400(Vec<crate::models::ValidationProblemDetailsInner>),
23    Status403(),
24    UnknownValue(serde_json::Value),
25}
26
27/// struct for typed errors of method [`stores_delete_store`]
28#[derive(Debug, Clone, Serialize, Deserialize)]
29#[serde(untagged)]
30pub enum StoresDeleteStoreError {
31    Status400(Vec<crate::models::ValidationProblemDetailsInner>),
32    Status403(),
33    Status404(),
34    UnknownValue(serde_json::Value),
35}
36
37/// struct for typed errors of method [`stores_get_store`]
38#[derive(Debug, Clone, Serialize, Deserialize)]
39#[serde(untagged)]
40pub enum StoresGetStoreError {
41    Status403(),
42    Status404(),
43    UnknownValue(serde_json::Value),
44}
45
46/// struct for typed errors of method [`stores_get_stores`]
47#[derive(Debug, Clone, Serialize, Deserialize)]
48#[serde(untagged)]
49pub enum StoresGetStoresError {
50    UnknownValue(serde_json::Value),
51}
52
53/// struct for typed errors of method [`stores_update_store`]
54#[derive(Debug, Clone, Serialize, Deserialize)]
55#[serde(untagged)]
56pub enum StoresUpdateStoreError {
57    Status400(Vec<crate::models::ValidationProblemDetailsInner>),
58    Status403(),
59    Status404(),
60    UnknownValue(serde_json::Value),
61}
62
63
64/// Create a new store
65pub async fn stores_create_store(configuration: &configuration::Configuration, store_base_data: crate::models::StoreBaseData) -> Result<crate::models::StoreData, Error<StoresCreateStoreError>> {
66    let local_var_configuration = configuration;
67
68    let local_var_client = &local_var_configuration.client;
69
70    let local_var_uri_str = format!("{}/api/v1/stores", local_var_configuration.base_path);
71    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
72
73    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
74        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
75    }
76    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
77        let local_var_key = local_var_apikey.key.clone();
78        let local_var_value = match local_var_apikey.prefix {
79            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
80            None => local_var_key,
81        };
82        local_var_req_builder = local_var_req_builder.header("Authorization", local_var_value);
83    };
84    if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
85        local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
86    };
87    local_var_req_builder = local_var_req_builder.json(&store_base_data);
88
89    let local_var_req = local_var_req_builder.build()?;
90    let local_var_resp = local_var_client.execute(local_var_req).await?;
91
92    let local_var_status = local_var_resp.status();
93    let local_var_content = local_var_resp.text().await?;
94
95    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
96        serde_json::from_str(&local_var_content).map_err(Error::from)
97    } else {
98        let local_var_entity: Option<StoresCreateStoreError> = serde_json::from_str(&local_var_content).ok();
99        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
100        Err(Error::ResponseError(local_var_error))
101    }
102}
103
104/// Removes the specified store. If there is another user with access, only your access will be removed.
105pub async fn stores_delete_store(configuration: &configuration::Configuration, store_id: &str) -> Result<(), Error<StoresDeleteStoreError>> {
106    let local_var_configuration = configuration;
107
108    let local_var_client = &local_var_configuration.client;
109
110    let local_var_uri_str = format!("{}/api/v1/stores/{storeId}", local_var_configuration.base_path, storeId=crate::apis::urlencode(store_id));
111    let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
112
113    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
114        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
115    }
116    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
117        let local_var_key = local_var_apikey.key.clone();
118        let local_var_value = match local_var_apikey.prefix {
119            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
120            None => local_var_key,
121        };
122        local_var_req_builder = local_var_req_builder.header("Authorization", local_var_value);
123    };
124    if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
125        local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
126    };
127
128    let local_var_req = local_var_req_builder.build()?;
129    let local_var_resp = local_var_client.execute(local_var_req).await?;
130
131    let local_var_status = local_var_resp.status();
132    let local_var_content = local_var_resp.text().await?;
133
134    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
135        Ok(())
136    } else {
137        let local_var_entity: Option<StoresDeleteStoreError> = serde_json::from_str(&local_var_content).ok();
138        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
139        Err(Error::ResponseError(local_var_error))
140    }
141}
142
143/// View information about the specified store
144pub async fn stores_get_store(configuration: &configuration::Configuration, store_id: &str) -> Result<crate::models::StoreData, Error<StoresGetStoreError>> {
145    let local_var_configuration = configuration;
146
147    let local_var_client = &local_var_configuration.client;
148
149    let local_var_uri_str = format!("{}/api/v1/stores/{storeId}", local_var_configuration.base_path, storeId=crate::apis::urlencode(store_id));
150    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
151
152    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
153        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
154    }
155    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
156        let local_var_key = local_var_apikey.key.clone();
157        let local_var_value = match local_var_apikey.prefix {
158            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
159            None => local_var_key,
160        };
161        local_var_req_builder = local_var_req_builder.header("Authorization", local_var_value);
162    };
163    if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
164        local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
165    };
166
167    let local_var_req = local_var_req_builder.build()?;
168    let local_var_resp = local_var_client.execute(local_var_req).await?;
169
170    let local_var_status = local_var_resp.status();
171    let local_var_content = local_var_resp.text().await?;
172
173    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
174        serde_json::from_str(&local_var_content).map_err(Error::from)
175    } else {
176        let local_var_entity: Option<StoresGetStoreError> = serde_json::from_str(&local_var_content).ok();
177        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
178        Err(Error::ResponseError(local_var_error))
179    }
180}
181
182/// View information about the available stores
183pub async fn stores_get_stores(configuration: &configuration::Configuration, ) -> Result<Vec<crate::models::StoreData>, Error<StoresGetStoresError>> {
184    let local_var_configuration = configuration;
185
186    let local_var_client = &local_var_configuration.client;
187
188    let local_var_uri_str = format!("{}/api/v1/stores", local_var_configuration.base_path);
189    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
190
191    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
192        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
193    }
194    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
195        let local_var_key = local_var_apikey.key.clone();
196        let local_var_value = match local_var_apikey.prefix {
197            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
198            None => local_var_key,
199        };
200        local_var_req_builder = local_var_req_builder.header("Authorization", local_var_value);
201    };
202    if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
203        local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
204    };
205
206    let local_var_req = local_var_req_builder.build()?;
207    let local_var_resp = local_var_client.execute(local_var_req).await?;
208
209    let local_var_status = local_var_resp.status();
210    let local_var_content = local_var_resp.text().await?;
211
212    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
213        serde_json::from_str(&local_var_content).map_err(Error::from)
214    } else {
215        let local_var_entity: Option<StoresGetStoresError> = serde_json::from_str(&local_var_content).ok();
216        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
217        Err(Error::ResponseError(local_var_error))
218    }
219}
220
221/// Update the specified store
222pub async fn stores_update_store(configuration: &configuration::Configuration, store_id: &str, store_data: crate::models::StoreData) -> Result<crate::models::StoreData, Error<StoresUpdateStoreError>> {
223    let local_var_configuration = configuration;
224
225    let local_var_client = &local_var_configuration.client;
226
227    let local_var_uri_str = format!("{}/api/v1/stores/{storeId}", local_var_configuration.base_path, storeId=crate::apis::urlencode(store_id));
228    let mut local_var_req_builder = local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
229
230    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
231        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
232    }
233    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
234        let local_var_key = local_var_apikey.key.clone();
235        let local_var_value = match local_var_apikey.prefix {
236            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
237            None => local_var_key,
238        };
239        local_var_req_builder = local_var_req_builder.header("Authorization", local_var_value);
240    };
241    if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
242        local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
243    };
244    local_var_req_builder = local_var_req_builder.json(&store_data);
245
246    let local_var_req = local_var_req_builder.build()?;
247    let local_var_resp = local_var_client.execute(local_var_req).await?;
248
249    let local_var_status = local_var_resp.status();
250    let local_var_content = local_var_resp.text().await?;
251
252    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
253        serde_json::from_str(&local_var_content).map_err(Error::from)
254    } else {
255        let local_var_entity: Option<StoresUpdateStoreError> = serde_json::from_str(&local_var_content).ok();
256        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
257        Err(Error::ResponseError(local_var_error))
258    }
259}
260