Skip to main content

nea_rs/rainfall/
parts.rs

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