class OpenWeatherApi::Location
Attributes
app_id[R]
city[R]
city_id[R]
lat[R]
lng[R]
Public Class Methods
new(args)
click to toggle source
# File lib/open_weather_api/location.rb, line 11 def initialize(args) @city = args[:city] @city_id = args[:city_id] @lat = args[:lat] @lng = args[:lng] @app_id = OpenWeatherApi.configuration.app_id end
Public Instance Methods
current()
click to toggle source
# File lib/open_weather_api/location.rb, line 30 def current current = make_request("/weather?#{location_query}") OpenWeatherApi::Current.new(current) end
forecast(options={})
click to toggle source
# File lib/open_weather_api/location.rb, line 19 def forecast(options={}) defaults = { daily: false, units: 'imperial', count: 16 } options = defaults.merge(options) forecast = get_forecast(options) OpenWeatherApi::Forecast.new(forecast) end
Private Instance Methods
add_app_id(url)
click to toggle source
# File lib/open_weather_api/location.rb, line 59 def add_app_id(url) return url unless app_id url + "&APPID=#{app_id}" end
daily_forecast(options)
click to toggle source
# File lib/open_weather_api/location.rb, line 41 def daily_forecast(options) make_request("/forecast/daily?#{location_query}&cnt=#{options[:count]}&units=#{options[:units]}") end
get_forecast(options)
click to toggle source
# File lib/open_weather_api/location.rb, line 37 def get_forecast(options) options[:daily] ? daily_forecast(options) : three_hour_forecast(options) end
location_query()
click to toggle source
# File lib/open_weather_api/location.rb, line 49 def location_query return "id=#{city_id}" if city_id return "q=#{city}" if city return "lat=#{lat}&lon=#{lng}" if lat && lng end
make_request(url)
click to toggle source
# File lib/open_weather_api/location.rb, line 55 def make_request(url) self.class.get(add_app_id(url)) end
three_hour_forecast(options)
click to toggle source
# File lib/open_weather_api/location.rb, line 45 def three_hour_forecast(options) make_request("/forecast?#{location_query}&units=#{options[:units]}") end