1use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17#[derive(Clone, Debug)]
19pub struct CreateCrawlParams {
20 pub create_crawl_request: models::CreateCrawlRequest
21}
22
23#[derive(Clone, Debug)]
25pub struct DeleteCrawlByIdParams {
26 pub crawl_id: String
28}
29
30#[derive(Clone, Debug)]
32pub struct GetCrawlByIdParams {
33 pub crawl_id: String
35}
36
37#[derive(Clone, Debug)]
39pub struct ListCrawlsParams {
40 pub limit: Option<u8>,
42 pub cursor: Option<String>,
44 pub address: Option<String>,
46 pub port: Option<u16>,
48 pub version: Option<String>,
50 pub protocol_version: Option<i32>,
52 pub crawled_from: Option<chrono::DateTime<chrono::FixedOffset>>,
54 pub crawled_to: Option<chrono::DateTime<chrono::FixedOffset>>
56}
57
58
59#[derive(Debug, Clone, Serialize, Deserialize)]
61#[serde(untagged)]
62pub enum CreateCrawlError {
63 Status400(),
64 Status401(),
65 Status403(),
66 UnknownValue(serde_json::Value),
67}
68
69#[derive(Debug, Clone, Serialize, Deserialize)]
71#[serde(untagged)]
72pub enum DeleteCrawlByIdError {
73 Status401(),
74 Status403(),
75 Status404(),
76 UnknownValue(serde_json::Value),
77}
78
79#[derive(Debug, Clone, Serialize, Deserialize)]
81#[serde(untagged)]
82pub enum GetCrawlByIdError {
83 Status401(),
84 Status403(),
85 Status404(),
86 UnknownValue(serde_json::Value),
87}
88
89#[derive(Debug, Clone, Serialize, Deserialize)]
91#[serde(untagged)]
92pub enum ListCrawlsError {
93 Status400(),
94 Status401(),
95 Status403(),
96 UnknownValue(serde_json::Value),
97}
98
99
100pub async fn create_crawl(configuration: &configuration::Configuration, params: CreateCrawlParams) -> Result<models::Crawl, Error<CreateCrawlError>> {
102
103 let uri_str = format!("{}/crawls", configuration.base_path);
104 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
105
106 if let Some(ref user_agent) = configuration.user_agent {
107 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
108 }
109 if let Some(ref token) = configuration.bearer_access_token {
110 req_builder = req_builder.bearer_auth(token.to_owned());
111 };
112 req_builder = req_builder.json(¶ms.create_crawl_request);
113
114 let req = req_builder.build()?;
115 let resp = configuration.client.execute(req).await?;
116
117 let status = resp.status();
118 let content_type = resp
119 .headers()
120 .get("content-type")
121 .and_then(|v| v.to_str().ok())
122 .unwrap_or("application/octet-stream");
123 let content_type = super::ContentType::from(content_type);
124
125 if !status.is_client_error() && !status.is_server_error() {
126 let content = resp.text().await?;
127 match content_type {
128 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
129 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Crawl`"))),
130 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::Crawl`")))),
131 }
132 } else {
133 let content = resp.text().await?;
134 let entity: Option<CreateCrawlError> = serde_json::from_str(&content).ok();
135 Err(Error::ResponseError(ResponseContent { status, content, entity }))
136 }
137}
138
139pub async fn delete_crawl_by_id(configuration: &configuration::Configuration, params: DeleteCrawlByIdParams) -> Result<(), Error<DeleteCrawlByIdError>> {
141
142 let uri_str = format!("{}/crawls/{crawlId}", configuration.base_path, crawlId=crate::apis::urlencode(params.crawl_id));
143 let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
144
145 if let Some(ref user_agent) = configuration.user_agent {
146 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
147 }
148 if let Some(ref token) = configuration.bearer_access_token {
149 req_builder = req_builder.bearer_auth(token.to_owned());
150 };
151
152 let req = req_builder.build()?;
153 let resp = configuration.client.execute(req).await?;
154
155 let status = resp.status();
156
157 if !status.is_client_error() && !status.is_server_error() {
158 Ok(())
159 } else {
160 let content = resp.text().await?;
161 let entity: Option<DeleteCrawlByIdError> = serde_json::from_str(&content).ok();
162 Err(Error::ResponseError(ResponseContent { status, content, entity }))
163 }
164}
165
166pub async fn get_crawl_by_id(configuration: &configuration::Configuration, params: GetCrawlByIdParams) -> Result<models::Crawl, Error<GetCrawlByIdError>> {
168
169 let uri_str = format!("{}/crawls/{crawlId}", configuration.base_path, crawlId=crate::apis::urlencode(params.crawl_id));
170 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
171
172 if let Some(ref user_agent) = configuration.user_agent {
173 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
174 }
175 if let Some(ref token) = configuration.bearer_access_token {
176 req_builder = req_builder.bearer_auth(token.to_owned());
177 };
178
179 let req = req_builder.build()?;
180 let resp = configuration.client.execute(req).await?;
181
182 let status = resp.status();
183 let content_type = resp
184 .headers()
185 .get("content-type")
186 .and_then(|v| v.to_str().ok())
187 .unwrap_or("application/octet-stream");
188 let content_type = super::ContentType::from(content_type);
189
190 if !status.is_client_error() && !status.is_server_error() {
191 let content = resp.text().await?;
192 match content_type {
193 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
194 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Crawl`"))),
195 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::Crawl`")))),
196 }
197 } else {
198 let content = resp.text().await?;
199 let entity: Option<GetCrawlByIdError> = serde_json::from_str(&content).ok();
200 Err(Error::ResponseError(ResponseContent { status, content, entity }))
201 }
202}
203
204pub async fn list_crawls(configuration: &configuration::Configuration, params: ListCrawlsParams) -> Result<models::ListCrawls200Response, Error<ListCrawlsError>> {
206
207 let uri_str = format!("{}/crawls", configuration.base_path);
208 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
209
210 if let Some(ref param_value) = params.limit {
211 req_builder = req_builder.query(&[("limit", ¶m_value.to_string())]);
212 }
213 if let Some(ref param_value) = params.cursor {
214 req_builder = req_builder.query(&[("cursor", ¶m_value.to_string())]);
215 }
216 if let Some(ref param_value) = params.address {
217 req_builder = req_builder.query(&[("address", ¶m_value.to_string())]);
218 }
219 if let Some(ref param_value) = params.port {
220 req_builder = req_builder.query(&[("port", ¶m_value.to_string())]);
221 }
222 if let Some(ref param_value) = params.version {
223 req_builder = req_builder.query(&[("version", ¶m_value.to_string())]);
224 }
225 if let Some(ref param_value) = params.protocol_version {
226 req_builder = req_builder.query(&[("protocolVersion", ¶m_value.to_string())]);
227 }
228 if let Some(ref param_value) = params.crawled_from {
229 req_builder = req_builder.query(&[("crawledFrom", ¶m_value.to_string())]);
230 }
231 if let Some(ref param_value) = params.crawled_to {
232 req_builder = req_builder.query(&[("crawledTo", ¶m_value.to_string())]);
233 }
234 if let Some(ref user_agent) = configuration.user_agent {
235 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
236 }
237 if let Some(ref token) = configuration.bearer_access_token {
238 req_builder = req_builder.bearer_auth(token.to_owned());
239 };
240
241 let req = req_builder.build()?;
242 let resp = configuration.client.execute(req).await?;
243
244 let status = resp.status();
245 let content_type = resp
246 .headers()
247 .get("content-type")
248 .and_then(|v| v.to_str().ok())
249 .unwrap_or("application/octet-stream");
250 let content_type = super::ContentType::from(content_type);
251
252 if !status.is_client_error() && !status.is_server_error() {
253 let content = resp.text().await?;
254 match content_type {
255 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
256 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ListCrawls200Response`"))),
257 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::ListCrawls200Response`")))),
258 }
259 } else {
260 let content = resp.text().await?;
261 let entity: Option<ListCrawlsError> = serde_json::from_str(&content).ok();
262 Err(Error::ResponseError(ResponseContent { status, content, entity }))
263 }
264}
265