nea_rs/weather_sub_api/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, NeaWeatherSubApi, RateLimitError, WeatherSubApiInvalidParamsError,
13 WeatherSubApiResponse,
14};
15/// Unified weather sub-API endpoint.
16///
17/// - `?api=lightning` — Cloud-to-ground and cloud-to-cloud lightning strikes. Updated every ~2–3 minutes.
18///
19/// - `?api=wbgt` — Wet Bulb Globe Temperature heat stress readings. Updated every 15 minutes.
20///
21/// <https://api-open.data.gov.sg/v2/real-time/api/weather?api=lightning>
22///
23/// - Updated multiple times throughout the day
24///
25/// - Filter for a specific date by providing `date` in query parameter (YYYY-MM-DD).
26///
27/// - example: `?date=2025-01-16`
28///
29/// - If `date` is not provided in query parameter, API will return the latest lightning observation
30#[derive(Debug, Clone, PartialEq)]
31pub struct WeatherSubApiInput {
32 /// Sub-API selector (lightning or wbgt). Required.
33 pub api: NeaWeatherSubApi,
34 /// SGT date for which to retrieve data (YYYY-MM-DD). Omit for latest.
35 pub date: Option<satay_runtime::Date>,
36 /// Pagination token for subsequent pages (only when date filter is used and more pages exist).
37 pub pagination_token: Option<String>,
38 /// Optional API key for higher rate limits.
39 pub x_api_key: Option<String>,
40}
41impl WeatherSubApiInput {
42 pub fn new(api: NeaWeatherSubApi) -> Self {
43 Self {
44 api,
45 date: None,
46 pagination_token: None,
47 x_api_key: None,
48 }
49 }
50 pub fn date(mut self, date: satay_runtime::Date) -> Self {
51 self.date = Some(date);
52 self
53 }
54 pub fn pagination_token(mut self, pagination_token: impl Into<String>) -> Self {
55 self.pagination_token = Some(pagination_token.into());
56 self
57 }
58 pub fn x_api_key(mut self, x_api_key: impl Into<String>) -> Self {
59 self.x_api_key = Some(x_api_key.into());
60 self
61 }
62}
63/// Unified weather sub-API endpoint.
64///
65/// - `?api=lightning` — Cloud-to-ground and cloud-to-cloud lightning strikes. Updated every ~2–3 minutes.
66///
67/// - `?api=wbgt` — Wet Bulb Globe Temperature heat stress readings. Updated every 15 minutes.
68///
69/// <https://api-open.data.gov.sg/v2/real-time/api/weather?api=lightning>
70///
71/// - Updated multiple times throughout the day
72///
73/// - Filter for a specific date by providing `date` in query parameter (YYYY-MM-DD).
74///
75/// - example: `?date=2025-01-16`
76///
77/// - If `date` is not provided in query parameter, API will return the latest lightning observation
78#[derive(Debug, Clone, PartialEq)]
79pub enum WeatherSubApiOperationResponse {
80 /// Lightning Observations
81 Ok(WeatherSubApiResponse),
82 /// Invalid HTTP request body
83 BadRequest(WeatherSubApiInvalidParamsError),
84 /// Weather data not found
85 NotFound(DataNotFoundError),
86 /// Rate limit exceeded (429). Wait and retry, or use an x-api-key.
87 Status429(RateLimitError),
88 UnexpectedStatus(http::StatusCode, Vec<u8>),
89}
90/// Unified weather sub-API endpoint.
91///
92/// - `?api=lightning` — Cloud-to-ground and cloud-to-cloud lightning strikes. Updated every ~2–3 minutes.
93///
94/// - `?api=wbgt` — Wet Bulb Globe Temperature heat stress readings. Updated every 15 minutes.
95///
96/// <https://api-open.data.gov.sg/v2/real-time/api/weather?api=lightning>
97///
98/// - Updated multiple times throughout the day
99///
100/// - Filter for a specific date by providing `date` in query parameter (YYYY-MM-DD).
101///
102/// - example: `?date=2025-01-16`
103///
104/// - If `date` is not provided in query parameter, API will return the latest lightning observation
105pub fn weather_sub_api_parts(
106 input: WeatherSubApiInput,
107) -> Result<satay_runtime::RequestParts<()>, satay_runtime::Error> {
108 let mut uri = String::with_capacity(8);
109 uri.push_str("/weather");
110 let mut first_query = true;
111 satay_runtime::append_query_pair(&mut uri, &mut first_query, "api", input.api.as_ref());
112 if let Some(value) = &input.date {
113 satay_runtime::append_query_pair(
114 &mut uri,
115 &mut first_query,
116 "date",
117 &satay_runtime::format_date(value),
118 );
119 }
120 if let Some(value) = &input.pagination_token {
121 satay_runtime::append_query_pair(
122 &mut uri,
123 &mut first_query,
124 "paginationToken",
125 value.as_str(),
126 );
127 }
128 let mut headers = http::HeaderMap::new();
129 if let Some(value) = &input.x_api_key {
130 satay_runtime::insert_header(&mut headers, "x-api-key", value.as_str())?;
131 }
132 Ok(satay_runtime::RequestParts {
133 method: http::Method::GET,
134 uri,
135 headers,
136 body: (),
137 })
138}