NOAA.Observations.TemplatesAgent (NOAA Observations v0.4.75)
View SourceAn agent process loading the state and station URL templates.
Summary
Functions
Returns a specification to start this module under a supervisor.
Resets the agent state.
Spawns an agent process that loads the state and station URL templates.
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
Functions
Returns a specification to start this module under a supervisor.
See Supervisor.
@spec reset() :: :ok
Resets the agent state.
@spec start_link(term()) :: Agent.on_start()
Spawns an agent process that loads the state and station URL templates.
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
Returns a state URL based on binding and the state of the templates agent.
Examples
iex> alias NOAA.Observations.TemplatesAgent
iex> :ok = TemplatesAgent.reset()
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> :ok = TemplatesAgent.update_state_template(template)
iex> TemplatesAgent.state_url(state_abbr: "NY")
"http://noaa.gov/seek.php?state=NY&Find=Find"
Returns a station URL based on binding and the state of the templates agent.
Examples
iex> alias NOAA.Observations.TemplatesAgent
iex> :ok = TemplatesAgent.reset()
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> :ok = TemplatesAgent.update_station_template(template)
iex> TemplatesAgent.station_url(stn_id: "KBTV")
"http://noaa.gov/display.php?stid=KBTV"
@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> :ok = TemplatesAgent.update_state_template(template)
iex> Agent.get(TemplatesAgent, & &1.state) == template
true
@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> :ok = TemplatesAgent.update_station_template(template)
iex> Agent.get(TemplatesAgent, & &1.station) == template
true