lib/undergroundweather/api_call.rb in undergroundweather-0.0.2 vs lib/undergroundweather/api_call.rb in undergroundweather-0.0.3
- old
+ new
@@ -11,27 +11,34 @@
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 get!
+ get
+ end
+
+ def response
+ @response ||= JSON.parse(get)
+ end
+
def url
URI.parse("#{BASE_URL}/#{@api_key}/#{@feature}/q/#{@query}.json")
end
+ private
+
def get
resp = Net::HTTP.get_response(url)
if resp.code == "200"
resp.body
else
@error = true
- # raise exception here
+ # raise exception here?
{}
end
end
end
end
\ No newline at end of file