9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/recastai/apis/request/analyse.rb', line 9
def analyse_text(text, token: nil, language: nil)
token ||= @token
raise RecastError.new('Token is missing') if token.nil?
language ||= @language
body = { text: text }
body[:language] = language unless language.nil?
response = HTTParty.post(
Utils::REQUEST_ENDPOINT,
body: body,
headers: { 'Authorization' => "Token #{token}" }
)
raise RecastError.new(JSON.parse(response.body)['message']) if response.code != 200
Response.new(JSON.parse(response.body))
end
|