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
9 10 11 12 13 14 15 |
# File 'lib/voicebase/v1/client.rb', line 9 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
17 18 19 20 21 22 23 24 25 |
# File 'lib/voicebase/v1/client.rb', line 17 def new_http_client(request = :url_encoded) conn = Faraday.new(:url => VoiceBase::VOICEBASE_API_BASE_PATH) do |faraday| faraday.request request # multipart/form-data faraday.response :json faraday.response :logger # log requests to STDOUT faraday.adapter Faraday.default_adapter # make requests with Net::HTTP end return conn end |
#upload_media(params = {}) ⇒ Object
27 28 29 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 |
# File 'lib/voicebase/v1/client.rb', line 27 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 response = nil if params.key?(:filePath) && params.key?(:fileContentType) params[:file] = Faraday::UploadIO.new(params[:filePath], params[:fileContentType]) params.delete :filePath params.delete :fileContentType response = @conn_multipart.post '/services', params else response = @conn_url_encoded.post '/services', params end return response end |