motis_openapi_sdk/apis/
timetable_api.rs

1/*
2 * MOTIS API
3 *
4 * This is the MOTIS routing API.
5 *
6 * The version of the OpenAPI document: v1
7 * Contact: felix@triptix.tech
8 * Generated by: https://openapi-generator.tech
9 */
10
11
12use reqwest;
13use serde::{Deserialize, Serialize};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration};
16
17
18/// struct for typed errors of method [`stoptimes`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum StoptimesError {
22    UnknownValue(serde_json::Value),
23}
24
25/// struct for typed errors of method [`trip`]
26#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(untagged)]
28pub enum TripError {
29    UnknownValue(serde_json::Value),
30}
31
32
33pub async fn stoptimes(configuration: &configuration::Configuration, stop_id: &str, n: i32, time: Option<String>, arrive_by: Option<bool>, direction: Option<&str>, mode: Option<Vec<models::Mode>>, radius: Option<i32>, page_cursor: Option<&str>) -> Result<models::Stoptimes200Response, Error<StoptimesError>> {
34    let local_var_configuration = configuration;
35
36    let local_var_client = &local_var_configuration.client;
37
38    let local_var_uri_str = format!("{}/api/v1/stoptimes", local_var_configuration.base_path);
39    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
40
41    local_var_req_builder = local_var_req_builder.query(&[("stopId", &stop_id.to_string())]);
42    if let Some(ref local_var_str) = time {
43        local_var_req_builder = local_var_req_builder.query(&[("time", &local_var_str.to_string())]);
44    }
45    if let Some(ref local_var_str) = arrive_by {
46        local_var_req_builder = local_var_req_builder.query(&[("arriveBy", &local_var_str.to_string())]);
47    }
48    if let Some(ref local_var_str) = direction {
49        local_var_req_builder = local_var_req_builder.query(&[("direction", &local_var_str.to_string())]);
50    }
51    if let Some(ref local_var_str) = mode {
52        local_var_req_builder = match "multi" {
53            "multi" => local_var_req_builder.query(&local_var_str.into_iter().map(|p| ("mode".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
54            _ => local_var_req_builder.query(&[("mode", &local_var_str.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
55        };
56    }
57    local_var_req_builder = local_var_req_builder.query(&[("n", &n.to_string())]);
58    if let Some(ref local_var_str) = radius {
59        local_var_req_builder = local_var_req_builder.query(&[("radius", &local_var_str.to_string())]);
60    }
61    if let Some(ref local_var_str) = page_cursor {
62        local_var_req_builder = local_var_req_builder.query(&[("pageCursor", &local_var_str.to_string())]);
63    }
64    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
65        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
66    }
67
68    let local_var_req = local_var_req_builder.build()?;
69    let local_var_resp = local_var_client.execute(local_var_req).await?;
70
71    let local_var_status = local_var_resp.status();
72    let local_var_content = local_var_resp.text().await?;
73
74    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
75        serde_json::from_str(&local_var_content).map_err(Error::from)
76    } else {
77        let local_var_entity: Option<StoptimesError> = serde_json::from_str(&local_var_content).ok();
78        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
79        Err(Error::ResponseError(local_var_error))
80    }
81}
82
83pub async fn trip(configuration: &configuration::Configuration, trip_id: &str) -> Result<models::Itinerary, Error<TripError>> {
84    let local_var_configuration = configuration;
85
86    let local_var_client = &local_var_configuration.client;
87
88    let local_var_uri_str = format!("{}/api/v1/trip", local_var_configuration.base_path);
89    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
90
91    local_var_req_builder = local_var_req_builder.query(&[("tripId", &trip_id.to_string())]);
92    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
93        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
94    }
95
96    let local_var_req = local_var_req_builder.build()?;
97    let local_var_resp = local_var_client.execute(local_var_req).await?;
98
99    let local_var_status = local_var_resp.status();
100    let local_var_content = local_var_resp.text().await?;
101
102    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
103        serde_json::from_str(&local_var_content).map_err(Error::from)
104    } else {
105        let local_var_entity: Option<TripError> = serde_json::from_str(&local_var_content).ok();
106        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
107        Err(Error::ResponseError(local_var_error))
108    }
109}
110