Class: Ollama::Transport::Response
- Inherits:
-
Object
- Object
- Ollama::Transport::Response
- Defined in:
- lib/ollama/transport/response.rb
Overview
Normalized transport response contract.
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#duration_ms ⇒ Object
readonly
Returns the value of attribute duration_ms.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#raw ⇒ Object
readonly
Returns the value of attribute raw.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Instance Method Summary collapse
- #code ⇒ Object
-
#initialize(status:, headers:, body:, raw:, duration_ms: nil) ⇒ Response
constructor
A new instance of Response.
-
#is_a?(klass) ⇒ Boolean
Compatibility with existing Net::HTTP response checks.
- #json ⇒ Object
- #message ⇒ Object
- #success? ⇒ Boolean
Constructor Details
#initialize(status:, headers:, body:, raw:, duration_ms: nil) ⇒ Response
Returns a new instance of Response.
9 10 11 12 13 14 15 |
# File 'lib/ollama/transport/response.rb', line 9 def initialize(status:, headers:, body:, raw:, duration_ms: nil) @status = status.to_i @headers = headers || {} @body = body @raw = raw @duration_ms = duration_ms end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
7 8 9 |
# File 'lib/ollama/transport/response.rb', line 7 def body @body end |
#duration_ms ⇒ Object (readonly)
Returns the value of attribute duration_ms.
7 8 9 |
# File 'lib/ollama/transport/response.rb', line 7 def duration_ms @duration_ms end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
7 8 9 |
# File 'lib/ollama/transport/response.rb', line 7 def headers @headers end |
#raw ⇒ Object (readonly)
Returns the value of attribute raw.
7 8 9 |
# File 'lib/ollama/transport/response.rb', line 7 def raw @raw end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
7 8 9 |
# File 'lib/ollama/transport/response.rb', line 7 def status @status end |
Instance Method Details
#code ⇒ Object
32 33 34 |
# File 'lib/ollama/transport/response.rb', line 32 def code status.to_s end |
#is_a?(klass) ⇒ Boolean
Compatibility with existing Net::HTTP response checks
26 27 28 29 30 |
# File 'lib/ollama/transport/response.rb', line 26 def is_a?(klass) return success? if klass == Net::HTTPSuccess super end |
#json ⇒ Object
17 18 19 |
# File 'lib/ollama/transport/response.rb', line 17 def json @json ||= JSON.parse(body.to_s) end |
#message ⇒ Object
36 37 38 |
# File 'lib/ollama/transport/response.rb', line 36 def raw.respond_to?(:message) ? raw. : "" end |
#success? ⇒ Boolean
21 22 23 |
# File 'lib/ollama/transport/response.rb', line 21 def success? status >= 200 && status < 300 end |