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
- #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.
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
#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.
55 56 57 |
# File 'lib/openai/http_client.rb', line 55 def body @body end |
#headers ⇒ Hash{String=>String} (readonly)
48 49 50 |
# File 'lib/openai/http_client.rb', line 48 def headers @headers end |
#status ⇒ Integer (readonly)
45 46 47 |
# File 'lib/openai/http_client.rb', line 45 def status @status end |