Class: Telapi::Call

Inherits:
Resource
  • Object
show all
Defined in:
lib/telapi/call.rb

Overview

Wraps TelAPI Call functionality

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Resource

#attributes, #initialize

Methods included from Network

api_uri, default_options, delete, post, response_format

Constructor Details

This class inherits a constructor from Telapi::Resource

Class Method Details

.get(id) ⇒ Object

Returns a Telapi::Call object given its id See www.telapi.com/docs/api/rest/calls/view/



24
25
26
27
# File 'lib/telapi/call.rb', line 24

def get(id)
  response = Network.get(['Calls', id])
  Call.new(response)
end

.hangup(id, status = 'completed') ⇒ Object

Hangs up a call, returning a Telapi::Call object See www.telapi.com/docs/api/rest/calls/hangup/

Required params:

id

call id

status

completed



77
78
79
80
81
# File 'lib/telapi/call.rb', line 77

def hangup(id, status = 'completed')
  opts = { :Status => status }
  response = Network.post(['Calls', id], opts)
  Call.new(response)
end

.interrupt(id, url, method = 'POST', status = 'completed') ⇒ Object

Interrupts a call, returning a Telapi::Call object See www.telapi.com/docs/api/rest/calls/interrupt/

Required params:

id

call id

url

valid url

method

(POST) or GET

status

canceled or (completed)



65
66
67
68
69
# File 'lib/telapi/call.rb', line 65

def interrupt(id, url, method = 'POST', status = 'completed')
  opts = { :Url => url, :Method => method, :Status => status }
  response = Network.post(['Calls', id], opts)
  Call.new(response)
end

.list(optional_params = {}) ⇒ Object

Returns a resource collection containing Telapi::Call objects See www.telapi.com/docs/api/rest/calls/list/

Optional params is a hash containing:

To

phone number, e.g. 7325551234

From

phone number, e.g. 7325551234

Status

ringing, in-progress, queued, busy, no-answer, or failed

StartTime

date in the following format: YYYY-MM-DD

Page

integer greater than 0

PageSize

integer greater than 0

DisableFaxDirections

true or (false)



17
18
19
20
# File 'lib/telapi/call.rb', line 17

def list(optional_params = {})
  response = Network.get(['Calls'], optional_params)
  ResourceCollection.new(response, 'calls', self)
end

.make(to, from, url, optional_params = {}) ⇒ Object

Creates a call, returning a Telapi::Call object See www.telapi.com/docs/api/rest/calls/make/

Required params:

to

phone number, e.g. 7325551234

from

phone number, e.g. 7325551234

url

valid url

Optional params is a hash containing:

ForwardedFrom

phone number, e.g. 7325551234

Method

(POST) or GET

FallbackUrl

valid URL

FallbackMethod

(POST) or GET

StatusCallback

valid URL

StatusCallbackMethod

(POST) or GET

SendDigits

0-9, #, or *

Timeout

integer greater than or equal to 0 (default: 60)

HideCallerId

true or (false)

StraightToVoicemail

true or (false)

IfMachine

redirect, hangup, or (continue)

IfMachineUrl

valid URL

IfMachineMethod

(POST) or GET



51
52
53
54
55
# File 'lib/telapi/call.rb', line 51

def make(to, from, url, optional_params = {})
  opts = { :To => to, :From => from, :Url => url }.merge(optional_params)
  response = Network.post(['Calls'], opts)
  Call.new(response)
end

.notifications(id, optional_params = {}) ⇒ Object

Returns a resource collection containing Telapi::Notification objects See www.telapi.com/docs/api/rest/notifications/list/

Required params:

id

call id

Optional params is a hash containing:

Log

0 (error), 1 (warning), or 2 (info)

Page

integer greater than 0

PageSize

integer greater than 0



172
173
174
175
# File 'lib/telapi/call.rb', line 172

def notifications(id, optional_params = {})
  response = Network.get(['Calls', id, 'Notifications'], optional_params)
  ResourceCollection.new(response, 'notifications', Notification)
end

.play_audio(id, sound_url, optional_params = {}) ⇒ Object

Play audio file during call, returning a Telapi::Call object See www.telapi.com/docs/api/rest/calls/play-audio/

Required params:

id

call id

sound_url

valid URL

Optional params is a hash containing:

Length

integer greater than or equal to 0

Legs

aleg, bleg, or (both)

Loop

true or (false)

Mix

true or (false)



108
109
110
111
112
# File 'lib/telapi/call.rb', line 108

def play_audio(id, sound_url, optional_params = {})
  opts = { :Sounds => sound_url }.merge(optional_params)
  response = Network.post(['Calls', id, 'Play'], opts)
  Call.new(response)
end

.record(id, record = true, optional_params = {}) ⇒ Object

Initiate or end a call recording, returning a Telapi::Call object See www.telapi.com/docs/api/rest/calls/record/

Required params:

id

call id

record

(true) or false

Optional params is a hash containing:

TimeLimit

integer greater than or equal to 0

CallbackUrl

valid URL



141
142
143
144
145
# File 'lib/telapi/call.rb', line 141

def record(id, record = true, optional_params = {})
  opts = { :Record => record }.merge(optional_params)
  response = Network.post(['Calls', id, 'Recordings'], opts)
  Call.new(response)
end

.recordings(id, optional_params = {}) ⇒ Object

Returns a resource collection containing Telapi::Recording objects See www.telapi.com/docs/api/rest/recordings/list/

Required params:

id

call id

Optional params is a hash containing:

DateCreated

date in the following format: YYYY-MM-DD

Page

integer greater than 0

PageSize

integer greater than 0



157
158
159
160
# File 'lib/telapi/call.rb', line 157

def recordings(id, optional_params = {})
  response = Network.get(['Calls', id, 'Recordings'], optional_params)
  ResourceCollection.new(response, 'recordings', Recording)
end

.send_digits(id, play_dtmf, play_dtmf_leg = 'aleg') ⇒ Object

Sends touch tones during call, returning a Telapi::Call object See www.telapi.com/docs/api/rest/calls/send-digits/

Required params:

id

call id

play_dtmf

0-9, W, or w

play_dtmf_leg

aleg or bleg



90
91
92
93
94
# File 'lib/telapi/call.rb', line 90

def send_digits(id, play_dtmf, play_dtmf_leg = 'aleg')
  opts = { :PlayDtmf => play_dtmf, :PlayDtmfLeg => play_dtmf_leg }
  response = Network.post(['Calls', id], opts)
  Call.new(response)
end

.voice_effect(id, optional_params = {}) ⇒ Object

Change caller’s voice via speed and pitch of audio, returning a Telapi::Call object See www.telapi.com/docs/api/rest/calls/voice-effects/

Required params:

id

call id

Optional params is a hash containing:

AudioDirection

in or (out)

Pitch

value between -1 and 1, including 0

PitchSemiTones

value between -14 and 14, including 0

PitchOctaves

value between -1 and 1, including 0

Rate

value between -1 and 1, including 0



126
127
128
129
# File 'lib/telapi/call.rb', line 126

def voice_effect(id, optional_params = {})
  response = Network.post(['Calls', id, 'Effect'], optional_params)
  Call.new(response)
end

Instance Method Details

#hangup(status = 'completed') ⇒ Object

See ::hangup



184
185
186
# File 'lib/telapi/call.rb', line 184

def hangup(status = 'completed')
  self.class.hangup(self.sid, status)
end

#interrupt(url, method = 'POST', status = 'completed') ⇒ Object

See ::interrupt



179
180
181
# File 'lib/telapi/call.rb', line 179

def interrupt(url, method = 'POST', status = 'completed')
  self.class.interrupt(self.sid, url, method, status)
end

#notifications(optional_params = {}) ⇒ Object

See ::notifications



214
215
216
# File 'lib/telapi/call.rb', line 214

def notifications(optional_params = {})
  self.class.notifications(self.sid, optional_params)
end

#play_audio(sound_url, optional_params = {}) ⇒ Object

See ::play_audio



194
195
196
# File 'lib/telapi/call.rb', line 194

def play_audio(sound_url, optional_params = {})
  self.class.play_audio(self.sid, sound_url, optional_params)
end

#record(record = true, optional_params = {}) ⇒ Object

See ::record



204
205
206
# File 'lib/telapi/call.rb', line 204

def record(record = true, optional_params = {})
  self.class.record(self.sid, record, optional_params)
end

#recordings(optional_params = {}) ⇒ Object

See ::recordings



209
210
211
# File 'lib/telapi/call.rb', line 209

def recordings(optional_params = {})
  self.class.recordings(self.sid, optional_params)
end

#send_digits(play_dtmf, play_dtmf_leg = 'aleg') ⇒ Object

See ::send_digits



189
190
191
# File 'lib/telapi/call.rb', line 189

def send_digits(play_dtmf, play_dtmf_leg = 'aleg')
  self.class.send_digits(self.sid, play_dtmf, play_dtmf_leg)
end

#voice_effect(optional_params = {}) ⇒ Object

See ::voice_effect



199
200
201
# File 'lib/telapi/call.rb', line 199

def voice_effect(optional_params = {})
  self.class.voice_effect(self.sid, optional_params)
end