class Moceansdk::Modules::Voice::Voice

Public Class Methods

new(obj_auth, transmitter) click to toggle source
Calls superclass method Moceansdk::Modules::AbstractClient::new
# File lib/moceansdk/modules/voice/voice.rb, line 6
def initialize(obj_auth, transmitter)
  super(obj_auth, transmitter)
  @required_fields = ['mocean-api-key', 'mocean-api-secret', 'mocean-to']
end

Public Instance Methods

call(params = {}) click to toggle source
# File lib/moceansdk/modules/voice/voice.rb, line 35
def call(params = {})
  sym_params = Moceansdk::Utils.convert_to_symbol_hash(params)

  unless sym_params[:'mocean-command'].nil?
    mc = sym_params[:'mocean-command']
    sym_params.delete(:'mocean-command')
    self.mocean_command = mc
  end

  create(sym_params)
  create_final_params
  required_field_set?

  @transmitter.post('/voice/dial', @params)
end
event_url=(param) click to toggle source
# File lib/moceansdk/modules/voice/voice.rb, line 15
def event_url=(param)
  @params['mocean-event-url'] = param
end
hangup(call_uuid) click to toggle source
# File lib/moceansdk/modules/voice/voice.rb, line 51
def hangup(call_uuid)
  @required_fields = ['mocean-api-key', 'mocean-api-secret', 'mocean-call-uuid']

  create({:'mocean-call-uuid' => call_uuid})
  create_final_params
  required_field_set?

  @transmitter.post("/voice/hangup", @params)
end
mocean_command=(param) click to toggle source
# File lib/moceansdk/modules/voice/voice.rb, line 19
def mocean_command=(param)
  if param.is_a? McBuilder
    @params['mocean-command'] = JSON.generate(param.build)
  elsif param.is_a? McObject::AbstractMc
    @params['mocean-command'] = JSON.generate([param.get_request_data])
  elsif param.is_a? Array
    @params['mocean-command'] = JSON.generate(param)
  else
    @params['mocean-command'] = param
  end
end
recording(call_uuid) click to toggle source
# File lib/moceansdk/modules/voice/voice.rb, line 61
def recording(call_uuid)
  @required_fields = ['mocean-api-key', 'mocean-api-secret', 'mocean-call-uuid']

  create({:'mocean-call-uuid' => call_uuid})
  create_final_params
  required_field_set?

  response = @transmitter.request('get', '/voice/rec', @params)

  if response['Content-Type'] === 'audio/mpeg'
    hashed_res = HashExtended.new.merge({'recording_buffer': response.to_s, 'filename': "#{call_uuid}.mp3"})
    return hashed_res.to_dot
  end

  # this method will raise exception if there's error
  processed_response = Moceansdk::Modules::ResponseFactory.create_object(response.to_s)
  processed_response.raw_response = response.to_s
  raise Moceansdk::Exceptions::MoceanError.new(processed_response['err_msg'], processed_response)
end
resp_format=(param) click to toggle source
# File lib/moceansdk/modules/voice/voice.rb, line 31
def resp_format=(param)
  @params['mocean-resp-format'] = param
end
to=(param) click to toggle source
# File lib/moceansdk/modules/voice/voice.rb, line 11
def to=(param)
  @params['mocean-to'] = param
end