Class: VoiceBase::V1::Client
- Inherits:
-
Object
- Object
- VoiceBase::V1::Client
- Defined in:
- lib/voicebase/v1/client.rb
Instance Method Summary collapse
-
#initialize(api_key, password, transcript_type = 'machine-best') ⇒ Client
constructor
A new instance of Client.
- #new_http_client(request = :url_encoded) ⇒ Object
- #upload_media(params = {}) ⇒ Object
Constructor Details
#initialize(api_key, password, transcript_type = 'machine-best') ⇒ Client
Returns a new instance of Client.
12 13 14 15 16 17 18 |
# File 'lib/voicebase/v1/client.rb', line 12 def initialize(api_key, password, transcript_type = 'machine-best') @api_key = api_key @password = password @transcript_type = transcript_type @conn_url_encoded = new_http_client :url_encoded @conn_multipart = new_http_client :multipart end |
Instance Method Details
#new_http_client(request = :url_encoded) ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'lib/voicebase/v1/client.rb', line 20 def new_http_client(request = :url_encoded) Faraday.new(url: VoiceBase::VOICEBASE_API_BASE_PATH) \ do |faraday| faraday.request request faraday.response :json faraday.response :logger # log requests to STDOUT faraday.adapter Faraday.default_adapter # make requests with Net::HTTP end end |
#upload_media(params = {}) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/voicebase/v1/client.rb', line 30 def upload_media(params = {}) params = { version: VOICEBASE_API_VERSION, apikey: @api_key, password: @password, action: 'uploadMedia', title: DateTime.now.strftime('%Y-%m-%d %I:%M:%S %p'), transcriptType: @transcript_type, desc: 'file description', recordedDate: DateTime.now.strftime('%Y-%m-%d %I:%M:%S'), collection: '', public: false, sourceUrl: '', lang: 'en', imageUrl: '' }.merge params if params.key?(:filePath) && params.key?(:fileContentType) params[:file] = Faraday::UploadIO.new( params[:filePath], params[:fileContentType] ) params.delete :filePath params.delete :fileContentType return @conn_multipart.post '/services', params else return @conn_url_encoded.post '/services', params end end |