Class: TalkApi::Client
- Inherits:
-
Object
- Object
- TalkApi::Client
- Defined in:
- lib/talk_api/client.rb
Overview
Entry point class
Constant Summary collapse
- ENDPOINT_URL =
'https://api.a3rt.recruit-tech.co.jp/talk/v1/smalltalk'
- HEADERS =
{ 'User-Agent' => "#{self}/#{VERSION}" }.freeze
Instance Method Summary collapse
-
#initialize(api_key: nil) ⇒ Client
constructor
A new instance of Client.
- #smalltalk(text) ⇒ Object
Constructor Details
#initialize(api_key: nil) ⇒ Client
Returns a new instance of Client.
12 13 14 |
# File 'lib/talk_api/client.rb', line 12 def initialize(api_key: nil) @api_key = api_key end |
Instance Method Details
#smalltalk(text) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# 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. end json = JSON.parse(response.body, symbolize_names: true) Response.new(json[:status], json[:message], json[:results]) end |