Trait darksky::bridge::hyper::DarkskyHyperRequester
[−]
[src]
pub trait DarkskyHyperRequester { fn get_forecast<'a>(
&'a self,
token: &'a str,
latitude: f64,
longitude: f64
) -> Box<Future<Item = Forecast, Error = Error> + 'a>; fn get_forecast_with_options<'a, F: FnOnce(Options) -> Options>(
&'a self,
token: &'a str,
latitude: f64,
longitude: f64,
options: F
) -> Box<Future<Item = Forecast, Error = Error> + 'a>; }
The trait for hyper
implementations to different DarkSky routes.
Required Methods
fn get_forecast<'a>(
&'a self,
token: &'a str,
latitude: f64,
longitude: f64
) -> Box<Future<Item = Forecast, Error = Error> + 'a>
&'a self,
token: &'a str,
latitude: f64,
longitude: f64
) -> Box<Future<Item = Forecast, Error = Error> + 'a>
Retrieve a forecast for the given latitude and longitude.
Examples
extern crate darksky; extern crate futures; extern crate hyper; extern crate hyper_tls; extern crate tokio_core; use darksky::{DarkskyHyperRequester, Block}; use futures::Future; use hyper::client::{Client, HttpConnector}; use hyper_tls::HttpsConnector; use std::env; use tokio_core::reactor::Core; let core = Core::new()?; let handle = core.handle(); let client = Client::configure() .connector(HttpsConnector::new(4, &handle)?) .build(&handle); let token = env::var("FORECAST_TOKEN")?; let lat = 37.8267; let long = -122.423; // We're waiting in this example, but you shouldn't in your code. match client.get_forecast(&token, lat, long).wait() { Ok(forecast) => println!("{:?}", forecast), Err(why) => println!("Error getting forecast: {:?}", why), }
fn get_forecast_with_options<'a, F: FnOnce(Options) -> Options>(
&'a self,
token: &'a str,
latitude: f64,
longitude: f64,
options: F
) -> Box<Future<Item = Forecast, Error = Error> + 'a>
&'a self,
token: &'a str,
latitude: f64,
longitude: f64,
options: F
) -> Box<Future<Item = Forecast, Error = Error> + 'a>
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 futures; extern crate hyper; extern crate hyper_tls; extern crate tokio_core; use darksky::{DarkskyHyperRequester, Block}; use futures::Future; use hyper::client::{Client, HttpConnector}; use hyper_tls::HttpsConnector; use std::env; use tokio_core::reactor::Core; let core = Core::new()?; let handle = core.handle(); let client = Client::configure() .connector(HttpsConnector::new(4, &handle)?) .build(&handle); 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()); // We're waiting in this example, but you shouldn't in your code. match req.wait() { Ok(forecast) => println!("{:?}", forecast), Err(why) => println!("Error getting forecast: {:?}", why), }
Implementations on Foreign Types
impl DarkskyHyperRequester for Client<HttpsConnector<HttpConnector>, Body>
[src]
fn get_forecast<'a>(
&'a self,
token: &'a str,
latitude: f64,
longitude: f64
) -> Box<Future<Item = Forecast, Error = Error> + 'a>
[src]
&'a self,
token: &'a str,
latitude: f64,
longitude: f64
) -> Box<Future<Item = Forecast, Error = Error> + 'a>
fn get_forecast_with_options<'a, F: FnOnce(Options) -> Options>(
&'a self,
token: &'a str,
latitude: f64,
longitude: f64,
options: F
) -> Box<Future<Item = Forecast, Error = Error> + 'a>
[src]
&'a self,
token: &'a str,
latitude: f64,
longitude: f64,
options: F
) -> Box<Future<Item = Forecast, Error = Error> + 'a>