NOAA.Observations.Station (NOAA Observations v0.4.75)
View SourceFetches the latest observation of a given NOAA station.
Summary
Functions
Fetches the latest observation of a given NOAA station.
Types
Functions
@spec observation(t(), NOAA.Observations.State.code()) :: {:ok, observation()} | {:error, error()}
Fetches the latest observation of a given NOAA station.
Returns either tuple {:ok, observation} or tuple {:error, error}.
Parameters
{station_id, station_name}- NOAA stationstate_code- US state/territory code
Examples
iex> alias NOAA.Observations.{Station, TemplatesAgent}
iex> :ok = TemplatesAgent.reset()
iex> {:ok, observation} =
...> Station.observation({"KFSO", "KFSO name"}, "VT")
iex> is_map(observation) and is_binary(observation["wind_mph"])
true
iex> alias NOAA.Observations.{Station, TemplatesAgent}
iex> template =
...> "htp://forecast.weather.gov/xml/current_obs" <>
...> "/display.php?stid=<%=station_id%>"
iex> :ok = TemplatesAgent.update_station_template(template)
iex> {:error, %{station_id: id, error_code: code, error_text: text}} =
...> Station.observation({"KFSO", "KFSO name"}, "VT")
iex> {id, code, text}
{"KFSO", :nxdomain, "Non-Existent Domain"}
iex> alias NOAA.Observations.{Station, TemplatesAgent}
iex> template =
...> "https://forecast.weather.gov/xml/past_obs" <>
...> "/display.php?stid=<%=station_id%>"
iex> :ok = TemplatesAgent.update_station_template(template)
iex> {:error, %{station_id: id, error_code: code, error_text: text}} =
...> Station.observation({"KFSO", "KFSO name"}, "VT")
iex> {id, code, text}
{"KFSO", 404, "Not Found"}