pipedrive_rs/apis/
goals_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_goal`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum AddGoalError {
22    UnknownValue(serde_json::Value),
23}
24
25/// struct for typed errors of method [`delete_goal`]
26#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(untagged)]
28pub enum DeleteGoalError {
29    UnknownValue(serde_json::Value),
30}
31
32/// struct for typed errors of method [`get_goal_result`]
33#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum GetGoalResultError {
36    UnknownValue(serde_json::Value),
37}
38
39/// struct for typed errors of method [`get_goals`]
40#[derive(Debug, Clone, Serialize, Deserialize)]
41#[serde(untagged)]
42pub enum GetGoalsError {
43    UnknownValue(serde_json::Value),
44}
45
46/// struct for typed errors of method [`update_goal`]
47#[derive(Debug, Clone, Serialize, Deserialize)]
48#[serde(untagged)]
49pub enum UpdateGoalError {
50    UnknownValue(serde_json::Value),
51}
52
53
54/// Adds a new goal. Along with adding a new goal, a report is created to track the progress of your goal.
55pub async fn add_goal(configuration: &configuration::Configuration, add_goal_request: Option<crate::models::AddGoalRequest>) -> Result<crate::models::AddOrUpdateGoalResponse200, Error<AddGoalError>> {
56    let local_var_configuration = configuration;
57
58    let local_var_client = &local_var_configuration.client;
59
60    let local_var_uri_str = format!("{}/goals", local_var_configuration.base_path);
61    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
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.query(&[("api_token", local_var_value)]);
70    }
71    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
72        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
73    }
74    if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
75        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
76    };
77    local_var_req_builder = local_var_req_builder.json(&add_goal_request);
78
79    let local_var_req = local_var_req_builder.build()?;
80    let local_var_resp = local_var_client.execute(local_var_req).await?;
81
82    let local_var_status = local_var_resp.status();
83    let local_var_content = local_var_resp.text().await?;
84
85    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
86        serde_json::from_str(&local_var_content).map_err(Error::from)
87    } else {
88        let local_var_entity: Option<AddGoalError> = serde_json::from_str(&local_var_content).ok();
89        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
90        Err(Error::ResponseError(local_var_error))
91    }
92}
93
94/// Marks a goal as deleted.
95pub async fn delete_goal(configuration: &configuration::Configuration, id: &str) -> Result<crate::models::DeleteGoalResponse200, Error<DeleteGoalError>> {
96    let local_var_configuration = configuration;
97
98    let local_var_client = &local_var_configuration.client;
99
100    let local_var_uri_str = format!("{}/goals/{id}", local_var_configuration.base_path, id=crate::apis::urlencode(id));
101    let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
102
103    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
104        let local_var_key = local_var_apikey.key.clone();
105        let local_var_value = match local_var_apikey.prefix {
106            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
107            None => local_var_key,
108        };
109        local_var_req_builder = local_var_req_builder.query(&[("api_token", local_var_value)]);
110    }
111    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
112        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
113    }
114    if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
115        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
116    };
117
118    let local_var_req = local_var_req_builder.build()?;
119    let local_var_resp = local_var_client.execute(local_var_req).await?;
120
121    let local_var_status = local_var_resp.status();
122    let local_var_content = local_var_resp.text().await?;
123
124    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
125        serde_json::from_str(&local_var_content).map_err(Error::from)
126    } else {
127        let local_var_entity: Option<DeleteGoalError> = serde_json::from_str(&local_var_content).ok();
128        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
129        Err(Error::ResponseError(local_var_error))
130    }
131}
132
133/// Gets the progress of a goal for the specified period.
134pub async fn get_goal_result(configuration: &configuration::Configuration, id: &str, period_period_start: String, period_period_end: String) -> Result<crate::models::GetGoalResultResponse200, Error<GetGoalResultError>> {
135    let local_var_configuration = configuration;
136
137    let local_var_client = &local_var_configuration.client;
138
139    let local_var_uri_str = format!("{}/goals/{id}/results", local_var_configuration.base_path, id=crate::apis::urlencode(id));
140    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
141
142    local_var_req_builder = local_var_req_builder.query(&[("period.start", &period_period_start.to_string())]);
143    local_var_req_builder = local_var_req_builder.query(&[("period.end", &period_period_end.to_string())]);
144    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
145        let local_var_key = local_var_apikey.key.clone();
146        let local_var_value = match local_var_apikey.prefix {
147            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
148            None => local_var_key,
149        };
150        local_var_req_builder = local_var_req_builder.query(&[("api_token", local_var_value)]);
151    }
152    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
153        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
154    }
155    if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
156        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
157    };
158
159    let local_var_req = local_var_req_builder.build()?;
160    let local_var_resp = local_var_client.execute(local_var_req).await?;
161
162    let local_var_status = local_var_resp.status();
163    let local_var_content = local_var_resp.text().await?;
164
165    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
166        serde_json::from_str(&local_var_content).map_err(Error::from)
167    } else {
168        let local_var_entity: Option<GetGoalResultError> = serde_json::from_str(&local_var_content).ok();
169        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
170        Err(Error::ResponseError(local_var_error))
171    }
172}
173
174/// Returns data about goals based on criteria. For searching, append `{searchField}={searchValue}` to the URL, where `searchField` can be any one of the lowest-level fields in dot-notation (e.g. `type.params.pipeline_id`; `title`). `searchValue` should be the value you are looking for on that field. Additionally, `is_active=<true|false>` can be provided to search for only active/inactive goals. When providing `period.start`, `period.end` must also be provided and vice versa.
175pub async fn get_goals(configuration: &configuration::Configuration, type_period_name: Option<&str>, title: Option<&str>, is_active: Option<bool>, assignee_period_id: Option<i32>, assignee_period_type: Option<&str>, expected_outcome_period_target: Option<f32>, expected_outcome_period_tracking_metric: Option<&str>, expected_outcome_period_currency_id: Option<i32>, type_period_params_period_pipeline_id: Option<Vec<i32>>, type_period_params_period_stage_id: Option<i32>, type_period_params_period_activity_type_id: Option<Vec<i32>>, period_period_start: Option<String>, period_period_end: Option<String>) -> Result<crate::models::GetGoalsResponse200, Error<GetGoalsError>> {
176    let local_var_configuration = configuration;
177
178    let local_var_client = &local_var_configuration.client;
179
180    let local_var_uri_str = format!("{}/goals/find", local_var_configuration.base_path);
181    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
182
183    if let Some(ref local_var_str) = type_period_name {
184        local_var_req_builder = local_var_req_builder.query(&[("type.name", &local_var_str.to_string())]);
185    }
186    if let Some(ref local_var_str) = title {
187        local_var_req_builder = local_var_req_builder.query(&[("title", &local_var_str.to_string())]);
188    }
189    if let Some(ref local_var_str) = is_active {
190        local_var_req_builder = local_var_req_builder.query(&[("is_active", &local_var_str.to_string())]);
191    }
192    if let Some(ref local_var_str) = assignee_period_id {
193        local_var_req_builder = local_var_req_builder.query(&[("assignee.id", &local_var_str.to_string())]);
194    }
195    if let Some(ref local_var_str) = assignee_period_type {
196        local_var_req_builder = local_var_req_builder.query(&[("assignee.type", &local_var_str.to_string())]);
197    }
198    if let Some(ref local_var_str) = expected_outcome_period_target {
199        local_var_req_builder = local_var_req_builder.query(&[("expected_outcome.target", &local_var_str.to_string())]);
200    }
201    if let Some(ref local_var_str) = expected_outcome_period_tracking_metric {
202        local_var_req_builder = local_var_req_builder.query(&[("expected_outcome.tracking_metric", &local_var_str.to_string())]);
203    }
204    if let Some(ref local_var_str) = expected_outcome_period_currency_id {
205        local_var_req_builder = local_var_req_builder.query(&[("expected_outcome.currency_id", &local_var_str.to_string())]);
206    }
207    if let Some(ref local_var_str) = type_period_params_period_pipeline_id {
208        local_var_req_builder = match "multi" {
209            "multi" => local_var_req_builder.query(&local_var_str.into_iter().map(|p| ("type.params.pipeline_id".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
210            _ => local_var_req_builder.query(&[("type.params.pipeline_id", &local_var_str.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
211        };
212    }
213    if let Some(ref local_var_str) = type_period_params_period_stage_id {
214        local_var_req_builder = local_var_req_builder.query(&[("type.params.stage_id", &local_var_str.to_string())]);
215    }
216    if let Some(ref local_var_str) = type_period_params_period_activity_type_id {
217        local_var_req_builder = match "multi" {
218            "multi" => local_var_req_builder.query(&local_var_str.into_iter().map(|p| ("type.params.activity_type_id".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
219            _ => local_var_req_builder.query(&[("type.params.activity_type_id", &local_var_str.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
220        };
221    }
222    if let Some(ref local_var_str) = period_period_start {
223        local_var_req_builder = local_var_req_builder.query(&[("period.start", &local_var_str.to_string())]);
224    }
225    if let Some(ref local_var_str) = period_period_end {
226        local_var_req_builder = local_var_req_builder.query(&[("period.end", &local_var_str.to_string())]);
227    }
228    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
229        let local_var_key = local_var_apikey.key.clone();
230        let local_var_value = match local_var_apikey.prefix {
231            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
232            None => local_var_key,
233        };
234        local_var_req_builder = local_var_req_builder.query(&[("api_token", local_var_value)]);
235    }
236    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
237        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
238    }
239    if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
240        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
241    };
242
243    let local_var_req = local_var_req_builder.build()?;
244    let local_var_resp = local_var_client.execute(local_var_req).await?;
245
246    let local_var_status = local_var_resp.status();
247    let local_var_content = local_var_resp.text().await?;
248
249    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
250        serde_json::from_str(&local_var_content).map_err(Error::from)
251    } else {
252        let local_var_entity: Option<GetGoalsError> = serde_json::from_str(&local_var_content).ok();
253        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
254        Err(Error::ResponseError(local_var_error))
255    }
256}
257
258/// Updates an existing goal.
259pub async fn update_goal(configuration: &configuration::Configuration, id: &str, basic_goal_request: Option<crate::models::BasicGoalRequest>) -> Result<crate::models::AddOrUpdateGoalResponse200, Error<UpdateGoalError>> {
260    let local_var_configuration = configuration;
261
262    let local_var_client = &local_var_configuration.client;
263
264    let local_var_uri_str = format!("{}/goals/{id}", local_var_configuration.base_path, id=crate::apis::urlencode(id));
265    let mut local_var_req_builder = local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
266
267    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
268        let local_var_key = local_var_apikey.key.clone();
269        let local_var_value = match local_var_apikey.prefix {
270            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
271            None => local_var_key,
272        };
273        local_var_req_builder = local_var_req_builder.query(&[("api_token", local_var_value)]);
274    }
275    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
276        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
277    }
278    if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
279        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
280    };
281    local_var_req_builder = local_var_req_builder.json(&basic_goal_request);
282
283    let local_var_req = local_var_req_builder.build()?;
284    let local_var_resp = local_var_client.execute(local_var_req).await?;
285
286    let local_var_status = local_var_resp.status();
287    let local_var_content = local_var_resp.text().await?;
288
289    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
290        serde_json::from_str(&local_var_content).map_err(Error::from)
291    } else {
292        let local_var_entity: Option<UpdateGoalError> = serde_json::from_str(&local_var_content).ok();
293        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
294        Err(Error::ResponseError(local_var_error))
295    }
296}
297