Module: ApiClient::ClassMethods
- Included in:
- Base
- Defined in:
- lib/api-client/class_methods.rb
Overview
This module handles the logic to make an api call and initialize an object with the response.
Instance Method Summary collapse
-
#delete(id, header = {}) ⇒ Base
(also: #destroy)
Make a delete requisition and initialize an object with the response.
-
#get(id, header = {}) ⇒ Base
(also: #find)
Make a get requisition and initialize an object with the response.
-
#patch(id, attributes, header = {}) ⇒ Base
Make a patch requisition and initialize an object with the response.
-
#post(attributes, header = {}) ⇒ Base
(also: #create)
Make a post requisition and initialize an object with the response.
-
#put(id, attributes, header = {}) ⇒ Base
(also: #update_attributes)
Make a put requisition and initialize an object with the response.
-
#remove_root(attributes = {}) ⇒ Hash
Removes the root node attribute if found.
Instance Method Details
#delete(id, header = {}) ⇒ Base Also known as: destroy
Make a delete requisition and initialize an object with the response.
63 64 65 66 67 68 |
# File 'lib/api-client/class_methods.rb', line 63 def delete(id, header = {}) return new(:id => id) if ApiClient.config.mock url = "#{ApiClient.config.path[path]}#{self.resource_path}/#{id}" response = ApiClient::Dispatcher.delete(url, header) build(response, url) end |
#get(id, header = {}) ⇒ Base Also known as: find
Make a get requisition and initialize an object with the response.
9 10 11 12 13 14 |
# File 'lib/api-client/class_methods.rb', line 9 def get(id, header = {}) return new(:id => id) if ApiClient.config.mock url = "#{ApiClient.config.path[path]}#{self.resource_path}/#{id}" response = ApiClient::Dispatcher.get(url, header) build(response, url) end |
#patch(id, attributes, header = {}) ⇒ Base
Make a patch requisition and initialize an object with the response.
51 52 53 54 55 56 |
# File 'lib/api-client/class_methods.rb', line 51 def patch(id, attributes, header = {}) return new(attributes) if ApiClient.config.mock url = "#{ApiClient.config.path[path]}#{self.resource_path}/#{id}" response = ApiClient::Dispatcher.patch(url, { self.root_node.to_sym => attributes }, header) build(response, url) end |
#post(attributes, header = {}) ⇒ Base Also known as: create
Make a post requisition and initialize an object with the response.
23 24 25 26 27 28 |
# File 'lib/api-client/class_methods.rb', line 23 def post(attributes, header = {}) return new(attributes) if ApiClient.config.mock url = "#{ApiClient.config.path[path]}#{self.resource_path}" response = ApiClient::Dispatcher.post(url, { self.root_node.to_sym => attributes }, header) build(response, url) end |
#put(id, attributes, header = {}) ⇒ Base Also known as: update_attributes
Make a put requisition and initialize an object with the response.
37 38 39 40 41 42 |
# File 'lib/api-client/class_methods.rb', line 37 def put(id, attributes, header = {}) return new(attributes) if ApiClient.config.mock url = "#{ApiClient.config.path[path]}#{self.resource_path}/#{id}" response = ApiClient::Dispatcher.put(url, { self.root_node.to_sym => attributes }, header) build(response, url) end |
#remove_root(attributes = {}) ⇒ Hash
Removes the root node attribute if found.
76 77 78 79 80 |
# File 'lib/api-client/class_methods.rb', line 76 def remove_root(attributes = {}) attributes = attributes[self.root_node.to_sym] if attributes.key?(self.root_node.to_sym) attributes = attributes[self.root_node.to_s] if attributes.key?(self.root_node.to_s) attributes end |