Module: ApiClient::InstanceMethods
- Included in:
- Base
- Defined in:
- lib/api-client/instance_methods.rb
Overview
This module handles the logic to make an api call and update_attributes the current object with the response.
Instance Method Summary collapse
-
#delete(header = {}) ⇒ Base
(also: #destroy)
Make a delete requisition and update the object with the response.
-
#get(header = {}) ⇒ Base
(also: #reload)
Make a get requisition and update the object with the response.
-
#patch(header = {}) ⇒ Base
Make a patch requisition and update the object with the response.
-
#post(header = {}) ⇒ Base
(also: #create)
Make a post requisition and update the object with the response.
-
#put(header = {}) ⇒ Base
(also: #update_attributes)
Make a put requisition and update the object with the response.
-
#remove_root(attributes = {}) ⇒ Hash
Removes the root node attribute if found.
Instance Method Details
#delete(header = {}) ⇒ Base Also known as: destroy
Make a delete requisition and update the object with the response.
58 59 60 61 62 63 |
# 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 |
#get(header = {}) ⇒ Base Also known as: reload
Make a get requisition and update the object with the response.
8 9 10 11 12 13 |
# 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 |
#patch(header = {}) ⇒ Base
Make a patch requisition and update the object with the response.
47 48 49 50 51 52 |
# 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 = {}) ⇒ Base Also known as: create
Make a post requisition and update the object with the response.
21 22 23 24 25 26 |
# 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 |
#put(header = {}) ⇒ Base Also known as: update_attributes
Make a put requisition and update the object with the response.
34 35 36 37 38 39 |
# 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 |
#remove_root(attributes = {}) ⇒ Hash
Removes the root node attribute if found.
71 72 73 74 75 |
# 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 |