Class: Saddle::BaseEndpoint
- Inherits:
-
Object
- Object
- Saddle::BaseEndpoint
- Defined in:
- lib/saddle/endpoint.rb
Overview
This base endpoint is what all implementation endpoints should inherit from. It automatically provides tree construction and traversal functionality. It also abstracts away url construction and requests to the underlying requester instance.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
-
#relative_path ⇒ Object
readonly
Returns the value of attribute relative_path.
-
#requester ⇒ Object
readonly
Returns the value of attribute requester.
Instance Method Summary collapse
-
#_build_and_attach_node(endpoint_class, method_name = nil) ⇒ Object
Create an endpoint instance and foist it upon this node Not private, but not part of the public interface for an endpoint.
-
#create_resource_endpoint(endpoint_class, resource_id) ⇒ Object
This will create a resource endpoint, based upon the parameters of this current node endpoint.
- #define_singleton_method(name, &block) ⇒ Object
-
#delete(action, params = {}, options = {}) ⇒ Object
Provide DELETE functionality for the implementer class.
-
#get(action, params = {}, options = {}) ⇒ Object
Provide GET functionality for the implementer class.
-
#initialize(requester, relative_path_override = nil, parent = nil) ⇒ BaseEndpoint
constructor
Each endpoint needs to have a requester in order to …
-
#post(action, params = {}, options = {}) ⇒ Object
Provide POST functionality for the implementer class.
-
#put(action, params = {}, options = {}) ⇒ Object
Provide PUT functionality for the implementer class.
-
#request(method, action, params = {}, options = {}) ⇒ Object
Generic request wrapper.
Constructor Details
#initialize(requester, relative_path_override = nil, parent = nil) ⇒ BaseEndpoint
Each endpoint needs to have a requester in order to … make … uh … requests.
22 23 24 25 26 |
# File 'lib/saddle/endpoint.rb', line 22 def initialize(requester, relative_path_override=nil, parent=nil) @requester = requester @parent = parent @relative_path = relative_path_override || _relative_path end |
Instance Attribute Details
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
19 20 21 |
# File 'lib/saddle/endpoint.rb', line 19 def parent @parent end |
#relative_path ⇒ Object (readonly)
Returns the value of attribute relative_path.
19 20 21 |
# File 'lib/saddle/endpoint.rb', line 19 def relative_path @relative_path end |
#requester ⇒ Object (readonly)
Returns the value of attribute requester.
19 20 21 |
# File 'lib/saddle/endpoint.rb', line 19 def requester @requester end |
Instance Method Details
#_build_and_attach_node(endpoint_class, method_name = nil) ⇒ Object
Create an endpoint instance and foist it upon this node Not private, but not part of the public interface for an endpoint
67 68 69 70 71 72 73 74 75 |
# File 'lib/saddle/endpoint.rb', line 67 def _build_and_attach_node(endpoint_class, method_name=nil) # Create the new endpoint endpoint_instance = endpoint_class.new(@requester, method_name, self) # Attach the endpoint as an instance variable and method method_name ||= endpoint_class.name.demodulize.underscore self.instance_variable_set("@#{method_name}", endpoint_instance) self.define_singleton_method(method_name.to_s) { endpoint_instance } endpoint_instance end |
#create_resource_endpoint(endpoint_class, resource_id) ⇒ Object
This will create a resource endpoint, based upon the parameters of this current node endpoint
60 61 62 |
# File 'lib/saddle/endpoint.rb', line 60 def create_resource_endpoint(endpoint_class, resource_id) endpoint_class.new(@requester, resource_id, self) end |
#define_singleton_method(name, &block) ⇒ Object
78 79 80 |
# File 'lib/saddle/endpoint.rb', line 78 def define_singleton_method(name, &block) (class << self; self end).send(:define_method, name, &block) end |
#delete(action, params = {}, options = {}) ⇒ Object
Provide DELETE functionality for the implementer class
53 54 55 |
# File 'lib/saddle/endpoint.rb', line 53 def delete(action, params={}, ={}) request(:delete, action, params, ) end |
#get(action, params = {}, options = {}) ⇒ Object
Provide GET functionality for the implementer class
38 39 40 |
# File 'lib/saddle/endpoint.rb', line 38 def get(action, params={}, ={}) request(:get, action, params, ) end |
#post(action, params = {}, options = {}) ⇒ Object
Provide POST functionality for the implementer class
43 44 45 |
# File 'lib/saddle/endpoint.rb', line 43 def post(action, params={}, ={}) request(:post, action, params, ) end |
#put(action, params = {}, options = {}) ⇒ Object
Provide PUT functionality for the implementer class
48 49 50 |
# File 'lib/saddle/endpoint.rb', line 48 def put(action, params={}, ={}) request(:put, action, params, ) end |
#request(method, action, params = {}, options = {}) ⇒ Object
Generic request wrapper
30 31 32 33 34 35 |
# File 'lib/saddle/endpoint.rb', line 30 def request(method, action, params={}, ={}) # Augment in interesting options [:call_chain] = _path_array [:action] = action @requester.send(method, _path(action), params, ) end |