class TalkApi::Client

Entry point class

Constants

ENDPOINT_URL
HEADERS

Public Class Methods

new(api_key: nil) click to toggle source
# File lib/talk_api/client.rb, line 12
def initialize(api_key: nil)
  @api_key = api_key
end

Public Instance Methods

smalltalk(text) click to toggle source
# File lib/talk_api/client.rb, line 16
def smalltalk(text)
  query = text.byteslice(0, 2048).scrub('')
  begin
    client = HTTPClient.new(default_header: HEADERS)
    response = client.post(ENDPOINT_URL, { apikey: @api_key, query: query })
  rescue StandardError => e
    raise HTTPError, e.message
  end
  json = JSON.parse(response.body, symbolize_names: true)
  Response.new(json[:status], json[:message], json[:results])
end