Class: Cowa::OpenWeatherMap
- Inherits:
-
Object
- Object
- Cowa::OpenWeatherMap
- Defined in:
- lib/cowa/open_weatherMap.rb
Instance Attribute Summary collapse
-
#api_key ⇒ Object
Returns the value of attribute api_key.
Instance Method Summary collapse
- #client(url) ⇒ Object
- #get_icon(icon) ⇒ Object
- #get_information_latlon(lat, lon) ⇒ Object
- #get_information_place(location) ⇒ Object
-
#initialize(api_key) ⇒ OpenWeatherMap
constructor
A new instance of OpenWeatherMap.
Constructor Details
#initialize(api_key) ⇒ OpenWeatherMap
8 9 10 |
# File 'lib/cowa/open_weatherMap.rb', line 8 def initialize(api_key) @api_key = api_key end |
Instance Attribute Details
#api_key ⇒ Object
Returns the value of attribute api_key.
6 7 8 |
# File 'lib/cowa/open_weatherMap.rb', line 6 def api_key @api_key end |
Instance Method Details
#client(url) ⇒ Object
12 13 14 |
# File 'lib/cowa/open_weatherMap.rb', line 12 def client url return open(URI.encode(url)).read end |
#get_icon(icon) ⇒ Object
16 17 18 |
# File 'lib/cowa/open_weatherMap.rb', line 16 def get_icon icon return open("http://openweathermap.org/img/w/#{icon}.png") end |
#get_information_latlon(lat, lon) ⇒ Object
25 26 27 28 |
# File 'lib/cowa/open_weatherMap.rb', line 25 def get_information_latlon lat, lon req_url = "http://api.openweathermap.org/data/2.5/weather?lat=#{lat}&lon=#{lon}&APPID=#{@api_key}" return JSON.parse(client(req_url), symbolize_names: true) end |
#get_information_place(location) ⇒ Object
20 21 22 23 |
# File 'lib/cowa/open_weatherMap.rb', line 20 def get_information_place location req_url = "http://api.openweathermap.org/data/2.5/weather?q=#{location}&APPID=#{@api_key}" return JSON.parse(client(req_url), symbolize_names: true) end |