Module: VoiceBase::V1::Client

Includes:
Helpers
Defined in:
lib/voicebase/v1/client.rb

Constant Summary collapse

TOKEN_TIMEOUT_IN_MS =
1440
PARAM_NORMALIZATION =
{"Url" => "URL", "Id" => "ID", "Callback" => "CallBack"}
ACTIONS =
['uploadMedia', 'getTranscript', 'deleteFile', 'getFileStatus']

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Helpers

included

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, args, &block) ⇒ Object

E.g. @client.upload_media media_url: “ut.aws.amazon.com/…”



29
30
31
32
33
34
35
# File 'lib/voicebase/v1/client.rb', line 29

def method_missing(method, args, &block)
  if actions.include?(camelize_name(method)) && args.size > 0
    post camelize_keys(args).merge({action: camelize_name(method)})
  else
    super
  end
end

Class Method Details

.extended(client, args = {}) ⇒ Object



10
11
12
13
# File 'lib/voicebase/v1/client.rb', line 10

def self.extended(client, args = {})
  client.api_host     = client.args[:api_host] || ENV.fetch('VOICEBASE_V1_API_HOST', 'https://api.voicebase.com')
  client.api_endpoint = client.args[:api_endpoint] || ENV.fetch('VOICEBASE_V1_API_ENDPOINT', '/services')
end

Instance Method Details

#authenticate!Object



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/voicebase/v1/client.rb', line 15

def authenticate!
  response = VoiceBase::Response.new(
    self.class.post(uri,
    query: {
      version: @api_version, apiKey: @auth_key,
      password: @auth_secret, action: 'getToken',
      timeout: TOKEN_TIMEOUT_IN_MS
    }), api_version)
  @token = Token.new(response.token, TOKEN_TIMEOUT_IN_MS)
rescue NoMethodError => ex
  raise VoiceBase::AuthenticationError, response.status_message
end