Class: Buble::MessagesResource

Inherits:
Object
  • Object
show all
Defined in:
lib/buble/chat.rb

Instance Method Summary collapse

Constructor Details

#initialize(http) ⇒ MessagesResource

Returns a new instance of MessagesResource.



44
45
46
# File 'lib/buble/chat.rb', line 44

def initialize(http)
  @http = http
end

Instance Method Details

#create(body = nil, **params) ⇒ Object



48
49
50
51
# File 'lib/buble/chat.rb', line 48

def create(body = nil, **params)
  payload = normalize_body(body, params).merge('stream' => false)
  @http.request('POST', '/api/v1/messages', body: payload)
end

#stream(body = nil, **params) ⇒ Object



53
54
55
56
# File 'lib/buble/chat.rb', line 53

def stream(body = nil, **params)
  payload = normalize_body(body, params).merge('stream' => true)
  Streaming.events_from_lines(@http.stream_lines('POST', '/api/v1/messages', body: payload))
end

#stream_text(body = nil, **params) ⇒ Object



58
59
60
# File 'lib/buble/chat.rb', line 58

def stream_text(body = nil, **params)
  Streaming.text_stream(stream(body, **params), :anthropic)
end