sendinblue_v3/apis/
attributes_api.rs

1/*
2 * SendinBlue API
3 *
4 * SendinBlue provide a RESTFul API that can be used with any languages. With this API, you will be able to :   - Manage your campaigns and get the statistics   - Manage your contacts   - Send transactional Emails and SMS   - and much more...  You can download our wrappers at https://github.com/orgs/sendinblue  **Possible responses**   | Code | Message |   | :-------------: | ------------- |   | 200  | OK. Successful Request  |   | 201  | OK. Successful Creation |   | 202  | OK. Request accepted |   | 204  | OK. Successful Update/Deletion  |   | 400  | Error. Bad Request  |   | 401  | Error. Authentication Needed  |   | 402  | Error. Not enough credit, plan upgrade needed  |   | 403  | Error. Permission denied  |   | 404  | Error. Object does not exist |   | 405  | Error. Method not allowed  |   | 406  | Error. Not Acceptable  | 
5 *
6 * The version of the OpenAPI document: 3.0.0
7 * Contact: contact@sendinblue.com
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 [`create_attribute`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum CreateAttributeError {
22    Status400(crate::models::ErrorModel),
23    UnknownValue(serde_json::Value),
24}
25
26/// struct for typed errors of method [`delete_attribute`]
27#[derive(Debug, Clone, Serialize, Deserialize)]
28#[serde(untagged)]
29pub enum DeleteAttributeError {
30    Status404(crate::models::ErrorModel),
31    Status400(crate::models::ErrorModel),
32    UnknownValue(serde_json::Value),
33}
34
35/// struct for typed errors of method [`get_attributes`]
36#[derive(Debug, Clone, Serialize, Deserialize)]
37#[serde(untagged)]
38pub enum GetAttributesError {
39    UnknownValue(serde_json::Value),
40}
41
42/// struct for typed errors of method [`update_attribute`]
43#[derive(Debug, Clone, Serialize, Deserialize)]
44#[serde(untagged)]
45pub enum UpdateAttributeError {
46    Status400(crate::models::ErrorModel),
47    Status404(crate::models::ErrorModel),
48    UnknownValue(serde_json::Value),
49}
50
51
52pub async fn create_attribute(configuration: &configuration::Configuration, attribute_category: &str, attribute_name: &str, create_attribute: crate::models::CreateAttribute) -> Result<(), Error<CreateAttributeError>> {
53    let local_var_configuration = configuration;
54
55    let local_var_client = &local_var_configuration.client;
56
57    let local_var_uri_str = format!("{}/contacts/attributes/{attributeCategory}/{attributeName}", local_var_configuration.base_path, attributeCategory=crate::apis::urlencode(attribute_category), attributeName=crate::apis::urlencode(attribute_name));
58    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
59
60    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
61        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
62    }
63    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
64        let local_var_key = local_var_apikey.key.clone();
65        let local_var_value = match local_var_apikey.prefix {
66            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
67            None => local_var_key,
68        };
69        local_var_req_builder = local_var_req_builder.header("api-key", local_var_value);
70    };
71    local_var_req_builder = local_var_req_builder.json(&create_attribute);
72
73    let local_var_req = local_var_req_builder.build()?;
74    let local_var_resp = local_var_client.execute(local_var_req).await?;
75
76    let local_var_status = local_var_resp.status();
77    let local_var_content = local_var_resp.text().await?;
78
79    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
80        Ok(())
81    } else {
82        let local_var_entity: Option<CreateAttributeError> = serde_json::from_str(&local_var_content).ok();
83        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
84        Err(Error::ResponseError(local_var_error))
85    }
86}
87
88pub async fn delete_attribute(configuration: &configuration::Configuration, attribute_category: &str, attribute_name: &str) -> Result<(), Error<DeleteAttributeError>> {
89    let local_var_configuration = configuration;
90
91    let local_var_client = &local_var_configuration.client;
92
93    let local_var_uri_str = format!("{}/contacts/attributes/{attributeCategory}/{attributeName}", local_var_configuration.base_path, attributeCategory=crate::apis::urlencode(attribute_category), attributeName=crate::apis::urlencode(attribute_name));
94    let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
95
96    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
97        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
98    }
99    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
100        let local_var_key = local_var_apikey.key.clone();
101        let local_var_value = match local_var_apikey.prefix {
102            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
103            None => local_var_key,
104        };
105        local_var_req_builder = local_var_req_builder.header("api-key", local_var_value);
106    };
107
108    let local_var_req = local_var_req_builder.build()?;
109    let local_var_resp = local_var_client.execute(local_var_req).await?;
110
111    let local_var_status = local_var_resp.status();
112    let local_var_content = local_var_resp.text().await?;
113
114    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
115        Ok(())
116    } else {
117        let local_var_entity: Option<DeleteAttributeError> = serde_json::from_str(&local_var_content).ok();
118        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
119        Err(Error::ResponseError(local_var_error))
120    }
121}
122
123pub async fn get_attributes(configuration: &configuration::Configuration, ) -> Result<crate::models::GetAttributes, Error<GetAttributesError>> {
124    let local_var_configuration = configuration;
125
126    let local_var_client = &local_var_configuration.client;
127
128    let local_var_uri_str = format!("{}/contacts/attributes", local_var_configuration.base_path);
129    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
130
131    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
132        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
133    }
134    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
135        let local_var_key = local_var_apikey.key.clone();
136        let local_var_value = match local_var_apikey.prefix {
137            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
138            None => local_var_key,
139        };
140        local_var_req_builder = local_var_req_builder.header("api-key", local_var_value);
141    };
142
143    let local_var_req = local_var_req_builder.build()?;
144    let local_var_resp = local_var_client.execute(local_var_req).await?;
145
146    let local_var_status = local_var_resp.status();
147    let local_var_content = local_var_resp.text().await?;
148
149    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
150        serde_json::from_str(&local_var_content).map_err(Error::from)
151    } else {
152        let local_var_entity: Option<GetAttributesError> = serde_json::from_str(&local_var_content).ok();
153        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
154        Err(Error::ResponseError(local_var_error))
155    }
156}
157
158pub async fn update_attribute(configuration: &configuration::Configuration, attribute_category: &str, attribute_name: &str, update_attribute: crate::models::UpdateAttribute) -> Result<(), Error<UpdateAttributeError>> {
159    let local_var_configuration = configuration;
160
161    let local_var_client = &local_var_configuration.client;
162
163    let local_var_uri_str = format!("{}/contacts/attributes/{attributeCategory}/{attributeName}", local_var_configuration.base_path, attributeCategory=crate::apis::urlencode(attribute_category), attributeName=crate::apis::urlencode(attribute_name));
164    let mut local_var_req_builder = local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
165
166    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
167        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
168    }
169    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
170        let local_var_key = local_var_apikey.key.clone();
171        let local_var_value = match local_var_apikey.prefix {
172            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
173            None => local_var_key,
174        };
175        local_var_req_builder = local_var_req_builder.header("api-key", local_var_value);
176    };
177    local_var_req_builder = local_var_req_builder.json(&update_attribute);
178
179    let local_var_req = local_var_req_builder.build()?;
180    let local_var_resp = local_var_client.execute(local_var_req).await?;
181
182    let local_var_status = local_var_resp.status();
183    let local_var_content = local_var_resp.text().await?;
184
185    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
186        Ok(())
187    } else {
188        let local_var_entity: Option<UpdateAttributeError> = serde_json::from_str(&local_var_content).ok();
189        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
190        Err(Error::ResponseError(local_var_error))
191    }
192}
193