lib/gotransverse-tract-api.rb in gotransverse-tract-api-0.0.6 vs lib/gotransverse-tract-api.rb in gotransverse-tract-api-0.0.7
- old
+ new
@@ -101,13 +101,13 @@
#
# self.get_response_for
#
# @param {Class} klass
- # @param {Hash} api_params
+ # @param {Hash} api_params (optional)
#
- def self.get_response_for(klass, api_params)
+ def self.get_response_for(klass, api_params={})
api_url = GoTransverseTractApi.get_api_url_for(klass)
if GoTransverseTractApi.configuration.cache_enabled
return self.get_cached_response_from(klass, api_params)
@@ -119,24 +119,24 @@
#
# self.post_request_for
#
# @param {Class} klass
- # @param {Hash} api_params
+ # @param {Hash} api_params (optional)
#
- def self.post_request_for(klass, api_params)
+ def self.post_request_for(klass, api_params={})
api_url = GoTransverseTractApi.get_api_url_for(klass)
self.call(api_url, api_params, :post)
end
#
# self.put_request_for
#
# @param {Class} klass
- # @param {Hash} api_params
+ # @param {Hash} api_params (optional)
#
- def self.put_request_for(klass, api_params)
+ def self.put_request_for(klass, api_params={})
api_url = GoTransverseTractApi.get_api_url_for(klass)
self.call(api_url, api_params, :put)
end
private
@@ -150,13 +150,13 @@
#
# self.get_cached_response_for
#
# @param {Class} klass
- # @param {Hash} api_params
+ # @param {Hash} api_params (optional)
#
- def self.get_cached_response_for(klass, api_params)
+ def self.get_cached_response_for(klass, api_params={})
key = "#{klass.classname}.#{api_params.sort}"
return Rails.cache.fetch(key, expires_in: 10.minutes) do
self.get_response_from(klass, api_params)
end
@@ -166,15 +166,17 @@
#
# self.call
#
# @param {String} api_url
- # @param {Hash} api_params
+ # @param {Hash} api_params (optional)
# @param {String} method (optional)
#
- def self.call(api_url, api_params, method=:get)
+ def self.call(api_url, api_params={}, method=:get)
headers = self.get_authentication_headers
+
+ # TODO: Recursively camelize all keys in api_params Hash.
http_client = HTTPClient.new
case method
when :get
response = http_client.get(api_url, api_params, headers)