fastly_api/apis/
customer_addresses_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 [`create_customer_address`]
15#[derive(Clone, Debug, Default)]
16pub struct CreateCustomerAddressParams {
17    pub customer_address: crate::models::CustomerAddress
18}
19
20/// struct for passing parameters to the method [`update_customer_address`]
21#[derive(Clone, Debug, Default)]
22pub struct UpdateCustomerAddressParams {
23    /// Alphanumeric type of the address being modified.
24    pub _type: String,
25    pub customer_address: crate::models::CustomerAddress
26}
27
28
29/// struct for typed errors of method [`create_customer_address`]
30#[derive(Debug, Clone, Serialize, Deserialize)]
31#[serde(untagged)]
32pub enum CreateCustomerAddressError {
33    Status400(crate::models::Error),
34    Status401(crate::models::Error),
35    Status404(crate::models::Error),
36    Status500(crate::models::Error),
37    UnknownValue(serde_json::Value),
38}
39
40/// struct for typed errors of method [`list_customer_addresses`]
41#[derive(Debug, Clone, Serialize, Deserialize)]
42#[serde(untagged)]
43pub enum ListCustomerAddressesError {
44    Status400(crate::models::Error),
45    Status401(crate::models::Error),
46    Status404(crate::models::Error),
47    Status500(crate::models::Error),
48    UnknownValue(serde_json::Value),
49}
50
51/// struct for typed errors of method [`update_customer_address`]
52#[derive(Debug, Clone, Serialize, Deserialize)]
53#[serde(untagged)]
54pub enum UpdateCustomerAddressError {
55    Status400(crate::models::Error),
56    Status401(crate::models::Error),
57    Status404(crate::models::Error),
58    Status500(crate::models::Error),
59    UnknownValue(serde_json::Value),
60}
61
62
63/// Creates an address associated with a customer account.
64pub async fn create_customer_address(configuration: &mut configuration::Configuration, params: CreateCustomerAddressParams) -> Result<crate::models::InlineResponse201, Error<CreateCustomerAddressError>> {
65    let local_var_configuration = configuration;
66
67    // unbox the parameters
68    let customer_address = params.customer_address;
69
70
71    let local_var_client = &local_var_configuration.client;
72
73    let local_var_uri_str = format!("{}/billing/v3/customer-addresses", local_var_configuration.base_path);
74    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
75
76    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
77        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
78    }
79    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
80        let local_var_key = local_var_apikey.key.clone();
81        let local_var_value = match local_var_apikey.prefix {
82            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
83            None => local_var_key,
84        };
85        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
86    };
87    local_var_req_builder = local_var_req_builder.json(&customer_address);
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    if "POST" != "GET" && "POST" != "HEAD" {
93      let headers = local_var_resp.headers();
94      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
95          Some(v) => v.to_str().unwrap().parse().unwrap(),
96          None => configuration::DEFAULT_RATELIMIT,
97      };
98      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
99          Some(v) => v.to_str().unwrap().parse().unwrap(),
100          None => 0,
101      };
102    }
103
104    let local_var_status = local_var_resp.status();
105    let local_var_content = local_var_resp.text().await?;
106
107    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
108        serde_json::from_str(&local_var_content).map_err(Error::from)
109    } else {
110        let local_var_entity: Option<CreateCustomerAddressError> = serde_json::from_str(&local_var_content).ok();
111        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
112        Err(Error::ResponseError(local_var_error))
113    }
114}
115
116/// Return the list of addresses associated with a customer account.
117pub async fn list_customer_addresses(configuration: &mut configuration::Configuration) -> Result<crate::models::ListCustomerAddressesResponse, Error<ListCustomerAddressesError>> {
118    let local_var_configuration = configuration;
119
120    // unbox the parameters
121
122
123    let local_var_client = &local_var_configuration.client;
124
125    let local_var_uri_str = format!("{}/billing/v3/customer-addresses", local_var_configuration.base_path);
126    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
127
128    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
129        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
130    }
131    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
132        let local_var_key = local_var_apikey.key.clone();
133        let local_var_value = match local_var_apikey.prefix {
134            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
135            None => local_var_key,
136        };
137        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
138    };
139
140    let local_var_req = local_var_req_builder.build()?;
141    let local_var_resp = local_var_client.execute(local_var_req).await?;
142
143    if "GET" != "GET" && "GET" != "HEAD" {
144      let headers = local_var_resp.headers();
145      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
146          Some(v) => v.to_str().unwrap().parse().unwrap(),
147          None => configuration::DEFAULT_RATELIMIT,
148      };
149      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
150          Some(v) => v.to_str().unwrap().parse().unwrap(),
151          None => 0,
152      };
153    }
154
155    let local_var_status = local_var_resp.status();
156    let local_var_content = local_var_resp.text().await?;
157
158    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
159        serde_json::from_str(&local_var_content).map_err(Error::from)
160    } else {
161        let local_var_entity: Option<ListCustomerAddressesError> = serde_json::from_str(&local_var_content).ok();
162        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
163        Err(Error::ResponseError(local_var_error))
164    }
165}
166
167/// Updates an address associated with a customer account.
168pub async fn update_customer_address(configuration: &mut configuration::Configuration, params: UpdateCustomerAddressParams) -> Result<(), Error<UpdateCustomerAddressError>> {
169    let local_var_configuration = configuration;
170
171    // unbox the parameters
172    let _type = params._type;
173    let customer_address = params.customer_address;
174
175
176    let local_var_client = &local_var_configuration.client;
177
178    let local_var_uri_str = format!("{}/billing/v3/customer-addresses/{type}", local_var_configuration.base_path, type=crate::apis::urlencode(_type));
179    let mut local_var_req_builder = local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
180
181    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
182        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
183    }
184    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
185        let local_var_key = local_var_apikey.key.clone();
186        let local_var_value = match local_var_apikey.prefix {
187            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
188            None => local_var_key,
189        };
190        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
191    };
192    local_var_req_builder = local_var_req_builder.json(&customer_address);
193
194    let local_var_req = local_var_req_builder.build()?;
195    let local_var_resp = local_var_client.execute(local_var_req).await?;
196
197    if "PUT" != "GET" && "PUT" != "HEAD" {
198      let headers = local_var_resp.headers();
199      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
200          Some(v) => v.to_str().unwrap().parse().unwrap(),
201          None => configuration::DEFAULT_RATELIMIT,
202      };
203      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
204          Some(v) => v.to_str().unwrap().parse().unwrap(),
205          None => 0,
206      };
207    }
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        Ok(())
214    } else {
215        let local_var_entity: Option<UpdateCustomerAddressError> = 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