Class: ApiRecipes::Route
- Inherits:
-
Object
- Object
- ApiRecipes::Route
- Defined in:
- lib/api_recipes/route.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
Returns the value of attribute attributes.
-
#path ⇒ Object
Returns the value of attribute path.
-
#request ⇒ Object
readonly
Returns the value of attribute request.
-
#request_params ⇒ Object
readonly
Returns the value of attribute request_params.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
- #fill(object) ⇒ Object
-
#initialize(api: nil, endpoint: nil, path: nil, attributes: {}, req_pars: {}) ⇒ Route
constructor
A new instance of Route.
- #start_request(&block) ⇒ Object
Constructor Details
#initialize(api: nil, endpoint: nil, path: nil, attributes: {}, req_pars: {}) ⇒ Route
Returns a new instance of Route.
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/api_recipes/route.rb', line 7 def initialize(api: nil, endpoint: nil, path: nil, attributes: {}, req_pars: {}) @api = api @endpoint = endpoint @path = path.to_s @attributes = attributes self.request_params = req_pars @url = nil prepare_request end |
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
5 6 7 |
# File 'lib/api_recipes/route.rb', line 5 def attributes @attributes end |
#path ⇒ Object
Returns the value of attribute path.
5 6 7 |
# File 'lib/api_recipes/route.rb', line 5 def path @path end |
#request ⇒ Object (readonly)
Returns the value of attribute request.
4 5 6 |
# File 'lib/api_recipes/route.rb', line 4 def request @request end |
#request_params ⇒ Object
Returns the value of attribute request_params.
5 6 7 |
# File 'lib/api_recipes/route.rb', line 5 def request_params @request_params end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
4 5 6 |
# File 'lib/api_recipes/route.rb', line 4 def response @response end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
4 5 6 |
# File 'lib/api_recipes/route.rb', line 4 def url @url end |
Instance Method Details
#fill(object) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/api_recipes/route.rb', line 18 def fill(object) data = @response.parse @attributes[:mime_type] if block_given? tap do try_to_fill object, data yield object, data, @response.status end else try_to_fill object, data end end |
#start_request(&block) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/api_recipes/route.rb', line 30 def start_request(&block) original_response = @request.send http_verb, @url, request_params @response = Response.new original_response, attributes check_response_code if block_given? tap { block.call @response } else response end end |