Skip to main content

mobilitydata_client/apis/
search_api.rs

1/*
2 * Mobility Database Catalog
3 *
4 * API for the Mobility Database Catalog. See [https://mobilitydatabase.org/](https://mobilitydatabase.org/).  The Mobility Database API uses OAuth2 authentication. To initiate a successful API request, an access token must be included as a bearer token in the HTTP header. Access tokens are valid for one hour. To obtain an access token, you'll first need a refresh token, which is long-lived and does not expire. 
5 *
6 * The version of the OpenAPI document: 1.0.0
7 * Contact: api@mobilitydata.org
8 * Generated by: https://openapi-generator.tech
9 */
10
11
12use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17
18/// struct for typed errors of method [`search_feeds`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum SearchFeedsError {
22    UnknownValue(serde_json::Value),
23}
24
25
26/// Search feeds on feed name, location and provider's information. <br> The current implementation leverages the text search functionalities from [PostgreSQL](https://www.postgresql.org/docs/current/textsearch-controls.html), in particulary `plainto_tsquery`. <br><br> Points to consider while using search endpoint: <br> - Operators are not currently supported. Operators are ignored as stop-words. - Search is based on lexemes(English) and case insensitive. The search_text_query_param is parsed and normalized much as for to_tsvector, then the & (AND) tsquery operator is inserted between surviving words. - The search will match all the lexemes with an AND operator. So, all lexemes must be present in the document. - Our current implementation only creates English lexemes. We are currently considering adding support to more languages. - The order of the words is not relevant for matching. The query __New York__ should give you the same results as __York New__. <br><br> Example: <br> Query: New York Transit <br> Search Executed: 'new' & york & 'transit' <br> 
27pub 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    // add a prefix to parameters to efficiently prevent name collisions
29    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", &param_value.to_string())]);
46    }
47    if let Some(ref param_value) = p_query_offset {
48        req_builder = req_builder.query(&[("offset", &param_value.to_string())]);
49    }
50    if let Some(ref param_value) = p_query_status {
51        req_builder = match "csv" {
52            "multi" => req_builder.query(&param_value.into_iter().map(|p| ("status".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
53            _ => req_builder.query(&[("status", &param_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", &param_value.to_string())]);
58    }
59    if let Some(ref param_value) = p_query_data_type {
60        req_builder = req_builder.query(&[("data_type", &param_value.to_string())]);
61    }
62    if let Some(ref param_value) = p_query_is_official {
63        req_builder = req_builder.query(&[("is_official", &param_value.to_string())]);
64    }
65    if let Some(ref param_value) = p_query_version {
66        req_builder = req_builder.query(&[("version", &param_value.to_string())]);
67    }
68    if let Some(ref param_value) = p_query_search_query {
69        req_builder = req_builder.query(&[("search_query", &param_value.to_string())]);
70    }
71    if let Some(ref param_value) = p_query_feature {
72        req_builder = match "csv" {
73            "multi" => req_builder.query(&param_value.into_iter().map(|p| ("feature".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
74            _ => req_builder.query(&[("feature", &param_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", &param_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", &param_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