Class: Twi::Call

Inherits:
Resource show all
Defined in:
lib/twi/call.rb

Overview

The representation of an outbound phone call.

Direct Known Subclasses

Mock::Call

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Resource

#initialize

Constructor Details

This class inherits a constructor from Twi::Resource

Class Method Details

.params_for(id:, status:, digits: nil) ⇒ Hash

Returns the shape of the payload send by Twilio to the callback URL.

Returns:

  • (Hash)

    the shape of the payload send by Twilio to the callback URL.



32
33
34
# File 'lib/twi/call.rb', line 32

def self.params_for(id:, status:, digits: nil)
  { CallSid: id, CallStatus: status, Digits: digits }.compact
end

Instance Method Details

#createObject

Places the call, asking Twilio to fetch its instructions from url.



22
23
24
25
26
27
28
29
# File 'lib/twi/call.rb', line 22

def create
  call = api_client.calls.create from: "+1#{@params[:sender]}", to: "+1#{@params[:recipient]}",
    url: @params[:url], method: 'GET', status_callback: @params[:status_callback]

  @params = { 'CallSid' => call.sid, 'CallStatus' => call.status }
rescue Twilio::REST::RestError => error
  raise Error, code: error.code, message: error.error_message
end

#digitsString?

Returns digits the callee pressed in answer to a Gather.

Returns:

  • (String, nil)

    digits the callee pressed in answer to a Gather.



13
# File 'lib/twi/call.rb', line 13

def digits = @params['Digits']

#idString

Returns unique identifier.

Returns:

  • (String)

    unique identifier



6
# File 'lib/twi/call.rb', line 6

def id = @params['CallSid']

#recipientString

Returns 10-digit phone number being called.

Returns:

  • (String)

    10-digit phone number being called.



19
# File 'lib/twi/call.rb', line 19

def recipient = remove_prefix_from @params['To']

#senderString

Returns 10-digit phone number placing the call.

Returns:

  • (String)

    10-digit phone number placing the call.



16
# File 'lib/twi/call.rb', line 16

def sender = remove_prefix_from @params['From']

#statusString

no-answer, canceled, failed # TODO: make an enum

Returns:

  • (String)

    call status, one of queued, ringing, in-progress, completed, busy,



10
# File 'lib/twi/call.rb', line 10

def status = @params['CallStatus']