Skip to main content

nea_rs/wind_direction/
parts.rs

1//! @generated by satay. Do not edit by hand.
2
3use super::super::types::{
4    DataNotFoundError, InvalidParamsError, RateLimitError, WindDirectionResponse,
5};
6/// <https://api-open.data.gov.sg/v2/real-time/api/wind-direction>
7///
8/// - Filter for a specific date by providing `date` in query parameter (YYYY-MM-DD).
9///
10/// - example: `?date=2024-07-16`
11///
12/// - If `date` is not provided in query parameter, API will return the latest reading
13///
14/// - Unit of measure for readings is `°`
15#[derive(Debug, Clone, PartialEq)]
16pub struct WindDirectionInput {
17    /// SGT date for which to retrieve data (YYYY-MM-DD). Omit for latest.
18    pub date: Option<satay_runtime::Date>,
19    /// Pagination token for subsequent pages (only when date filter is used and more pages exist).
20    pub pagination_token: Option<String>,
21    /// Optional API key for higher rate limits.
22    pub x_api_key: Option<String>,
23}
24impl WindDirectionInput {
25    pub fn new() -> Self {
26        Self {
27            date: None,
28            pagination_token: None,
29            x_api_key: None,
30        }
31    }
32    pub fn date(mut self, date: satay_runtime::Date) -> Self {
33        self.date = Some(date);
34        self
35    }
36    pub fn pagination_token(mut self, pagination_token: impl Into<String>) -> Self {
37        self.pagination_token = Some(pagination_token.into());
38        self
39    }
40    pub fn x_api_key(mut self, x_api_key: impl Into<String>) -> Self {
41        self.x_api_key = Some(x_api_key.into());
42        self
43    }
44}
45impl Default for WindDirectionInput {
46    fn default() -> Self {
47        Self::new()
48    }
49}
50/// <https://api-open.data.gov.sg/v2/real-time/api/wind-direction>
51///
52/// - Filter for a specific date by providing `date` in query parameter (YYYY-MM-DD).
53///
54/// - example: `?date=2024-07-16`
55///
56/// - If `date` is not provided in query parameter, API will return the latest reading
57///
58/// - Unit of measure for readings is `°`
59#[derive(Debug, Clone, PartialEq)]
60pub enum WindDirectionOperationResponse {
61    /// Wind Direction Information
62    Ok(WindDirectionResponse),
63    /// Invalid request (bad date format or pagination token)
64    BadRequest(InvalidParamsError),
65    /// Weather data not found
66    NotFound(DataNotFoundError),
67    /// Rate limit exceeded (429). Wait and retry, or use an x-api-key.
68    Status429(RateLimitError),
69    UnexpectedStatus(http::StatusCode, Vec<u8>),
70}
71/// <https://api-open.data.gov.sg/v2/real-time/api/wind-direction>
72///
73/// - Filter for a specific date by providing `date` in query parameter (YYYY-MM-DD).
74///
75/// - example: `?date=2024-07-16`
76///
77/// - If `date` is not provided in query parameter, API will return the latest reading
78///
79/// - Unit of measure for readings is `°`
80pub fn wind_direction_parts(
81    input: WindDirectionInput,
82) -> Result<satay_runtime::RequestParts<()>, satay_runtime::Error> {
83    let mut uri = String::with_capacity(15);
84    uri.push_str("/wind-direction");
85    let mut first_query = true;
86    if let Some(value) = &input.date {
87        satay_runtime::append_query_pair(
88            &mut uri,
89            &mut first_query,
90            "date",
91            &satay_runtime::format_date(value),
92        );
93    }
94    if let Some(value) = &input.pagination_token {
95        satay_runtime::append_query_pair(
96            &mut uri,
97            &mut first_query,
98            "paginationToken",
99            value.as_str(),
100        );
101    }
102    let mut headers = http::HeaderMap::new();
103    if let Some(value) = &input.x_api_key {
104        satay_runtime::insert_header(&mut headers, "x-api-key", value.as_str())?;
105    }
106    Ok(satay_runtime::RequestParts {
107        method: http::Method::GET,
108        uri,
109        headers,
110        body: (),
111    })
112}