View Source NOAA.Observations.State (NOAA Observations v0.4.58)
Fetches the stations for a US state/territory code.
Summary
Functions
Fetches the stations for a state_code
.
Types
@type code() :: <<_::16>>
US state/territory code
@type error() :: map()
Erroneous state
Functions
@spec stations(code()) :: {:ok, [NOAA.Observations.Station.t()]} | {:error, any(), 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.refresh()
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> TemplatesAgent.update_state_template(template)
iex> State.stations("VT")
{:error, 301, "Moved Permanently"}
iex> alias NOAA.Observations.{State, TemplatesAgent}
iex> template =
...> "https://www.weather.gov/xml/current_obs" <>
...> "/seek.php?state=<%=state_code%>&Find=Find"
iex> TemplatesAgent.update_state_template(template)
iex> State.stations("VT")
{:error, 302, "Found (Moved Temporarily)"}
iex> alias NOAA.Observations.{State, TemplatesAgent}
iex> template =
...> "https://forecast.weather.gov/xml/past_obs" <>
...> "/seek.php?state=<%=state_code%>&Find=Find"
iex> TemplatesAgent.update_state_template(template)
iex> State.stations("VT")
{:error, 404, "Not Found"}
iex> alias NOAA.Observations.{State, TemplatesAgent}
iex> template =
...> "htp://forecast.weather.gov/xml/current_obs" <>
...> "/seek.php?state=<%=state_code%>&Find=Find"
iex> TemplatesAgent.update_state_template(template)
iex> State.stations("VT")
{:error, :nxdomain, "Non-Existent Domain"}
iex> alias NOAA.Observations.{State, TemplatesAgent}
iex> template = "http://localhost:65535"
iex> TemplatesAgent.update_state_template(template)
iex> State.stations("VT")
{:error, :econnrefused, "Connection Refused By Server"}
iex> alias NOAA.Observations.{State, TemplatesAgent}
iex> template = "http://localhost:65536"
iex> TemplatesAgent.update_state_template(template)
iex> State.stations("VT")
{:error, :checkout_failure, "Checkout Failure"}