Class: YuiRestClient::Http::Response
- Inherits:
-
Object
- Object
- YuiRestClient::Http::Response
- Defined in:
- lib/yui_rest_client/http/response.rb
Instance Method Summary collapse
- #body(regex_filter: {}) ⇒ Object
-
#initialize(res) ⇒ Response
constructor
A new instance of Response.
Constructor Details
#initialize(res) ⇒ Response
Returns a new instance of Response.
6 7 8 |
# File 'lib/yui_rest_client/http/response.rb', line 6 def initialize(res) @res = res end |
Instance Method Details
#body(regex_filter: {}) ⇒ Object
10 11 12 13 14 15 16 17 18 |
# File 'lib/yui_rest_client/http/response.rb', line 10 def body(regex_filter: {}) result = JSON.parse(@res.body, symbolize_names: true) result.select do || regex_filter.all? { |key, value| value.match([key.to_sym]) } end rescue JSON::ParserError => e YuiRestClient.logger.error("Error while parsing JSON from response:\n"\ "#{e.}\n#{e.backtrace.inspect}") end |