sunny/api/forecast
The module for interactiong with the Forecast API.
Types
pub type CellSelection {
Land
Sea
Nearest
}
Constructors
-
Land
-
Sea
-
Nearest
The different parameters available on the Forecast API.
See https://open-meteo.com/en/docs for further reference.
pub type ForecastParams {
ForecastParams(
position: position.Position,
hourly: List(instant.InstantVariable),
daily: List(daily.DailyVariable),
minutely: List(instant.InstantVariable),
current: List(instant.InstantVariable),
temperature_unit: TemperatureUnit,
wind_speed_unit: WindSpeedUnit,
precipitation_unit: PrecipitationUnit,
timezone: String,
past_days: Int,
forecast_days: Int,
forecast_hours: option.Option(Int),
forecast_minutely_15: option.Option(Int),
past_hours: option.Option(Int),
past_minutely_15: option.Option(Int),
start_date: option.Option(birl.Time),
end_date: option.Option(birl.Time),
start_hour: option.Option(birl.Time),
end_hour: option.Option(birl.Time),
start_minutely_15: option.Option(birl.Time),
end_minutely_15: option.Option(birl.Time),
cell_selection: CellSelection,
)
}
Constructors
-
ForecastParams( position: position.Position, hourly: List(instant.InstantVariable), daily: List(daily.DailyVariable), minutely: List(instant.InstantVariable), current: List(instant.InstantVariable), temperature_unit: TemperatureUnit, wind_speed_unit: WindSpeedUnit, precipitation_unit: PrecipitationUnit, timezone: String, past_days: Int, forecast_days: Int, forecast_hours: option.Option(Int), forecast_minutely_15: option.Option(Int), past_hours: option.Option(Int), past_minutely_15: option.Option(Int), start_date: option.Option(birl.Time), end_date: option.Option(birl.Time), start_hour: option.Option(birl.Time), end_hour: option.Option(birl.Time), start_minutely_15: option.Option(birl.Time), end_minutely_15: option.Option(birl.Time), cell_selection: CellSelection, )
Arguments
-
minutely
Get data every 15 minutes. Some data can’t be optained every 15 minutes, so it will be interpolated over the hour (or more if needed)
-
timezone
Full list here : https://en.wikipedia.org/wiki/List_of_tz_database_time_zones#List
You can set
timezone
toauto
, and the API will deduce the local timezone from the coordinates.For abbreviations, in my experience only three letter ones work (e.g.
CEST
returns an error). -
past_days
Will be clamped between 0 and 92.
-
forecast_days
Will be clamped between 0 and 16.
-
forecast_hours
If
forecast_hours
is negative or null, it will be set tooption.None
. -
forecast_minutely_15
If
forecast_minutely_15
is negative or null, it will be set tooption.None
. -
past_hours
If
past_hours
is negative or null, it will be set tooption.None
. -
past_minutely_15
If
past_minutely_15
is negative or null, it will be set tooption.None
.
-
The result of a request to the Forecast API.
pub type ForecastResult {
ForecastResult(
position: position.Position,
elevation: Float,
utc_offset_seconds: Int,
timezone: String,
timezone_abbreviation: String,
hourly: data.TimeRangedData(instant.InstantVariable),
daily: data.TimeRangedData(daily.DailyVariable),
minutely: data.TimeRangedData(instant.InstantVariable),
current: option.Option(
data.CurrentData(instant.InstantVariable),
),
)
}
Constructors
-
ForecastResult( position: position.Position, elevation: Float, utc_offset_seconds: Int, timezone: String, timezone_abbreviation: String, hourly: data.TimeRangedData(instant.InstantVariable), daily: data.TimeRangedData(daily.DailyVariable), minutely: data.TimeRangedData(instant.InstantVariable), current: option.Option( data.CurrentData(instant.InstantVariable), ), )
pub type PrecipitationUnit {
Millimeters
Inches
}
Constructors
-
Millimeters
-
Inches
pub type TemperatureUnit {
Celsius
Fahrenheit
}
Constructors
-
Celsius
-
Fahrenheit
pub type WindSpeedUnit {
KilometersPerHour
MetersPerSecond
MilesPerHour
Knots
}
Constructors
-
KilometersPerHour
-
MetersPerSecond
-
MilesPerHour
-
Knots
Functions
pub fn get_request(
client: Client,
params: ForecastParams,
) -> Request(String)
Get a request.Request(String)
according to the specified ForecastParams
.
Once you made a request using your favorite HTTP client, pass the String
body to get_result
.
pub fn get_result(
response_body: String,
) -> Result(ForecastResult, SunnyError)
Get a ForecastResult
from the body of a HTTP request response.
You can get a request to the Forecast API by using get_request
.
pub fn params(position: Position) -> ForecastParams
Creates a new ForecastParams with the default values. Takes the Position
of the place you to get the forecast (see the sunny/position
module).
Defaults :
- temperature_unit : Celsius
- wind_speed_unit : Kilometers per hour
- precipitation_unit : Millimeters
- timezone : GMT
- past_days : 0
- forecast_days : 7
- cell_selection : Land
These are the same defaults as the Open-Meteo API’s ones. Other parameters
are set to
option.None
or to an emptyList
.
pub fn set_all_current(
params: ForecastParams,
except: List(InstantVariable),
) -> ForecastParams
Returns a new ForecastParams
with all the current variables except the
ones in the except
argument.
pub fn set_all_daily(
params: ForecastParams,
except: List(DailyVariable),
) -> ForecastParams
Returns a new ForecastParams
with all the daily variables except the
ones in the except
argument
pub fn set_all_hourly(
params: ForecastParams,
except: List(InstantVariable),
) -> ForecastParams
Returns a new ForecastParams
with all the hourly variables except the
ones in the except
argument.
pub fn set_all_minutely(
params: ForecastParams,
except: List(InstantVariable),
) -> ForecastParams
Returns a new ForecastParams
with all the minutely variables except the
ones in the except
argument.
pub fn set_cell_selection(
params: ForecastParams,
cell_selection: CellSelection,
) -> ForecastParams
Returns a new ForecastParams with the specified cell selection.
pub fn set_current(
params: ForecastParams,
current_list: List(InstantVariable),
) -> ForecastParams
Returns a new ForecastParams with the specified hourly list
pub fn set_daily(
params: ForecastParams,
daily_list: List(DailyVariable),
) -> ForecastParams
Returns a new ForecastParams with the specified daily list
pub fn set_end_date(
params: ForecastParams,
end_date: Time,
) -> ForecastParams
Returns a new ForecastParams with the specified end date.
pub fn set_end_hour(
params: ForecastParams,
end_hour: Time,
) -> ForecastParams
Returns a new ForecastParams with the specified end hour.
pub fn set_end_minutely_15(
params: ForecastParams,
end_minutely_15: Time,
) -> ForecastParams
Returns a new ForecastParams with the specified end minutely 15.
pub fn set_forecast_days(
params: ForecastParams,
forecast_days: Int,
) -> ForecastParams
Returns a new ForecastParams with the specified forecast days.
forecast_days
will be clamped between 0 and 16.
pub fn set_forecast_hours(
params: ForecastParams,
forecast_hours: Int,
) -> ForecastParams
Returns a new ForecastParams with the specified forecast hours.
If forecast_hours
is negative or null, it will be set to option.None
.
pub fn set_forecast_minutely_15(
params: ForecastParams,
forecast_minutely_15: Int,
) -> ForecastParams
Returns a new ForecastParams with the specified forecast minutely 15.
If forecast_minutely_15
is negative or null, it will be set to option.None
.
pub fn set_hourly(
params: ForecastParams,
hourly_list: List(InstantVariable),
) -> ForecastParams
Returns a new ForecastParams with the specified hourly list.
pub fn set_minutely(
params: ForecastParams,
minutely_list: List(InstantVariable),
) -> ForecastParams
Returns a new ForecastParams with the specified 15-minutely list
pub fn set_past_days(
params: ForecastParams,
past_days: Int,
) -> ForecastParams
Returns a new ForecastParams with the specified past days.
past_days
will be clamped between 0 and 92.
pub fn set_past_hours(
params: ForecastParams,
past_hours: Int,
) -> ForecastParams
Returns a new ForecastParams with the specified past hours.
If past_hours
is negative or null, it will be set to option.None
.
pub fn set_past_minutely_15(
params: ForecastParams,
past_minutely_15: Int,
) -> ForecastParams
Returns a new ForecastParams with the specified past minutely 15.
If past_minutely_15
is negative or null, it will be set to option.None
.
pub fn set_precipitation_unit(
params: ForecastParams,
unit: PrecipitationUnit,
) -> ForecastParams
Returns a new ForecastParams with the specified temperature unit.
pub fn set_start_date(
params: ForecastParams,
start_date: Time,
) -> ForecastParams
Returns a new ForecastParams with the specified start date.
pub fn set_start_hour(
params: ForecastParams,
start_hour: Time,
) -> ForecastParams
Returns a new ForecastParams with the specified start hour.
pub fn set_start_minutely_15(
params: ForecastParams,
start_minutely_15: Time,
) -> ForecastParams
Returns a new ForecastParams with the specified start minutely 15.
pub fn set_temperature_unit(
params: ForecastParams,
unit: TemperatureUnit,
) -> ForecastParams
Returns a new ForecastParams with the specified temperature unit.
pub fn set_timezone(
params: ForecastParams,
timezone: String,
) -> ForecastParams
Returns a new ForecastParams with the specified timezone.
pub fn set_wind_speed_unit(
params: ForecastParams,
unit: WindSpeedUnit,
) -> ForecastParams
Returns a new ForecastParams with the specified temperature unit.