Trait darksky::DarkskyRequester
[−]
[src]
pub trait DarkskyRequester { 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; }
The trait for implementations to different DarkSky routes.
Required Methods
fn get_forecast(
&self,
token: &str,
latitude: f64,
longitude: f64
) -> Result<Forecast>
&self,
token: &str,
latitude: f64,
longitude: f64
) -> Result<Forecast>
Retrieve a forecast for the given latitude and longitude.
Examples
extern crate darksky; extern crate hyper; extern crate hyper_native_tls; use darksky::{DarkskyRequester, Block}; use hyper::net::HttpsConnector; use hyper::Client; use hyper_native_tls::NativeTlsClient; use std::env; let tc = NativeTlsClient::new()?; let connector = HttpsConnector::new(tc); let client = Client::with_connector(connector); let token = env::var("FORECAST_TOKEN")?; let lat = 37.8267; let long = -122.423; match client.get_forecast(&token, lat, long) { Ok(forecast) => println!("{:?}", forecast), Err(why) => println!("Error getting forecast: {:?}", why), }
fn get_forecast_with_options<F>(
&self,
token: &str,
latitude: f64,
longitude: f64,
options: F
) -> Result<Forecast> where
F: FnOnce(Options) -> Options,
&self,
token: &str,
latitude: f64,
longitude: f64,
options: F
) -> Result<Forecast> where
F: FnOnce(Options) -> Options,
Retrieve a forecast for the given latitude and longitude,
setting options where needed. For a full list of options, refer to the
documentation for the Options
builder.
Examples
Retrieve an extended forecast, excluding the minutely block.
extern crate darksky; extern crate hyper; extern crate hyper_native_tls; use darksky::{DarkskyRequester, Block}; use hyper::net::HttpsConnector; use hyper::Client; use hyper_native_tls::NativeTlsClient; use std::env; let tc = NativeTlsClient::new()?; let connector = HttpsConnector::new(tc); let client = Client::with_connector(connector); let token = env::var("FORECAST_TOKEN").expect("forecast token"); let lat = 37.8267; let long = -122.423; let req = client.get_forecast_with_options(&token, lat, long, |o| o .exclude(vec![Block::Minutely]) .extend_hourly()); match req { Ok(forecast) => println!("{:?}", forecast), Err(why) => println!("Error getting forecast: {:?}", why), }
Implementors
impl DarkskyRequester for Client