1use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17
18#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum AddSightingError {
22 Status403(models::UnauthorizedApiError),
23 Status404(models::NotFoundApiError),
24 DefaultResponse(models::ApiError),
25 UnknownValue(serde_json::Value),
26}
27
28#[derive(Debug, Clone, Serialize, Deserialize)]
30#[serde(untagged)]
31pub enum AddSightingByValueError {
32 Status403(models::UnauthorizedApiError),
33 Status404(models::NotFoundApiError),
34 DefaultResponse(models::ApiError),
35 UnknownValue(serde_json::Value),
36}
37
38#[derive(Debug, Clone, Serialize, Deserialize)]
40#[serde(untagged)]
41pub enum DeleteSightingError {
42 Status403(models::UnauthorizedApiError),
43 Status404(models::NotFoundApiError),
44 DefaultResponse(models::ApiError),
45 UnknownValue(serde_json::Value),
46}
47
48#[derive(Debug, Clone, Serialize, Deserialize)]
50#[serde(untagged)]
51pub enum GetSightingsByEventIdError {
52 Status403(models::UnauthorizedApiError),
53 Status404(models::NotFoundApiError),
54 DefaultResponse(models::ApiError),
55 UnknownValue(serde_json::Value),
56}
57
58
59pub async fn add_sighting(configuration: &configuration::Configuration, attribute_id: &str) -> Result<models::Sighting, Error<AddSightingError>> {
60 let p_attribute_id = attribute_id;
62
63 let uri_str = format!("{}/sightings/add/{attributeId}", configuration.base_path, attributeId=p_attribute_id.to_string());
64 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
65
66 if let Some(ref user_agent) = configuration.user_agent {
67 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
68 }
69 if let Some(ref apikey) = configuration.api_key {
70 let key = apikey.key.clone();
71 let value = match apikey.prefix {
72 Some(ref prefix) => format!("{} {}", prefix, key),
73 None => key,
74 };
75 req_builder = req_builder.header("Authorization", value);
76 };
77
78 let req = req_builder.build()?;
79 let resp = configuration.client.execute(req).await?;
80
81 let status = resp.status();
82 let content_type = resp
83 .headers()
84 .get("content-type")
85 .and_then(|v| v.to_str().ok())
86 .unwrap_or("application/octet-stream");
87 let content_type = super::ContentType::from(content_type);
88
89 if !status.is_client_error() && !status.is_server_error() {
90 let content = resp.text().await?;
91 match content_type {
92 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
93 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Sighting`"))),
94 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::Sighting`")))),
95 }
96 } else {
97 let content = resp.text().await?;
98 let entity: Option<AddSightingError> = serde_json::from_str(&content).ok();
99 Err(Error::ResponseError(ResponseContent { status, content, entity }))
100 }
101}
102
103pub async fn add_sighting_by_value(configuration: &configuration::Configuration, add_sighting_by_value_request: Option<models::AddSightingByValueRequest>) -> Result<models::Sighting, Error<AddSightingByValueError>> {
104 let p_add_sighting_by_value_request = add_sighting_by_value_request;
106
107 let uri_str = format!("{}/sightings/add", configuration.base_path);
108 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
109
110 if let Some(ref user_agent) = configuration.user_agent {
111 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
112 }
113 if let Some(ref apikey) = configuration.api_key {
114 let key = apikey.key.clone();
115 let value = match apikey.prefix {
116 Some(ref prefix) => format!("{} {}", prefix, key),
117 None => key,
118 };
119 req_builder = req_builder.header("Authorization", value);
120 };
121 req_builder = req_builder.json(&p_add_sighting_by_value_request);
122
123 let req = req_builder.build()?;
124 let resp = configuration.client.execute(req).await?;
125
126 let status = resp.status();
127 let content_type = resp
128 .headers()
129 .get("content-type")
130 .and_then(|v| v.to_str().ok())
131 .unwrap_or("application/octet-stream");
132 let content_type = super::ContentType::from(content_type);
133
134 if !status.is_client_error() && !status.is_server_error() {
135 let content = resp.text().await?;
136 match content_type {
137 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
138 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Sighting`"))),
139 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::Sighting`")))),
140 }
141 } else {
142 let content = resp.text().await?;
143 let entity: Option<AddSightingByValueError> = serde_json::from_str(&content).ok();
144 Err(Error::ResponseError(ResponseContent { status, content, entity }))
145 }
146}
147
148pub async fn delete_sighting(configuration: &configuration::Configuration, sighting_id: &str) -> Result<models::DeleteSighting200Response, Error<DeleteSightingError>> {
149 let p_sighting_id = sighting_id;
151
152 let uri_str = format!("{}/sightings/delete/{sightingId}", configuration.base_path, sightingId=crate::apis::urlencode(p_sighting_id));
153 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
154
155 if let Some(ref user_agent) = configuration.user_agent {
156 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
157 }
158 if let Some(ref apikey) = configuration.api_key {
159 let key = apikey.key.clone();
160 let value = match apikey.prefix {
161 Some(ref prefix) => format!("{} {}", prefix, key),
162 None => key,
163 };
164 req_builder = req_builder.header("Authorization", value);
165 };
166
167 let req = req_builder.build()?;
168 let resp = configuration.client.execute(req).await?;
169
170 let status = resp.status();
171 let content_type = resp
172 .headers()
173 .get("content-type")
174 .and_then(|v| v.to_str().ok())
175 .unwrap_or("application/octet-stream");
176 let content_type = super::ContentType::from(content_type);
177
178 if !status.is_client_error() && !status.is_server_error() {
179 let content = resp.text().await?;
180 match content_type {
181 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
182 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::DeleteSighting200Response`"))),
183 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::DeleteSighting200Response`")))),
184 }
185 } else {
186 let content = resp.text().await?;
187 let entity: Option<DeleteSightingError> = serde_json::from_str(&content).ok();
188 Err(Error::ResponseError(ResponseContent { status, content, entity }))
189 }
190}
191
192pub async fn get_sightings_by_event_id(configuration: &configuration::Configuration, event_id: &str) -> Result<Vec<models::Sighting>, Error<GetSightingsByEventIdError>> {
193 let p_event_id = event_id;
195
196 let uri_str = format!("{}/sightings/index/{eventId}", configuration.base_path, eventId=p_event_id.to_string());
197 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
198
199 if let Some(ref user_agent) = configuration.user_agent {
200 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
201 }
202 if let Some(ref apikey) = configuration.api_key {
203 let key = apikey.key.clone();
204 let value = match apikey.prefix {
205 Some(ref prefix) => format!("{} {}", prefix, key),
206 None => key,
207 };
208 req_builder = req_builder.header("Authorization", value);
209 };
210
211 let req = req_builder.build()?;
212 let resp = configuration.client.execute(req).await?;
213
214 let status = resp.status();
215 let content_type = resp
216 .headers()
217 .get("content-type")
218 .and_then(|v| v.to_str().ok())
219 .unwrap_or("application/octet-stream");
220 let content_type = super::ContentType::from(content_type);
221
222 if !status.is_client_error() && !status.is_server_error() {
223 let content = resp.text().await?;
224 match content_type {
225 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
226 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec<models::Sighting>`"))),
227 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `Vec<models::Sighting>`")))),
228 }
229 } else {
230 let content = resp.text().await?;
231 let entity: Option<GetSightingsByEventIdError> = serde_json::from_str(&content).ok();
232 Err(Error::ResponseError(ResponseContent { status, content, entity }))
233 }
234}
235