use super::{
AirTemperatureInput, AirTemperatureOperationResponse, FourDayOutlookInput,
FourDayOutlookOperationResponse, NeaWeatherSubApi, Pm25Input, Pm25OperationResponse, PsiInput,
PsiOperationResponse, RainfallInput, RainfallOperationResponse, RelativeHumidityInput,
RelativeHumidityOperationResponse, TwentyFourHrForecastInput,
TwentyFourHrForecastOperationResponse, TwoHrForecastInput, TwoHrForecastOperationResponse,
UvInput, UvOperationResponse, WeatherSubApiInput, WeatherSubApiOperationResponse,
WindDirectionInput, WindDirectionOperationResponse, WindSpeedInput, WindSpeedOperationResponse,
air_temperature_parts, decode_air_temperature_response, decode_four_day_outlook_response,
decode_pm25_response, decode_psi_response, decode_rainfall_response,
decode_relative_humidity_response, decode_twenty_four_hr_forecast_response,
decode_two_hr_forecast_response, decode_uv_response, decode_weather_sub_api_response,
decode_wind_direction_response, decode_wind_speed_response, four_day_outlook_parts, pm25_parts,
psi_parts, rainfall_parts, relative_humidity_parts, twenty_four_hr_forecast_parts,
two_hr_forecast_parts, uv_parts, weather_sub_api_parts, wind_direction_parts, wind_speed_parts,
};
#[derive(Debug, Clone)]
pub struct Api {
base_url: String,
x_api_key: Option<String>,
}
impl Default for Api {
fn default() -> Self {
Self::new()
}
}
impl Api {
pub fn new() -> Self {
Self {
base_url: super::SERVER_URL.to_owned(),
x_api_key: None,
}
}
pub fn base_url(mut self, base_url: impl Into<String>) -> Self {
self.base_url = base_url.into();
self
}
pub fn x_api_key(mut self, value: impl Into<String>) -> Self {
self.x_api_key = Some(value.into());
self
}
pub fn psi(&self) -> PsiAction<'_> {
PsiAction {
api: self,
input: PsiInput::new(),
}
}
pub fn pm25(&self) -> Pm25Action<'_> {
Pm25Action {
api: self,
input: Pm25Input::new(),
}
}
pub fn air_temperature(&self) -> AirTemperatureAction<'_> {
AirTemperatureAction {
api: self,
input: AirTemperatureInput::new(),
}
}
pub fn relative_humidity(&self) -> RelativeHumidityAction<'_> {
RelativeHumidityAction {
api: self,
input: RelativeHumidityInput::new(),
}
}
pub fn wind_speed(&self) -> WindSpeedAction<'_> {
WindSpeedAction {
api: self,
input: WindSpeedInput::new(),
}
}
pub fn wind_direction(&self) -> WindDirectionAction<'_> {
WindDirectionAction {
api: self,
input: WindDirectionInput::new(),
}
}
pub fn rainfall(&self) -> RainfallAction<'_> {
RainfallAction {
api: self,
input: RainfallInput::new(),
}
}
pub fn two_hr_forecast(&self) -> TwoHrForecastAction<'_> {
TwoHrForecastAction {
api: self,
input: TwoHrForecastInput::new(),
}
}
pub fn twenty_four_hr_forecast(&self) -> TwentyFourHrForecastAction<'_> {
TwentyFourHrForecastAction {
api: self,
input: TwentyFourHrForecastInput::new(),
}
}
pub fn four_day_outlook(&self) -> FourDayOutlookAction<'_> {
FourDayOutlookAction {
api: self,
input: FourDayOutlookInput::new(),
}
}
pub fn uv(&self) -> UvAction<'_> {
UvAction {
api: self,
input: UvInput::new(),
}
}
pub fn weather_sub_api(&self, api: NeaWeatherSubApi) -> WeatherSubApiAction<'_> {
WeatherSubApiAction {
api: self,
input: WeatherSubApiInput::new(api),
}
}
fn apply<B>(
&self,
parts: &mut satay_runtime::RequestParts<B>,
) -> Result<(), satay_runtime::Error> {
if let Some(value) = &self.x_api_key {
satay_runtime::insert_header(&mut parts.headers, "x-api-key", value)?;
}
if self.base_url.is_empty() {
return Ok(());
}
let path_and_query = parts.uri.as_str();
let base_url = self.base_url.trim_end_matches('/');
let separator = if path_and_query.starts_with('/') {
""
} else {
"/"
};
parts.uri = format!("{base_url}{separator}{path_and_query}");
Ok(())
}
}
#[derive(Debug, Clone)]
pub struct PsiAction<'a> {
api: &'a Api,
input: PsiInput,
}
impl PsiAction<'_> {
pub fn date(mut self, date: satay_runtime::Date) -> Self {
self.input = self.input.date(date);
self
}
pub fn pagination_token(mut self, pagination_token: impl Into<String>) -> Self {
self.input = self.input.pagination_token(pagination_token);
self
}
pub fn x_api_key(mut self, x_api_key: impl Into<String>) -> Self {
self.input = self.input.x_api_key(x_api_key);
self
}
pub fn request(self) -> Result<http::Request<Vec<u8>>, satay_runtime::Error> {
let api = self.api;
let mut parts = psi_parts(self.input)?;
api.apply(&mut parts)?;
satay_runtime::into_empty_request(parts)
}
pub fn decode<B: AsRef<[u8]>>(
response: satay_runtime::ResponseParts<B>,
) -> Result<PsiOperationResponse, satay_runtime::Error> {
decode_psi_response(response)
}
}
impl satay_runtime::Action for PsiAction<'_> {
type Response = PsiOperationResponse;
fn request(self) -> Result<http::Request<Vec<u8>>, satay_runtime::Error> {
self.request()
}
fn decode<B: AsRef<[u8]>>(
response: satay_runtime::ResponseParts<B>,
) -> Result<Self::Response, satay_runtime::Error> {
Self::decode(response)
}
}
#[derive(Debug, Clone)]
pub struct Pm25Action<'a> {
api: &'a Api,
input: Pm25Input,
}
impl Pm25Action<'_> {
pub fn date(mut self, date: satay_runtime::Date) -> Self {
self.input = self.input.date(date);
self
}
pub fn pagination_token(mut self, pagination_token: impl Into<String>) -> Self {
self.input = self.input.pagination_token(pagination_token);
self
}
pub fn x_api_key(mut self, x_api_key: impl Into<String>) -> Self {
self.input = self.input.x_api_key(x_api_key);
self
}
pub fn request(self) -> Result<http::Request<Vec<u8>>, satay_runtime::Error> {
let api = self.api;
let mut parts = pm25_parts(self.input)?;
api.apply(&mut parts)?;
satay_runtime::into_empty_request(parts)
}
pub fn decode<B: AsRef<[u8]>>(
response: satay_runtime::ResponseParts<B>,
) -> Result<Pm25OperationResponse, satay_runtime::Error> {
decode_pm25_response(response)
}
}
impl satay_runtime::Action for Pm25Action<'_> {
type Response = Pm25OperationResponse;
fn request(self) -> Result<http::Request<Vec<u8>>, satay_runtime::Error> {
self.request()
}
fn decode<B: AsRef<[u8]>>(
response: satay_runtime::ResponseParts<B>,
) -> Result<Self::Response, satay_runtime::Error> {
Self::decode(response)
}
}
#[derive(Debug, Clone)]
pub struct AirTemperatureAction<'a> {
api: &'a Api,
input: AirTemperatureInput,
}
impl AirTemperatureAction<'_> {
pub fn date(mut self, date: satay_runtime::Date) -> Self {
self.input = self.input.date(date);
self
}
pub fn pagination_token(mut self, pagination_token: impl Into<String>) -> Self {
self.input = self.input.pagination_token(pagination_token);
self
}
pub fn x_api_key(mut self, x_api_key: impl Into<String>) -> Self {
self.input = self.input.x_api_key(x_api_key);
self
}
pub fn request(self) -> Result<http::Request<Vec<u8>>, satay_runtime::Error> {
let api = self.api;
let mut parts = air_temperature_parts(self.input)?;
api.apply(&mut parts)?;
satay_runtime::into_empty_request(parts)
}
pub fn decode<B: AsRef<[u8]>>(
response: satay_runtime::ResponseParts<B>,
) -> Result<AirTemperatureOperationResponse, satay_runtime::Error> {
decode_air_temperature_response(response)
}
}
impl satay_runtime::Action for AirTemperatureAction<'_> {
type Response = AirTemperatureOperationResponse;
fn request(self) -> Result<http::Request<Vec<u8>>, satay_runtime::Error> {
self.request()
}
fn decode<B: AsRef<[u8]>>(
response: satay_runtime::ResponseParts<B>,
) -> Result<Self::Response, satay_runtime::Error> {
Self::decode(response)
}
}
#[derive(Debug, Clone)]
pub struct RelativeHumidityAction<'a> {
api: &'a Api,
input: RelativeHumidityInput,
}
impl RelativeHumidityAction<'_> {
pub fn date(mut self, date: satay_runtime::Date) -> Self {
self.input = self.input.date(date);
self
}
pub fn pagination_token(mut self, pagination_token: impl Into<String>) -> Self {
self.input = self.input.pagination_token(pagination_token);
self
}
pub fn x_api_key(mut self, x_api_key: impl Into<String>) -> Self {
self.input = self.input.x_api_key(x_api_key);
self
}
pub fn request(self) -> Result<http::Request<Vec<u8>>, satay_runtime::Error> {
let api = self.api;
let mut parts = relative_humidity_parts(self.input)?;
api.apply(&mut parts)?;
satay_runtime::into_empty_request(parts)
}
pub fn decode<B: AsRef<[u8]>>(
response: satay_runtime::ResponseParts<B>,
) -> Result<RelativeHumidityOperationResponse, satay_runtime::Error> {
decode_relative_humidity_response(response)
}
}
impl satay_runtime::Action for RelativeHumidityAction<'_> {
type Response = RelativeHumidityOperationResponse;
fn request(self) -> Result<http::Request<Vec<u8>>, satay_runtime::Error> {
self.request()
}
fn decode<B: AsRef<[u8]>>(
response: satay_runtime::ResponseParts<B>,
) -> Result<Self::Response, satay_runtime::Error> {
Self::decode(response)
}
}
#[derive(Debug, Clone)]
pub struct WindSpeedAction<'a> {
api: &'a Api,
input: WindSpeedInput,
}
impl WindSpeedAction<'_> {
pub fn date(mut self, date: satay_runtime::Date) -> Self {
self.input = self.input.date(date);
self
}
pub fn pagination_token(mut self, pagination_token: impl Into<String>) -> Self {
self.input = self.input.pagination_token(pagination_token);
self
}
pub fn x_api_key(mut self, x_api_key: impl Into<String>) -> Self {
self.input = self.input.x_api_key(x_api_key);
self
}
pub fn request(self) -> Result<http::Request<Vec<u8>>, satay_runtime::Error> {
let api = self.api;
let mut parts = wind_speed_parts(self.input)?;
api.apply(&mut parts)?;
satay_runtime::into_empty_request(parts)
}
pub fn decode<B: AsRef<[u8]>>(
response: satay_runtime::ResponseParts<B>,
) -> Result<WindSpeedOperationResponse, satay_runtime::Error> {
decode_wind_speed_response(response)
}
}
impl satay_runtime::Action for WindSpeedAction<'_> {
type Response = WindSpeedOperationResponse;
fn request(self) -> Result<http::Request<Vec<u8>>, satay_runtime::Error> {
self.request()
}
fn decode<B: AsRef<[u8]>>(
response: satay_runtime::ResponseParts<B>,
) -> Result<Self::Response, satay_runtime::Error> {
Self::decode(response)
}
}
#[derive(Debug, Clone)]
pub struct WindDirectionAction<'a> {
api: &'a Api,
input: WindDirectionInput,
}
impl WindDirectionAction<'_> {
pub fn date(mut self, date: satay_runtime::Date) -> Self {
self.input = self.input.date(date);
self
}
pub fn pagination_token(mut self, pagination_token: impl Into<String>) -> Self {
self.input = self.input.pagination_token(pagination_token);
self
}
pub fn x_api_key(mut self, x_api_key: impl Into<String>) -> Self {
self.input = self.input.x_api_key(x_api_key);
self
}
pub fn request(self) -> Result<http::Request<Vec<u8>>, satay_runtime::Error> {
let api = self.api;
let mut parts = wind_direction_parts(self.input)?;
api.apply(&mut parts)?;
satay_runtime::into_empty_request(parts)
}
pub fn decode<B: AsRef<[u8]>>(
response: satay_runtime::ResponseParts<B>,
) -> Result<WindDirectionOperationResponse, satay_runtime::Error> {
decode_wind_direction_response(response)
}
}
impl satay_runtime::Action for WindDirectionAction<'_> {
type Response = WindDirectionOperationResponse;
fn request(self) -> Result<http::Request<Vec<u8>>, satay_runtime::Error> {
self.request()
}
fn decode<B: AsRef<[u8]>>(
response: satay_runtime::ResponseParts<B>,
) -> Result<Self::Response, satay_runtime::Error> {
Self::decode(response)
}
}
#[derive(Debug, Clone)]
pub struct RainfallAction<'a> {
api: &'a Api,
input: RainfallInput,
}
impl RainfallAction<'_> {
pub fn date(mut self, date: satay_runtime::Date) -> Self {
self.input = self.input.date(date);
self
}
pub fn pagination_token(mut self, pagination_token: impl Into<String>) -> Self {
self.input = self.input.pagination_token(pagination_token);
self
}
pub fn x_api_key(mut self, x_api_key: impl Into<String>) -> Self {
self.input = self.input.x_api_key(x_api_key);
self
}
pub fn request(self) -> Result<http::Request<Vec<u8>>, satay_runtime::Error> {
let api = self.api;
let mut parts = rainfall_parts(self.input)?;
api.apply(&mut parts)?;
satay_runtime::into_empty_request(parts)
}
pub fn decode<B: AsRef<[u8]>>(
response: satay_runtime::ResponseParts<B>,
) -> Result<RainfallOperationResponse, satay_runtime::Error> {
decode_rainfall_response(response)
}
}
impl satay_runtime::Action for RainfallAction<'_> {
type Response = RainfallOperationResponse;
fn request(self) -> Result<http::Request<Vec<u8>>, satay_runtime::Error> {
self.request()
}
fn decode<B: AsRef<[u8]>>(
response: satay_runtime::ResponseParts<B>,
) -> Result<Self::Response, satay_runtime::Error> {
Self::decode(response)
}
}
#[derive(Debug, Clone)]
pub struct TwoHrForecastAction<'a> {
api: &'a Api,
input: TwoHrForecastInput,
}
impl TwoHrForecastAction<'_> {
pub fn date(mut self, date: satay_runtime::Date) -> Self {
self.input = self.input.date(date);
self
}
pub fn pagination_token(mut self, pagination_token: impl Into<String>) -> Self {
self.input = self.input.pagination_token(pagination_token);
self
}
pub fn x_api_key(mut self, x_api_key: impl Into<String>) -> Self {
self.input = self.input.x_api_key(x_api_key);
self
}
pub fn request(self) -> Result<http::Request<Vec<u8>>, satay_runtime::Error> {
let api = self.api;
let mut parts = two_hr_forecast_parts(self.input)?;
api.apply(&mut parts)?;
satay_runtime::into_empty_request(parts)
}
pub fn decode<B: AsRef<[u8]>>(
response: satay_runtime::ResponseParts<B>,
) -> Result<TwoHrForecastOperationResponse, satay_runtime::Error> {
decode_two_hr_forecast_response(response)
}
}
impl satay_runtime::Action for TwoHrForecastAction<'_> {
type Response = TwoHrForecastOperationResponse;
fn request(self) -> Result<http::Request<Vec<u8>>, satay_runtime::Error> {
self.request()
}
fn decode<B: AsRef<[u8]>>(
response: satay_runtime::ResponseParts<B>,
) -> Result<Self::Response, satay_runtime::Error> {
Self::decode(response)
}
}
#[derive(Debug, Clone)]
pub struct TwentyFourHrForecastAction<'a> {
api: &'a Api,
input: TwentyFourHrForecastInput,
}
impl TwentyFourHrForecastAction<'_> {
pub fn date(mut self, date: satay_runtime::Date) -> Self {
self.input = self.input.date(date);
self
}
pub fn pagination_token(mut self, pagination_token: impl Into<String>) -> Self {
self.input = self.input.pagination_token(pagination_token);
self
}
pub fn x_api_key(mut self, x_api_key: impl Into<String>) -> Self {
self.input = self.input.x_api_key(x_api_key);
self
}
pub fn request(self) -> Result<http::Request<Vec<u8>>, satay_runtime::Error> {
let api = self.api;
let mut parts = twenty_four_hr_forecast_parts(self.input)?;
api.apply(&mut parts)?;
satay_runtime::into_empty_request(parts)
}
pub fn decode<B: AsRef<[u8]>>(
response: satay_runtime::ResponseParts<B>,
) -> Result<TwentyFourHrForecastOperationResponse, satay_runtime::Error> {
decode_twenty_four_hr_forecast_response(response)
}
}
impl satay_runtime::Action for TwentyFourHrForecastAction<'_> {
type Response = TwentyFourHrForecastOperationResponse;
fn request(self) -> Result<http::Request<Vec<u8>>, satay_runtime::Error> {
self.request()
}
fn decode<B: AsRef<[u8]>>(
response: satay_runtime::ResponseParts<B>,
) -> Result<Self::Response, satay_runtime::Error> {
Self::decode(response)
}
}
#[derive(Debug, Clone)]
pub struct FourDayOutlookAction<'a> {
api: &'a Api,
input: FourDayOutlookInput,
}
impl FourDayOutlookAction<'_> {
pub fn date(mut self, date: satay_runtime::Date) -> Self {
self.input = self.input.date(date);
self
}
pub fn pagination_token(mut self, pagination_token: impl Into<String>) -> Self {
self.input = self.input.pagination_token(pagination_token);
self
}
pub fn x_api_key(mut self, x_api_key: impl Into<String>) -> Self {
self.input = self.input.x_api_key(x_api_key);
self
}
pub fn request(self) -> Result<http::Request<Vec<u8>>, satay_runtime::Error> {
let api = self.api;
let mut parts = four_day_outlook_parts(self.input)?;
api.apply(&mut parts)?;
satay_runtime::into_empty_request(parts)
}
pub fn decode<B: AsRef<[u8]>>(
response: satay_runtime::ResponseParts<B>,
) -> Result<FourDayOutlookOperationResponse, satay_runtime::Error> {
decode_four_day_outlook_response(response)
}
}
impl satay_runtime::Action for FourDayOutlookAction<'_> {
type Response = FourDayOutlookOperationResponse;
fn request(self) -> Result<http::Request<Vec<u8>>, satay_runtime::Error> {
self.request()
}
fn decode<B: AsRef<[u8]>>(
response: satay_runtime::ResponseParts<B>,
) -> Result<Self::Response, satay_runtime::Error> {
Self::decode(response)
}
}
#[derive(Debug, Clone)]
pub struct UvAction<'a> {
api: &'a Api,
input: UvInput,
}
impl UvAction<'_> {
pub fn date(mut self, date: satay_runtime::Date) -> Self {
self.input = self.input.date(date);
self
}
pub fn pagination_token(mut self, pagination_token: impl Into<String>) -> Self {
self.input = self.input.pagination_token(pagination_token);
self
}
pub fn x_api_key(mut self, x_api_key: impl Into<String>) -> Self {
self.input = self.input.x_api_key(x_api_key);
self
}
pub fn request(self) -> Result<http::Request<Vec<u8>>, satay_runtime::Error> {
let api = self.api;
let mut parts = uv_parts(self.input)?;
api.apply(&mut parts)?;
satay_runtime::into_empty_request(parts)
}
pub fn decode<B: AsRef<[u8]>>(
response: satay_runtime::ResponseParts<B>,
) -> Result<UvOperationResponse, satay_runtime::Error> {
decode_uv_response(response)
}
}
impl satay_runtime::Action for UvAction<'_> {
type Response = UvOperationResponse;
fn request(self) -> Result<http::Request<Vec<u8>>, satay_runtime::Error> {
self.request()
}
fn decode<B: AsRef<[u8]>>(
response: satay_runtime::ResponseParts<B>,
) -> Result<Self::Response, satay_runtime::Error> {
Self::decode(response)
}
}
#[derive(Debug, Clone)]
pub struct WeatherSubApiAction<'a> {
api: &'a Api,
input: WeatherSubApiInput,
}
impl WeatherSubApiAction<'_> {
pub fn date(mut self, date: satay_runtime::Date) -> Self {
self.input = self.input.date(date);
self
}
pub fn pagination_token(mut self, pagination_token: impl Into<String>) -> Self {
self.input = self.input.pagination_token(pagination_token);
self
}
pub fn x_api_key(mut self, x_api_key: impl Into<String>) -> Self {
self.input = self.input.x_api_key(x_api_key);
self
}
pub fn request(self) -> Result<http::Request<Vec<u8>>, satay_runtime::Error> {
let api = self.api;
let mut parts = weather_sub_api_parts(self.input)?;
api.apply(&mut parts)?;
satay_runtime::into_empty_request(parts)
}
pub fn decode<B: AsRef<[u8]>>(
response: satay_runtime::ResponseParts<B>,
) -> Result<WeatherSubApiOperationResponse, satay_runtime::Error> {
decode_weather_sub_api_response(response)
}
}
impl satay_runtime::Action for WeatherSubApiAction<'_> {
type Response = WeatherSubApiOperationResponse;
fn request(self) -> Result<http::Request<Vec<u8>>, satay_runtime::Error> {
self.request()
}
fn decode<B: AsRef<[u8]>>(
response: satay_runtime::ResponseParts<B>,
) -> Result<Self::Response, satay_runtime::Error> {
Self::decode(response)
}
}