class OpenWeatherLite::Weather
Look up current weather conditions by available api calls
all methods return parsed json response objects
Constants
- BASE_URL
- VERSION
Attributes
api_key[RW]
units[RW]
version[RW]
Public Class Methods
new(api_key = nil)
click to toggle source
# File lib/open_weather_lite/weather.rb, line 9 def initialize(api_key = nil) @api_key = api_key @version = VERSION end
Public Instance Methods
by_city_id(city_id)
click to toggle source
# File lib/open_weather_lite/weather.rb, line 18 def by_city_id(city_id) run(id: city_id) end
by_coords(latitude, longitude)
click to toggle source
# File lib/open_weather_lite/weather.rb, line 22 def by_coords(latitude, longitude) run(lat: latitude, lon: longitude) end
by_zip_code(zip_code, country = 'us')
click to toggle source
# File lib/open_weather_lite/weather.rb, line 14 def by_zip_code(zip_code, country = 'us') run(zip: "#{zip_code},#{country}") end
Private Instance Methods
params_to_string(params)
click to toggle source
# File lib/open_weather_lite/weather.rb, line 41 def params_to_string(params) params.map { |key, value| "#{key}=#{value}" }.join('&') end
run(params)
click to toggle source
# File lib/open_weather_lite/weather.rb, line 28 def run(params) fail ArgumentError, 'Missing api key' unless @api_key params[:appid] = @api_key params[:units] = @units if @units response = RestClient::Request.execute(method: :get, url: url(params)) WeatherResponse.new(response) end
url(params)
click to toggle source
# File lib/open_weather_lite/weather.rb, line 37 def url(params) "#{BASE_URL}#{version}/weather?" + params_to_string(params) end