fastly_api/apis/
billing_address_api.rs

1/*
2 * Fastly API
3 *
4 * Via the Fastly API you can perform any of the operations that are possible within the management console,  including creating services, domains, and backends, configuring rules or uploading your own application code, as well as account operations such as user administration and billing reports. The API is organized into collections of endpoints that allow manipulation of objects related to Fastly services and accounts. For the most accurate and up-to-date API reference content, visit our [Developer Hub](https://www.fastly.com/documentation/reference/api/) 
5 *
6 */
7
8
9use reqwest;
10
11use crate::apis::ResponseContent;
12use super::{Error, configuration};
13
14/// struct for passing parameters to the method [`add_billing_addr`]
15#[derive(Clone, Debug, Default)]
16pub struct AddBillingAddrParams {
17    /// Alphanumeric string identifying the customer.
18    pub customer_id: String,
19    /// Billing address
20    pub billing_address_request: Option<crate::models::BillingAddressRequest>
21}
22
23/// struct for passing parameters to the method [`delete_billing_addr`]
24#[derive(Clone, Debug, Default)]
25pub struct DeleteBillingAddrParams {
26    /// Alphanumeric string identifying the customer.
27    pub customer_id: String
28}
29
30/// struct for passing parameters to the method [`get_billing_addr`]
31#[derive(Clone, Debug, Default)]
32pub struct GetBillingAddrParams {
33    /// Alphanumeric string identifying the customer.
34    pub customer_id: String
35}
36
37/// struct for passing parameters to the method [`update_billing_addr`]
38#[derive(Clone, Debug, Default)]
39pub struct UpdateBillingAddrParams {
40    /// Alphanumeric string identifying the customer.
41    pub customer_id: String,
42    /// One or more billing address attributes
43    pub update_billing_address_request: Option<crate::models::UpdateBillingAddressRequest>
44}
45
46
47/// struct for typed errors of method [`add_billing_addr`]
48#[derive(Debug, Clone, Serialize, Deserialize)]
49#[serde(untagged)]
50pub enum AddBillingAddrError {
51    Status400(crate::models::BillingAddressVerificationErrorResponse),
52    UnknownValue(serde_json::Value),
53}
54
55/// struct for typed errors of method [`delete_billing_addr`]
56#[derive(Debug, Clone, Serialize, Deserialize)]
57#[serde(untagged)]
58pub enum DeleteBillingAddrError {
59    UnknownValue(serde_json::Value),
60}
61
62/// struct for typed errors of method [`get_billing_addr`]
63#[derive(Debug, Clone, Serialize, Deserialize)]
64#[serde(untagged)]
65pub enum GetBillingAddrError {
66    UnknownValue(serde_json::Value),
67}
68
69/// struct for typed errors of method [`update_billing_addr`]
70#[derive(Debug, Clone, Serialize, Deserialize)]
71#[serde(untagged)]
72pub enum UpdateBillingAddrError {
73    Status400(crate::models::BillingAddressVerificationErrorResponse),
74    UnknownValue(serde_json::Value),
75}
76
77
78/// Add a billing address to a customer.
79pub async fn add_billing_addr(configuration: &mut configuration::Configuration, params: AddBillingAddrParams) -> Result<crate::models::BillingAddressResponse, Error<AddBillingAddrError>> {
80    let local_var_configuration = configuration;
81
82    // unbox the parameters
83    let customer_id = params.customer_id;
84    let billing_address_request = params.billing_address_request;
85
86
87    let local_var_client = &local_var_configuration.client;
88
89    let local_var_uri_str = format!("{}/customer/{customer_id}/billing_address", local_var_configuration.base_path, customer_id=crate::apis::urlencode(customer_id));
90    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
91
92    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
93        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
94    }
95    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
96        let local_var_key = local_var_apikey.key.clone();
97        let local_var_value = match local_var_apikey.prefix {
98            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
99            None => local_var_key,
100        };
101        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
102    };
103    local_var_req_builder = local_var_req_builder.json(&billing_address_request);
104
105    let local_var_req = local_var_req_builder.build()?;
106    let local_var_resp = local_var_client.execute(local_var_req).await?;
107
108    if "POST" != "GET" && "POST" != "HEAD" {
109      let headers = local_var_resp.headers();
110      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
111          Some(v) => v.to_str().unwrap().parse().unwrap(),
112          None => configuration::DEFAULT_RATELIMIT,
113      };
114      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
115          Some(v) => v.to_str().unwrap().parse().unwrap(),
116          None => 0,
117      };
118    }
119
120    let local_var_status = local_var_resp.status();
121    let local_var_content = local_var_resp.text().await?;
122
123    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
124        serde_json::from_str(&local_var_content).map_err(Error::from)
125    } else {
126        let local_var_entity: Option<AddBillingAddrError> = serde_json::from_str(&local_var_content).ok();
127        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
128        Err(Error::ResponseError(local_var_error))
129    }
130}
131
132/// Delete a customer's billing address.
133pub async fn delete_billing_addr(configuration: &mut configuration::Configuration, params: DeleteBillingAddrParams) -> Result<(), Error<DeleteBillingAddrError>> {
134    let local_var_configuration = configuration;
135
136    // unbox the parameters
137    let customer_id = params.customer_id;
138
139
140    let local_var_client = &local_var_configuration.client;
141
142    let local_var_uri_str = format!("{}/customer/{customer_id}/billing_address", local_var_configuration.base_path, customer_id=crate::apis::urlencode(customer_id));
143    let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
144
145    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
146        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
147    }
148    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
149        let local_var_key = local_var_apikey.key.clone();
150        let local_var_value = match local_var_apikey.prefix {
151            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
152            None => local_var_key,
153        };
154        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
155    };
156
157    let local_var_req = local_var_req_builder.build()?;
158    let local_var_resp = local_var_client.execute(local_var_req).await?;
159
160    if "DELETE" != "GET" && "DELETE" != "HEAD" {
161      let headers = local_var_resp.headers();
162      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
163          Some(v) => v.to_str().unwrap().parse().unwrap(),
164          None => configuration::DEFAULT_RATELIMIT,
165      };
166      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
167          Some(v) => v.to_str().unwrap().parse().unwrap(),
168          None => 0,
169      };
170    }
171
172    let local_var_status = local_var_resp.status();
173    let local_var_content = local_var_resp.text().await?;
174
175    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
176        Ok(())
177    } else {
178        let local_var_entity: Option<DeleteBillingAddrError> = serde_json::from_str(&local_var_content).ok();
179        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
180        Err(Error::ResponseError(local_var_error))
181    }
182}
183
184/// Get a customer's billing address.
185pub async fn get_billing_addr(configuration: &mut configuration::Configuration, params: GetBillingAddrParams) -> Result<crate::models::BillingAddressResponse, Error<GetBillingAddrError>> {
186    let local_var_configuration = configuration;
187
188    // unbox the parameters
189    let customer_id = params.customer_id;
190
191
192    let local_var_client = &local_var_configuration.client;
193
194    let local_var_uri_str = format!("{}/customer/{customer_id}/billing_address", local_var_configuration.base_path, customer_id=crate::apis::urlencode(customer_id));
195    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
196
197    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
198        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
199    }
200    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
201        let local_var_key = local_var_apikey.key.clone();
202        let local_var_value = match local_var_apikey.prefix {
203            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
204            None => local_var_key,
205        };
206        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
207    };
208
209    let local_var_req = local_var_req_builder.build()?;
210    let local_var_resp = local_var_client.execute(local_var_req).await?;
211
212    if "GET" != "GET" && "GET" != "HEAD" {
213      let headers = local_var_resp.headers();
214      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
215          Some(v) => v.to_str().unwrap().parse().unwrap(),
216          None => configuration::DEFAULT_RATELIMIT,
217      };
218      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
219          Some(v) => v.to_str().unwrap().parse().unwrap(),
220          None => 0,
221      };
222    }
223
224    let local_var_status = local_var_resp.status();
225    let local_var_content = local_var_resp.text().await?;
226
227    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
228        serde_json::from_str(&local_var_content).map_err(Error::from)
229    } else {
230        let local_var_entity: Option<GetBillingAddrError> = serde_json::from_str(&local_var_content).ok();
231        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
232        Err(Error::ResponseError(local_var_error))
233    }
234}
235
236/// Update a customer's billing address. You may update only part of the customer's billing address.
237pub async fn update_billing_addr(configuration: &mut configuration::Configuration, params: UpdateBillingAddrParams) -> Result<crate::models::BillingAddressResponse, Error<UpdateBillingAddrError>> {
238    let local_var_configuration = configuration;
239
240    // unbox the parameters
241    let customer_id = params.customer_id;
242    let update_billing_address_request = params.update_billing_address_request;
243
244
245    let local_var_client = &local_var_configuration.client;
246
247    let local_var_uri_str = format!("{}/customer/{customer_id}/billing_address", local_var_configuration.base_path, customer_id=crate::apis::urlencode(customer_id));
248    let mut local_var_req_builder = local_var_client.request(reqwest::Method::PATCH, local_var_uri_str.as_str());
249
250    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
251        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
252    }
253    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
254        let local_var_key = local_var_apikey.key.clone();
255        let local_var_value = match local_var_apikey.prefix {
256            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
257            None => local_var_key,
258        };
259        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
260    };
261    local_var_req_builder = local_var_req_builder.json(&update_billing_address_request);
262
263    let local_var_req = local_var_req_builder.build()?;
264    let local_var_resp = local_var_client.execute(local_var_req).await?;
265
266    if "PATCH" != "GET" && "PATCH" != "HEAD" {
267      let headers = local_var_resp.headers();
268      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
269          Some(v) => v.to_str().unwrap().parse().unwrap(),
270          None => configuration::DEFAULT_RATELIMIT,
271      };
272      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
273          Some(v) => v.to_str().unwrap().parse().unwrap(),
274          None => 0,
275      };
276    }
277
278    let local_var_status = local_var_resp.status();
279    let local_var_content = local_var_resp.text().await?;
280
281    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
282        serde_json::from_str(&local_var_content).map_err(Error::from)
283    } else {
284        let local_var_entity: Option<UpdateBillingAddrError> = serde_json::from_str(&local_var_content).ok();
285        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
286        Err(Error::ResponseError(local_var_error))
287    }
288}
289