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.
-
#inspect ⇒ String
Inspect response metadata without exposing sensitive headers or body content.
Constructor Details
#initialize(status:, headers:, body:) ⇒ Response
Returns a new instance of Response.
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
# File 'lib/openai/http_client.rb', line 160 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.
150 151 152 |
# File 'lib/openai/http_client.rb', line 150 def body @body end |
#headers ⇒ Hash{String=>String} (readonly)
143 144 145 |
# File 'lib/openai/http_client.rb', line 143 def headers @headers end |
#metadata ⇒ OpenAI::ResponseMetadata (readonly)
Immutable metadata safe to retain after the response body is consumed.
155 156 157 |
# File 'lib/openai/http_client.rb', line 155 def @metadata end |
#status ⇒ Integer (readonly)
140 141 142 |
# File 'lib/openai/http_client.rb', line 140 def status @status end |
Instance Method Details
#inspect ⇒ String
Inspect response metadata without exposing sensitive headers or body content.
183 |
# File 'lib/openai/http_client.rb', line 183 def inspect = "#<#{self.class} status=#{@status} request_id=#{@metadata.request_id.inspect}>" |