nea-rs 0.1.0

A type-safe, sans-IO Rust client for Singapore NEA real-time weather and environmental APIs.
Documentation
//! @generated by satay. Do not edit by hand.

use super::super::types::{
    DataNotFoundError, InvalidParamsError, RateLimitError, RelativeHumidityResponse,
};
/// <https://api-open.data.gov.sg/v2/real-time/api/relative-humidity>
///
/// - Filter for a specific date by providing `date` in query parameter (YYYY-MM-DD).
///
/// - example: `?date=2024-07-16`
///
/// - If `date` is not provided in query parameter, API will return the latest reading
///
/// - Unit of measure for readings is `%`
#[derive(Debug, Clone, PartialEq)]
pub struct RelativeHumidityInput {
    /// SGT date for which to retrieve data (YYYY-MM-DD). Omit for latest.
    pub date: Option<satay_runtime::Date>,
    /// Pagination token for subsequent pages (only when date filter is used and more pages exist).
    pub pagination_token: Option<String>,
    /// Optional API key for higher rate limits.
    pub x_api_key: Option<String>,
}
impl RelativeHumidityInput {
    pub fn new() -> Self {
        Self {
            date: None,
            pagination_token: None,
            x_api_key: None,
        }
    }
    pub fn date(mut self, date: satay_runtime::Date) -> Self {
        self.date = Some(date);
        self
    }
    pub fn pagination_token(mut self, pagination_token: impl Into<String>) -> Self {
        self.pagination_token = Some(pagination_token.into());
        self
    }
    pub fn x_api_key(mut self, x_api_key: impl Into<String>) -> Self {
        self.x_api_key = Some(x_api_key.into());
        self
    }
}
impl Default for RelativeHumidityInput {
    fn default() -> Self {
        Self::new()
    }
}
/// <https://api-open.data.gov.sg/v2/real-time/api/relative-humidity>
///
/// - Filter for a specific date by providing `date` in query parameter (YYYY-MM-DD).
///
/// - example: `?date=2024-07-16`
///
/// - If `date` is not provided in query parameter, API will return the latest reading
///
/// - Unit of measure for readings is `%`
#[derive(Debug, Clone, PartialEq)]
pub enum RelativeHumidityOperationResponse {
    /// Relative Humidity Information
    Ok(RelativeHumidityResponse),
    /// Invalid request (bad date format or pagination token)
    BadRequest(InvalidParamsError),
    /// Weather data not found
    NotFound(DataNotFoundError),
    /// Rate limit exceeded (429). Wait and retry, or use an x-api-key.
    Status429(RateLimitError),
    UnexpectedStatus(http::StatusCode, Vec<u8>),
}
/// <https://api-open.data.gov.sg/v2/real-time/api/relative-humidity>
///
/// - Filter for a specific date by providing `date` in query parameter (YYYY-MM-DD).
///
/// - example: `?date=2024-07-16`
///
/// - If `date` is not provided in query parameter, API will return the latest reading
///
/// - Unit of measure for readings is `%`
pub fn relative_humidity_parts(
    input: RelativeHumidityInput,
) -> Result<satay_runtime::RequestParts<()>, satay_runtime::Error> {
    let mut uri = String::with_capacity(18);
    uri.push_str("/relative-humidity");
    let mut first_query = true;
    if let Some(value) = &input.date {
        satay_runtime::append_query_pair(
            &mut uri,
            &mut first_query,
            "date",
            &satay_runtime::format_date(value),
        );
    }
    if let Some(value) = &input.pagination_token {
        satay_runtime::append_query_pair(
            &mut uri,
            &mut first_query,
            "paginationToken",
            value.as_str(),
        );
    }
    let mut headers = http::HeaderMap::new();
    if let Some(value) = &input.x_api_key {
        satay_runtime::insert_header(&mut headers, "x-api-key", value.as_str())?;
    }
    Ok(satay_runtime::RequestParts {
        method: http::Method::GET,
        uri,
        headers,
        body: (),
    })
}