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['response']['error'] end def url URI.parse("#{BASE_URL}/#{@api_key}/#{@feature}/q/#{@query}.json") end def get resp = Net::HTTP.get_response(url) if resp.code == "200" resp.body else @error = true # raise exception here {} end end end end