Trait darksky::bridge::hyper::DarkskyHyperRequester [] [src]

pub trait DarkskyHyperRequester {
    fn get_forecast<'a, 'b, T: AsRef<str>>(
        &'a self,
        token: T,
        latitude: f64,
        longitude: f64
    ) -> Box<Future<Item = Forecast, Error = Error> + 'b>;
fn get_forecast_with_options<'a, 'b, F, T>(
        &'a self,
        token: T,
        latitude: f64,
        longitude: f64,
        options: F
    ) -> Box<Future<Item = Forecast, Error = Error> + 'b>
    where
        F: FnOnce(Options) -> Options,
        T: AsRef<str>
;
fn get_forecast_time_machine<D, F, T>(
        &self,
        token: T,
        latitude: f64,
        longitude: f64,
        time: D,
        options: F
    ) -> Box<Future<Item = Forecast, Error = Error>>
    where
        D: Display,
        F: FnOnce(Options) -> Options,
        T: AsRef<str>
; }

The trait for hyper implementations to different DarkSky routes.

Required Methods

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),
}

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),
}

Sets the time to request a forecast for by using DarkSky's Time Machine API.

This accepts either a Unix timestamp or a string in the format of [YYYY]-[MM]-[DD]T[HH]:[MM]:[SS][timezone, where timezone should either be:

  • omitted (referring to the local time for the location being requested);
  • Z referring to GMT time;
  • or -[HH][MM] for an offset from GMT in hours and minutes.

The timezone is only used for determining the time of the request. The response will always be relative to the local time zone.

Refer to DarkSky's documentation on Time Machine Request Parametersfor information.

This function accepts anything that implements the Display trait, so you should validate data beforehand. This is to avoid implementing a time validation scheme, while avoiding locking the parameter type to that of a time library (e.g. Chrono).

Implementations on Foreign Types

impl<B, C: Connect> DarkskyHyperRequester for Client<C, B> where
    B: Stream<Error = HyperError> + 'static,
    B::Item: AsRef<[u8]>, 
[src]

[src]

[src]

[src]

Implementors