Class: RestAPIBuilder::ResponseHandler
- Inherits:
-
Object
- Object
- RestAPIBuilder::ResponseHandler
- Defined in:
- lib/rest_api_builder/response_handler.rb
Instance Method Summary collapse
- #handle_json_response(**options, &block) ⇒ Object
- #handle_response(logger: nil, &block) ⇒ Object
- #handle_response_error ⇒ Object
Instance Method Details
#handle_json_response(**options, &block) ⇒ Object
5 6 7 8 |
# File 'lib/rest_api_builder/response_handler.rb', line 5 def handle_json_response(**, &block) result = handle_response(**, &block) result.merge(body: parse_json(result[:body])) end |
#handle_response(logger: nil, &block) ⇒ Object
10 11 12 13 14 |
# File 'lib/rest_api_builder/response_handler.rb', line 10 def handle_response(logger: nil, &block) result = parse_response(**handle_response_error(&block)) maybe_log_result(result, logger: logger) result end |
#handle_response_error ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/rest_api_builder/response_handler.rb', line 16 def handle_response_error response = yield { raw_response: response, success: true } rescue RestClient::RequestFailed => e raise e unless e.response { raw_response: e.response, success: false } end |