Class: NoaaWeatherClient::Client
- Inherits:
-
Object
- Object
- NoaaWeatherClient::Client
- Defined in:
- lib/noaa_weather_client/client.rb
Overview
Provides entry point for interacting with the noaa api via multiple services.
Instance Method Summary collapse
-
#current_observations(lat, lon, options = {}) ⇒ Responses::CurrentObservation
Retrieves the current weather observations for a location.
-
#forecast_by_day(lat, lon, options = {}) ⇒ Responses::Forecast
Fetches a daily forecast for a location from today.
-
#nearest_weather_station(lat, lon, options = {}) ⇒ Responses::Station
Retrieves the weather station nearest to the location.
-
#postal_code_to_coordinate(postal_code, options = {}) ⇒ Responses::LatLonList
Converts a zip code to a latitude and longitude.
-
#weather_stations(options = {}) ⇒ Responses::Stations
Retrieves a list of weather stations from noaa.
Instance Method Details
#current_observations(lat, lon, options = {}) ⇒ Responses::CurrentObservation
It is important to cache a copy of the available stations for use here, as the xml stations response is quite large noaa does not appreciate repeated calls.
Retrieves the current weather observations for a location.
36 37 38 39 |
# File 'lib/noaa_weather_client/client.rb', line 36 def current_observations(lat, lon, = {}) station = .fetch(:station) { nearest_weather_station(lat, lon, ) } Services::CurrentObservations.new().fetch(station) end |
#forecast_by_day(lat, lon, options = {}) ⇒ Responses::Forecast
Fetches a daily forecast for a location from today. Default is 7 days. The forecast for the current day ceases to be returned after 6:00pm at the observation area.
16 17 18 |
# File 'lib/noaa_weather_client/client.rb', line 16 def forecast_by_day(lat, lon, = {}) Services::ForecastByDay.new.fetch(lat, lon, ) end |
#nearest_weather_station(lat, lon, options = {}) ⇒ Responses::Station
It is important to cache a copy of the available stations for use here, as the xml stations response is quite large noaa does not appreciate repeated calls.
Retrieves the weather station nearest to the location.
48 49 50 51 |
# File 'lib/noaa_weather_client/client.rb', line 48 def nearest_weather_station(lat, lon, = {}) stations = .fetch(:stations) { weather_stations } Services::FindNearestStation.find(lat, lon, stations) end |
#postal_code_to_coordinate(postal_code, options = {}) ⇒ Responses::LatLonList
Converts a zip code to a latitude and longitude.
57 58 59 |
# File 'lib/noaa_weather_client/client.rb', line 57 def postal_code_to_coordinate(postal_code, = {}) Services::PostalCodeToCoordinate.new().resolve(postal_code) end |
#weather_stations(options = {}) ⇒ Responses::Stations
Retrieves a list of weather stations from noaa.
22 23 24 25 26 27 |
# File 'lib/noaa_weather_client/client.rb', line 22 def weather_stations( = {}) if .delete(:reload) { false } || @weather_stations.nil? @weather_stations = Services::WeatherStations.new().fetch end @weather_stations end |