Class: OpenAI::HTTPClient::Response
- Inherits:
-
Object
- Object
- OpenAI::HTTPClient::Response
- Defined in:
- lib/openai/http_client.rb,
sig/openai/http_client.rbs
Overview
An HTTP response returned to the SDK.
Instance Attribute Summary collapse
-
#body ⇒ Enumerable<String>
readonly
The body is normalized to a one-shot enumerable.
- #headers ⇒ Hash{String=>String} readonly
-
#metadata ⇒ OpenAI::ResponseMetadata
readonly
Immutable metadata safe to retain after the response body is consumed.
- #status ⇒ Integer readonly
Instance Method Summary collapse
-
#initialize(status:, headers:, body:) ⇒ Response
constructor
A new instance of Response.
Constructor Details
#initialize(status:, headers:, body:) ⇒ Response
Returns a new instance of Response.
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
#body ⇒ Enumerable<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.
144 145 146 |
# File 'lib/openai/http_client.rb', line 144 def body @body end |
#headers ⇒ Hash{String=>String} (readonly)
137 138 139 |
# File 'lib/openai/http_client.rb', line 137 def headers @headers end |
#metadata ⇒ OpenAI::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 |
#status ⇒ Integer (readonly)
134 135 136 |
# File 'lib/openai/http_client.rb', line 134 def status @status end |