pipedrive_rs/apis/
files_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_file`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum AddFileError {
22    UnknownValue(serde_json::Value),
23}
24
25/// struct for typed errors of method [`add_file_and_link_it`]
26#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(untagged)]
28pub enum AddFileAndLinkItError {
29    UnknownValue(serde_json::Value),
30}
31
32/// struct for typed errors of method [`delete_file`]
33#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum DeleteFileError {
36    UnknownValue(serde_json::Value),
37}
38
39/// struct for typed errors of method [`download_file`]
40#[derive(Debug, Clone, Serialize, Deserialize)]
41#[serde(untagged)]
42pub enum DownloadFileError {
43    UnknownValue(serde_json::Value),
44}
45
46/// struct for typed errors of method [`get_file`]
47#[derive(Debug, Clone, Serialize, Deserialize)]
48#[serde(untagged)]
49pub enum GetFileError {
50    UnknownValue(serde_json::Value),
51}
52
53/// struct for typed errors of method [`get_files`]
54#[derive(Debug, Clone, Serialize, Deserialize)]
55#[serde(untagged)]
56pub enum GetFilesError {
57    UnknownValue(serde_json::Value),
58}
59
60/// struct for typed errors of method [`link_file_to_item`]
61#[derive(Debug, Clone, Serialize, Deserialize)]
62#[serde(untagged)]
63pub enum LinkFileToItemError {
64    UnknownValue(serde_json::Value),
65}
66
67/// struct for typed errors of method [`update_file`]
68#[derive(Debug, Clone, Serialize, Deserialize)]
69#[serde(untagged)]
70pub enum UpdateFileError {
71    UnknownValue(serde_json::Value),
72}
73
74
75/// Lets you upload a file and associate it with a deal, person, organization, activity, product or lead. For more information, see the tutorial for <a href=\"https://pipedrive.readme.io/docs/adding-a-file\" target=\"_blank\" rel=\"noopener noreferrer\">adding a file</a>.
76pub async fn add_file(configuration: &configuration::Configuration, file: std::path::PathBuf, deal_id: Option<i32>, person_id: Option<i32>, org_id: Option<i32>, product_id: Option<i32>, activity_id: Option<i32>, lead_id: Option<&str>) -> Result<crate::models::AddFileResponse200, Error<AddFileError>> {
77    let local_var_configuration = configuration;
78
79    let local_var_client = &local_var_configuration.client;
80
81    let local_var_uri_str = format!("{}/files", local_var_configuration.base_path);
82    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
83
84    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
85        let local_var_key = local_var_apikey.key.clone();
86        let local_var_value = match local_var_apikey.prefix {
87            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
88            None => local_var_key,
89        };
90        local_var_req_builder = local_var_req_builder.query(&[("api_token", local_var_value)]);
91    }
92    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
93        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
94    }
95    if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
96        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
97    };
98    let mut local_var_form = reqwest::multipart::Form::new();
99    // TODO: support file upload for 'file' parameter
100    if let Some(local_var_param_value) = deal_id {
101        local_var_form = local_var_form.text("deal_id", local_var_param_value.to_string());
102    }
103    if let Some(local_var_param_value) = person_id {
104        local_var_form = local_var_form.text("person_id", local_var_param_value.to_string());
105    }
106    if let Some(local_var_param_value) = org_id {
107        local_var_form = local_var_form.text("org_id", local_var_param_value.to_string());
108    }
109    if let Some(local_var_param_value) = product_id {
110        local_var_form = local_var_form.text("product_id", local_var_param_value.to_string());
111    }
112    if let Some(local_var_param_value) = activity_id {
113        local_var_form = local_var_form.text("activity_id", local_var_param_value.to_string());
114    }
115    if let Some(local_var_param_value) = lead_id {
116        local_var_form = local_var_form.text("lead_id", local_var_param_value.to_string());
117    }
118    local_var_req_builder = local_var_req_builder.multipart(local_var_form);
119
120    let local_var_req = local_var_req_builder.build()?;
121    let local_var_resp = local_var_client.execute(local_var_req).await?;
122
123    let local_var_status = local_var_resp.status();
124    let local_var_content = local_var_resp.text().await?;
125
126    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
127        serde_json::from_str(&local_var_content).map_err(Error::from)
128    } else {
129        let local_var_entity: Option<AddFileError> = serde_json::from_str(&local_var_content).ok();
130        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
131        Err(Error::ResponseError(local_var_error))
132    }
133}
134
135/// Creates a new empty file in the remote location (`googledrive`) that will be linked to the item you supply. For more information, see the tutorial for <a href=\"https://pipedrive.readme.io/docs/adding-a-remote-file\" target=\"_blank\" rel=\"noopener noreferrer\">adding a remote file</a>.
136pub async fn add_file_and_link_it(configuration: &configuration::Configuration, file_type: &str, title: &str, item_type: &str, item_id: i32, remote_location: &str) -> Result<crate::models::AddFileAndLinkItResponse200, Error<AddFileAndLinkItError>> {
137    let local_var_configuration = configuration;
138
139    let local_var_client = &local_var_configuration.client;
140
141    let local_var_uri_str = format!("{}/files/remote", local_var_configuration.base_path);
142    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
143
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    let mut local_var_form_params = std::collections::HashMap::new();
159    local_var_form_params.insert("file_type", file_type.to_string());
160    local_var_form_params.insert("title", title.to_string());
161    local_var_form_params.insert("item_type", item_type.to_string());
162    local_var_form_params.insert("item_id", item_id.to_string());
163    local_var_form_params.insert("remote_location", remote_location.to_string());
164    local_var_req_builder = local_var_req_builder.form(&local_var_form_params);
165
166    let local_var_req = local_var_req_builder.build()?;
167    let local_var_resp = local_var_client.execute(local_var_req).await?;
168
169    let local_var_status = local_var_resp.status();
170    let local_var_content = local_var_resp.text().await?;
171
172    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
173        serde_json::from_str(&local_var_content).map_err(Error::from)
174    } else {
175        let local_var_entity: Option<AddFileAndLinkItError> = serde_json::from_str(&local_var_content).ok();
176        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
177        Err(Error::ResponseError(local_var_error))
178    }
179}
180
181/// Marks a file as deleted. After 30 days, the file will be permanently deleted.
182pub async fn delete_file(configuration: &configuration::Configuration, id: i32) -> Result<crate::models::DeleteFileResponse200, Error<DeleteFileError>> {
183    let local_var_configuration = configuration;
184
185    let local_var_client = &local_var_configuration.client;
186
187    let local_var_uri_str = format!("{}/files/{id}", local_var_configuration.base_path, id=id);
188    let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
189
190    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
191        let local_var_key = local_var_apikey.key.clone();
192        let local_var_value = match local_var_apikey.prefix {
193            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
194            None => local_var_key,
195        };
196        local_var_req_builder = local_var_req_builder.query(&[("api_token", local_var_value)]);
197    }
198    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
199        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
200    }
201    if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
202        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
203    };
204
205    let local_var_req = local_var_req_builder.build()?;
206    let local_var_resp = local_var_client.execute(local_var_req).await?;
207
208    let local_var_status = local_var_resp.status();
209    let local_var_content = local_var_resp.text().await?;
210
211    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
212        serde_json::from_str(&local_var_content).map_err(Error::from)
213    } else {
214        let local_var_entity: Option<DeleteFileError> = serde_json::from_str(&local_var_content).ok();
215        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
216        Err(Error::ResponseError(local_var_error))
217    }
218}
219
220/// Initializes a file download.
221pub async fn download_file(configuration: &configuration::Configuration, id: i32) -> Result<String, Error<DownloadFileError>> {
222    let local_var_configuration = configuration;
223
224    let local_var_client = &local_var_configuration.client;
225
226    let local_var_uri_str = format!("{}/files/{id}/download", local_var_configuration.base_path, id=id);
227    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
228
229    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
230        let local_var_key = local_var_apikey.key.clone();
231        let local_var_value = match local_var_apikey.prefix {
232            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
233            None => local_var_key,
234        };
235        local_var_req_builder = local_var_req_builder.query(&[("api_token", local_var_value)]);
236    }
237    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
238        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
239    }
240    if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
241        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
242    };
243
244    let local_var_req = local_var_req_builder.build()?;
245    let local_var_resp = local_var_client.execute(local_var_req).await?;
246
247    let local_var_status = local_var_resp.status();
248    let local_var_content = local_var_resp.text().await?;
249
250    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
251        serde_json::from_str(&local_var_content).map_err(Error::from)
252    } else {
253        let local_var_entity: Option<DownloadFileError> = serde_json::from_str(&local_var_content).ok();
254        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
255        Err(Error::ResponseError(local_var_error))
256    }
257}
258
259/// Returns data about a specific file.
260pub async fn get_file(configuration: &configuration::Configuration, id: i32) -> Result<crate::models::GetFileResponse200, Error<GetFileError>> {
261    let local_var_configuration = configuration;
262
263    let local_var_client = &local_var_configuration.client;
264
265    let local_var_uri_str = format!("{}/files/{id}", local_var_configuration.base_path, id=id);
266    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
267
268    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
269        let local_var_key = local_var_apikey.key.clone();
270        let local_var_value = match local_var_apikey.prefix {
271            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
272            None => local_var_key,
273        };
274        local_var_req_builder = local_var_req_builder.query(&[("api_token", local_var_value)]);
275    }
276    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
277        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
278    }
279    if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
280        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
281    };
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<GetFileError> = 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
298/// Returns data about all files.
299pub async fn get_files(configuration: &configuration::Configuration, start: Option<i32>, limit: Option<i32>, sort: Option<&str>) -> Result<crate::models::GetFilesResponse200, Error<GetFilesError>> {
300    let local_var_configuration = configuration;
301
302    let local_var_client = &local_var_configuration.client;
303
304    let local_var_uri_str = format!("{}/files", local_var_configuration.base_path);
305    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
306
307    if let Some(ref local_var_str) = start {
308        local_var_req_builder = local_var_req_builder.query(&[("start", &local_var_str.to_string())]);
309    }
310    if let Some(ref local_var_str) = limit {
311        local_var_req_builder = local_var_req_builder.query(&[("limit", &local_var_str.to_string())]);
312    }
313    if let Some(ref local_var_str) = sort {
314        local_var_req_builder = local_var_req_builder.query(&[("sort", &local_var_str.to_string())]);
315    }
316    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
317        let local_var_key = local_var_apikey.key.clone();
318        let local_var_value = match local_var_apikey.prefix {
319            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
320            None => local_var_key,
321        };
322        local_var_req_builder = local_var_req_builder.query(&[("api_token", local_var_value)]);
323    }
324    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
325        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
326    }
327    if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
328        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
329    };
330
331    let local_var_req = local_var_req_builder.build()?;
332    let local_var_resp = local_var_client.execute(local_var_req).await?;
333
334    let local_var_status = local_var_resp.status();
335    let local_var_content = local_var_resp.text().await?;
336
337    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
338        serde_json::from_str(&local_var_content).map_err(Error::from)
339    } else {
340        let local_var_entity: Option<GetFilesError> = serde_json::from_str(&local_var_content).ok();
341        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
342        Err(Error::ResponseError(local_var_error))
343    }
344}
345
346/// Links an existing remote file (`googledrive`) to the item you supply. For more information, see the tutorial for <a href=\"https://pipedrive.readme.io/docs/adding-a-remote-file\" target=\"_blank\" rel=\"noopener noreferrer\">adding a remote file</a>.
347pub async fn link_file_to_item(configuration: &configuration::Configuration, item_type: &str, item_id: i32, remote_id: &str, remote_location: &str) -> Result<crate::models::LinkFileToItemResponse200, Error<LinkFileToItemError>> {
348    let local_var_configuration = configuration;
349
350    let local_var_client = &local_var_configuration.client;
351
352    let local_var_uri_str = format!("{}/files/remoteLink", local_var_configuration.base_path);
353    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
354
355    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
356        let local_var_key = local_var_apikey.key.clone();
357        let local_var_value = match local_var_apikey.prefix {
358            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
359            None => local_var_key,
360        };
361        local_var_req_builder = local_var_req_builder.query(&[("api_token", local_var_value)]);
362    }
363    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
364        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
365    }
366    if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
367        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
368    };
369    let mut local_var_form_params = std::collections::HashMap::new();
370    local_var_form_params.insert("item_type", item_type.to_string());
371    local_var_form_params.insert("item_id", item_id.to_string());
372    local_var_form_params.insert("remote_id", remote_id.to_string());
373    local_var_form_params.insert("remote_location", remote_location.to_string());
374    local_var_req_builder = local_var_req_builder.form(&local_var_form_params);
375
376    let local_var_req = local_var_req_builder.build()?;
377    let local_var_resp = local_var_client.execute(local_var_req).await?;
378
379    let local_var_status = local_var_resp.status();
380    let local_var_content = local_var_resp.text().await?;
381
382    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
383        serde_json::from_str(&local_var_content).map_err(Error::from)
384    } else {
385        let local_var_entity: Option<LinkFileToItemError> = serde_json::from_str(&local_var_content).ok();
386        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
387        Err(Error::ResponseError(local_var_error))
388    }
389}
390
391/// Updates the properties of a file.
392pub async fn update_file(configuration: &configuration::Configuration, id: i32, name: Option<&str>, description: Option<&str>) -> Result<crate::models::UpdateFileResponse200, Error<UpdateFileError>> {
393    let local_var_configuration = configuration;
394
395    let local_var_client = &local_var_configuration.client;
396
397    let local_var_uri_str = format!("{}/files/{id}", local_var_configuration.base_path, id=id);
398    let mut local_var_req_builder = local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
399
400    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
401        let local_var_key = local_var_apikey.key.clone();
402        let local_var_value = match local_var_apikey.prefix {
403            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
404            None => local_var_key,
405        };
406        local_var_req_builder = local_var_req_builder.query(&[("api_token", local_var_value)]);
407    }
408    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
409        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
410    }
411    if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
412        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
413    };
414    let mut local_var_form_params = std::collections::HashMap::new();
415    if let Some(local_var_param_value) = name {
416        local_var_form_params.insert("name", local_var_param_value.to_string());
417    }
418    if let Some(local_var_param_value) = description {
419        local_var_form_params.insert("description", local_var_param_value.to_string());
420    }
421    local_var_req_builder = local_var_req_builder.form(&local_var_form_params);
422
423    let local_var_req = local_var_req_builder.build()?;
424    let local_var_resp = local_var_client.execute(local_var_req).await?;
425
426    let local_var_status = local_var_resp.status();
427    let local_var_content = local_var_resp.text().await?;
428
429    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
430        serde_json::from_str(&local_var_content).map_err(Error::from)
431    } else {
432        let local_var_entity: Option<UpdateFileError> = serde_json::from_str(&local_var_content).ok();
433        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
434        Err(Error::ResponseError(local_var_error))
435    }
436}
437