pipedrive_rs/apis/
recents_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 [`get_recents`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum GetRecentsError {
22    UnknownValue(serde_json::Value),
23}
24
25
26/// Returns data about all recent changes occurred after the given timestamp.
27pub async fn get_recents(configuration: &configuration::Configuration, since_timestamp: &str, items: Option<&str>, start: Option<i32>, limit: Option<i32>) -> Result<crate::models::GetRecentsResponse200, Error<GetRecentsError>> {
28    let local_var_configuration = configuration;
29
30    let local_var_client = &local_var_configuration.client;
31
32    let local_var_uri_str = format!("{}/recents", local_var_configuration.base_path);
33    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
34
35    local_var_req_builder = local_var_req_builder.query(&[("since_timestamp", &since_timestamp.to_string())]);
36    if let Some(ref local_var_str) = items {
37        local_var_req_builder = local_var_req_builder.query(&[("items", &local_var_str.to_string())]);
38    }
39    if let Some(ref local_var_str) = start {
40        local_var_req_builder = local_var_req_builder.query(&[("start", &local_var_str.to_string())]);
41    }
42    if let Some(ref local_var_str) = limit {
43        local_var_req_builder = local_var_req_builder.query(&[("limit", &local_var_str.to_string())]);
44    }
45    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
46        let local_var_key = local_var_apikey.key.clone();
47        let local_var_value = match local_var_apikey.prefix {
48            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
49            None => local_var_key,
50        };
51        local_var_req_builder = local_var_req_builder.query(&[("api_token", local_var_value)]);
52    }
53    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
54        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
55    }
56    if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
57        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
58    };
59
60    let local_var_req = local_var_req_builder.build()?;
61    let local_var_resp = local_var_client.execute(local_var_req).await?;
62
63    let local_var_status = local_var_resp.status();
64    let local_var_content = local_var_resp.text().await?;
65
66    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
67        serde_json::from_str(&local_var_content).map_err(Error::from)
68    } else {
69        let local_var_entity: Option<GetRecentsError> = serde_json::from_str(&local_var_content).ok();
70        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
71        Err(Error::ResponseError(local_var_error))
72    }
73}
74