pipedrive_rs/apis/
activity_types_api.rs1use reqwest;
13
14use crate::apis::ResponseContent;
15use super::{Error, configuration};
16
17
18#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum AddActivityTypeError {
22 UnknownValue(serde_json::Value),
23}
24
25#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(untagged)]
28pub enum DeleteActivityTypeError {
29 UnknownValue(serde_json::Value),
30}
31
32#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum DeleteActivityTypesError {
36 UnknownValue(serde_json::Value),
37}
38
39#[derive(Debug, Clone, Serialize, Deserialize)]
41#[serde(untagged)]
42pub enum GetActivityTypesError {
43 UnknownValue(serde_json::Value),
44}
45
46#[derive(Debug, Clone, Serialize, Deserialize)]
48#[serde(untagged)]
49pub enum UpdateActivityTypeError {
50 UnknownValue(serde_json::Value),
51}
52
53
54pub async fn add_activity_type(configuration: &configuration::Configuration, add_activity_type_request: Option<crate::models::AddActivityTypeRequest>) -> Result<crate::models::CreateUpdateDeleteActivityTypeResponse200, Error<AddActivityTypeError>> {
56 let local_var_configuration = configuration;
57
58 let local_var_client = &local_var_configuration.client;
59
60 let local_var_uri_str = format!("{}/activityTypes", 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_activity_type_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<AddActivityTypeError> = 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
94pub async fn delete_activity_type(configuration: &configuration::Configuration, id: i32) -> Result<crate::models::CreateUpdateDeleteActivityTypeResponse200, Error<DeleteActivityTypeError>> {
96 let local_var_configuration = configuration;
97
98 let local_var_client = &local_var_configuration.client;
99
100 let local_var_uri_str = format!("{}/activityTypes/{id}", local_var_configuration.base_path, id=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<DeleteActivityTypeError> = 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
133pub async fn delete_activity_types(configuration: &configuration::Configuration, ids: &str) -> Result<crate::models::DeleteActivityTypesResponse200, Error<DeleteActivityTypesError>> {
135 let local_var_configuration = configuration;
136
137 let local_var_client = &local_var_configuration.client;
138
139 let local_var_uri_str = format!("{}/activityTypes", local_var_configuration.base_path);
140 let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
141
142 local_var_req_builder = local_var_req_builder.query(&[("ids", &ids.to_string())]);
143 if let Some(ref local_var_apikey) = local_var_configuration.api_key {
144 let local_var_key = local_var_apikey.key.clone();
145 let local_var_value = match local_var_apikey.prefix {
146 Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
147 None => local_var_key,
148 };
149 local_var_req_builder = local_var_req_builder.query(&[("api_token", local_var_value)]);
150 }
151 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
152 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
153 }
154 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
155 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
156 };
157
158 let local_var_req = local_var_req_builder.build()?;
159 let local_var_resp = local_var_client.execute(local_var_req).await?;
160
161 let local_var_status = local_var_resp.status();
162 let local_var_content = local_var_resp.text().await?;
163
164 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
165 serde_json::from_str(&local_var_content).map_err(Error::from)
166 } else {
167 let local_var_entity: Option<DeleteActivityTypesError> = serde_json::from_str(&local_var_content).ok();
168 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
169 Err(Error::ResponseError(local_var_error))
170 }
171}
172
173pub async fn get_activity_types(configuration: &configuration::Configuration, ) -> Result<crate::models::GetActivityTypesResponse200, Error<GetActivityTypesError>> {
175 let local_var_configuration = configuration;
176
177 let local_var_client = &local_var_configuration.client;
178
179 let local_var_uri_str = format!("{}/activityTypes", local_var_configuration.base_path);
180 let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
181
182 if let Some(ref local_var_apikey) = local_var_configuration.api_key {
183 let local_var_key = local_var_apikey.key.clone();
184 let local_var_value = match local_var_apikey.prefix {
185 Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
186 None => local_var_key,
187 };
188 local_var_req_builder = local_var_req_builder.query(&[("api_token", local_var_value)]);
189 }
190 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
191 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
192 }
193 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
194 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
195 };
196
197 let local_var_req = local_var_req_builder.build()?;
198 let local_var_resp = local_var_client.execute(local_var_req).await?;
199
200 let local_var_status = local_var_resp.status();
201 let local_var_content = local_var_resp.text().await?;
202
203 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
204 serde_json::from_str(&local_var_content).map_err(Error::from)
205 } else {
206 let local_var_entity: Option<GetActivityTypesError> = serde_json::from_str(&local_var_content).ok();
207 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
208 Err(Error::ResponseError(local_var_error))
209 }
210}
211
212pub async fn update_activity_type(configuration: &configuration::Configuration, id: i32, update_activity_type_request: Option<crate::models::UpdateActivityTypeRequest>) -> Result<crate::models::CreateUpdateDeleteActivityTypeResponse200, Error<UpdateActivityTypeError>> {
214 let local_var_configuration = configuration;
215
216 let local_var_client = &local_var_configuration.client;
217
218 let local_var_uri_str = format!("{}/activityTypes/{id}", local_var_configuration.base_path, id=id);
219 let mut local_var_req_builder = local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
220
221 if let Some(ref local_var_apikey) = local_var_configuration.api_key {
222 let local_var_key = local_var_apikey.key.clone();
223 let local_var_value = match local_var_apikey.prefix {
224 Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
225 None => local_var_key,
226 };
227 local_var_req_builder = local_var_req_builder.query(&[("api_token", local_var_value)]);
228 }
229 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
230 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
231 }
232 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
233 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
234 };
235 local_var_req_builder = local_var_req_builder.json(&update_activity_type_request);
236
237 let local_var_req = local_var_req_builder.build()?;
238 let local_var_resp = local_var_client.execute(local_var_req).await?;
239
240 let local_var_status = local_var_resp.status();
241 let local_var_content = local_var_resp.text().await?;
242
243 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
244 serde_json::from_str(&local_var_content).map_err(Error::from)
245 } else {
246 let local_var_entity: Option<UpdateActivityTypeError> = serde_json::from_str(&local_var_content).ok();
247 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
248 Err(Error::ResponseError(local_var_error))
249 }
250}
251