lib/restful_resource/base.rb in restful_resource-2.7.0 vs lib/restful_resource/base.rb in restful_resource-2.8.0

- old
+ new

@@ -31,26 +31,26 @@ def self.resource_path(url) @resource_path = url end - def self.find(id, params = {}) + def self.find(id, **params) params_without_options, options = format_params(params) response = http.get(member_url(id, params_without_options), **options) new(parse_json(response.body)) end - def self.where(params = {}) + def self.where(**params) params_without_options, options = format_params(params) url = collection_url(params_without_options) response = http.get(url, **options) paginate_response(response) end - def self.get(params = {}) + def self.get(**params) params_without_options, options = format_params(params) response = http.get(collection_url(params_without_options), **options) new(parse_json(response.body)) end @@ -90,11 +90,11 @@ response = http.post(url, data: data, headers: headers, **options) new(parse_json(response.body)) end - def self.all(params = {}) + def self.all(**params) where(params) end def self.action(action_name) clone = self.clone @@ -131,18 +131,18 @@ raise 'Base url missing' if result.nil? result end - def self.collection_url(params) + def self.collection_url(**params) url = merge_url_paths(base_url, @resource_path, @action_prefix) replace_parameters(url, params) end private - def self.format_params(params = {}) + def self.format_params(**params) headers = params.delete(:headers) || {} headers[:cache_control] = 'no-cache' if params.delete(:no_cache) open_timeout = params.delete(:open_timeout) timeout = params.delete(:timeout) @@ -152,11 +152,11 @@ def self.merge_url_paths(uri, *paths) uri.merge(paths.compact.join('/')).to_s end - def self.member_url(id, params) + def self.member_url(id, **params) raise ResourceIdMissingError if id.blank? url = merge_url_paths(base_url, @resource_path, CGI.escape(id.to_s), @action_prefix) replace_parameters(url, params) end @@ -171,10 +171,10 @@ return nil if json.strip.empty? ActiveSupport::JSON.decode(json) end - def self.replace_parameters(url, params) + def self.replace_parameters(url, **params) missing_params = [] params = params.with_indifferent_access url_params = url.scan(/:([A-Za-z][^\/]*)/).flatten url_params.each do |key|