Class: WeatherAPI
- Inherits:
-
Object
- Object
- WeatherAPI
- Defined in:
- lib/getweather.rb
Instance Attribute Summary collapse
-
#info ⇒ Object
Returns the value of attribute info.
-
#zip ⇒ Object
Returns the value of attribute zip.
Instance Method Summary collapse
- #apicall ⇒ Object
-
#initialize(zip) ⇒ WeatherAPI
constructor
A new instance of WeatherAPI.
- #returnhash ⇒ Object
Constructor Details
#initialize(zip) ⇒ WeatherAPI
Returns a new instance of WeatherAPI.
5 6 7 8 9 10 |
# File 'lib/getweather.rb', line 5 def initialize(zip) @zip = zip.to_i @url = "http://api.openweathermap.org/data/2.5/weather?zip=#{@zip},us&units=imperial&APPID=#{WEATHER_KEY}" @info = {} apicall end |
Instance Attribute Details
#info ⇒ Object
Returns the value of attribute info.
4 5 6 |
# File 'lib/getweather.rb', line 4 def info @info end |
#zip ⇒ Object
Returns the value of attribute zip.
4 5 6 |
# File 'lib/getweather.rb', line 4 def zip @zip end |
Instance Method Details
#apicall ⇒ Object
12 13 14 15 16 17 |
# File 'lib/getweather.rb', line 12 def apicall openweather_json = RestClient.get(@url) @parsed = JSON.parse(openweather_json) rescue "bad link" end |
#returnhash ⇒ Object
19 20 21 22 23 24 |
# File 'lib/getweather.rb', line 19 def returnhash @info[:city] = @parsed["name"] @info[:id] = @parsed["weather"][0]["id"] @info[:temp] = @parsed["main"]["temp"] @info end |