require 'json' require 'net/http' require 'uri' module UndergroundWeather class ApiCall attr_reader :response, :error BASE_URL = 'http://api.wunderground.com/api' def initialize(api_key, feature, query) @api_key = api_key @feature = feature @query = query @error = false @response = JSON.parse(get) @error = true if @response['error'] end def url URI.parse("#{BASE_URL}/#{@api_key}/#{@feature}/q/#{@query}.json") end def get puts "Calling #{url}" resp = Net::HTTP.get_response(url) if resp.code == "200" resp.body else puts "error retrieving weather feed" @error = true {} end end end end