pipedrive_rs/apis/
filters_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_filter`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum AddFilterError {
22    UnknownValue(serde_json::Value),
23}
24
25/// struct for typed errors of method [`delete_filter`]
26#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(untagged)]
28pub enum DeleteFilterError {
29    UnknownValue(serde_json::Value),
30}
31
32/// struct for typed errors of method [`delete_filters`]
33#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum DeleteFiltersError {
36    UnknownValue(serde_json::Value),
37}
38
39/// struct for typed errors of method [`get_filter`]
40#[derive(Debug, Clone, Serialize, Deserialize)]
41#[serde(untagged)]
42pub enum GetFilterError {
43    UnknownValue(serde_json::Value),
44}
45
46/// struct for typed errors of method [`get_filter_helpers`]
47#[derive(Debug, Clone, Serialize, Deserialize)]
48#[serde(untagged)]
49pub enum GetFilterHelpersError {
50    UnknownValue(serde_json::Value),
51}
52
53/// struct for typed errors of method [`get_filters`]
54#[derive(Debug, Clone, Serialize, Deserialize)]
55#[serde(untagged)]
56pub enum GetFiltersError {
57    UnknownValue(serde_json::Value),
58}
59
60/// struct for typed errors of method [`update_filter`]
61#[derive(Debug, Clone, Serialize, Deserialize)]
62#[serde(untagged)]
63pub enum UpdateFilterError {
64    UnknownValue(serde_json::Value),
65}
66
67
68/// Adds a new filter, returns the ID upon success. Note that in the conditions JSON object only one first-level condition group is supported, and it must be glued with 'AND', and only two second level condition groups are supported of which one must be glued with 'AND' and the second with 'OR'. Other combinations do not work (yet) but the syntax supports introducing them in future. For more information, see the tutorial for <a href=\"https://pipedrive.readme.io/docs/adding-a-filter\" target=\"_blank\" rel=\"noopener noreferrer\">adding a filter</a>.
69pub async fn add_filter(configuration: &configuration::Configuration, add_filter_request: Option<crate::models::AddFilterRequest>) -> Result<crate::models::PostFilterResponse200, Error<AddFilterError>> {
70    let local_var_configuration = configuration;
71
72    let local_var_client = &local_var_configuration.client;
73
74    let local_var_uri_str = format!("{}/filters", local_var_configuration.base_path);
75    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
76
77    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
78        let local_var_key = local_var_apikey.key.clone();
79        let local_var_value = match local_var_apikey.prefix {
80            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
81            None => local_var_key,
82        };
83        local_var_req_builder = local_var_req_builder.query(&[("api_token", local_var_value)]);
84    }
85    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
86        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
87    }
88    if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
89        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
90    };
91    local_var_req_builder = local_var_req_builder.json(&add_filter_request);
92
93    let local_var_req = local_var_req_builder.build()?;
94    let local_var_resp = local_var_client.execute(local_var_req).await?;
95
96    let local_var_status = local_var_resp.status();
97    let local_var_content = local_var_resp.text().await?;
98
99    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
100        serde_json::from_str(&local_var_content).map_err(Error::from)
101    } else {
102        let local_var_entity: Option<AddFilterError> = serde_json::from_str(&local_var_content).ok();
103        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
104        Err(Error::ResponseError(local_var_error))
105    }
106}
107
108/// Marks a filter as deleted.
109pub async fn delete_filter(configuration: &configuration::Configuration, id: i32) -> Result<crate::models::DeleteFilterResponse200, Error<DeleteFilterError>> {
110    let local_var_configuration = configuration;
111
112    let local_var_client = &local_var_configuration.client;
113
114    let local_var_uri_str = format!("{}/filters/{id}", local_var_configuration.base_path, id=id);
115    let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
116
117    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
118        let local_var_key = local_var_apikey.key.clone();
119        let local_var_value = match local_var_apikey.prefix {
120            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
121            None => local_var_key,
122        };
123        local_var_req_builder = local_var_req_builder.query(&[("api_token", local_var_value)]);
124    }
125    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
126        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
127    }
128    if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
129        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
130    };
131
132    let local_var_req = local_var_req_builder.build()?;
133    let local_var_resp = local_var_client.execute(local_var_req).await?;
134
135    let local_var_status = local_var_resp.status();
136    let local_var_content = local_var_resp.text().await?;
137
138    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
139        serde_json::from_str(&local_var_content).map_err(Error::from)
140    } else {
141        let local_var_entity: Option<DeleteFilterError> = serde_json::from_str(&local_var_content).ok();
142        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
143        Err(Error::ResponseError(local_var_error))
144    }
145}
146
147/// Marks multiple filters as deleted.
148pub async fn delete_filters(configuration: &configuration::Configuration, ids: &str) -> Result<crate::models::DeleteFiltersResponse200, Error<DeleteFiltersError>> {
149    let local_var_configuration = configuration;
150
151    let local_var_client = &local_var_configuration.client;
152
153    let local_var_uri_str = format!("{}/filters", local_var_configuration.base_path);
154    let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
155
156    local_var_req_builder = local_var_req_builder.query(&[("ids", &ids.to_string())]);
157    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
158        let local_var_key = local_var_apikey.key.clone();
159        let local_var_value = match local_var_apikey.prefix {
160            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
161            None => local_var_key,
162        };
163        local_var_req_builder = local_var_req_builder.query(&[("api_token", local_var_value)]);
164    }
165    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
166        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
167    }
168    if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
169        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
170    };
171
172    let local_var_req = local_var_req_builder.build()?;
173    let local_var_resp = local_var_client.execute(local_var_req).await?;
174
175    let local_var_status = local_var_resp.status();
176    let local_var_content = local_var_resp.text().await?;
177
178    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
179        serde_json::from_str(&local_var_content).map_err(Error::from)
180    } else {
181        let local_var_entity: Option<DeleteFiltersError> = serde_json::from_str(&local_var_content).ok();
182        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
183        Err(Error::ResponseError(local_var_error))
184    }
185}
186
187/// Returns data about a specific filter. Note that this also returns the condition lines of the filter.
188pub async fn get_filter(configuration: &configuration::Configuration, id: i32) -> Result<crate::models::GetFilterResponse200, Error<GetFilterError>> {
189    let local_var_configuration = configuration;
190
191    let local_var_client = &local_var_configuration.client;
192
193    let local_var_uri_str = format!("{}/filters/{id}", local_var_configuration.base_path, id=id);
194    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
195
196    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
197        let local_var_key = local_var_apikey.key.clone();
198        let local_var_value = match local_var_apikey.prefix {
199            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
200            None => local_var_key,
201        };
202        local_var_req_builder = local_var_req_builder.query(&[("api_token", local_var_value)]);
203    }
204    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
205        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
206    }
207    if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
208        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
209    };
210
211    let local_var_req = local_var_req_builder.build()?;
212    let local_var_resp = local_var_client.execute(local_var_req).await?;
213
214    let local_var_status = local_var_resp.status();
215    let local_var_content = local_var_resp.text().await?;
216
217    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
218        serde_json::from_str(&local_var_content).map_err(Error::from)
219    } else {
220        let local_var_entity: Option<GetFilterError> = serde_json::from_str(&local_var_content).ok();
221        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
222        Err(Error::ResponseError(local_var_error))
223    }
224}
225
226/// Returns all supported filter helpers. It helps to know what conditions and helpers are available when you want to <a href=\"/docs/api/v1/Filters#addFilter\">add</a> or <a href=\"/docs/api/v1/Filters#updateFilter\">update</a> filters. For more information, see the tutorial for <a href=\"https://pipedrive.readme.io/docs/adding-a-filter\" target=\"_blank\" rel=\"noopener noreferrer\">adding a filter</a>.
227pub async fn get_filter_helpers(configuration: &configuration::Configuration, ) -> Result<serde_json::Value, Error<GetFilterHelpersError>> {
228    let local_var_configuration = configuration;
229
230    let local_var_client = &local_var_configuration.client;
231
232    let local_var_uri_str = format!("{}/filters/helpers", local_var_configuration.base_path);
233    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
234
235    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
236        let local_var_key = local_var_apikey.key.clone();
237        let local_var_value = match local_var_apikey.prefix {
238            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
239            None => local_var_key,
240        };
241        local_var_req_builder = local_var_req_builder.query(&[("api_token", local_var_value)]);
242    }
243    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
244        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
245    }
246
247    let local_var_req = local_var_req_builder.build()?;
248    let local_var_resp = local_var_client.execute(local_var_req).await?;
249
250    let local_var_status = local_var_resp.status();
251    let local_var_content = local_var_resp.text().await?;
252
253    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
254        serde_json::from_str(&local_var_content).map_err(Error::from)
255    } else {
256        let local_var_entity: Option<GetFilterHelpersError> = serde_json::from_str(&local_var_content).ok();
257        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
258        Err(Error::ResponseError(local_var_error))
259    }
260}
261
262/// Returns data about all filters.
263pub async fn get_filters(configuration: &configuration::Configuration, r#type: Option<&str>) -> Result<crate::models::GetFiltersResponse200, Error<GetFiltersError>> {
264    let local_var_configuration = configuration;
265
266    let local_var_client = &local_var_configuration.client;
267
268    let local_var_uri_str = format!("{}/filters", local_var_configuration.base_path);
269    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
270
271    if let Some(ref local_var_str) = r#type {
272        local_var_req_builder = local_var_req_builder.query(&[("type", &local_var_str.to_string())]);
273    }
274    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
275        let local_var_key = local_var_apikey.key.clone();
276        let local_var_value = match local_var_apikey.prefix {
277            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
278            None => local_var_key,
279        };
280        local_var_req_builder = local_var_req_builder.query(&[("api_token", local_var_value)]);
281    }
282    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
283        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
284    }
285    if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
286        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
287    };
288
289    let local_var_req = local_var_req_builder.build()?;
290    let local_var_resp = local_var_client.execute(local_var_req).await?;
291
292    let local_var_status = local_var_resp.status();
293    let local_var_content = local_var_resp.text().await?;
294
295    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
296        serde_json::from_str(&local_var_content).map_err(Error::from)
297    } else {
298        let local_var_entity: Option<GetFiltersError> = serde_json::from_str(&local_var_content).ok();
299        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
300        Err(Error::ResponseError(local_var_error))
301    }
302}
303
304/// Updates an existing filter.
305pub async fn update_filter(configuration: &configuration::Configuration, id: i32, update_filter_request: Option<crate::models::UpdateFilterRequest>) -> Result<crate::models::PostFilterResponse200, Error<UpdateFilterError>> {
306    let local_var_configuration = configuration;
307
308    let local_var_client = &local_var_configuration.client;
309
310    let local_var_uri_str = format!("{}/filters/{id}", local_var_configuration.base_path, id=id);
311    let mut local_var_req_builder = local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
312
313    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
314        let local_var_key = local_var_apikey.key.clone();
315        let local_var_value = match local_var_apikey.prefix {
316            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
317            None => local_var_key,
318        };
319        local_var_req_builder = local_var_req_builder.query(&[("api_token", local_var_value)]);
320    }
321    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
322        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
323    }
324    if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
325        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
326    };
327    local_var_req_builder = local_var_req_builder.json(&update_filter_request);
328
329    let local_var_req = local_var_req_builder.build()?;
330    let local_var_resp = local_var_client.execute(local_var_req).await?;
331
332    let local_var_status = local_var_resp.status();
333    let local_var_content = local_var_resp.text().await?;
334
335    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
336        serde_json::from_str(&local_var_content).map_err(Error::from)
337    } else {
338        let local_var_entity: Option<UpdateFilterError> = serde_json::from_str(&local_var_content).ok();
339        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
340        Err(Error::ResponseError(local_var_error))
341    }
342}
343