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>)


154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# File 'lib/openai/http_client.rb', line 154

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

  @metadata = OpenAI::ResponseMetadata.new(status: status, headers: headers)
  @status = @metadata.status
  @headers = @metadata.headers
  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>)


144
145
146
# File 'lib/openai/http_client.rb', line 144

def body
  @body
end

#headersHash{String=>String} (readonly)

Returns:

  • (Hash{String=>String})


137
138
139
# File 'lib/openai/http_client.rb', line 137

def headers
  @headers
end

#metadataOpenAI::ResponseMetadata (readonly)

Immutable metadata safe to retain after the response body is consumed.



149
150
151
# File 'lib/openai/http_client.rb', line 149

def 
  @metadata
end

#statusInteger (readonly)

Returns:

  • (Integer)


134
135
136
# File 'lib/openai/http_client.rb', line 134

def status
  @status
end