Class: YuiRestClient::Http::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/yui_rest_client/http/response.rb

Instance Method Summary collapse

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 |widget|
    regex_filter.all? { |key, value| value.match(widget[key.to_sym]) }
  end
rescue JSON::ParserError => e
  YuiRestClient.logger.error("Error while parsing JSON from response:\n"\
"#{e.message}\n#{e.backtrace.inspect}")
end