Class: Inttegro::TransportResponse

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/inttegro/transport_response.rb

Overview

Normalizes Net::HTTP and custom adapter responses at the SDK boundary. Adapter objects are deliberately accepted as Object and validated here so unknown values cannot flow unchecked through the rest of the SDK.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ TransportResponse

Returns a new instance of TransportResponse.



22
23
24
25
26
27
# File 'lib/inttegro/transport_response.rb', line 22

def initialize(response)
  @code = T.let(read_string(response, :code), String)
  @body = T.let(read_string(response, :body), String)
  @message = T.let(read_string(response, :message), String)
  @headers = T.let(normalize_headers(read_headers(response)), Types::ResponseHeaders)
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



16
17
18
# File 'lib/inttegro/transport_response.rb', line 16

def body
  @body
end

#codeObject (readonly)

Returns the value of attribute code.



16
17
18
# File 'lib/inttegro/transport_response.rb', line 16

def code
  @code
end

#headersObject (readonly)

Returns the value of attribute headers.



19
20
21
# File 'lib/inttegro/transport_response.rb', line 19

def headers
  @headers
end

#messageObject (readonly)

Returns the value of attribute message.



16
17
18
# File 'lib/inttegro/transport_response.rb', line 16

def message
  @message
end

Instance Method Details

#[](name) ⇒ Object



30
31
32
33
# File 'lib/inttegro/transport_response.rb', line 30

def [](name)
  pair = @headers.find { |key, _values| key.casecmp?(name) }
  pair&.last&.first
end