module ApiClient::InstanceMethods
This module handles the logic to make an api call and update_attributes the current object with the response.
Public Instance Methods
Make a delete requisition and update the object with the response.
@param [Hash] header hash with the header options. @return [Base] the object updated.
# File lib/api-client/instance_methods.rb, line 58 def delete(header = {}) return self if ApiClient.config.mock url = "#{ApiClient.config.path[path]}#{self.class.resource_path}/#{id}" response = ApiClient::Dispatcher.delete(url, header) update(response, url) end
Make a get requisition and update the object with the response.
@param [Hash] header hash with the header options. @return [Base] the object updated.
# File lib/api-client/instance_methods.rb, line 8 def get(header = {}) return self if ApiClient.config.mock url = "#{ApiClient.config.path[path]}#{self.class.resource_path}/#{id}" response = ApiClient::Dispatcher.get(url, header) update(response, url) end
Make a patch requisition and update the object with the response.
@param [Hash] header hash with the header options. @return [Base] the object updated.
# File lib/api-client/instance_methods.rb, line 47 def patch(header = {}) return self if ApiClient.config.mock url = "#{ApiClient.config.path[path]}#{self.class.resource_path}/#{id}" response = ApiClient::Dispatcher.patch(url, self.to_hash, header) update(response, url) end
Make a post requisition and update the object with the response.
@param [Hash] header hash with the header options. @return [Base] the object updated.
# File lib/api-client/instance_methods.rb, line 21 def post(header = {}) return self if ApiClient.config.mock url = "#{ApiClient.config.path[path]}#{self.class.resource_path}" response = ApiClient::Dispatcher.post(url, self.to_hash, header) update(response, url) end
Make a put requisition and update the object with the response.
@param [Hash] header hash with the header options. @return [Base] the object updated.
# File lib/api-client/instance_methods.rb, line 34 def put(header = {}) return self if ApiClient.config.mock url = "#{ApiClient.config.path[path]}#{self.class.resource_path}/#{id}" response = ApiClient::Dispatcher.put(url, self.to_hash, header) update(response, url) end
Removes the root node attribute if found.
@param [Hash] attributes the hash with attributes. @return [Hash] the hash with attributes without the root node.
# File lib/api-client/instance_methods.rb, line 71 def remove_root(attributes = {}) attributes = attributes[self.class.root_node.to_sym] if attributes.key?(self.class.root_node.to_sym) attributes = attributes[self.class.root_node.to_s] if attributes.key?(self.class.root_node.to_s) attributes end
Protected Instance Methods
Update an object based on a hash of attributes.
@param [Response] response requisition response. @param [String] url the url of the requisition. @return [Base] the update_attributes object.
# File lib/api-client/instance_methods.rb, line 84 def update(response, url) return response if ApiClient.config.hydra attributes = ApiClient::Parser.response(response, url) hash = remove_root(attributes) hash = hash.merge({ 'response' => attributes }) self.attributes = hash self end