View Source NOAA.Observations.TemplatesAgent (NOAA Observations v0.4.58)

An agent process loading state and station URL templates from a config file.

Summary

Types

URL template

URL

Functions

Returns a specification to start this module under a supervisor.

Refreshes the agent state from a config file.

Spawns an agent process that loads URL templates from a config file.

Returns a state URL based on binding and the state of the templates agent.

Returns a station URL based on binding and the state of the templates agent.

Updates the state URL template in the templates agent.

Updates the station URL template in the templates agent.

Types

template()

@type template() :: String.t()

URL template

url()

@type url() :: String.t()

URL

Functions

child_spec(arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

refresh()

@spec refresh() :: :ok

Refreshes the agent state from a config file.

start_link(arg)

@spec start_link(term()) :: Agent.on_start()

Spawns an agent process that loads URL templates from a config file.

Examples

iex> alias NOAA.Observations.TemplatesAgent
iex> {:error, {:already_started, agent}} = TemplatesAgent.start_link(:ok)
iex> is_pid(agent) and agent == Process.whereis(TemplatesAgent)
true

state_url(binding)

@spec state_url(keyword()) :: url()

Returns a state URL based on binding and the state of the templates agent.

Examples

iex> alias NOAA.Observations.TemplatesAgent
iex> TemplatesAgent.refresh()
iex> TemplatesAgent.state_url(state_code: "VT")
"https://forecast.weather.gov/xml/current_obs/seek.php?state=VT&Find=Find"

iex> alias NOAA.Observations.TemplatesAgent
iex> template = "http://noaa.gov/seek.php?state=<%=state_abbr%>&Find=Find"
iex> TemplatesAgent.update_state_template(template)
iex> TemplatesAgent.state_url(state_abbr: "NY")
"http://noaa.gov/seek.php?state=NY&Find=Find"

station_url(binding)

@spec station_url(keyword()) :: url()

Returns a station URL based on binding and the state of the templates agent.

Examples

iex> alias NOAA.Observations.TemplatesAgent
iex> TemplatesAgent.refresh()
iex> TemplatesAgent.station_url(station_id: "KFSO")
"https://forecast.weather.gov/xml/current_obs/display.php?stid=KFSO"

iex> alias NOAA.Observations.TemplatesAgent
iex> template = "http://noaa.gov/display.php?stid=<%=stn_id%>"
iex> TemplatesAgent.update_station_template(template)
iex> TemplatesAgent.station_url(stn_id: "KBTV")
"http://noaa.gov/display.php?stid=KBTV"

update_state_template(template)

@spec update_state_template(template()) :: :ok

Updates the state URL template in the templates agent.

Examples

iex> alias NOAA.Observations.TemplatesAgent
iex> template = "http://noaa.gov/seek.php?state=<%=state_code%>&Find=Find"
iex> TemplatesAgent.update_state_template(template)
iex> Agent.get(TemplatesAgent, & &1.state) == template
true

update_station_template(template)

@spec update_station_template(template()) :: :ok

Updates the station URL template in the templates agent.

Examples

iex> alias NOAA.Observations.TemplatesAgent
iex> template = "http://noaa.gov/display.php?stid=<%=station_id%>"
iex> TemplatesAgent.update_station_template(template)
iex> Agent.get(TemplatesAgent, & &1.station) == template
true