lib/restful_resource/base.rb in restful_resource-0.0.9 vs lib/restful_resource/base.rb in restful_resource-0.0.10
- old
+ new
@@ -74,10 +74,16 @@
def self.find(id, url_params={})
response = RestClient.get("#{url(url_params)}/#{id}", params: {})
self.new(ActiveSupport::JSON.decode(response))
end
+ def self.get_one(url_params={})
+ resource = create_new_resource(url_params)
+ response = resource.get
+ self.new(ActiveSupport::JSON.decode(response))
+ end
+
def self.update_attributes(id, attributes)
begin
result = parse(RestClient.put("#{url}/#{id}", attributes))
rescue RestClient::UnprocessableEntity => e
errors = parse(e.response)
@@ -100,12 +106,12 @@
response = RestClient.get("#{url}/search", params: params)
paginate_response(response)
end
def self.all(params = {})
- url, other_params = processed_url_and_params(params)
- response = RestClient.get("#{url}", params: other_params)
+ resource = create_new_resource(params)
+ response = resource.get
paginate_response(response)
end
def self.get(postfix_url = "", params = {})
response = RestClient.get("#{url}#{postfix_url}", params: params)
@@ -153,7 +159,14 @@
next_url = links.find_link(['rel', 'next']).try(:href)
array = ActiveSupport::JSON.decode(response).map { |attributes| self.new(attributes) }
PaginatedArray.new(array, previous_page_url: prev_url, next_page_url: next_url)
end
+
+ def self.create_new_resource(params={})
+ url, other_params = processed_url_and_params(params)
+ url += "?#{other_params.to_query}" if not other_params.empty?
+ resource = RestClient::Resource.new("#{url}")
+ end
+
end
end