class InstanceId::Response
Attributes
body[R]
headers[R]
status[R]
Public Class Methods
new(status:, body: nil, headers: nil)
click to toggle source
# File lib/instance_id/response.rb, line 10 def initialize(status:, body: nil, headers: nil) @status = status.to_i @body = body @headers = headers end
Public Instance Methods
body_json()
click to toggle source
# File lib/instance_id/response.rb, line 24 def body_json parse_body.tap do |json| break json.key?(:error) ? nil : json end end
errors()
click to toggle source
# File lib/instance_id/response.rb, line 30 def errors parse_body.tap do |json| break json.key?(:error) ? [json.slice(:error)] : [] end end
failure?()
click to toggle source
# File lib/instance_id/response.rb, line 20 def failure? !success? end
success?()
click to toggle source
# File lib/instance_id/response.rb, line 16 def success? @status.in? 200...400 end
Private Instance Methods
parse_body()
click to toggle source
# File lib/instance_id/response.rb, line 38 def parse_body JSON.parse(@body, symbolize_names: true) rescue JSON::ParserError => e { error: e.class.to_s } end