Crate forecast [] [src]

This module exposes an SDK for interacting with the Dark Sky API.

Overview

The ApiClient is the main entrypoint. It exposes two methods for sending HTTP requests to the Dark Sky API:

  1. ApiClient::get_forecast(request: ForecastRequest) makes an HTTP request against the API and returns a deserialized response containing a weather forecast given the current weather conditions.

  2. ApiClient::get_time_machine(request: TimeMachineRequest) makes a request against the API and returns a deserialized response containing weather data corresponding to the time parameter in the TimeMachineRequest.

For your convenience, there are two builder objects ForecastRequestBuilder and TimeMachineRequestBuilder which you can use to construct ForecastRequest and TimeMachineRequest instances.

Examples

The following example builds a ForecastRequest and a TimeMachineRequest and executes them against the API:

extern crate reqwest;
extern crate forecast;

use reqwest::Client;

use forecast::{ApiResponse, ApiClient, ForecastRequestBuilder,
               TimeMachineRequestBuilder, ExcludeBlock, ExtendBy,
               Lang, Units};

const LAT: f64 = 6.66;
const LONG: f64 = 66.6;
const TIME: u64 = 666;

fn main() {
    let api_key = "my_dark_sky_api_key"; // please don't actually hardcode your API key!

    let reqwest_client = Client::new().unwrap();
    let api_client = ApiClient::new(&reqwest_client);

    let mut blocks = vec![ExcludeBlock::Daily, ExcludeBlock::Alerts];

    let forecast_request = ForecastRequestBuilder::new(api_key, LAT, LONG)
        .exclude_block(ExcludeBlock::Hourly)
        .exclude_blocks(&mut blocks)
        .extend(ExtendBy::Hourly)
        .lang(Lang::Arabic)
        .units(Units::Imperial)
        .build();

    let time_machine_request = TimeMachineRequestBuilder::new(api_key, LAT, LONG, TIME)
        .exclude_block(ExcludeBlock::Hourly)
        .exclude_blocks(&mut blocks)
        .lang(Lang::Arabic)
        .units(Units::Imperial)
        .build();

    // let forecast_response = api_client.get_forecast(forecast_request).unwrap();
    // let time_machine_response = api_client.get_time_machine(time_machine_request).unwrap();
}

Structs

Alert

Model object representing a severe weather warning issued by a government authority for the requested location.

ApiClient

The ApiClient is a thin wrapper around a reqwest::Client which sends requests to the Forecast and Time Machine APIs.

ApiResponse

Model object representing a Forecast or Time Machine API response.

DataBlock

Model object representing the various weather phenomena ocurring over a period of time.

DataPoint

Model object containing various properties, each representing the average (unless otherwise specified) of a particular weather phenomenon ocurring during a period of time.

Flags

Model object representing a flag which contains miscellaneous metadata about a request.

ForecastRequest

Model object representing a request to the Forecast API.

ForecastRequestBuilder

Builder object used to construct a ForecastRequest.

TimeMachineRequest

Model object representing a request to the Time Machine API.

TimeMachineRequestBuilder

Builder object used to construct a TimeMachineRequest.

Enums

ExcludeBlock

Model object representing a DataBlock to exclude from the response.

ExtendBy

When present in a request, this feature causes response data to be reported for 168 hours into the future instead of 48 hours.

Icon

Model object representing an icon for display.

Lang

Model object representing language.

PrecipType

Model object representing the kind of precipitation ocurring at a particular time.

Units

Model object representing measurement units.