lib/restful_resource/base.rb in restful_resource-2.10.1 vs lib/restful_resource/base.rb in restful_resource-2.10.3
- old
+ new
@@ -32,70 +32,70 @@
def self.resource_path(url)
@resource_path = url
end
def self.find(id, **params)
- params_without_options, options = format_params(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)
- params_without_options, options = format_params(params)
+ params_without_options, options = format_params(**params)
- url = collection_url(params_without_options)
+ url = collection_url(**params_without_options)
response = http.get(url, **options)
paginate_response(response)
end
def self.get(**params)
- params_without_options, options = format_params(params)
+ params_without_options, options = format_params(**params)
- response = http.get(collection_url(params_without_options), **options)
+ response = http.get(collection_url(**params_without_options), **options)
new(parse_json(response.body))
end
def self.delete(id, **params)
- params_without_options, options = format_params(params)
+ params_without_options, options = format_params(**params)
response = http.delete(member_url(id, **params_without_options), **options)
new(parse_json(response.body))
end
def self.patch(id, data: {}, headers: {}, **params)
- params_without_options, options = format_params(params)
+ params_without_options, options = format_params(**params)
options.delete(:headers)
url = member_url(id, **params_without_options)
response = http.patch(url, data: data, headers: headers, **options)
new(parse_json(response.body))
end
def self.put(id, data: {}, headers: {}, **params)
- params_without_options, options = format_params(params)
+ params_without_options, options = format_params(**params)
options.delete(:headers)
url = member_url(id, **params_without_options)
response = http.put(url, data: data, headers: headers, **options)
new(parse_json(response.body))
end
def self.post(data: {}, headers: {}, **params)
- params_without_options, options = format_params(params)
+ params_without_options, options = format_params(**params)
options.delete(:headers)
- url = collection_url(params_without_options)
+ url = collection_url(**params_without_options)
response = http.post(url, data: data, headers: headers, **options)
new(parse_json(response.body))
end
def self.all(**params)
- where(params)
+ where(**params)
end
def self.action(action_name)
clone = self.clone
clone.action_prefix = action_name
@@ -117,12 +117,10 @@
next_page = resources.next_page
end while !next_page.nil?
end
end
- protected
-
def self.http
@http || superclass.http
end
def self.base_url
@@ -133,23 +131,21 @@
result
end
def self.collection_url(**params)
url = merge_url_paths(base_url, @resource_path, @action_prefix)
- replace_parameters(url, params)
+ replace_parameters(url, **params)
end
- private
-
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)
- [params, headers: headers, open_timeout: open_timeout, timeout: timeout]
+ [params, { headers: headers, open_timeout: open_timeout, timeout: timeout }]
end
def self.merge_url_paths(uri, *paths)
uri.merge(paths.compact.join('/')).to_s
end
@@ -175,10 +171,10 @@
def self.replace_parameters(url, **params)
missing_params = []
params = params.with_indifferent_access
- url_params = url.scan(/:([A-Za-z][^\/]*)/).flatten
+ url_params = url.scan(%r{:([A-Za-z][^/]*)}).flatten
url_params.each do |key|
value = params.delete(key)
if value.nil?
missing_params << key
else