Class: Plivo::Resources::CallInterface
- Inherits:
-
Base::ResourceInterface
- Object
- Base::ResourceInterface
- Plivo::Resources::CallInterface
- Defined in:
- lib/plivo/resources/calls.rb
Instance Method Summary collapse
- #cancel_request(call_uuid) ⇒ Object
-
#create(from, to, answer_url, answer_method = 'POST', options = nil) ⇒ Call
Makes an outbound call.
- #delete(call_uuid) ⇒ Object
- #each ⇒ Object
- #each_live ⇒ Object
-
#get(call_uuid) ⇒ Object
Get details of a call.
- #get_live(call_uuid) ⇒ Object
-
#initialize(client, resource_list_json = nil) ⇒ CallInterface
constructor
A new instance of CallInterface.
- #list(options = nil) ⇒ Object
- #list_live ⇒ Object
- #play(call_uuid, urls, options = nil) ⇒ Object
- #record(call_uuid, options = nil) ⇒ Object
- #send_digits(call_uuid, digits, leg = nil) ⇒ Object
- #speak(call_uuid, text, options = nil) ⇒ Object
- #stop_play(call_uuid) ⇒ Object
- #stop_record(call_uuid, url = nil) ⇒ Object
- #stop_speak(call_uuid) ⇒ Object
-
#update(call_uuid, details) ⇒ Call
Transfer a call.
Methods included from Utils
expected_type?, expected_value?, raise_invalid_request, valid_account?, valid_mainaccount?, valid_param?, valid_signature?, valid_subaccount?
Constructor Details
#initialize(client, resource_list_json = nil) ⇒ CallInterface
Returns a new instance of CallInterface.
228 229 230 231 232 233 |
# File 'lib/plivo/resources/calls.rb', line 228 def initialize(client, resource_list_json = nil) @_name = 'Call' @_resource_type = Call @_identifier_string = 'call_uuid' super end |
Instance Method Details
#cancel_request(call_uuid) ⇒ Object
487 488 489 490 |
# File 'lib/plivo/resources/calls.rb', line 487 def cancel_request(call_uuid) valid_param?(:call_uuid, call_uuid, [String, Symbol], true) Call.new(@_client, resource_id: call_uuid).cancel_request end |
#create(from, to, answer_url, answer_method = 'POST', options = nil) ⇒ Call
Makes an outbound call
264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 |
# File 'lib/plivo/resources/calls.rb', line 264 def create(from, to, answer_url, answer_method = 'POST', = nil) valid_param?(:from, from, [String, Symbol, Integer], true) valid_param?(:to, to, Array, true) to.each do |to_num| valid_param?(:to_num, to_num, [Integer, String, Symbol], true) end valid_param?(:answer_url, answer_url, [String, Symbol], true) valid_param?(:answer_method, answer_method, [String, Symbol], true, %w[GET POST]) params = { from: from, to: to.join('<'), answer_url: answer_url, answer_method: answer_method } return perform_create(params) if .nil? perform_create(params.merge()) end |
#delete(call_uuid) ⇒ Object
402 403 404 405 |
# File 'lib/plivo/resources/calls.rb', line 402 def delete(call_uuid) valid_param?(:call_uuid, call_uuid, [String, Symbol], true) Call.new(@_client, resource_id: call_uuid).delete end |
#each ⇒ Object
363 364 365 366 367 368 369 370 371 |
# File 'lib/plivo/resources/calls.rb', line 363 def each offset = 0 loop do call_list = list(offset: offset) call_list[:objects].each { |call| yield call } offset += 20 return unless call_list.length == 20 end end |
#each_live ⇒ Object
381 382 383 384 |
# File 'lib/plivo/resources/calls.rb', line 381 def each_live call_list = list_live call_list[:calls].each { |call| yield call } end |
#get(call_uuid) ⇒ Object
Get details of a call
289 290 291 292 |
# File 'lib/plivo/resources/calls.rb', line 289 def get(call_uuid) valid_param?(:call_uuid, call_uuid, [String, Symbol], true) perform_get(call_uuid) end |
#get_live(call_uuid) ⇒ Object
295 296 297 |
# File 'lib/plivo/resources/calls.rb', line 295 def get_live(call_uuid) perform_get(call_uuid, status: 'live') end |
#list(options = nil) ⇒ Object
324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 |
# File 'lib/plivo/resources/calls.rb', line 324 def list( = nil) return perform_list if .nil? valid_param?(:options, , Hash, true) params = {} params_expected = %i[ subaccount bill_duration bill_duration__gt bill_duration__gte bill_duration__lt bill_duration__lte end_time end_time__gt end_time__gte end_time__lt end_time__lte ] params_expected.each do |param| if .key?(param) && valid_param?(param, [param], [String, Symbol], true) params[param] = [param] end end if .key?(:call_direction) && valid_param?(:call_direction, [:call_direction], [String, Symbol], true, %w[inbound outbound]) params[:call_direction] = [:call_direction] end %i[offset limit].each do |param| if .key?(param) && valid_param?(param, [param], [Integer, Integer], true) params[param] = [param] end end raise_invalid_request("Offset can't be negative") if .key?(:offset) && [:offset] < 0 if .key?(:limit) && ([:limit] > 20 || [:limit] <= 0) raise_invalid_request('The maximum number of results that can be '\ "fetched is 20. limit can't be more than 20 or less than 1") end perform_list(params) end |
#list_live ⇒ Object
373 374 375 376 377 378 379 |
# File 'lib/plivo/resources/calls.rb', line 373 def list_live perform_list_without_object(status: 'live') { api_id: @api_id, calls: @calls } end |
#play(call_uuid, urls, options = nil) ⇒ Object
447 448 449 450 451 |
# File 'lib/plivo/resources/calls.rb', line 447 def play(call_uuid, urls, = nil) valid_param?(:call_uuid, call_uuid, [String, Symbol], true) valid_param?(:urls, urls, Array, true) Call.new(@_client, resource_id: call_uuid).play(urls, ) end |
#record(call_uuid, options = nil) ⇒ Object
427 428 429 430 |
# File 'lib/plivo/resources/calls.rb', line 427 def record(call_uuid, = nil) valid_param?(:call_uuid, call_uuid, [String, Symbol], true) Call.new(@_client, resource_id: call_uuid).record() end |
#send_digits(call_uuid, digits, leg = nil) ⇒ Object
481 482 483 484 |
# File 'lib/plivo/resources/calls.rb', line 481 def send_digits(call_uuid, digits, leg = nil) valid_param?(:call_uuid, call_uuid, [String, Symbol], true) Call.new(@_client, resource_id: call_uuid).send_digits(digits, leg) end |
#speak(call_uuid, text, options = nil) ⇒ Object
467 468 469 470 |
# File 'lib/plivo/resources/calls.rb', line 467 def speak(call_uuid, text, = nil) valid_param?(:call_uuid, call_uuid, [String, Symbol], true) Call.new(@_client, resource_id: call_uuid).speak(text, ) end |
#stop_play(call_uuid) ⇒ Object
454 455 456 457 |
# File 'lib/plivo/resources/calls.rb', line 454 def stop_play(call_uuid) valid_param?(:call_uuid, call_uuid, [String, Symbol], true) Call.new(@_client, resource_id: call_uuid).stop_play end |
#stop_record(call_uuid, url = nil) ⇒ Object
434 435 436 437 |
# File 'lib/plivo/resources/calls.rb', line 434 def stop_record(call_uuid, url = nil) valid_param?(:call_uuid, call_uuid, [String, Symbol], true) Call.new(@_client, resource_id: call_uuid).stop_record(url) end |
#stop_speak(call_uuid) ⇒ Object
473 474 475 476 |
# File 'lib/plivo/resources/calls.rb', line 473 def stop_speak(call_uuid) valid_param?(:call_uuid, call_uuid, [String, Symbol], true) Call.new(@_client, resource_id: call_uuid).stop_speak end |