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, InvalidParamsError, Pm25Response, RateLimitError};
use super::parts::{Pm25Input, Pm25OperationResponse, pm25_parts};
/// <https://api-open.data.gov.sg/v2/real-time/api/pm25>
///
/// - Readings are provided for each major region in Singapore
///
/// - 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
///
/// - The `region_metadata` field in the response provides longitude/latitude information for the regions. You can use that to place the readings on a map.
///
/// - Unit of measure for readings is `µg/m3`.
pub fn encode_pm25(input: Pm25Input) -> Result<http::Request<Vec<u8>>, satay_runtime::Error> {
    let parts = pm25_parts(input)?;
    satay_runtime::into_empty_request(parts)
}
pub fn decode_pm25_response<B: AsRef<[u8]>>(
    response: satay_runtime::ResponseParts<B>,
) -> Result<Pm25OperationResponse, satay_runtime::Error> {
    let status = response.status;
    match status.as_u16() {
        200 => {
            let body = response.body;
            let value = satay_runtime::from_json_slice::<Pm25Response>(body.as_ref())?;
            Ok(Pm25OperationResponse::Ok(value))
        }
        400 => {
            let body = response.body;
            let value = satay_runtime::from_json_slice::<InvalidParamsError>(body.as_ref())?;
            Ok(Pm25OperationResponse::BadRequest(value))
        }
        404 => {
            let body = response.body;
            let value = satay_runtime::from_json_slice::<DataNotFoundError>(body.as_ref())?;
            Ok(Pm25OperationResponse::NotFound(value))
        }
        429 => {
            let body = response.body;
            let value = satay_runtime::from_json_slice::<RateLimitError>(body.as_ref())?;
            Ok(Pm25OperationResponse::Status429(value))
        }
        _ => {
            let body = response.body;
            Ok(Pm25OperationResponse::UnexpectedStatus(
                status,
                body.as_ref().to_vec(),
            ))
        }
    }
}