Class: IBMCloudSdkCore::DetailedResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/ibm_cloud_sdk_core/detailed_response.rb

Overview

Custom class for objects returned from API calls

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(status: nil, headers: nil, body: nil, response: nil) ⇒ DetailedResponse

Returns a new instance of DetailedResponse.



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/ibm_cloud_sdk_core/detailed_response.rb', line 9

def initialize(status: nil, headers: nil, body: nil, response: nil)
  if status.nil? || headers.nil? || body.nil?
    @status = response.code
    @headers = response.headers.to_h
    @headers = response.headers.to_hash if response.headers.respond_to?("to_hash")
    @result = response.body.to_s
    @result = JSON.parse(response.body.to_s) if !response.body.to_s.empty? && @headers.key?("Content-Type") && @headers["Content-Type"].start_with?("application/json")
  else
    @status = status
    @headers = headers
    @result = body
  end
end

Instance Attribute Details

#headersObject (readonly)

Returns the value of attribute headers.



8
9
10
# File 'lib/ibm_cloud_sdk_core/detailed_response.rb', line 8

def headers
  @headers
end

#resultObject (readonly)

Returns the value of attribute result.



8
9
10
# File 'lib/ibm_cloud_sdk_core/detailed_response.rb', line 8

def result
  @result
end

#statusObject (readonly)

Returns the value of attribute status.



8
9
10
# File 'lib/ibm_cloud_sdk_core/detailed_response.rb', line 8

def status
  @status
end