Class: InstanceId::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/instance_id/response.rb,
lib/instance_id/response/delete.rb,
lib/instance_id/response/get_info.rb,
lib/instance_id/response/batch_operation.rb

Direct Known Subclasses

BatchOperation, Delete, GetInfo

Defined Under Namespace

Classes: BatchOperation, Delete, GetInfo

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(status:, body: nil, headers: nil) ⇒ Response

Returns a new instance of Response.



10
11
12
13
14
# File 'lib/instance_id/response.rb', line 10

def initialize(status:, body: nil, headers: nil)
  @status  = status.to_i
  @body    = body
  @headers = headers
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



7
8
9
# File 'lib/instance_id/response.rb', line 7

def body
  @body
end

#headersObject (readonly)

Returns the value of attribute headers.



8
9
10
# File 'lib/instance_id/response.rb', line 8

def headers
  @headers
end

#statusObject (readonly)

Returns the value of attribute status.



6
7
8
# File 'lib/instance_id/response.rb', line 6

def status
  @status
end

Instance Method Details

#body_jsonObject



24
25
26
27
28
# File 'lib/instance_id/response.rb', line 24

def body_json
  parse_body.tap do |json|
    break json.key?(:error) ? nil : json
  end
end

#errorsObject



30
31
32
33
34
# 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?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/instance_id/response.rb', line 20

def failure?
  !success?
end

#success?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/instance_id/response.rb', line 16

def success?
  @status.in? 200...400
end