Class: ApiRecipes::Endpoint
- Inherits:
-
Object
- Object
- ApiRecipes::Endpoint
- Defined in:
- lib/api_recipes/endpoint.rb
Constant Summary collapse
- FORWARDABLE_PARAMS =
%i[verify_with].freeze
Instance Attribute Summary collapse
-
#api ⇒ Object
readonly
Returns the value of attribute api.
-
#children ⇒ Object
readonly
Returns the value of attribute children.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#route ⇒ Object
readonly
Returns the value of attribute route.
Instance Method Summary collapse
-
#initialize(api: nil, name: nil, path: nil, params: {}, request_params: [], &block) ⇒ Endpoint
constructor
A new instance of Endpoint.
- #run(&block) ⇒ Object
- #url ⇒ Object
Constructor Details
#initialize(api: nil, name: nil, path: nil, params: {}, request_params: [], &block) ⇒ Endpoint
Returns a new instance of Endpoint.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/api_recipes/endpoint.rb', line 8 def initialize(api: nil, name: nil, path: nil, params: {}, request_params: [], &block) @api = api @name = name @path = path.to_s new_params = params.dup || {} self.params = new_params @children = new_params.delete :endpoints @route = nil @request_params = request_params. self.path_params = request_params generate_route generate_children if block_given? run &block end end |
Instance Attribute Details
#api ⇒ Object (readonly)
Returns the value of attribute api.
4 5 6 |
# File 'lib/api_recipes/endpoint.rb', line 4 def api @api end |
#children ⇒ Object (readonly)
Returns the value of attribute children.
4 5 6 |
# File 'lib/api_recipes/endpoint.rb', line 4 def children @children end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/api_recipes/endpoint.rb', line 4 def name @name end |
#params ⇒ Object
Returns the value of attribute params.
4 5 6 |
# File 'lib/api_recipes/endpoint.rb', line 4 def params @params end |
#route ⇒ Object (readonly)
Returns the value of attribute route.
4 5 6 |
# File 'lib/api_recipes/endpoint.rb', line 4 def route @route end |
Instance Method Details
#run(&block) ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/api_recipes/endpoint.rb', line 26 def run(&block) if @route @route.start_request &block else raise NoRouteExists.new @name end end |
#url ⇒ Object
34 35 36 37 38 39 40 41 |
# File 'lib/api_recipes/endpoint.rb', line 34 def url if @route @route.url else ApiRecipes.logger.debug "No route configured for '#{api.name}#{absolute_path}': Is option 'route: no' present?" nil end end |