Skip to main content

dtz_billing/apis/
default_api.rs

1/*
2 * DTZ Billing Api
3 *
4 * a generated client for the DTZ Billing API
5 *
6 * Contact: jens@apimeister.com
7 * Generated by: https://openapi-generator.tech
8 */
9
10
11use reqwest;
12#[allow(unused_imports)]
13use serde::{de::Error as _};
14use crate::{apis::ResponseContent, models};
15#[allow(unused_imports)]
16use super::{Error, ContentType};
17use dtz_config::Configuration;
18
19fn build_url(config: &Configuration) -> String {
20    if let Some(base_path) = &config.base_path {
21        let base = url::Url::parse(base_path).unwrap();
22        let mut target_url = url::Url::parse(crate::apis::SVC_URL).unwrap();
23        let _ = target_url.set_scheme(base.scheme());
24        let _ = target_url.set_port(base.port());
25        let _ = target_url.set_host(Some(base.host_str().unwrap()));
26        format!("{target_url}")
27    } else {
28        crate::apis::SVC_URL.to_string()
29    }
30}
31
32
33/// struct for typed errors of method [`charge_stripe_post`]
34#[derive(Debug, Clone, Serialize, Deserialize)]
35#[serde(untagged)]
36pub enum ChargeStripePostError {
37    UnknownValue(serde_json::Value),
38}
39
40/// struct for typed errors of method [`check_funded`]
41#[derive(Debug, Clone, Serialize, Deserialize)]
42#[serde(untagged)]
43pub enum CheckFundedError {
44    UnknownValue(serde_json::Value),
45}
46
47/// struct for typed errors of method [`get_stats`]
48#[derive(Debug, Clone, Serialize, Deserialize)]
49#[serde(untagged)]
50pub enum GetStatsError {
51    UnknownValue(serde_json::Value),
52}
53
54/// struct for typed errors of method [`list_transactions`]
55#[derive(Debug, Clone, Serialize, Deserialize)]
56#[serde(untagged)]
57pub enum ListTransactionsError {
58    UnknownValue(serde_json::Value),
59}
60
61/// struct for typed errors of method [`post_consumption`]
62#[derive(Debug, Clone, Serialize, Deserialize)]
63#[serde(untagged)]
64pub enum PostConsumptionError {
65    UnknownValue(serde_json::Value),
66}
67
68
69/// stripe webhook This endpoint cannot be used with service credentials. Only system credentials can update charge information. 
70pub async fn charge_stripe_post(configuration: &Configuration) -> Result<(), Error<ChargeStripePostError>> {
71
72    let uri_str = format!("{}/charge/stripe", build_url(configuration));
73    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
74
75
76    if let Some(ref token) = configuration.oauth_access_token {
77        req_builder = req_builder.bearer_auth(token.to_owned());
78    };
79    if let Some(ref value) = configuration.api_key {
80        req_builder = req_builder.header("X-API-KEY", value);
81    };
82
83    let req = req_builder.build()?;
84    let resp = configuration.client.execute(req).await?;
85
86    let status = resp.status();
87
88    if !status.is_client_error() && !status.is_server_error() {
89        Ok(())
90    } else {
91        let content = resp.text().await?;
92        let entity: Option<ChargeStripePostError> = serde_json::from_str(&content).ok();
93        Err(Error::ResponseError(ResponseContent { status, content, entity }))
94    }
95}
96
97pub async fn check_funded(configuration: &Configuration, identity: Option<&str>) -> Result<models::CheckFunded200Response, Error<CheckFundedError>> {
98    // add a prefix to parameters to efficiently prevent name collisions
99    let p_query_identity = identity;
100
101    let uri_str = format!("{}/funded", build_url(configuration));
102    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
103
104
105    if let Some(ref param_value) = p_query_identity {
106        req_builder = req_builder.query(&[("identity", &param_value.to_string())]);
107    }
108    if let Some(ref token) = configuration.oauth_access_token {
109        req_builder = req_builder.bearer_auth(token.to_owned());
110    };
111    if let Some(ref value) = configuration.api_key {
112        req_builder = req_builder.header("X-API-KEY", value);
113    };
114
115    let req = req_builder.build()?;
116    let resp = configuration.client.execute(req).await?;
117
118    let status = resp.status();
119    let content_type = resp
120        .headers()
121        .get("content-type")
122        .and_then(|v| v.to_str().ok())
123        .unwrap_or("application/octet-stream");
124    let content_type = super::ContentType::from(content_type);
125
126    if !status.is_client_error() && !status.is_server_error() {
127        let content = resp.text().await?;
128        match content_type {
129            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
130            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::CheckFunded200Response`"))),
131            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::CheckFunded200Response`")))),
132        }
133    } else {
134        let content = resp.text().await?;
135        let entity: Option<CheckFundedError> = serde_json::from_str(&content).ok();
136        Err(Error::ResponseError(ResponseContent { status, content, entity }))
137    }
138}
139
140pub async fn get_stats(configuration: &Configuration) -> Result<models::GetStats200Response, Error<GetStatsError>> {
141
142    let uri_str = format!("{}/stats", build_url(configuration));
143    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
144
145
146    if let Some(ref token) = configuration.oauth_access_token {
147        req_builder = req_builder.bearer_auth(token.to_owned());
148    };
149    if let Some(ref value) = configuration.api_key {
150        req_builder = req_builder.header("X-API-KEY", value);
151    };
152
153    let req = req_builder.build()?;
154    let resp = configuration.client.execute(req).await?;
155
156    let status = resp.status();
157    let content_type = resp
158        .headers()
159        .get("content-type")
160        .and_then(|v| v.to_str().ok())
161        .unwrap_or("application/octet-stream");
162    let content_type = super::ContentType::from(content_type);
163
164    if !status.is_client_error() && !status.is_server_error() {
165        let content = resp.text().await?;
166        match content_type {
167            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
168            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GetStats200Response`"))),
169            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::GetStats200Response`")))),
170        }
171    } else {
172        let content = resp.text().await?;
173        let entity: Option<GetStatsError> = serde_json::from_str(&content).ok();
174        Err(Error::ResponseError(ResponseContent { status, content, entity }))
175    }
176}
177
178pub async fn list_transactions(configuration: &Configuration, start: Option<String>, end: Option<String>, service: Option<&str>, context_id: Option<&str>) -> Result<Vec<models::Transaction>, Error<ListTransactionsError>> {
179    // add a prefix to parameters to efficiently prevent name collisions
180    let p_query_start = start;
181    let p_query_end = end;
182    let p_query_service = service;
183    let p_query_context_id = context_id;
184
185    let uri_str = format!("{}/transaction", build_url(configuration));
186    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
187
188
189    if let Some(ref param_value) = p_query_start {
190        req_builder = req_builder.query(&[("start", &param_value.to_string())]);
191    }
192    if let Some(ref param_value) = p_query_end {
193        req_builder = req_builder.query(&[("end", &param_value.to_string())]);
194    }
195    if let Some(ref param_value) = p_query_service {
196        req_builder = req_builder.query(&[("service", &param_value.to_string())]);
197    }
198    if let Some(ref param_value) = p_query_context_id {
199        req_builder = req_builder.query(&[("contextId", &param_value.to_string())]);
200    }
201    if let Some(ref token) = configuration.oauth_access_token {
202        req_builder = req_builder.bearer_auth(token.to_owned());
203    };
204    if let Some(ref value) = configuration.api_key {
205        req_builder = req_builder.header("X-API-KEY", value);
206    };
207
208    let req = req_builder.build()?;
209    let resp = configuration.client.execute(req).await?;
210
211    let status = resp.status();
212    let content_type = resp
213        .headers()
214        .get("content-type")
215        .and_then(|v| v.to_str().ok())
216        .unwrap_or("application/octet-stream");
217    let content_type = super::ContentType::from(content_type);
218
219    if !status.is_client_error() && !status.is_server_error() {
220        let content = resp.text().await?;
221        match content_type {
222            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
223            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec&lt;models::Transaction&gt;`"))),
224            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;models::Transaction&gt;`")))),
225        }
226    } else {
227        let content = resp.text().await?;
228        let entity: Option<ListTransactionsError> = serde_json::from_str(&content).ok();
229        Err(Error::ResponseError(ResponseContent { status, content, entity }))
230    }
231}
232
233/// post new service consumption This endpoint cannot be used with service credentials. Only system credentials can update service consumption. 
234pub async fn post_consumption(configuration: &Configuration, consumption: Option<models::Consumption>) -> Result<(), Error<PostConsumptionError>> {
235    // add a prefix to parameters to efficiently prevent name collisions
236    let p_body_consumption = consumption;
237
238    let uri_str = format!("{}/consumption", build_url(configuration));
239    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
240
241
242    if let Some(ref token) = configuration.oauth_access_token {
243        req_builder = req_builder.bearer_auth(token.to_owned());
244    };
245    if let Some(ref value) = configuration.api_key {
246        req_builder = req_builder.header("X-API-KEY", value);
247    };
248    req_builder = req_builder.json(&p_body_consumption);
249
250    let req = req_builder.build()?;
251    let resp = configuration.client.execute(req).await?;
252
253    let status = resp.status();
254
255    if !status.is_client_error() && !status.is_server_error() {
256        Ok(())
257    } else {
258        let content = resp.text().await?;
259        let entity: Option<PostConsumptionError> = serde_json::from_str(&content).ok();
260        Err(Error::ResponseError(ResponseContent { status, content, entity }))
261    }
262}
263