Class: APIClientBuilder::Request
- Inherits:
-
Object
- Object
- APIClientBuilder::Request
- Defined in:
- lib/api_client_builder/request.rb
Direct Known Subclasses
DeleteRequest, GetCollectionRequest, GetItemRequest, PostRequest, PutRequest
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#error_handlers_collection ⇒ Object
readonly
Returns the value of attribute error_handlers_collection.
-
#response_handler ⇒ Object
readonly
Returns the value of attribute response_handler.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
-
#error_handlers ⇒ Array<Block>
Yields the collection of error handlers that have been populated via the on_error interface.
-
#initialize(type, response_handler, body = {}) ⇒ Request
constructor
a pagination strategy.
-
#on_error(&block) ⇒ Object
Used to define custom error handling on this response.
Constructor Details
#initialize(type, response_handler, body = {}) ⇒ Request
a pagination strategy
11 12 13 14 15 16 |
# File 'lib/api_client_builder/request.rb', line 11 def initialize(type, response_handler, body = {}) @type = type @response_handler = response_handler @body = body @error_handlers_collection = [] end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
5 6 7 |
# File 'lib/api_client_builder/request.rb', line 5 def body @body end |
#error_handlers_collection ⇒ Object (readonly)
Returns the value of attribute error_handlers_collection.
5 6 7 |
# File 'lib/api_client_builder/request.rb', line 5 def error_handlers_collection @error_handlers_collection end |
#response_handler ⇒ Object (readonly)
Returns the value of attribute response_handler.
5 6 7 |
# File 'lib/api_client_builder/request.rb', line 5 def response_handler @response_handler end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
5 6 7 |
# File 'lib/api_client_builder/request.rb', line 5 def type @type end |
Instance Method Details
#error_handlers ⇒ Array<Block>
Yields the collection of error handlers that have been populated via the on_error interface. If none are defined, this will provide a default error handler that will provide context about the error and also how to define a new error handler.
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/api_client_builder/request.rb', line 24 def error_handlers if error_handlers_collection.empty? on_error do |page, _handler| raise DefaultPageError, <<~MESSAGE Default error for bad response. If you want to handle this error use #on_error on the response in your api consumer. Error Code: #{page.status_code}. MESSAGE end end error_handlers_collection end |
#on_error(&block) ⇒ Object
Used to define custom error handling on this response. The error handlers will be called if there is not a success
41 42 43 |
# File 'lib/api_client_builder/request.rb', line 41 def on_error(&block) @error_handlers_collection << block end |