nea-rs 0.1.1

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, RateLimitError, WeatherSubApiInvalidParamsError, WeatherSubApiResponse,
};
use super::parts::{WeatherSubApiInput, WeatherSubApiOperationResponse, weather_sub_api_parts};
/// Unified weather sub-API endpoint.
///
/// - `?api=lightning` — Cloud-to-ground and cloud-to-cloud lightning strikes. Updated every ~2–3 minutes.
///
/// - `?api=wbgt` — Wet Bulb Globe Temperature heat stress readings. Updated every 15 minutes.
///
/// <https://api-open.data.gov.sg/v2/real-time/api/weather?api=lightning>
///
/// - Updated multiple times throughout the day
///
/// - Filter for a specific date by providing `date` in query parameter (YYYY-MM-DD).
///
/// - example: `?date=2025-01-16`
///
/// - If `date` is not provided in query parameter, API will return the latest lightning observation
pub fn encode_weather_sub_api(
    input: WeatherSubApiInput,
) -> Result<http::Request<Vec<u8>>, satay_runtime::Error> {
    let parts = weather_sub_api_parts(input)?;
    satay_runtime::into_empty_request(parts)
}
pub fn decode_weather_sub_api_response<B: AsRef<[u8]>>(
    response: satay_runtime::ResponseParts<B>,
) -> Result<WeatherSubApiOperationResponse, satay_runtime::Error> {
    let status = response.status;
    match status.as_u16() {
        200 => {
            let body = response.body;
            let value = satay_runtime::from_json_slice::<WeatherSubApiResponse>(body.as_ref())?;
            Ok(WeatherSubApiOperationResponse::Ok(value))
        }
        400 => {
            let body = response.body;
            let value =
                satay_runtime::from_json_slice::<WeatherSubApiInvalidParamsError>(body.as_ref())?;
            Ok(WeatherSubApiOperationResponse::BadRequest(value))
        }
        404 => {
            let body = response.body;
            let value = satay_runtime::from_json_slice::<DataNotFoundError>(body.as_ref())?;
            Ok(WeatherSubApiOperationResponse::NotFound(value))
        }
        429 => {
            let body = response.body;
            let value = satay_runtime::from_json_slice::<RateLimitError>(body.as_ref())?;
            Ok(WeatherSubApiOperationResponse::Status429(value))
        }
        _ => {
            let body = response.body;
            Ok(WeatherSubApiOperationResponse::UnexpectedStatus(
                status,
                body.as_ref().to_vec(),
            ))
        }
    }
}