pipedrive_rs/apis/
lead_labels_api.rs

1/*
2 * Pipedrive API v1
3 *
4 * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
5 *
6 * The version of the OpenAPI document: 1.0.0
7 * 
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 [`add_lead_label`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum AddLeadLabelError {
22    UnknownValue(serde_json::Value),
23}
24
25/// struct for typed errors of method [`delete_lead_label`]
26#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(untagged)]
28pub enum DeleteLeadLabelError {
29    Status404(crate::models::LeadResponse404),
30    UnknownValue(serde_json::Value),
31}
32
33/// struct for typed errors of method [`get_lead_labels`]
34#[derive(Debug, Clone, Serialize, Deserialize)]
35#[serde(untagged)]
36pub enum GetLeadLabelsError {
37    UnknownValue(serde_json::Value),
38}
39
40/// struct for typed errors of method [`update_lead_label`]
41#[derive(Debug, Clone, Serialize, Deserialize)]
42#[serde(untagged)]
43pub enum UpdateLeadLabelError {
44    Status404(crate::models::LeadResponse404),
45    UnknownValue(serde_json::Value),
46}
47
48
49/// Creates a lead label.
50pub async fn add_lead_label(configuration: &configuration::Configuration, add_lead_label_request: Option<crate::models::AddLeadLabelRequest>) -> Result<crate::models::AddOrUpdateLeadLabelResponse200, Error<AddLeadLabelError>> {
51    let local_var_configuration = configuration;
52
53    let local_var_client = &local_var_configuration.client;
54
55    let local_var_uri_str = format!("{}/leadLabels", local_var_configuration.base_path);
56    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
57
58    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
59        let local_var_key = local_var_apikey.key.clone();
60        let local_var_value = match local_var_apikey.prefix {
61            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
62            None => local_var_key,
63        };
64        local_var_req_builder = local_var_req_builder.query(&[("api_token", local_var_value)]);
65    }
66    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
67        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
68    }
69    if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
70        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
71    };
72    local_var_req_builder = local_var_req_builder.json(&add_lead_label_request);
73
74    let local_var_req = local_var_req_builder.build()?;
75    let local_var_resp = local_var_client.execute(local_var_req).await?;
76
77    let local_var_status = local_var_resp.status();
78    let local_var_content = local_var_resp.text().await?;
79
80    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
81        serde_json::from_str(&local_var_content).map_err(Error::from)
82    } else {
83        let local_var_entity: Option<AddLeadLabelError> = serde_json::from_str(&local_var_content).ok();
84        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
85        Err(Error::ResponseError(local_var_error))
86    }
87}
88
89/// Deletes a specific lead label.
90pub async fn delete_lead_label(configuration: &configuration::Configuration, id: &str) -> Result<crate::models::LeadIdResponse200, Error<DeleteLeadLabelError>> {
91    let local_var_configuration = configuration;
92
93    let local_var_client = &local_var_configuration.client;
94
95    let local_var_uri_str = format!("{}/leadLabels/{id}", local_var_configuration.base_path, id=crate::apis::urlencode(id));
96    let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
97
98    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
99        let local_var_key = local_var_apikey.key.clone();
100        let local_var_value = match local_var_apikey.prefix {
101            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
102            None => local_var_key,
103        };
104        local_var_req_builder = local_var_req_builder.query(&[("api_token", local_var_value)]);
105    }
106    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
107        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
108    }
109    if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
110        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
111    };
112
113    let local_var_req = local_var_req_builder.build()?;
114    let local_var_resp = local_var_client.execute(local_var_req).await?;
115
116    let local_var_status = local_var_resp.status();
117    let local_var_content = local_var_resp.text().await?;
118
119    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
120        serde_json::from_str(&local_var_content).map_err(Error::from)
121    } else {
122        let local_var_entity: Option<DeleteLeadLabelError> = serde_json::from_str(&local_var_content).ok();
123        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
124        Err(Error::ResponseError(local_var_error))
125    }
126}
127
128/// Returns details of all lead labels. This endpoint does not support pagination and all labels are always returned.
129pub async fn get_lead_labels(configuration: &configuration::Configuration, ) -> Result<crate::models::GetLeadLabelsResponse200, Error<GetLeadLabelsError>> {
130    let local_var_configuration = configuration;
131
132    let local_var_client = &local_var_configuration.client;
133
134    let local_var_uri_str = format!("{}/leadLabels", local_var_configuration.base_path);
135    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
136
137    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
138        let local_var_key = local_var_apikey.key.clone();
139        let local_var_value = match local_var_apikey.prefix {
140            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
141            None => local_var_key,
142        };
143        local_var_req_builder = local_var_req_builder.query(&[("api_token", local_var_value)]);
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_token) = local_var_configuration.oauth_access_token {
149        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
150    };
151
152    let local_var_req = local_var_req_builder.build()?;
153    let local_var_resp = local_var_client.execute(local_var_req).await?;
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<GetLeadLabelsError> = 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 one or more properties of a lead label. Only properties included in the request will be updated. 
168pub async fn update_lead_label(configuration: &configuration::Configuration, id: &str, update_lead_label_request: Option<crate::models::UpdateLeadLabelRequest>) -> Result<crate::models::AddOrUpdateLeadLabelResponse200, Error<UpdateLeadLabelError>> {
169    let local_var_configuration = configuration;
170
171    let local_var_client = &local_var_configuration.client;
172
173    let local_var_uri_str = format!("{}/leadLabels/{id}", local_var_configuration.base_path, id=crate::apis::urlencode(id));
174    let mut local_var_req_builder = local_var_client.request(reqwest::Method::PATCH, local_var_uri_str.as_str());
175
176    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
177        let local_var_key = local_var_apikey.key.clone();
178        let local_var_value = match local_var_apikey.prefix {
179            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
180            None => local_var_key,
181        };
182        local_var_req_builder = local_var_req_builder.query(&[("api_token", local_var_value)]);
183    }
184    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
185        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
186    }
187    if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
188        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
189    };
190    local_var_req_builder = local_var_req_builder.json(&update_lead_label_request);
191
192    let local_var_req = local_var_req_builder.build()?;
193    let local_var_resp = local_var_client.execute(local_var_req).await?;
194
195    let local_var_status = local_var_resp.status();
196    let local_var_content = local_var_resp.text().await?;
197
198    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
199        serde_json::from_str(&local_var_content).map_err(Error::from)
200    } else {
201        let local_var_entity: Option<UpdateLeadLabelError> = serde_json::from_str(&local_var_content).ok();
202        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
203        Err(Error::ResponseError(local_var_error))
204    }
205}
206