use crate::client::Call;
use crate::error::Result;
use crate::model::time::{TimestampInfo, TimezoneInfo, TimezoneListResponse};
use crate::transport::HttpTransport;
use crate::types::timestamp::Timestamp;
use crate::types::timezone_name::TimezoneName;
use crate::types::try_into_value::TryIntoValue;
crate::api::endpoint!(
Time
);
impl<T: HttpTransport> Time<'_, T> {
pub async fn now(&self) -> Result<Timestamp> {
let response: TimestampInfo = self.client.json(Call::get("time")).await?;
Ok(response.timestamp)
}
pub async fn set_timestamp(&self, timestamp: impl TryIntoValue<Timestamp>) -> Result<()> {
let request = Call::post("time/timestamp").query("timestamp", timestamp.try_into_value()?);
self.client.ok(request).await
}
pub async fn timezone(&self) -> Result<TimezoneInfo> {
self.client.json(Call::get("time/timezone")).await
}
pub async fn set_timezone(&self, timezone: impl TryIntoValue<TimezoneName>) -> Result<()> {
let request = Call::post("time/timezone").query("timezone", timezone.try_into_value()?);
self.client.ok(request).await
}
pub async fn tzlist(&self) -> Result<Vec<TimezoneInfo>> {
let response: TimezoneListResponse = self.client.json(Call::get("time/tzlist")).await?;
Ok(response.list)
}
}