Class: Minter::Api::Result

Inherits:
Object
  • Object
show all
Defined in:
lib/minter/api/result.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response, **options) ⇒ Result

Returns a new instance of Result.



8
9
10
11
12
13
14
# File 'lib/minter/api/result.rb', line 8

def initialize(response, **options)
  handle_error_response(response) if !response.status.success? && !options[:suppress_errors]

  @headers = response.headers
  @body = JSON.parse(response.body)
  @status = response.status
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



6
7
8
# File 'lib/minter/api/result.rb', line 6

def body
  @body
end

#headersObject (readonly)

Returns the value of attribute headers.



6
7
8
# File 'lib/minter/api/result.rb', line 6

def headers
  @headers
end

#statusObject (readonly)

Returns the value of attribute status.



6
7
8
# File 'lib/minter/api/result.rb', line 6

def status
  @status
end

Instance Method Details

#to_hObject



16
17
18
19
20
21
22
# File 'lib/minter/api/result.rb', line 16

def to_h
  {
    headers: @headers.to_h,
    body: @body,
    status: @status.code
  }
end

#to_sObject



24
25
26
# File 'lib/minter/api/result.rb', line 24

def to_s
  to_h.slice(:body, :status).to_s
end