[−][src]Crate forecast
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:
-
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. -
ApiClient::get_time_machine(request: TimeMachineRequest)
makes a request against the API and returns a deserialized response containing weather data corresponding to thetime
parameter in theTimeMachineRequest
.
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:
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(); 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).await.unwrap(); // let time_machine_response = api_client.get_time_machine(time_machine_request).await.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 |
ApiResponse | Model object representing a Forecast or Time Machine API response. |
DataBlock | Model object representing the various weather phenomena occurring over a period of time. |
DataPoint | Model object containing various properties, each representing the average (unless otherwise specified) of a particular weather phenomenon occurring 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 occurring at a particular time. |
Severity | Model object representing an Alert's severity. |
Units | Model object representing measurement units. |