Class: LLM::Transport::Response::Curb

Inherits:
LLM::Transport::Response show all
Defined in:
lib/llm/transport/response/curb.rb

Overview

LLM::Transport::Response::Curb adapts a raw status code, header hash, and body string to the LLM::Transport::Response interface.

This is the response wrapper used by the LLM::Transport::Curb transport.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from LLM::Transport::Response

from

Constructor Details

#initialize(code, headers = {}, body = +"")) ⇒ LLM::Transport::Response::Curb

Parameters:

  • code (#to_i)
  • headers (Hash) (defaults to: {})
  • body (String) (defaults to: +""))


29
30
31
32
33
34
# File 'lib/llm/transport/response/curb.rb', line 29

def initialize(code, headers = {}, body = +"")
  @code = code.to_i
  @headers = {}
  (headers || {}).each { @headers[_1.to_s.downcase] = _2.to_s }
  @body = body
end

Instance Attribute Details

#bodyString

Returns:

  • (String)


22
23
24
# File 'lib/llm/transport/response/curb.rb', line 22

def body
  @body
end

#codeInteger (readonly)

Returns:

  • (Integer)


14
15
16
# File 'lib/llm/transport/response/curb.rb', line 14

def code
  @code
end

#headersHash (readonly)

Returns:

  • (Hash)


18
19
20
# File 'lib/llm/transport/response/curb.rb', line 18

def headers
  @headers
end

Instance Method Details

#[](key) ⇒ String?

Parameters:

  • key (String)

Returns:

  • (String, nil)


39
40
41
# File 'lib/llm/transport/response/curb.rb', line 39

def [](key)
  @headers[key.to_s.downcase]
end

#bad_request?Boolean

Returns:

  • (Boolean)


71
72
73
# File 'lib/llm/transport/response/curb.rb', line 71

def bad_request?
  code == 400
end

#forbidden?Boolean

Returns:

  • (Boolean)


83
84
85
# File 'lib/llm/transport/response/curb.rb', line 83

def forbidden?
  code == 403
end

#inspectString

Returns:

  • (String)


107
108
109
110
# File 'lib/llm/transport/response/curb.rb', line 107

def inspect
  "#<#{self.class.name}:0x#{object_id.to_s(16)}" \
    " @code=#{@code} @headers=#{@headers.inspect}>"
end

#not_found?Boolean

Returns:

  • (Boolean)


89
90
91
# File 'lib/llm/transport/response/curb.rb', line 89

def not_found?
  code == 404
end

#ok?Boolean

Returns:

  • (Boolean)


65
66
67
# File 'lib/llm/transport/response/curb.rb', line 65

def ok?
  code == 200
end

#rate_limited?Boolean

Returns:

  • (Boolean)


95
96
97
# File 'lib/llm/transport/response/curb.rb', line 95

def rate_limited?
  code == 429
end

#read_body(dest = nil) {|chunk| ... } ⇒ void

This method returns an undefined value.

Parameters:

  • dest (Object, nil) (defaults to: nil)

Yield Parameters:

  • chunk (String)


47
48
49
50
51
52
53
54
55
# File 'lib/llm/transport/response/curb.rb', line 47

def read_body(dest = nil, &block)
  return @body unless block_given? || dest
  if dest
    dest << @body.to_s
  else
    yield @body.to_s
  end
  @body
end

#server_error?Boolean

Returns:

  • (Boolean)


101
102
103
# File 'lib/llm/transport/response/curb.rb', line 101

def server_error?
  code.between?(500, 599)
end

#success?Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/llm/transport/response/curb.rb', line 59

def success?
  code.between?(200, 299)
end

#unauthorized?Boolean

Returns:

  • (Boolean)


77
78
79
# File 'lib/llm/transport/response/curb.rb', line 77

def unauthorized?
  code == 401
end