fastly_api/apis/
contact_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_contacts`]
15#[derive(Clone, Debug, Default)]
16pub struct CreateContactsParams {
17    /// Alphanumeric string identifying the customer.
18    pub customer_id: String,
19    /// The alphanumeric string representing the user for this customer contact.
20    pub user_id: Option<String>,
21    /// The type of contact.
22    pub contact_type: Option<String>,
23    /// The name of this contact, when user_id is not provided.
24    pub name: Option<String>,
25    /// The email of this contact, when a user_id is not provided.
26    pub email: Option<String>,
27    /// The phone number for this contact. Required for primary, technical, and security contact types.
28    pub phone: Option<String>,
29    /// The alphanumeric string representing the customer for this customer contact.
30    pub customer_id2: Option<String>
31}
32
33/// struct for passing parameters to the method [`delete_contact`]
34#[derive(Clone, Debug, Default)]
35pub struct DeleteContactParams {
36    /// Alphanumeric string identifying the customer.
37    pub customer_id: String,
38    /// An alphanumeric string identifying the customer contact.
39    pub contact_id: String
40}
41
42/// struct for passing parameters to the method [`list_contacts`]
43#[derive(Clone, Debug, Default)]
44pub struct ListContactsParams {
45    /// Alphanumeric string identifying the customer.
46    pub customer_id: String
47}
48
49
50/// struct for typed errors of method [`create_contacts`]
51#[derive(Debug, Clone, Serialize, Deserialize)]
52#[serde(untagged)]
53pub enum CreateContactsError {
54    UnknownValue(serde_json::Value),
55}
56
57/// struct for typed errors of method [`delete_contact`]
58#[derive(Debug, Clone, Serialize, Deserialize)]
59#[serde(untagged)]
60pub enum DeleteContactError {
61    UnknownValue(serde_json::Value),
62}
63
64/// struct for typed errors of method [`list_contacts`]
65#[derive(Debug, Clone, Serialize, Deserialize)]
66#[serde(untagged)]
67pub enum ListContactsError {
68    UnknownValue(serde_json::Value),
69}
70
71
72/// Create a contact.
73pub async fn create_contacts(configuration: &mut configuration::Configuration, params: CreateContactsParams) -> Result<crate::models::ContactResponse, Error<CreateContactsError>> {
74    let local_var_configuration = configuration;
75
76    // unbox the parameters
77    let customer_id = params.customer_id;
78    let user_id = params.user_id;
79    let contact_type = params.contact_type;
80    let name = params.name;
81    let email = params.email;
82    let phone = params.phone;
83    let customer_id2 = params.customer_id2;
84
85
86    let local_var_client = &local_var_configuration.client;
87
88    let local_var_uri_str = format!("{}/customer/{customer_id}/contacts", local_var_configuration.base_path, customer_id=crate::apis::urlencode(customer_id));
89    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
90
91    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
92        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
93    }
94    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
95        let local_var_key = local_var_apikey.key.clone();
96        let local_var_value = match local_var_apikey.prefix {
97            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
98            None => local_var_key,
99        };
100        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
101    };
102    let mut local_var_form_params = std::collections::HashMap::new();
103    if let Some(local_var_param_value) = user_id {
104        local_var_form_params.insert("user_id", local_var_param_value.to_string());
105    }
106    if let Some(local_var_param_value) = contact_type {
107        local_var_form_params.insert("contact_type", local_var_param_value.to_string());
108    }
109    if let Some(local_var_param_value) = name {
110        local_var_form_params.insert("name", local_var_param_value.to_string());
111    }
112    if let Some(local_var_param_value) = email {
113        local_var_form_params.insert("email", local_var_param_value.to_string());
114    }
115    if let Some(local_var_param_value) = phone {
116        local_var_form_params.insert("phone", local_var_param_value.to_string());
117    }
118    if let Some(local_var_param_value) = customer_id2 {
119        local_var_form_params.insert("customer_id", local_var_param_value.to_string());
120    }
121    local_var_req_builder = local_var_req_builder.form(&local_var_form_params);
122
123    let local_var_req = local_var_req_builder.build()?;
124    let local_var_resp = local_var_client.execute(local_var_req).await?;
125
126    if "POST" != "GET" && "POST" != "HEAD" {
127      let headers = local_var_resp.headers();
128      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
129          Some(v) => v.to_str().unwrap().parse().unwrap(),
130          None => configuration::DEFAULT_RATELIMIT,
131      };
132      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
133          Some(v) => v.to_str().unwrap().parse().unwrap(),
134          None => 0,
135      };
136    }
137
138    let local_var_status = local_var_resp.status();
139    let local_var_content = local_var_resp.text().await?;
140
141    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
142        serde_json::from_str(&local_var_content).map_err(Error::from)
143    } else {
144        let local_var_entity: Option<CreateContactsError> = serde_json::from_str(&local_var_content).ok();
145        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
146        Err(Error::ResponseError(local_var_error))
147    }
148}
149
150/// Delete a contact.
151pub async fn delete_contact(configuration: &mut configuration::Configuration, params: DeleteContactParams) -> Result<crate::models::InlineResponse200, Error<DeleteContactError>> {
152    let local_var_configuration = configuration;
153
154    // unbox the parameters
155    let customer_id = params.customer_id;
156    let contact_id = params.contact_id;
157
158
159    let local_var_client = &local_var_configuration.client;
160
161    let local_var_uri_str = format!("{}/customer/{customer_id}/contacts/{contact_id}", local_var_configuration.base_path, customer_id=crate::apis::urlencode(customer_id), contact_id=crate::apis::urlencode(contact_id));
162    let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
163
164    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
165        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
166    }
167    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
168        let local_var_key = local_var_apikey.key.clone();
169        let local_var_value = match local_var_apikey.prefix {
170            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
171            None => local_var_key,
172        };
173        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
174    };
175
176    let local_var_req = local_var_req_builder.build()?;
177    let local_var_resp = local_var_client.execute(local_var_req).await?;
178
179    if "DELETE" != "GET" && "DELETE" != "HEAD" {
180      let headers = local_var_resp.headers();
181      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
182          Some(v) => v.to_str().unwrap().parse().unwrap(),
183          None => configuration::DEFAULT_RATELIMIT,
184      };
185      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
186          Some(v) => v.to_str().unwrap().parse().unwrap(),
187          None => 0,
188      };
189    }
190
191    let local_var_status = local_var_resp.status();
192    let local_var_content = local_var_resp.text().await?;
193
194    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
195        serde_json::from_str(&local_var_content).map_err(Error::from)
196    } else {
197        let local_var_entity: Option<DeleteContactError> = serde_json::from_str(&local_var_content).ok();
198        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
199        Err(Error::ResponseError(local_var_error))
200    }
201}
202
203/// List all contacts from a specified customer ID.
204pub async fn list_contacts(configuration: &mut configuration::Configuration, params: ListContactsParams) -> Result<Vec<crate::models::SchemasContactResponse>, Error<ListContactsError>> {
205    let local_var_configuration = configuration;
206
207    // unbox the parameters
208    let customer_id = params.customer_id;
209
210
211    let local_var_client = &local_var_configuration.client;
212
213    let local_var_uri_str = format!("{}/customer/{customer_id}/contacts", local_var_configuration.base_path, customer_id=crate::apis::urlencode(customer_id));
214    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
215
216    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
217        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
218    }
219    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
220        let local_var_key = local_var_apikey.key.clone();
221        let local_var_value = match local_var_apikey.prefix {
222            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
223            None => local_var_key,
224        };
225        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
226    };
227
228    let local_var_req = local_var_req_builder.build()?;
229    let local_var_resp = local_var_client.execute(local_var_req).await?;
230
231    if "GET" != "GET" && "GET" != "HEAD" {
232      let headers = local_var_resp.headers();
233      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
234          Some(v) => v.to_str().unwrap().parse().unwrap(),
235          None => configuration::DEFAULT_RATELIMIT,
236      };
237      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
238          Some(v) => v.to_str().unwrap().parse().unwrap(),
239          None => 0,
240      };
241    }
242
243    let local_var_status = local_var_resp.status();
244    let local_var_content = local_var_resp.text().await?;
245
246    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
247        serde_json::from_str(&local_var_content).map_err(Error::from)
248    } else {
249        let local_var_entity: Option<ListContactsError> = serde_json::from_str(&local_var_content).ok();
250        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
251        Err(Error::ResponseError(local_var_error))
252    }
253}
254