Class: Call

Inherits:
Object
  • Object
show all
Defined in:
lib/voip.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ops_ip_address = nil, http_api_service_port = nil, username = nil, password = nil, call_id = nil, call_state = nil, source = nil, caller_id = nil, destination = nil, start_time = nil, ring_duration = nil, talk_duration = nil) ⇒ Call

Returns a new instance of Call.



217
218
219
220
221
222
223
224
225
226
227
228
229
230
# File 'lib/voip.rb', line 217

def initialize ops_ip_address=nil, http_api_service_port=nil, username=nil, password=nil, call_id=nil, call_state=nil, source=nil, caller_id=nil, destination=nil, start_time=nil, ring_duration=nil, talk_duration=nil
  @http_api_service_port = http_api_service_port || 7780
  @ops_ip_address = ops_ip_address || "localhost"
  @username = username
  @password = password
  @call_id = call_id || ""
  @call_state = call_state || ""
  @source = source || ""
  @caller_id = caller_id || ""
  @destination = destination || ""
  @start_time = start_time || ""
  @ring_duration = ring_duration || ""
  @talk_duration = talk_duration || ""
end

Instance Attribute Details

#call_idObject

Returns the value of attribute call_id.



232
233
234
# File 'lib/voip.rb', line 232

def call_id
  @call_id
end

#call_stateObject

Returns the value of attribute call_state.



232
233
234
# File 'lib/voip.rb', line 232

def call_state
  @call_state
end

#caller_idObject

Returns the value of attribute caller_id.



232
233
234
# File 'lib/voip.rb', line 232

def caller_id
  @caller_id
end

#destinationObject

Returns the value of attribute destination.



232
233
234
# File 'lib/voip.rb', line 232

def destination
  @destination
end

#ring_durationObject

Returns the value of attribute ring_duration.



232
233
234
# File 'lib/voip.rb', line 232

def ring_duration
  @ring_duration
end

#sourceObject

Returns the value of attribute source.



232
233
234
# File 'lib/voip.rb', line 232

def source
  @source
end

#start_timeObject

Returns the value of attribute start_time.



232
233
234
# File 'lib/voip.rb', line 232

def start_time
  @start_time
end

#talk_durationObject

Returns the value of attribute talk_duration.



232
233
234
# File 'lib/voip.rb', line 232

def talk_duration
  @talk_duration
end

Instance Method Details

#attended_transfer(target_call_id) ⇒ Object

If getting a call, you can put it on hold and call a 2nd number, then connect the call with the 2nd number using AttendedTransfer.



240
241
242
# File 'lib/voip.rb', line 240

def attended_transfer target_call_id
  execute_query "http://#{@ops_ip_address}:#{@http_api_service_port}/?Command=AttendedTransfer&TransferredCallId=#{@call_id}&TargetCallId=#{target_call_id}"
end

#blind_transfer_callee(target) ⇒ Object

Transfer the call during the conversation, and the callee will leave the conversation.



245
246
247
# File 'lib/voip.rb', line 245

def blind_transfer_callee target
  execute_query "http://#{@ops_ip_address}:#{@http_api_service_port}/?Command=BlindTransfer&CallId=#{@call_id}&TransferorParty=callee&Target=#{target}"
end

#blind_transfer_caller(target) ⇒ Object

Transfer the call during the conversation, and the caller will leave the conversation.



250
251
252
# File 'lib/voip.rb', line 250

def blind_transfer_caller target
  execute_query "http://#{@ops_ip_address}:#{@http_api_service_port}/?Command=BlindTransfer&CallId=#{@call_id}&TransferorParty=caller&Target=#{target}"
end

#dtmf(keys) ⇒ Object

Sends a DTMF message for both party.



297
298
299
# File 'lib/voip.rb', line 297

def dtmf keys
  execute_query "http://#{@ops_ip_address}:#{@http_api_service_port}/?Command=SendDTMF&CallId=#{@call_id}&Party=all&Keys=#{keys}"
end

#dtmf_to_callee(keys) ⇒ Object

Sends a DTMF message for the callee.



302
303
304
# File 'lib/voip.rb', line 302

def dtmf_to_callee keys
  execute_query "http://#{@ops_ip_address}:#{@http_api_service_port}/?Command=SendDTMF&CallId=#{@call_id}&Party=callee&Keys=#{keys}"
end

#dtmf_to_caller(keys) ⇒ Object

Sends a DTMF message for the caller.



307
308
309
# File 'lib/voip.rb', line 307

def dtmf_to_caller keys
  execute_query "http://#{@ops_ip_address}:#{@http_api_service_port}/?Command=SendDTMF&CallId=#{@call_id}&Party=caller&Keys=#{keys}"
end

#forward(destination) ⇒ Object

Forward a call by ID to another number if it can’t be answered.



255
256
257
# File 'lib/voip.rb', line 255

def forward destination
  execute_query "http://#{@ops_ip_address}:#{@http_api_service_port}/?Command=Forward&CallId=#{@call_id}&Destination=#{destination}"
end

#hangupObject

Terminates a call in progress by ID.



260
261
262
# File 'lib/voip.rb', line 260

def hangup
  execute_query "http://#{@ops_ip_address}:#{@http_api_service_port}/?Command=Hangup&CallId=#{@call_id}"
end

#holdObject

Puts both legs of the call from InCall state to Hold state by ID.



265
266
267
# File 'lib/voip.rb', line 265

def hold
  execute_query "http://#{@ops_ip_address}:#{@http_api_service_port}/?Command=Hold&CallId=#{@call_id}"
end

#play_file(filename, repeat = false) ⇒ Object

Plays an audio file (local or downloaded from URL) in an existing call for both party.



270
271
272
# File 'lib/voip.rb', line 270

def play_file filename, repeat=false
  execute_query "http://#{@ops_ip_address}:#{@http_api_service_port}/?Command=Play&CallId=#{@call_id}&Party=all&AudioFile=#{filename}&Repeat=#{repeat}"
end

#play_file_to_callee(filename, repeat = false) ⇒ Object

Plays an audio file (local or downloaded from URL) in an existing call for the callee.



275
276
277
# File 'lib/voip.rb', line 275

def play_file_to_callee filename, repeat=false
  execute_query "http://#{@ops_ip_address}:#{@http_api_service_port}/?Command=Play&CallId=#{@call_id}&Party=callee&AudioFile=#{filename}&Repeat=#{repeat}"
end

#play_file_to_caller(filename, repeat = false) ⇒ Object

Plays an audio file (local or downloaded from URL) in an existing call for the caller.



280
281
282
# File 'lib/voip.rb', line 280

def play_file_to_caller filename, repeat=false
  execute_query "http://#{@ops_ip_address}:#{@http_api_service_port}/?Command=Play&CallId=#{@call_id}&Party=caller&AudioFile=#{filename}&Repeat=#{repeat}"
end

#record_mp3(finished_url = "") ⇒ Object

Records a call in mp3 format.



285
286
287
288
# File 'lib/voip.rb', line 285

def record_mp3 finished_url=""
  finished_url ||= ""
  execute_query "http://#{@ops_ip_address}:#{@http_api_service_port}/?Command=Record&CallId=#{@call_id}&Format=mp3&FinishedUrl=#{finished_url}"
end

#record_wav(finished_url = "") ⇒ Object

Records a call in wav format.



291
292
293
294
# File 'lib/voip.rb', line 291

def record_wav finished_url=""
  finished_url ||= ""
  execute_query "http://#{@ops_ip_address}:#{@http_api_service_port}/?Command=Record&CallId=#{@call_id}&Format=wav&FinishedUrl=#{finished_url}"
end

#speak(message) ⇒ Object

Reads a text for both party using the text to speech engine into a call in progress.



312
313
314
315
# File 'lib/voip.rb', line 312

def speak message
  message = URI::encode message
  execute_query "http://#{@ops_ip_address}:#{@http_api_service_port}/?Command=Speak&CallId=#{@call_id}&Text=#{message}&Party=all"
end

#speak_to_callee(message) ⇒ Object

Reads a text for callee using the text to speech engine into a call in progress.



318
319
320
321
# File 'lib/voip.rb', line 318

def speak_to_callee message
  message = URI::encode message
  execute_query "http://#{@ops_ip_address}:#{@http_api_service_port}/?Command=Speak&CallId=#{@call_id}&Text=#{message}&Party=callee"
end

#speak_to_caller(message) ⇒ Object

Reads a text for caller using the text to speech engine into a call in progress.



324
325
326
327
# File 'lib/voip.rb', line 324

def speak_to_caller message
  message = URI::encode message
  execute_query "http://#{@ops_ip_address}:#{@http_api_service_port}/?Command=Speak&CallId=#{@call_id}&Text=#{message}&Party=caller"
end

#to_sObject



235
236
237
# File 'lib/voip.rb', line 235

def to_s
  caller_id + " => " + destination + " - " + call_id + "(" + call_state + ")"
end

#unholdObject

Puts both legs of the call to InCall state by ID.



330
331
332
# File 'lib/voip.rb', line 330

def unhold
  execute_query "http://#{@ops_ip_address}:#{@http_api_service_port}/?Command=Unhold&CallId=#{@call_id}"
end