Class: Twi::Call
Overview
The representation of an outbound phone call.
Direct Known Subclasses
Class Method Summary collapse
-
.params_for(id:, status:, digits: nil) ⇒ Hash
The shape of the payload send by Twilio to the callback URL.
Instance Method Summary collapse
-
#create ⇒ Object
Places the call, asking Twilio to fetch its instructions from
url. -
#digits ⇒ String?
Digits the callee pressed in answer to a Gather.
-
#id ⇒ String
Unique identifier.
-
#recipient ⇒ String
10-digit phone number being called.
-
#sender ⇒ String
10-digit phone number placing the call.
-
#status ⇒ String
no-answer, canceled, failed # TODO: make an enum.
Methods inherited from Resource
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.
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
#create ⇒ Object
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. end |
#digits ⇒ String?
Returns digits the callee pressed in answer to a Gather.
13 |
# File 'lib/twi/call.rb', line 13 def digits = @params['Digits'] |
#id ⇒ String
Returns unique identifier.
6 |
# File 'lib/twi/call.rb', line 6 def id = @params['CallSid'] |
#recipient ⇒ String
Returns 10-digit phone number being called.
19 |
# File 'lib/twi/call.rb', line 19 def recipient = remove_prefix_from @params['To'] |
#sender ⇒ String
Returns 10-digit phone number placing the call.
16 |
# File 'lib/twi/call.rb', line 16 def sender = remove_prefix_from @params['From'] |
#status ⇒ String
no-answer, canceled, failed # TODO: make an enum
10 |
# File 'lib/twi/call.rb', line 10 def status = @params['CallStatus'] |