NOAA Observations v0.1.8 NOAA.Observations

Fetches a list of weather observations from a US state/territory.

Summary

Functions

Fetches weather observations from a US state/territory

Fetches the latest observation for a given NOAA station ID

Fetches a list of station IDs for a US state/territory

Returns a URL based on the given station ID or state code

Types

observation()
observation() :: map
station_id()
station_id() :: String.t

Functions

fetch(state, options \\ [])
fetch(String.t, Keyword.t) ::
  {:ok, [observation]} |
  {:error, String.t}

Fetches weather observations from a US state/territory.

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

Parameters

  • state - US state/territory code
  • options - URL templates (keyword)

Options

  • :url_templates - defaults to config value :url_templates (map)

Examples

alias NOAA.Observations
Observations.fetch("vt")
observation(station, map)
observation(station_id, map) ::
  {:ok, observation} |
  {:error, String.t}

Fetches the latest observation for a given NOAA station ID.

Returns a tuple of either {:ok, observation} or {:error, text}.

Parameters

  • station - NOAA station ID (string)
  • url_templates - URL templates (map)

Examples

alias NOAA.Observations
app = Mix.Project.config[:app]
url_templates = Application.get_env(app, :url_templates)
Observations.observation("KBTV", url_templates)
stations(state, map)
stations(String.t, map) ::
  {:ok, [station_id]} |
  {:error, String.t}

Fetches a list of station IDs for a US state/territory.

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

Parameters

  • state - US state/territory code (string)
  • url_templates - URL templates (map)

Examples

alias NOAA.Observations
app = Mix.Project.config[:app]
url_templates = Application.get_env(app, :url_templates)
Observations.stations("vt", url_templates)
url(url_template, list)

Returns a URL based on the given station ID or state code.

Parameters

  • url_template - URL template
  • keyword - [station: station] or [state: state]

Examples

iex> alias NOAA.Observations
iex> app = Mix.Project.config[:app]
iex> %{station: url_template} = Application.get_env(app, :url_templates)
iex> Observations.url(url_template, station: "KBTV")
"http://w1.weather.gov/xml/current_obs/KBTV.xml"

iex> alias NOAA.Observations
iex> app = Mix.Project.config[:app]
iex> %{state: url_template} = Application.get_env(app, :url_templates)
iex> Observations.url(url_template, state: "vt")
"http://w1.weather.gov/xml/current_obs/seek.php?state=vt&Find=Find"

iex> alias NOAA.Observations
iex> url_template = "https://weather.gc.ca/forecast/canada/" <>
...>   "index_e.html?id=<st>"
iex> Observations.url(url_template, state: "qc")
"https://weather.gc.ca/forecast/canada/index_e.html?id=qc"