use reqwest::Client;
use std::fmt::Display;
use ::models::Forecast;
use ::{Options, Result, internal, utils};
pub trait DarkskyReqwestRequester {
fn get_forecast(&self, token: &str, latitude: f64, longitude: f64)
-> Result<Forecast>;
fn get_forecast_with_options<F>(
&self,
token: &str,
latitude: f64,
longitude: f64,
options: F,
) -> Result<Forecast> where F: FnOnce(Options) -> Options;
fn get_forecast_time_machine<D, F>(
&self,
token: &str,
latitude: f64,
longitude: f64,
time: D,
options: F,
) -> Result<Forecast> where D: Display, F: FnOnce(Options) -> Options;
}
impl DarkskyReqwestRequester for Client {
fn get_forecast(&self, token: &str, latitude: f64, longitude: f64)
-> Result<Forecast> {
let uri = utils::uri(token, latitude, longitude);
internal::from_reader(self.get(&uri).send()?)
}
fn get_forecast_with_options<F>(
&self,
token: &str,
latitude: f64,
longitude: f64,
options: F,
) -> Result<Forecast> where F: FnOnce(Options) -> Options {
let options = options(Options::default()).0;
let uri = utils::uri_optioned(
token,
latitude,
longitude,
None,
options,
)?;
internal::from_reader(self.get(&uri).send()?)
}
fn get_forecast_time_machine<D, F>(
&self,
token: &str,
latitude: f64,
longitude: f64,
time: D,
options: F,
) -> Result<Forecast> where D: Display, F: FnOnce(Options) -> Options {
let options = options(Options::default()).0;
let uri = utils::uri_optioned(
token,
latitude,
longitude,
Some(time.to_string()),
options,
)?;
internal::from_reader(self.get(&uri).send()?)
}
}