Class: BN::Middleware::HTTPResponse
- Defined in:
- lib/bn/middleware/http_response.rb
Overview
Transforms the body of an HTTP request from JSON to Ruby.
Instance Method Summary collapse
-
#execute(response) ⇒ Hash
Execute the middleware.
Methods inherited from Base
Constructor Details
This class inherits a constructor from BN::Middleware::Base
Instance Method Details
#execute(response) ⇒ Hash
Execute the middleware.
14 15 16 17 18 19 20 21 |
# File 'lib/bn/middleware/http_response.rb', line 14 def execute(response) raise Error::Middleware::InvalidHTTPResponse, response: response unless response.respond_to?(:body) raise Error::Middleware::InvalidHTTPResponse, response: response unless response.respond_to?(:code) && (200...300).include?(response.code) body = response.body.to_s ::JSON.parse(body) end |