NOAA.Observations.State (NOAA Observations v0.4.75)

View Source

Fetches the stations of a US state/territory.

Summary

Types

US state/territory code

State error

State error code

Functions

Fetches the stations for a state_code.

Types

code()

@type code() :: <<_::16>>

US state/territory code

error()

@type error() :: map()

State error

error_code()

@type error_code() :: pos_integer() | atom()

State error code

Functions

stations(state_code)

@spec stations(code()) ::
  {:ok, [NOAA.Observations.Station.t()]} | {:error, error_code(), String.t()}

Fetches the stations for a state_code.

Returns a tuple of either {:ok, [station]} or {:error, error_code, text}.

Parameters

  • state_code - US state/territory code

Examples

iex> alias NOAA.Observations.{State, TemplatesAgent}
iex> :ok = TemplatesAgent.reset()
iex> {:ok, stations} = State.stations("VT")
iex> %{"KFSO" => name} = Map.new(stations)
iex> name
"Franklin County State Airport"

iex> alias NOAA.Observations.{State, TemplatesAgent}
iex> template =
...>   "http://forecast.weather.gov/xml/current_obs" <>
...>     "/seek.php?state=<%=state_code%>&Find=Find"
iex> :ok = TemplatesAgent.update_state_template(template)
iex> State.stations("VT")
{:error, 301, "Moved Permanently"}

iex> alias NOAA.Observations.{State, TemplatesAgent}
iex> template =
...>   "htp://forecast.weather.gov/xml/current_obs" <>
...>     "/seek.php?state=<%=state_code%>&Find=Find"
iex> :ok = TemplatesAgent.update_state_template(template)
iex> State.stations("VT")
{:error, :nxdomain, "Non-Existent Domain"}