module HTTP::RestClient::CRUD
Create/Read/Update/Delete helpers.
Public Instance Methods
Resource collection finder, uses the default limit
@param params [Hash] URI parameters to pass to the endpoint. @return [Array] of [Object] instances
# File lib/http/rest_client/crud.rb, line 9 def all(params = {}) objectify(request(:get, uri, params: params)) end
Resource creation helper
@param params [Hash] request parameters to pass to the endpoint as JSON. @return [Object] instance
# File lib/http/rest_client/crud.rb, line 34 def create(params = {}) objectify(request(:post, uri, json: params)) end
Resource deletion handler
@param id [String] resource indentifier @return [Object] instance
# File lib/http/rest_client/crud.rb, line 26 def delete(id) objectify(request(:delete, uri(id))) end
Resource finder
@param id [String] resource indentifier @param params [Hash] URI parameters to pass to the endpoint. @return [Object] instance
# File lib/http/rest_client/crud.rb, line 18 def find(id, params = {}) objectify(request(:get, uri(id), params: params)) end
Resource update helper
@param id [String] resource indentifier @param params [Hash] request parameters to pass to the endpoint as JSON. @return [Object] instance
# File lib/http/rest_client/crud.rb, line 43 def update(id, params = {}) objectify(request(:patch, uri(id), json: params)) end
Private Instance Methods
Resource constructor wrapper
@param payload [Hash] response payload to build a resource. @return [Object] instance or a list of instances.
# File lib/http/rest_client/crud.rb, line 53 def objectify(payload) if payload.is_a?(Array) payload.map { |data| new(data) } elsif payload.is_a?(Hash) new(payload) else payload end end