mobilitydata_client/apis/
beta_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 GetGbfsFeedsError {
22 UnknownValue(serde_json::Value),
23}
24
25#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(untagged)]
28pub enum GetGtfsFeedError {
29 UnknownValue(serde_json::Value),
30}
31
32
33pub async fn get_gbfs_feeds(configuration: &configuration::Configuration, limit: Option<i32>, offset: Option<i32>, provider: Option<&str>, producer_url: Option<&str>, country_code: Option<&str>, subdivision_name: Option<&str>, municipality: Option<&str>, system_id: Option<&str>, version: Option<&str>) -> Result<Vec<models::GbfsFeed>, Error<GetGbfsFeedsError>> {
35 let p_query_limit = limit;
37 let p_query_offset = offset;
38 let p_query_provider = provider;
39 let p_query_producer_url = producer_url;
40 let p_query_country_code = country_code;
41 let p_query_subdivision_name = subdivision_name;
42 let p_query_municipality = municipality;
43 let p_query_system_id = system_id;
44 let p_query_version = version;
45
46 let uri_str = format!("{}/v1/gbfs_feeds", configuration.base_path);
47 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
48
49 if let Some(ref param_value) = p_query_limit {
50 req_builder = req_builder.query(&[("limit", ¶m_value.to_string())]);
51 }
52 if let Some(ref param_value) = p_query_offset {
53 req_builder = req_builder.query(&[("offset", ¶m_value.to_string())]);
54 }
55 if let Some(ref param_value) = p_query_provider {
56 req_builder = req_builder.query(&[("provider", ¶m_value.to_string())]);
57 }
58 if let Some(ref param_value) = p_query_producer_url {
59 req_builder = req_builder.query(&[("producer_url", ¶m_value.to_string())]);
60 }
61 if let Some(ref param_value) = p_query_country_code {
62 req_builder = req_builder.query(&[("country_code", ¶m_value.to_string())]);
63 }
64 if let Some(ref param_value) = p_query_subdivision_name {
65 req_builder = req_builder.query(&[("subdivision_name", ¶m_value.to_string())]);
66 }
67 if let Some(ref param_value) = p_query_municipality {
68 req_builder = req_builder.query(&[("municipality", ¶m_value.to_string())]);
69 }
70 if let Some(ref param_value) = p_query_system_id {
71 req_builder = req_builder.query(&[("system_id", ¶m_value.to_string())]);
72 }
73 if let Some(ref param_value) = p_query_version {
74 req_builder = req_builder.query(&[("version", ¶m_value.to_string())]);
75 }
76 if let Some(ref user_agent) = configuration.user_agent {
77 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
78 }
79 if let Some(ref token) = configuration.bearer_access_token {
80 req_builder = req_builder.bearer_auth(token.to_owned());
81 };
82
83 let req = req_builder.build()?;
84 let resp = configuration.client.execute(req).await?;
85
86 let status = resp.status();
87 let content_type = resp
88 .headers()
89 .get("content-type")
90 .and_then(|v| v.to_str().ok())
91 .unwrap_or("application/octet-stream");
92 let content_type = super::ContentType::from(content_type);
93
94 if !status.is_client_error() && !status.is_server_error() {
95 let content = resp.text().await?;
96 match content_type {
97 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
98 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec<models::GbfsFeed>`"))),
99 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::GbfsFeed>`")))),
100 }
101 } else {
102 let content = resp.text().await?;
103 let entity: Option<GetGbfsFeedsError> = serde_json::from_str(&content).ok();
104 Err(Error::ResponseError(ResponseContent { status, content, entity }))
105 }
106}
107
108pub async fn get_gtfs_feed(configuration: &configuration::Configuration, id: &str) -> Result<models::GtfsFeed, Error<GetGtfsFeedError>> {
110 let p_path_id = id;
112
113 let uri_str = format!("{}/v1/gtfs_feeds/{id}", configuration.base_path, id=crate::apis::urlencode(p_path_id));
114 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
115
116 if let Some(ref user_agent) = configuration.user_agent {
117 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
118 }
119 if let Some(ref token) = configuration.bearer_access_token {
120 req_builder = req_builder.bearer_auth(token.to_owned());
121 };
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::GtfsFeed`"))),
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::GtfsFeed`")))),
140 }
141 } else {
142 let content = resp.text().await?;
143 let entity: Option<GetGtfsFeedError> = serde_json::from_str(&content).ok();
144 Err(Error::ResponseError(ResponseContent { status, content, entity }))
145 }
146}
147