libtad_rs/service/tides/
request.rs

1use crate::models::time::DateTime;
2use crate::service::{ProvidedArgument, RequiredArgument};
3use serde::Serialize;
4
5macro_rules! return_type {
6    ($self:ident) => {
7        TidesRequest {
8            placeid: $self.placeid,
9            onlyhighlow: $self.onlyhighlow,
10            startdt: $self.startdt,
11            enddt: $self.enddt,
12            radius: $self.radius,
13            subordinate: $self.subordinate,
14            interval: $self.interval,
15            localtime: $self.localtime,
16            _a: Default::default(),
17        }
18    };
19}
20
21#[derive(Default, Serialize)]
22/// Tides API request.
23///
24/// Request is validated when supplied to the client.
25pub struct TidesRequest<A = ProvidedArgument> {
26    placeid: Vec<String>,
27    onlyhighlow: Option<u8>,
28    startdt: Option<DateTime>,
29    enddt: Option<DateTime>,
30    radius: Option<i32>,
31    subordinate: Option<u8>,
32    interval: Option<i32>,
33    localtime: Option<u8>,
34    _a: std::marker::PhantomData<A>,
35}
36
37impl TidesRequest {
38    /// Start building a new request.
39    pub fn new() -> TidesRequest<RequiredArgument> {
40        Default::default()
41    }
42}
43
44impl<A> TidesRequest<A> {
45    /// Add a placeid to the request.
46    pub fn with_placeid(mut self, placeid: impl Into<String>) -> TidesRequest<ProvidedArgument> {
47        self.placeid.push(placeid.into());
48
49        return_type!(self)
50    }
51
52    /// Set whether to return every point per interval or just the highest and lowest points.
53    pub fn set_onlyhighlow(mut self, enable: bool) -> Self {
54        self.onlyhighlow.insert(enable.into());
55
56        self
57    }
58
59    /// Set start of the requested time interval.
60    pub fn set_startdt(mut self, startdt: DateTime) -> Self {
61        self.startdt.insert(startdt);
62
63        self
64    }
65
66    /// Set end of the requested time interval.
67    pub fn set_enddt(mut self, enddt: DateTime) -> Self {
68        self.enddt.insert(enddt);
69
70        self
71    }
72
73    /// Set radius from the requested location to query for stations. Given in kilometers.
74    pub fn set_radius(mut self, radius: i32) -> Self {
75        self.radius.insert(radius);
76
77        self
78    }
79
80    /// Toggle whether to resolve also subordinate stations or just reference stations.
81    pub fn set_subordinate(mut self, enable: bool) -> Self {
82        self.subordinate.insert(enable.into());
83
84        self
85    }
86
87    /// Set how many minutes to calculate the range in. Supported: 5 min, 15, min, 30 min, 60 min.
88    pub fn set_interval(mut self, interval: i32) -> Self {
89        self.interval.insert(interval);
90
91        self
92    }
93
94    /// Toggle whether input and output time stamps should be resolved to local time.
95    pub fn set_localtime(mut self, enable: bool) -> Self {
96        self.localtime.insert(enable.into());
97
98        self
99    }
100}