Class: RecastAI::Client
- Inherits:
-
Object
- Object
- RecastAI::Client
- Defined in:
- lib/recastai/client.rb
Instance Attribute Summary collapse
-
#token ⇒ Object
Returns the value of attribute token.
Instance Method Summary collapse
-
#file_request(file, options = {}) ⇒ Object
Perform a voice file request to Recast.AI.
-
#initialize(token = nil, language = nil) ⇒ Client
constructor
A new instance of Client.
-
#text_request(text, options = {}) ⇒ Object
Perform a text request to Recast.AI.
Constructor Details
#initialize(token = nil, language = nil) ⇒ Client
Returns a new instance of Client.
7 8 9 10 |
# File 'lib/recastai/client.rb', line 7 def initialize(token = nil, language = nil) @token = token @language = language end |
Instance Attribute Details
#token ⇒ Object
Returns the value of attribute token.
5 6 7 |
# File 'lib/recastai/client.rb', line 5 def token @token end |
Instance Method Details
#file_request(file, options = {}) ⇒ Object
Perform a voice file request to Recast.AI
-
Args :
-
file- String or File, the voice file to process -
options- Hash, request’s options
-
-
Returns :
-
An instance of Response
-
-
Throws :
-
RecastError
-
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/recastai/client.rb', line 50 def file_request(file, = {}) token = [:token] || @token raise(RecastError.new('Token is missing')) if token.nil? language = [:language] || @language body = { 'voice' => File.new(file) } body['language'] = language unless language.nil? response = HTTMultiParty.post( Utils::API_ENDPOINT, body: body, headers: { 'Authorization' => "Token #{token}" } ) raise(RecastError.new(response.)) if response.code != 200 Response.new(response.body) end |
#text_request(text, options = {}) ⇒ Object
Perform a text request to Recast.AI
-
Args :
-
text- String, the text to process -
options- Hash, request’s options
-
-
Returns :
-
An instance of Response
-
-
Throws :
-
RecastError
-
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/recastai/client.rb', line 22 def text_request(text, = {}) token = [:token] || @token raise(RecastError.new('Token is missing')) if token.nil? language = [:language] || @language body = { 'text' => text } body['language'] = language unless language.nil? response = HTTParty.post( Utils::API_ENDPOINT, body: body, headers: { 'Authorization' => "Token #{token}" } ) raise(RecastError.new(response.)) if response.code != 200 Response.new(response.body) end |