lib/open-weather-api/resources/base.rb in open-weather-api-0.0.3 vs lib/open-weather-api/resources/base.rb in open-weather-api-0.0.4
- old
+ new
@@ -10,22 +10,24 @@
def execute(**hash, &block)
@parameters = hash
setup_indifferent_access(@parameters)
- response = request
+ # Let's use json
+ execute_json **hash, &block
+ end
+
+ private
+
+ def execute_json(**hash, &block)
+ response = RestClient.send :get, base_url, params: build_params(@parameters), accept: :json
raise "Invalid response." unless response.code == 200
json = JSON.parse(response.body)
+ setup_indifferent_access(json)
return block.call(json) if block_given?
json
- end
-
- private
-
- def request(type = :get)
- RestClient.send type, base_url, params: build_params(@parameters), accept: :json
end
def base_url
'http://api.openweathermap.org/data/2.5/'
end
\ No newline at end of file