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

create(header = {})
Alias for: post
delete(header = {}) click to toggle source

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
Also aliased as: destroy
destroy(header = {})
Alias for: delete
get(header = {}) click to toggle source

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
Also aliased as: reload
patch(header = {}) click to toggle source

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
post(header = {}) click to toggle source

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
Also aliased as: create
put(header = {}) click to toggle source

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
Also aliased as: update_attributes
reload(header = {})
Alias for: get
remove_root(attributes = {}) click to toggle source

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
update_attributes(header = {})
Alias for: put

Protected Instance Methods

update(response, url) click to toggle source

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