lib/gotransverse-tract-api.rb in gotransverse-tract-api-0.0.1 vs lib/gotransverse-tract-api.rb in gotransverse-tract-api-0.0.2
- old
+ new
@@ -100,71 +100,75 @@
#
# self.get_response_from
#
# @param {String} api_url
# @param {Hash} api_params
- # @param {Hash} headers (optional)
#
- def self.get_response_from(api_url, api_params, headers={})
+ def self.get_response_from(api_url, api_params)
if GoTransverseTractApi.configuration.cache_enabled
- return self.get_cached_response_from(api_url, api_params, headers)
+ return self.get_cached_response_from(api_url, api_params)
end
# Unless cached
- self.call(api_url, api_params, headers, :get)
+ self.call(api_url, api_params, :get)
end
#
# self.post_request_to
#
# @param {String} api_url
# @param {Hash} api_params
- # @param {Hash} headers (optional)
#
- def self.post_request_to(api_url, api_params, headers={})
- self.call(api_url, api_params, headers, :post)
+ def self.post_request_to(api_url, api_params)
+ self.call(api_url, api_params, :post)
end
#
# self.put_request_to
#
# @param {String} api_url
# @param {Hash} api_params
- # @param {Hash} headers (optional)
#
- def self.put_request_to(api_url, api_params, headers={})
- self.call(api_url, api_params, headers, :put)
+ def self.put_request_to(api_url, api_params)
+ self.call(api_url, api_params, :put)
end
private
#
+ # self.get_authentication_headers
+ #
+ def self.get_authentication_headers
+ {"basic-credentials" => GoTransverseTractApi.configuration.basic_credentials}
+ end
+
+ #
# self.get_cached_response_from
#
# @param {String} api_url
# @param {Hash} api_params
- # @param {Hash} headers (optional)
#
- def self.get_cached_response_from(api_url, api_params, headers={})
+ def self.get_cached_response_from(api_url, api_params)
key = "#{api_url}.#{api_params.sort}"
return Rails.cache.fetch(key, expires_in: 10.minutes) do
- self.get_response_from(api_url, api_params, headers)
+ self.get_response_from(api_url, api_params)
end
- return self.get_response_from(api_url, api_params, headers)
+ return self.get_response_from(api_url, api_params)
end
#
# self.call
#
# @param {String} api_url
# @param {Hash} api_params
- # @param {Hash} headers (optional)
# @param {String} method (optional)
#
- def self.call(api_url, api_params, headers={}, method=:get)
+ def self.call(api_url, api_params, method=:get)
+
+ headers = self.get_authentication_headers
http_client = HTTPClient.new
case method
when :get
response = http_client.get(api_url, api_params, headers)