class Voice
Constants
- HTTP_CREATED
- HTTP_OK
Public Class Methods
new(username, apikey)
click to toggle source
Set debug flag to to true to view response body
# File lib/AfricasTalking/Voice.rb, line 8 def initialize username, apikey @username = username @apikey = apikey end
Public Instance Methods
call(options)
click to toggle source
# File lib/AfricasTalking/Voice.rb, line 13 def call options if validateParamsPresence?(options, ['from', 'to']) post_body = { 'username' => @username, 'from' => options['from'], 'to' => options['to'], 'clientRequestId' => options['clientRequestId'] } # response = sendNormalRequest(getVoiceHost() + "/call", post_body) end if(@response_code == HTTP_OK || @response_code == HTTP_CREATED) ob = JSON.parse(response, :quirky_mode => true) # if (ob['entries'].length > 0) results = ob['entries'].collect{|result| CallEntries.new result['status'], result['phoneNumber'] } end return CallResponse.new results, ob['errorMessage'] # else raise AfricasTalkingException, response end end
fetchQueuedCalls(options)
click to toggle source
# File lib/AfricasTalking/Voice.rb, line 39 def fetchQueuedCalls options if validateParamsPresence?(options, ['phoneNumber']) post_body = { 'username' => @username, 'phoneNumbers' => options['phoneNumber'], } url = getVoiceHost() + "/queueStatus" response = sendNormalRequest(url, post_body) end # if(@response_code == HTTP_OK || @response_code == HTTP_CREATED) ob = JSON.parse(response, :quirky_mode => true) results = [] if (ob['entries'].length > 0) results = ob['entries'].collect{|result| QueuedCalls.new result['phoneNumber'], result['numCalls'], result['queueName'] } end # return QueuedCallsResponse.new ob['status'], ob['errorMessage'], results end raise AfricasTalkingException, response end
uploadMediaFile(options)
click to toggle source
# File lib/AfricasTalking/Voice.rb, line 66 def uploadMediaFile options if validateParamsPresence?(options, ['url','phoneNumber']) post_body = { 'username' => @username, 'url' => options['url'], 'phoneNumber' => options['phoneNumber'] } url = getVoiceHost() + "/mediaUpload" # response = sendNormalRequest(url, post_body) end if(@response_code == HTTP_OK || @response_code == HTTP_CREATED) return UploadMediaResponse.new response end # raise AfricasTalkingException, response end
Private Instance Methods
getVoiceHost()
click to toggle source
# File lib/AfricasTalking/Voice.rb, line 87 def getVoiceHost() if(@username == "sandbox") return "https://voice.sandbox.africastalking.com" else return "https://voice.africastalking.com" end end