Class: Plivo::Resources::CallInterface
- Inherits:
-
Base::ResourceInterface
- Object
- Base::ResourceInterface
- Plivo::Resources::CallInterface
- Defined in:
- lib/plivo/resources/calls.rb
Constant Summary
Constants included from Utils
Instance Method Summary collapse
- #cancel_request(call_uuid) ⇒ Object
-
#create(from, to, answer_url, options = nil) ⇒ Call
Makes an outbound call.
- #delete(call_uuid) ⇒ Object
- #each ⇒ Object
- #each_live ⇒ Object
- #each_queued ⇒ Object
-
#get(call_uuid) ⇒ Object
Get details of a call.
- #get_all_streams(call_uuid) ⇒ Object
- #get_live(call_uuid) ⇒ Object
- #get_queued(call_uuid) ⇒ Object
- #get_stream(call_uuid, stream_id) ⇒ Object
-
#initialize(client, resource_list_json = nil) ⇒ CallInterface
constructor
A new instance of CallInterface.
- #list(options = nil) ⇒ Object
- #list_live(options = nil) ⇒ Object
- #list_queued ⇒ 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
- #start_stream(call_uuid, service_url, options = {}) ⇒ Object
- #stop_all_streams(call_uuid) ⇒ Object
- #stop_play(call_uuid) ⇒ Object
- #stop_record(call_uuid, url = nil) ⇒ Object
- #stop_speak(call_uuid) ⇒ Object
- #stop_stream(call_uuid, stream_id) ⇒ Object
-
#update(call_uuid, details) ⇒ Call
Transfer a call.
Methods included from Utils
GetSortedQueryParamString?, compute_signatureV3?, expected_type?, expected_value?, generate_url?, getMapFromQueryString?, is_one_among_string_url?, multi_valid_param?, raise_invalid_request, valid_account?, valid_date_format?, valid_mainaccount?, valid_multiple_destination_integers?, valid_multiple_destination_nos?, valid_param?, valid_range?, valid_signature?, valid_signatureV3?, valid_subaccount?, valid_url?
Constructor Details
#initialize(client, resource_list_json = nil) ⇒ CallInterface
Returns a new instance of CallInterface.
324 325 326 327 328 329 330 |
# File 'lib/plivo/resources/calls.rb', line 324 def initialize(client, resource_list_json = nil) @_name = 'Call' @_resource_type = Call @_identifier_string = 'call_uuid' super @_is_voice_request = true end |
Instance Method Details
#cancel_request(call_uuid) ⇒ Object
656 657 658 659 |
# File 'lib/plivo/resources/calls.rb', line 656 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, options = nil) ⇒ Call
Makes an outbound call
360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 |
# File 'lib/plivo/resources/calls.rb', line 360 def create(from, to, answer_url, = 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) params = { from: from, to: to.join('<'), answer_url: answer_url, } return perform_create(params, false) if .nil? perform_create(params.merge(), false) end |
#delete(call_uuid) ⇒ Object
566 567 568 569 |
# File 'lib/plivo/resources/calls.rb', line 566 def delete(call_uuid) valid_param?(:call_uuid, call_uuid, [String, Symbol], true) Call.new(@_client, resource_id: call_uuid).delete end |
#each ⇒ Object
481 482 483 484 485 486 487 488 489 |
# File 'lib/plivo/resources/calls.rb', line 481 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
540 541 542 543 |
# File 'lib/plivo/resources/calls.rb', line 540 def each_live call_list = list_live call_list[:calls].each { |call| yield call } end |
#each_queued ⇒ Object
545 546 547 548 |
# File 'lib/plivo/resources/calls.rb', line 545 def each_queued call_queued = list_queued call_queued[:calls].each { |call| yield call} end |
#get(call_uuid) ⇒ Object
Get details of a call
383 384 385 386 |
# File 'lib/plivo/resources/calls.rb', line 383 def get(call_uuid) valid_param?(:call_uuid, call_uuid, [String, Symbol], true) perform_get(call_uuid) end |
#get_all_streams(call_uuid) ⇒ Object
688 689 690 691 692 693 694 |
# File 'lib/plivo/resources/calls.rb', line 688 def get_all_streams(call_uuid) valid_param?(:call_uuid, call_uuid, [String, Symbol], true ) response = Call.new(@_client, resource_id: call_uuid).get_all_streams return Base::Response.new(Hash["api_id" => response.api_id, "meta" => response., "objects" => response.objects]) end |
#get_live(call_uuid) ⇒ Object
389 390 391 |
# File 'lib/plivo/resources/calls.rb', line 389 def get_live(call_uuid) perform_get(call_uuid, status: 'live') end |
#get_queued(call_uuid) ⇒ Object
394 395 396 |
# File 'lib/plivo/resources/calls.rb', line 394 def get_queued(call_uuid) perform_get(call_uuid, status: 'queued') end |
#get_stream(call_uuid, stream_id) ⇒ Object
696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 |
# File 'lib/plivo/resources/calls.rb', line 696 def get_stream(call_uuid, stream_id) valid_param?(:call_uuid, call_uuid, [String, Symbol], true ) response = Call.new(@_client, resource_id: call_uuid).get_stream(stream_id) return Base::Response.new(Hash["api_id" => response.instance_variable_get(:@api_id), "audio_track" => response.instance_variable_get(:@audio_track), "bidirectional" => response.instance_variable_get(:@bidirectional), "bill_duration" => response.instance_variable_get(:@bill_duration), "billed_amount" => response.instance_variable_get(:@billed_amount), "call_uuid" => response.instance_variable_get(:@call_uuid), "created_at" => response.instance_variable_get(:@created_at), "end_time" => response.instance_variable_get(:@end_time), "plivo_auth_id" => response.instance_variable_get(:@plivo_auth_id), "resource_uri" => response.instance_variable_get(:@resource_uri), "rounded_bill_duration" => response.instance_variable_get(:@rounded_bill_duration), "service_url" => response.instance_variable_get(:@service_url), "start_time" => response.instance_variable_get(:@start_time), "status" => response.instance_variable_get(:@status), "status_callback_url" => response.instance_variable_get(:@status_callback_url), "stream_id" => response.instance_variable_get(:@stream_id)]) end |
#list(options = nil) ⇒ Object
426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 |
# File 'lib/plivo/resources/calls.rb', line 426 def list( = nil) return perform_list if .nil? valid_param?(:options, , Hash, true) 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 # initial list of possible params params = %i[ bill_duration bill_duration__gt bill_duration__gte bill_duration__lt bill_duration__lte call_direction end_time end_time__gt end_time__gte end_time__lt end_time__lte from_number hangup_cause_code hangup_source limit offset parent_call_uuid subaccount to_number stir_verification ].reduce({}) do |result_hash, param| if .key?(param) if param == :call_direction if valid_param?(:call_direction, [:call_direction], [String, Symbol], true, %w[inbound outbound]) result_hash[:call_direction] = [:call_direction] end elsif %i[offset limit hangup_cause_code].include?(param) if valid_param?(param, [param], [Integer, Integer], true) result_hash[param] = [param] end elsif valid_param?(param, [param], [String, Symbol], true) result_hash[param] = [param] end end result_hash end perform_list(params) end |
#list_live(options = nil) ⇒ Object
499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 |
# File 'lib/plivo/resources/calls.rb', line 499 def list_live( = nil) if .nil? = {} else valid_param?(:options, , Hash, true) end params = {} params[:status] = 'live' params_expected = %i[ from_number to_number ] 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 perform_list_without_object(params) { api_id: @api_id, calls: @calls } end |
#list_queued ⇒ Object
532 533 534 535 536 537 538 |
# File 'lib/plivo/resources/calls.rb', line 532 def list_queued perform_list_without_object(status: 'queued') { api_id: @api_id, calls: @calls } end |
#play(call_uuid, urls, options = nil) ⇒ Object
615 616 617 618 619 |
# File 'lib/plivo/resources/calls.rb', line 615 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
591 592 593 594 595 596 597 598 |
# File 'lib/plivo/resources/calls.rb', line 591 def record(call_uuid, = nil) valid_param?(:call_uuid, call_uuid, [String, Symbol], true) response = Call.new(@_client, resource_id: call_uuid).record() return Base::Response.new(Hash["api_id" => response.api_id, "recording_id" => response.recording_id, "message" => response., "url" => response.url]) end |
#send_digits(call_uuid, digits, leg = nil) ⇒ Object
650 651 652 653 |
# File 'lib/plivo/resources/calls.rb', line 650 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
636 637 638 639 |
# File 'lib/plivo/resources/calls.rb', line 636 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 |
#start_stream(call_uuid, service_url, options = {}) ⇒ Object
670 671 672 673 674 675 676 |
# File 'lib/plivo/resources/calls.rb', line 670 def start_stream(call_uuid, service_url, = {}) valid_param?(:call_uuid, call_uuid, [String, Symbol], true) response = Call.new(@_client, resource_id: call_uuid).start_stream(service_url, ) return Base::Response.new(Hash["api_id" => response.api_id, "stream_id" => response.stream_id, "message" => response.]) end |
#stop_all_streams(call_uuid) ⇒ Object
678 679 680 681 |
# File 'lib/plivo/resources/calls.rb', line 678 def stop_all_streams(call_uuid) valid_param?(:call_uuid, call_uuid, [String, Symbol], true ) Call.new(@_client, resource_id: call_uuid).stop_all_streams end |
#stop_play(call_uuid) ⇒ Object
622 623 624 625 |
# File 'lib/plivo/resources/calls.rb', line 622 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
602 603 604 605 |
# File 'lib/plivo/resources/calls.rb', line 602 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
642 643 644 645 |
# File 'lib/plivo/resources/calls.rb', line 642 def stop_speak(call_uuid) valid_param?(:call_uuid, call_uuid, [String, Symbol], true) Call.new(@_client, resource_id: call_uuid).stop_speak end |
#stop_stream(call_uuid, stream_id) ⇒ Object
683 684 685 686 |
# File 'lib/plivo/resources/calls.rb', line 683 def stop_stream(call_uuid, stream_id) valid_param?(:call_uuid, call_uuid, [String, Symbol], true ) Call.new(@_client, resource_id: call_uuid).stop_stream(stream_id) end |