mobilitydata_client/apis/
search_api.rs1use 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 SearchFeedsError {
22 UnknownValue(serde_json::Value),
23}
24
25
26pub async fn search_feeds(configuration: &configuration::Configuration, limit: Option<i32>, offset: Option<i32>, status: Option<Vec<String>>, feed_id: Option<&str>, data_type: Option<&str>, is_official: Option<bool>, version: Option<&str>, search_query: Option<&str>, feature: Option<Vec<String>>, license_ids: Option<&str>, license_is_spdx: Option<bool>) -> Result<models::SearchFeeds200Response, Error<SearchFeedsError>> {
28 let p_query_limit = limit;
30 let p_query_offset = offset;
31 let p_query_status = status;
32 let p_query_feed_id = feed_id;
33 let p_query_data_type = data_type;
34 let p_query_is_official = is_official;
35 let p_query_version = version;
36 let p_query_search_query = search_query;
37 let p_query_feature = feature;
38 let p_query_license_ids = license_ids;
39 let p_query_license_is_spdx = license_is_spdx;
40
41 let uri_str = format!("{}/v1/search", configuration.base_path);
42 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
43
44 if let Some(ref param_value) = p_query_limit {
45 req_builder = req_builder.query(&[("limit", ¶m_value.to_string())]);
46 }
47 if let Some(ref param_value) = p_query_offset {
48 req_builder = req_builder.query(&[("offset", ¶m_value.to_string())]);
49 }
50 if let Some(ref param_value) = p_query_status {
51 req_builder = match "csv" {
52 "multi" => req_builder.query(¶m_value.into_iter().map(|p| ("status".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
53 _ => req_builder.query(&[("status", ¶m_value.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
54 };
55 }
56 if let Some(ref param_value) = p_query_feed_id {
57 req_builder = req_builder.query(&[("feed_id", ¶m_value.to_string())]);
58 }
59 if let Some(ref param_value) = p_query_data_type {
60 req_builder = req_builder.query(&[("data_type", ¶m_value.to_string())]);
61 }
62 if let Some(ref param_value) = p_query_is_official {
63 req_builder = req_builder.query(&[("is_official", ¶m_value.to_string())]);
64 }
65 if let Some(ref param_value) = p_query_version {
66 req_builder = req_builder.query(&[("version", ¶m_value.to_string())]);
67 }
68 if let Some(ref param_value) = p_query_search_query {
69 req_builder = req_builder.query(&[("search_query", ¶m_value.to_string())]);
70 }
71 if let Some(ref param_value) = p_query_feature {
72 req_builder = match "csv" {
73 "multi" => req_builder.query(¶m_value.into_iter().map(|p| ("feature".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
74 _ => req_builder.query(&[("feature", ¶m_value.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
75 };
76 }
77 if let Some(ref param_value) = p_query_license_ids {
78 req_builder = req_builder.query(&[("license_ids", ¶m_value.to_string())]);
79 }
80 if let Some(ref param_value) = p_query_license_is_spdx {
81 req_builder = req_builder.query(&[("license_is_spdx", ¶m_value.to_string())]);
82 }
83 if let Some(ref user_agent) = configuration.user_agent {
84 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
85 }
86 if let Some(ref token) = configuration.bearer_access_token {
87 req_builder = req_builder.bearer_auth(token.to_owned());
88 };
89
90 let req = req_builder.build()?;
91 let resp = configuration.client.execute(req).await?;
92
93 let status = resp.status();
94 let content_type = resp
95 .headers()
96 .get("content-type")
97 .and_then(|v| v.to_str().ok())
98 .unwrap_or("application/octet-stream");
99 let content_type = super::ContentType::from(content_type);
100
101 if !status.is_client_error() && !status.is_server_error() {
102 let content = resp.text().await?;
103 match content_type {
104 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
105 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::SearchFeeds200Response`"))),
106 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::SearchFeeds200Response`")))),
107 }
108 } else {
109 let content = resp.text().await?;
110 let entity: Option<SearchFeedsError> = serde_json::from_str(&content).ok();
111 Err(Error::ResponseError(ResponseContent { status, content, entity }))
112 }
113}
114