class WeatherAPI
Attributes
info[RW]
zip[RW]
Public Class Methods
new(zip)
click to toggle source
# 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
Public Instance Methods
apicall()
click to toggle source
# File lib/getweather.rb, line 12 def apicall openweather_json = RestClient.get(@url) @parsed = JSON.parse(openweather_json) rescue "bad link" end
returnhash()
click to toggle source
# 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