Class: OpenAI::HTTPClient::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/openai/http_client.rb,
sig/openai/http_client.rbs

Overview

An HTTP response returned to the SDK.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Response.

Parameters:

  • status (Integer)
  • headers (Hash{String=>String})
  • body (String, Enumerable<String>)


60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/openai/http_client.rb', line 60

def initialize(status:, headers:, body:)
  unless body.is_a?(String) || body.respond_to?(:each)
    raise ArgumentError, "`body` must be a String or respond to `each`"
  end

  @status = Integer(status)
  @headers =
    headers.to_h do |name, value|
      [name.to_s.downcase, value.to_s]
    end.freeze
  source = body.is_a?(String) ? [body].freeze : body
  @body = OpenAI::Internal::Util.fused_enum(source) do
    if source.respond_to?(:close)
      source.close
    else
      OpenAI::Internal::Util.close_fused!(source)
    end
  end
  freeze
end

Instance Attribute Details

#bodyEnumerable<String> (readonly)

The body is normalized to a one-shot enumerable. If the supplied body responds to close, the SDK calls it when the body is consumed or discarded.

Returns:

  • (Enumerable<String>)


55
56
57
# File 'lib/openai/http_client.rb', line 55

def body
  @body
end

#headersHash{String=>String} (readonly)

Returns:

  • (Hash{String=>String})


48
49
50
# File 'lib/openai/http_client.rb', line 48

def headers
  @headers
end

#statusInteger (readonly)

Returns:

  • (Integer)


45
46
47
# File 'lib/openai/http_client.rb', line 45

def status
  @status
end