pipedrive_rs/apis/
lead_sources_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_lead_sources`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum GetLeadSourcesError {
22    UnknownValue(serde_json::Value),
23}
24
25
26/// Returns all lead sources. Please note that the list of lead sources is fixed, it cannot be modified. All leads created through the Pipedrive API will have a lead source `API` assigned. 
27pub async fn get_lead_sources(configuration: &configuration::Configuration, ) -> Result<crate::models::GetLeadSourcesResponse200, Error<GetLeadSourcesError>> {
28    let local_var_configuration = configuration;
29
30    let local_var_client = &local_var_configuration.client;
31
32    let local_var_uri_str = format!("{}/leadSources", 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    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
36        let local_var_key = local_var_apikey.key.clone();
37        let local_var_value = match local_var_apikey.prefix {
38            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
39            None => local_var_key,
40        };
41        local_var_req_builder = local_var_req_builder.query(&[("api_token", local_var_value)]);
42    }
43    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
44        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
45    }
46    if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
47        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
48    };
49
50    let local_var_req = local_var_req_builder.build()?;
51    let local_var_resp = local_var_client.execute(local_var_req).await?;
52
53    let local_var_status = local_var_resp.status();
54    let local_var_content = local_var_resp.text().await?;
55
56    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
57        serde_json::from_str(&local_var_content).map_err(Error::from)
58    } else {
59        let local_var_entity: Option<GetLeadSourcesError> = serde_json::from_str(&local_var_content).ok();
60        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
61        Err(Error::ResponseError(local_var_error))
62    }
63}
64