1use super::{
4 AirTemperatureInput, AirTemperatureOperationResponse, FourDayOutlookInput,
5 FourDayOutlookOperationResponse, NeaWeatherSubApi, Pm25Input, Pm25OperationResponse, PsiInput,
6 PsiOperationResponse, RainfallInput, RainfallOperationResponse, RelativeHumidityInput,
7 RelativeHumidityOperationResponse, TwentyFourHrForecastInput,
8 TwentyFourHrForecastOperationResponse, TwoHrForecastInput, TwoHrForecastOperationResponse,
9 UvInput, UvOperationResponse, WeatherSubApiInput, WeatherSubApiOperationResponse,
10 WindDirectionInput, WindDirectionOperationResponse, WindSpeedInput, WindSpeedOperationResponse,
11 air_temperature_parts, decode_air_temperature_response, decode_four_day_outlook_response,
12 decode_pm25_response, decode_psi_response, decode_rainfall_response,
13 decode_relative_humidity_response, decode_twenty_four_hr_forecast_response,
14 decode_two_hr_forecast_response, decode_uv_response, decode_weather_sub_api_response,
15 decode_wind_direction_response, decode_wind_speed_response, four_day_outlook_parts, pm25_parts,
16 psi_parts, rainfall_parts, relative_humidity_parts, twenty_four_hr_forecast_parts,
17 two_hr_forecast_parts, uv_parts, weather_sub_api_parts, wind_direction_parts, wind_speed_parts,
18};
19#[derive(Debug, Clone)]
20pub struct Api {
21 base_url: String,
22 x_api_key: Option<String>,
23}
24impl Default for Api {
25 fn default() -> Self {
26 Self::new()
27 }
28}
29impl Api {
30 pub fn new() -> Self {
31 Self {
32 base_url: super::SERVER_URL.to_owned(),
33 x_api_key: None,
34 }
35 }
36 pub fn base_url(mut self, base_url: impl Into<String>) -> Self {
37 self.base_url = base_url.into();
38 self
39 }
40 pub fn x_api_key(mut self, value: impl Into<String>) -> Self {
41 self.x_api_key = Some(value.into());
42 self
43 }
44 pub fn psi(&self) -> PsiAction<'_> {
58 PsiAction {
59 api: self,
60 input: PsiInput::new(),
61 }
62 }
63 pub fn pm25(&self) -> Pm25Action<'_> {
77 Pm25Action {
78 api: self,
79 input: Pm25Input::new(),
80 }
81 }
82 pub fn air_temperature(&self) -> AirTemperatureAction<'_> {
92 AirTemperatureAction {
93 api: self,
94 input: AirTemperatureInput::new(),
95 }
96 }
97 pub fn relative_humidity(&self) -> RelativeHumidityAction<'_> {
107 RelativeHumidityAction {
108 api: self,
109 input: RelativeHumidityInput::new(),
110 }
111 }
112 pub fn wind_speed(&self) -> WindSpeedAction<'_> {
122 WindSpeedAction {
123 api: self,
124 input: WindSpeedInput::new(),
125 }
126 }
127 pub fn wind_direction(&self) -> WindDirectionAction<'_> {
137 WindDirectionAction {
138 api: self,
139 input: WindDirectionInput::new(),
140 }
141 }
142 pub fn rainfall(&self) -> RainfallAction<'_> {
152 RainfallAction {
153 api: self,
154 input: RainfallInput::new(),
155 }
156 }
157 pub fn two_hr_forecast(&self) -> TwoHrForecastAction<'_> {
169 TwoHrForecastAction {
170 api: self,
171 input: TwoHrForecastInput::new(),
172 }
173 }
174 pub fn twenty_four_hr_forecast(&self) -> TwentyFourHrForecastAction<'_> {
186 TwentyFourHrForecastAction {
187 api: self,
188 input: TwentyFourHrForecastInput::new(),
189 }
190 }
191 pub fn four_day_outlook(&self) -> FourDayOutlookAction<'_> {
203 FourDayOutlookAction {
204 api: self,
205 input: FourDayOutlookInput::new(),
206 }
207 }
208 pub fn uv(&self) -> UvAction<'_> {
222 UvAction {
223 api: self,
224 input: UvInput::new(),
225 }
226 }
227 pub fn weather_sub_api(&self, api: NeaWeatherSubApi) -> WeatherSubApiAction<'_> {
243 WeatherSubApiAction {
244 api: self,
245 input: WeatherSubApiInput::new(api),
246 }
247 }
248 fn apply<B>(
249 &self,
250 parts: &mut satay_runtime::RequestParts<B>,
251 ) -> Result<(), satay_runtime::Error> {
252 if let Some(value) = &self.x_api_key {
253 satay_runtime::insert_header(&mut parts.headers, "x-api-key", value)?;
254 }
255 if self.base_url.is_empty() {
256 return Ok(());
257 }
258 let path_and_query = parts.uri.as_str();
259 let base_url = self.base_url.trim_end_matches('/');
260 let separator = if path_and_query.starts_with('/') {
261 ""
262 } else {
263 "/"
264 };
265 parts.uri = format!("{base_url}{separator}{path_and_query}");
266 Ok(())
267 }
268}
269#[derive(Debug, Clone)]
283pub struct PsiAction<'a> {
284 api: &'a Api,
285 input: PsiInput,
286}
287impl PsiAction<'_> {
288 pub fn date(mut self, date: satay_runtime::Date) -> Self {
289 self.input = self.input.date(date);
290 self
291 }
292 pub fn pagination_token(mut self, pagination_token: impl Into<String>) -> Self {
293 self.input = self.input.pagination_token(pagination_token);
294 self
295 }
296 pub fn x_api_key(mut self, x_api_key: impl Into<String>) -> Self {
297 self.input = self.input.x_api_key(x_api_key);
298 self
299 }
300 pub fn request(self) -> Result<http::Request<Vec<u8>>, satay_runtime::Error> {
301 let api = self.api;
302 let mut parts = psi_parts(self.input)?;
303 api.apply(&mut parts)?;
304 satay_runtime::into_empty_request(parts)
305 }
306 pub fn decode<B: AsRef<[u8]>>(
307 response: satay_runtime::ResponseParts<B>,
308 ) -> Result<PsiOperationResponse, satay_runtime::Error> {
309 decode_psi_response(response)
310 }
311}
312impl satay_runtime::Action for PsiAction<'_> {
313 type Response = PsiOperationResponse;
314 fn request(self) -> Result<http::Request<Vec<u8>>, satay_runtime::Error> {
315 self.request()
316 }
317 fn decode<B: AsRef<[u8]>>(
318 response: satay_runtime::ResponseParts<B>,
319 ) -> Result<Self::Response, satay_runtime::Error> {
320 Self::decode(response)
321 }
322}
323#[derive(Debug, Clone)]
337pub struct Pm25Action<'a> {
338 api: &'a Api,
339 input: Pm25Input,
340}
341impl Pm25Action<'_> {
342 pub fn date(mut self, date: satay_runtime::Date) -> Self {
343 self.input = self.input.date(date);
344 self
345 }
346 pub fn pagination_token(mut self, pagination_token: impl Into<String>) -> Self {
347 self.input = self.input.pagination_token(pagination_token);
348 self
349 }
350 pub fn x_api_key(mut self, x_api_key: impl Into<String>) -> Self {
351 self.input = self.input.x_api_key(x_api_key);
352 self
353 }
354 pub fn request(self) -> Result<http::Request<Vec<u8>>, satay_runtime::Error> {
355 let api = self.api;
356 let mut parts = pm25_parts(self.input)?;
357 api.apply(&mut parts)?;
358 satay_runtime::into_empty_request(parts)
359 }
360 pub fn decode<B: AsRef<[u8]>>(
361 response: satay_runtime::ResponseParts<B>,
362 ) -> Result<Pm25OperationResponse, satay_runtime::Error> {
363 decode_pm25_response(response)
364 }
365}
366impl satay_runtime::Action for Pm25Action<'_> {
367 type Response = Pm25OperationResponse;
368 fn request(self) -> Result<http::Request<Vec<u8>>, satay_runtime::Error> {
369 self.request()
370 }
371 fn decode<B: AsRef<[u8]>>(
372 response: satay_runtime::ResponseParts<B>,
373 ) -> Result<Self::Response, satay_runtime::Error> {
374 Self::decode(response)
375 }
376}
377#[derive(Debug, Clone)]
387pub struct AirTemperatureAction<'a> {
388 api: &'a Api,
389 input: AirTemperatureInput,
390}
391impl AirTemperatureAction<'_> {
392 pub fn date(mut self, date: satay_runtime::Date) -> Self {
393 self.input = self.input.date(date);
394 self
395 }
396 pub fn pagination_token(mut self, pagination_token: impl Into<String>) -> Self {
397 self.input = self.input.pagination_token(pagination_token);
398 self
399 }
400 pub fn x_api_key(mut self, x_api_key: impl Into<String>) -> Self {
401 self.input = self.input.x_api_key(x_api_key);
402 self
403 }
404 pub fn request(self) -> Result<http::Request<Vec<u8>>, satay_runtime::Error> {
405 let api = self.api;
406 let mut parts = air_temperature_parts(self.input)?;
407 api.apply(&mut parts)?;
408 satay_runtime::into_empty_request(parts)
409 }
410 pub fn decode<B: AsRef<[u8]>>(
411 response: satay_runtime::ResponseParts<B>,
412 ) -> Result<AirTemperatureOperationResponse, satay_runtime::Error> {
413 decode_air_temperature_response(response)
414 }
415}
416impl satay_runtime::Action for AirTemperatureAction<'_> {
417 type Response = AirTemperatureOperationResponse;
418 fn request(self) -> Result<http::Request<Vec<u8>>, satay_runtime::Error> {
419 self.request()
420 }
421 fn decode<B: AsRef<[u8]>>(
422 response: satay_runtime::ResponseParts<B>,
423 ) -> Result<Self::Response, satay_runtime::Error> {
424 Self::decode(response)
425 }
426}
427#[derive(Debug, Clone)]
437pub struct RelativeHumidityAction<'a> {
438 api: &'a Api,
439 input: RelativeHumidityInput,
440}
441impl RelativeHumidityAction<'_> {
442 pub fn date(mut self, date: satay_runtime::Date) -> Self {
443 self.input = self.input.date(date);
444 self
445 }
446 pub fn pagination_token(mut self, pagination_token: impl Into<String>) -> Self {
447 self.input = self.input.pagination_token(pagination_token);
448 self
449 }
450 pub fn x_api_key(mut self, x_api_key: impl Into<String>) -> Self {
451 self.input = self.input.x_api_key(x_api_key);
452 self
453 }
454 pub fn request(self) -> Result<http::Request<Vec<u8>>, satay_runtime::Error> {
455 let api = self.api;
456 let mut parts = relative_humidity_parts(self.input)?;
457 api.apply(&mut parts)?;
458 satay_runtime::into_empty_request(parts)
459 }
460 pub fn decode<B: AsRef<[u8]>>(
461 response: satay_runtime::ResponseParts<B>,
462 ) -> Result<RelativeHumidityOperationResponse, satay_runtime::Error> {
463 decode_relative_humidity_response(response)
464 }
465}
466impl satay_runtime::Action for RelativeHumidityAction<'_> {
467 type Response = RelativeHumidityOperationResponse;
468 fn request(self) -> Result<http::Request<Vec<u8>>, satay_runtime::Error> {
469 self.request()
470 }
471 fn decode<B: AsRef<[u8]>>(
472 response: satay_runtime::ResponseParts<B>,
473 ) -> Result<Self::Response, satay_runtime::Error> {
474 Self::decode(response)
475 }
476}
477#[derive(Debug, Clone)]
487pub struct WindSpeedAction<'a> {
488 api: &'a Api,
489 input: WindSpeedInput,
490}
491impl WindSpeedAction<'_> {
492 pub fn date(mut self, date: satay_runtime::Date) -> Self {
493 self.input = self.input.date(date);
494 self
495 }
496 pub fn pagination_token(mut self, pagination_token: impl Into<String>) -> Self {
497 self.input = self.input.pagination_token(pagination_token);
498 self
499 }
500 pub fn x_api_key(mut self, x_api_key: impl Into<String>) -> Self {
501 self.input = self.input.x_api_key(x_api_key);
502 self
503 }
504 pub fn request(self) -> Result<http::Request<Vec<u8>>, satay_runtime::Error> {
505 let api = self.api;
506 let mut parts = wind_speed_parts(self.input)?;
507 api.apply(&mut parts)?;
508 satay_runtime::into_empty_request(parts)
509 }
510 pub fn decode<B: AsRef<[u8]>>(
511 response: satay_runtime::ResponseParts<B>,
512 ) -> Result<WindSpeedOperationResponse, satay_runtime::Error> {
513 decode_wind_speed_response(response)
514 }
515}
516impl satay_runtime::Action for WindSpeedAction<'_> {
517 type Response = WindSpeedOperationResponse;
518 fn request(self) -> Result<http::Request<Vec<u8>>, satay_runtime::Error> {
519 self.request()
520 }
521 fn decode<B: AsRef<[u8]>>(
522 response: satay_runtime::ResponseParts<B>,
523 ) -> Result<Self::Response, satay_runtime::Error> {
524 Self::decode(response)
525 }
526}
527#[derive(Debug, Clone)]
537pub struct WindDirectionAction<'a> {
538 api: &'a Api,
539 input: WindDirectionInput,
540}
541impl WindDirectionAction<'_> {
542 pub fn date(mut self, date: satay_runtime::Date) -> Self {
543 self.input = self.input.date(date);
544 self
545 }
546 pub fn pagination_token(mut self, pagination_token: impl Into<String>) -> Self {
547 self.input = self.input.pagination_token(pagination_token);
548 self
549 }
550 pub fn x_api_key(mut self, x_api_key: impl Into<String>) -> Self {
551 self.input = self.input.x_api_key(x_api_key);
552 self
553 }
554 pub fn request(self) -> Result<http::Request<Vec<u8>>, satay_runtime::Error> {
555 let api = self.api;
556 let mut parts = wind_direction_parts(self.input)?;
557 api.apply(&mut parts)?;
558 satay_runtime::into_empty_request(parts)
559 }
560 pub fn decode<B: AsRef<[u8]>>(
561 response: satay_runtime::ResponseParts<B>,
562 ) -> Result<WindDirectionOperationResponse, satay_runtime::Error> {
563 decode_wind_direction_response(response)
564 }
565}
566impl satay_runtime::Action for WindDirectionAction<'_> {
567 type Response = WindDirectionOperationResponse;
568 fn request(self) -> Result<http::Request<Vec<u8>>, satay_runtime::Error> {
569 self.request()
570 }
571 fn decode<B: AsRef<[u8]>>(
572 response: satay_runtime::ResponseParts<B>,
573 ) -> Result<Self::Response, satay_runtime::Error> {
574 Self::decode(response)
575 }
576}
577#[derive(Debug, Clone)]
587pub struct RainfallAction<'a> {
588 api: &'a Api,
589 input: RainfallInput,
590}
591impl RainfallAction<'_> {
592 pub fn date(mut self, date: satay_runtime::Date) -> Self {
593 self.input = self.input.date(date);
594 self
595 }
596 pub fn pagination_token(mut self, pagination_token: impl Into<String>) -> Self {
597 self.input = self.input.pagination_token(pagination_token);
598 self
599 }
600 pub fn x_api_key(mut self, x_api_key: impl Into<String>) -> Self {
601 self.input = self.input.x_api_key(x_api_key);
602 self
603 }
604 pub fn request(self) -> Result<http::Request<Vec<u8>>, satay_runtime::Error> {
605 let api = self.api;
606 let mut parts = rainfall_parts(self.input)?;
607 api.apply(&mut parts)?;
608 satay_runtime::into_empty_request(parts)
609 }
610 pub fn decode<B: AsRef<[u8]>>(
611 response: satay_runtime::ResponseParts<B>,
612 ) -> Result<RainfallOperationResponse, satay_runtime::Error> {
613 decode_rainfall_response(response)
614 }
615}
616impl satay_runtime::Action for RainfallAction<'_> {
617 type Response = RainfallOperationResponse;
618 fn request(self) -> Result<http::Request<Vec<u8>>, satay_runtime::Error> {
619 self.request()
620 }
621 fn decode<B: AsRef<[u8]>>(
622 response: satay_runtime::ResponseParts<B>,
623 ) -> Result<Self::Response, satay_runtime::Error> {
624 Self::decode(response)
625 }
626}
627#[derive(Debug, Clone)]
639pub struct TwoHrForecastAction<'a> {
640 api: &'a Api,
641 input: TwoHrForecastInput,
642}
643impl TwoHrForecastAction<'_> {
644 pub fn date(mut self, date: satay_runtime::Date) -> Self {
645 self.input = self.input.date(date);
646 self
647 }
648 pub fn pagination_token(mut self, pagination_token: impl Into<String>) -> Self {
649 self.input = self.input.pagination_token(pagination_token);
650 self
651 }
652 pub fn x_api_key(mut self, x_api_key: impl Into<String>) -> Self {
653 self.input = self.input.x_api_key(x_api_key);
654 self
655 }
656 pub fn request(self) -> Result<http::Request<Vec<u8>>, satay_runtime::Error> {
657 let api = self.api;
658 let mut parts = two_hr_forecast_parts(self.input)?;
659 api.apply(&mut parts)?;
660 satay_runtime::into_empty_request(parts)
661 }
662 pub fn decode<B: AsRef<[u8]>>(
663 response: satay_runtime::ResponseParts<B>,
664 ) -> Result<TwoHrForecastOperationResponse, satay_runtime::Error> {
665 decode_two_hr_forecast_response(response)
666 }
667}
668impl satay_runtime::Action for TwoHrForecastAction<'_> {
669 type Response = TwoHrForecastOperationResponse;
670 fn request(self) -> Result<http::Request<Vec<u8>>, satay_runtime::Error> {
671 self.request()
672 }
673 fn decode<B: AsRef<[u8]>>(
674 response: satay_runtime::ResponseParts<B>,
675 ) -> Result<Self::Response, satay_runtime::Error> {
676 Self::decode(response)
677 }
678}
679#[derive(Debug, Clone)]
691pub struct TwentyFourHrForecastAction<'a> {
692 api: &'a Api,
693 input: TwentyFourHrForecastInput,
694}
695impl TwentyFourHrForecastAction<'_> {
696 pub fn date(mut self, date: satay_runtime::Date) -> Self {
697 self.input = self.input.date(date);
698 self
699 }
700 pub fn pagination_token(mut self, pagination_token: impl Into<String>) -> Self {
701 self.input = self.input.pagination_token(pagination_token);
702 self
703 }
704 pub fn x_api_key(mut self, x_api_key: impl Into<String>) -> Self {
705 self.input = self.input.x_api_key(x_api_key);
706 self
707 }
708 pub fn request(self) -> Result<http::Request<Vec<u8>>, satay_runtime::Error> {
709 let api = self.api;
710 let mut parts = twenty_four_hr_forecast_parts(self.input)?;
711 api.apply(&mut parts)?;
712 satay_runtime::into_empty_request(parts)
713 }
714 pub fn decode<B: AsRef<[u8]>>(
715 response: satay_runtime::ResponseParts<B>,
716 ) -> Result<TwentyFourHrForecastOperationResponse, satay_runtime::Error> {
717 decode_twenty_four_hr_forecast_response(response)
718 }
719}
720impl satay_runtime::Action for TwentyFourHrForecastAction<'_> {
721 type Response = TwentyFourHrForecastOperationResponse;
722 fn request(self) -> Result<http::Request<Vec<u8>>, satay_runtime::Error> {
723 self.request()
724 }
725 fn decode<B: AsRef<[u8]>>(
726 response: satay_runtime::ResponseParts<B>,
727 ) -> Result<Self::Response, satay_runtime::Error> {
728 Self::decode(response)
729 }
730}
731#[derive(Debug, Clone)]
743pub struct FourDayOutlookAction<'a> {
744 api: &'a Api,
745 input: FourDayOutlookInput,
746}
747impl FourDayOutlookAction<'_> {
748 pub fn date(mut self, date: satay_runtime::Date) -> Self {
749 self.input = self.input.date(date);
750 self
751 }
752 pub fn pagination_token(mut self, pagination_token: impl Into<String>) -> Self {
753 self.input = self.input.pagination_token(pagination_token);
754 self
755 }
756 pub fn x_api_key(mut self, x_api_key: impl Into<String>) -> Self {
757 self.input = self.input.x_api_key(x_api_key);
758 self
759 }
760 pub fn request(self) -> Result<http::Request<Vec<u8>>, satay_runtime::Error> {
761 let api = self.api;
762 let mut parts = four_day_outlook_parts(self.input)?;
763 api.apply(&mut parts)?;
764 satay_runtime::into_empty_request(parts)
765 }
766 pub fn decode<B: AsRef<[u8]>>(
767 response: satay_runtime::ResponseParts<B>,
768 ) -> Result<FourDayOutlookOperationResponse, satay_runtime::Error> {
769 decode_four_day_outlook_response(response)
770 }
771}
772impl satay_runtime::Action for FourDayOutlookAction<'_> {
773 type Response = FourDayOutlookOperationResponse;
774 fn request(self) -> Result<http::Request<Vec<u8>>, satay_runtime::Error> {
775 self.request()
776 }
777 fn decode<B: AsRef<[u8]>>(
778 response: satay_runtime::ResponseParts<B>,
779 ) -> Result<Self::Response, satay_runtime::Error> {
780 Self::decode(response)
781 }
782}
783#[derive(Debug, Clone)]
797pub struct UvAction<'a> {
798 api: &'a Api,
799 input: UvInput,
800}
801impl UvAction<'_> {
802 pub fn date(mut self, date: satay_runtime::Date) -> Self {
803 self.input = self.input.date(date);
804 self
805 }
806 pub fn pagination_token(mut self, pagination_token: impl Into<String>) -> Self {
807 self.input = self.input.pagination_token(pagination_token);
808 self
809 }
810 pub fn x_api_key(mut self, x_api_key: impl Into<String>) -> Self {
811 self.input = self.input.x_api_key(x_api_key);
812 self
813 }
814 pub fn request(self) -> Result<http::Request<Vec<u8>>, satay_runtime::Error> {
815 let api = self.api;
816 let mut parts = uv_parts(self.input)?;
817 api.apply(&mut parts)?;
818 satay_runtime::into_empty_request(parts)
819 }
820 pub fn decode<B: AsRef<[u8]>>(
821 response: satay_runtime::ResponseParts<B>,
822 ) -> Result<UvOperationResponse, satay_runtime::Error> {
823 decode_uv_response(response)
824 }
825}
826impl satay_runtime::Action for UvAction<'_> {
827 type Response = UvOperationResponse;
828 fn request(self) -> Result<http::Request<Vec<u8>>, satay_runtime::Error> {
829 self.request()
830 }
831 fn decode<B: AsRef<[u8]>>(
832 response: satay_runtime::ResponseParts<B>,
833 ) -> Result<Self::Response, satay_runtime::Error> {
834 Self::decode(response)
835 }
836}
837#[derive(Debug, Clone)]
853pub struct WeatherSubApiAction<'a> {
854 api: &'a Api,
855 input: WeatherSubApiInput,
856}
857impl WeatherSubApiAction<'_> {
858 pub fn date(mut self, date: satay_runtime::Date) -> Self {
859 self.input = self.input.date(date);
860 self
861 }
862 pub fn pagination_token(mut self, pagination_token: impl Into<String>) -> Self {
863 self.input = self.input.pagination_token(pagination_token);
864 self
865 }
866 pub fn x_api_key(mut self, x_api_key: impl Into<String>) -> Self {
867 self.input = self.input.x_api_key(x_api_key);
868 self
869 }
870 pub fn request(self) -> Result<http::Request<Vec<u8>>, satay_runtime::Error> {
871 let api = self.api;
872 let mut parts = weather_sub_api_parts(self.input)?;
873 api.apply(&mut parts)?;
874 satay_runtime::into_empty_request(parts)
875 }
876 pub fn decode<B: AsRef<[u8]>>(
877 response: satay_runtime::ResponseParts<B>,
878 ) -> Result<WeatherSubApiOperationResponse, satay_runtime::Error> {
879 decode_weather_sub_api_response(response)
880 }
881}
882impl satay_runtime::Action for WeatherSubApiAction<'_> {
883 type Response = WeatherSubApiOperationResponse;
884 fn request(self) -> Result<http::Request<Vec<u8>>, satay_runtime::Error> {
885 self.request()
886 }
887 fn decode<B: AsRef<[u8]>>(
888 response: satay_runtime::ResponseParts<B>,
889 ) -> Result<Self::Response, satay_runtime::Error> {
890 Self::decode(response)
891 }
892}