telapi 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +20 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +162 -0
- data/Rakefile +1 -0
- data/lib/telapi.rb +24 -0
- data/lib/telapi/account.rb +14 -0
- data/lib/telapi/application.rb +88 -0
- data/lib/telapi/available_phone_number.rb +24 -0
- data/lib/telapi/call.rb +214 -0
- data/lib/telapi/caller_id.rb +16 -0
- data/lib/telapi/carrier.rb +16 -0
- data/lib/telapi/conference.rb +206 -0
- data/lib/telapi/configuration.rb +40 -0
- data/lib/telapi/error.rb +22 -0
- data/lib/telapi/fraud.rb +79 -0
- data/lib/telapi/inbound_xml.rb +36 -0
- data/lib/telapi/incoming_phone_number.rb +86 -0
- data/lib/telapi/message.rb +47 -0
- data/lib/telapi/network.rb +50 -0
- data/lib/telapi/notification.rb +29 -0
- data/lib/telapi/recording.rb +69 -0
- data/lib/telapi/resource.rb +18 -0
- data/lib/telapi/resource_collection.rb +38 -0
- data/lib/telapi/transcription.rb +44 -0
- data/lib/telapi/version.rb +3 -0
- data/spec/spec_helper.rb +17 -0
- data/spec/support/telapi_helpers.rb +38 -0
- data/spec/telapi/account_spec.rb +17 -0
- data/spec/telapi/application_spec.rb +69 -0
- data/spec/telapi/available_phone_number_spec.rb +27 -0
- data/spec/telapi/call_spec.rb +173 -0
- data/spec/telapi/caller_id_spec.rb +17 -0
- data/spec/telapi/carrier_spec.rb +17 -0
- data/spec/telapi/conference_spec.rb +174 -0
- data/spec/telapi/configuration_spec.rb +38 -0
- data/spec/telapi/error_spec.rb +32 -0
- data/spec/telapi/fraud_spec.rb +55 -0
- data/spec/telapi/inbound_xml_spec.rb +49 -0
- data/spec/telapi/incoming_phone_number_spec.rb +69 -0
- data/spec/telapi/message_spec.rb +41 -0
- data/spec/telapi/network_spec.rb +80 -0
- data/spec/telapi/notification_spec.rb +34 -0
- data/spec/telapi/recording_spec.rb +72 -0
- data/spec/telapi/resource_collection_spec.rb +64 -0
- data/spec/telapi/resource_spec.rb +25 -0
- data/spec/telapi/transcription_spec.rb +41 -0
- data/telapi-ruby.gemspec +32 -0
- metadata +227 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Phil Misiowiec
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,162 @@
|
|
1
|
+
# Telapi::Ruby
|
2
|
+
|
3
|
+
See www.telapi.com to signup for TelAPI.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'telapi'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install telapi
|
18
|
+
|
19
|
+
## Authentication and Configuration
|
20
|
+
|
21
|
+
Every API request requires a valid *account_sid* and *auth_token*. By default these are set to *nil*, so your application
|
22
|
+
should set them in its configuration (e.g. Ruby on Rails initializer).
|
23
|
+
|
24
|
+
For example:
|
25
|
+
|
26
|
+
Telapi.config do |config|
|
27
|
+
config.account_sid = 'abc123'
|
28
|
+
config.auth_token = 'xyz567'
|
29
|
+
end
|
30
|
+
|
31
|
+
You can also set individual settings directly:
|
32
|
+
|
33
|
+
Telapi.config.ssl_ca_path = '/some/path'
|
34
|
+
|
35
|
+
Inspecting the current configuration returns a hash:
|
36
|
+
|
37
|
+
p Telapi.config # (or Telapi.config.inspect)
|
38
|
+
#=> {:base_uri=>"https://api.telapi.com/2011-07-01/", :ssl_ca_path=>"/some/path", :account_sid=>'abc123', :auth_token=>'xyz567'}
|
39
|
+
|
40
|
+
## Design
|
41
|
+
|
42
|
+
Minimal code is needed to retrieve objects and perform operations. There's no need to instantiate a client object -- work directly with the desired classes.
|
43
|
+
|
44
|
+
Most classes provide identically named class and instance methods for ultimate flexibility. For example, to hang up an existing call, you can call either of the following:
|
45
|
+
|
46
|
+
call = Telapi::Call.get('123abc')
|
47
|
+
call.hangup
|
48
|
+
|
49
|
+
# avoids an additional network request
|
50
|
+
Telapi::Call.hangup('123abc')
|
51
|
+
|
52
|
+
Individual objects are wrapped into a Resource instance, which exposes all of the attributes documented in the [TelAPI documentation](http://www.telapi.com/docs/) as accessors and avoids the need to deal with direct JSON responses in your application code. A convenient *attributes* method allows you to dump out the object's values.
|
53
|
+
|
54
|
+
Telapi::Account.get.attributes
|
55
|
+
# => { ...hash of keys and values... }
|
56
|
+
|
57
|
+
Methods that return collections wrap Resource objects in a Resource Collection instance, which behaves similar to an Array, but also includes meta info about totals, page size, current page, etc.
|
58
|
+
|
59
|
+
## Documentation
|
60
|
+
|
61
|
+
Detailed documentation can be found at [RubyDoc](http://rubydoc.info/gems/telapi/) and [the official TelAPI documentation site](http://www.telapi.com/docs/).
|
62
|
+
|
63
|
+
## Usage Examples - REST API
|
64
|
+
|
65
|
+
Refer to the documentation for more examples.
|
66
|
+
|
67
|
+
### Get account details
|
68
|
+
|
69
|
+
acct = Telapi::Account.get
|
70
|
+
acct.friendly_name # => "My Account"
|
71
|
+
acct.account_balance # => "25.000"
|
72
|
+
|
73
|
+
### Get available numbers
|
74
|
+
|
75
|
+
numbers = Telapi::AvailablePhoneNumber.list('US', :AreaCode => '805')
|
76
|
+
numbers.each { |n| puts n.phone_number }
|
77
|
+
# => +18052585701
|
78
|
+
# +18052585702
|
79
|
+
|
80
|
+
### Get list of calls
|
81
|
+
|
82
|
+
Telapi::Call.list # => returns ResouceCollection of Telapi::Call objects
|
83
|
+
|
84
|
+
### Make a call
|
85
|
+
|
86
|
+
Telapi::Call.make('12223334444', '13334445555', 'http://mycallback...')
|
87
|
+
|
88
|
+
### Record a call
|
89
|
+
|
90
|
+
call = Telapi::Call.get('123abc')
|
91
|
+
call.record
|
92
|
+
|
93
|
+
# or invoke the class method to avoid an additional network request
|
94
|
+
Telapi::Call.record('123abc')
|
95
|
+
|
96
|
+
### Send an SMS message
|
97
|
+
|
98
|
+
Telapi::Message.create('12223334444', '13334445555', 'Hey you')
|
99
|
+
|
100
|
+
### Transcribe audio
|
101
|
+
|
102
|
+
Telapi::Transcription.transcribe_audio('http://some-audio-url')
|
103
|
+
|
104
|
+
### Caller ID
|
105
|
+
|
106
|
+
Telapi::CallerId.lookup('12223334444')
|
107
|
+
|
108
|
+
## Usage Examples - Inbound XML
|
109
|
+
|
110
|
+
### Say
|
111
|
+
|
112
|
+
ix = Telapi::InboundXml.new do
|
113
|
+
Say('Hello.', :loop => 3, :voice => 'man')
|
114
|
+
Say('Hello, my name is Jane.', :voice => 'woman')
|
115
|
+
Say('Now I will not stop talking.', :loop => 0)
|
116
|
+
end
|
117
|
+
|
118
|
+
ix.response
|
119
|
+
|
120
|
+
# results in the following XML:
|
121
|
+
# <?xml version="1.0"?>
|
122
|
+
# <Response>
|
123
|
+
# <Say loop="3" voice="man">Hello.</Say>
|
124
|
+
# <Say voice="woman">Hello, my name is Jane.</Say>
|
125
|
+
# <Say loop="0">Now I will not stop talking.</Say>
|
126
|
+
# </Response>
|
127
|
+
|
128
|
+
### Play
|
129
|
+
|
130
|
+
Telapi::InboundXml.new { Play('http://example.com/hello.mp3', :loop => 3) }
|
131
|
+
|
132
|
+
### Gather
|
133
|
+
|
134
|
+
Telapi::InboundXml.new do
|
135
|
+
Gather(:action => 'http://example.com/example-callback-url/say?example=simple.xml',
|
136
|
+
:method => 'GET',
|
137
|
+
:numDigits => '4',
|
138
|
+
:finishOnKey => '#') {
|
139
|
+
Say 'Please enter your 4 digit pin.'
|
140
|
+
}
|
141
|
+
end
|
142
|
+
|
143
|
+
### SMS Response
|
144
|
+
|
145
|
+
Telapi::InboundXml.new do
|
146
|
+
Sms(
|
147
|
+
'Test message sent from TelAPI!',
|
148
|
+
:action => 'http://liveoutput.com/telapi-test-sms-action',
|
149
|
+
:method => 'POST',
|
150
|
+
:from => '1112223333',
|
151
|
+
:to => '3334445555',
|
152
|
+
:statusCallback => 'http://liveoutput.com/telapi-test-status-callback'
|
153
|
+
)
|
154
|
+
end
|
155
|
+
|
156
|
+
## Contributing
|
157
|
+
|
158
|
+
1. Fork it
|
159
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
160
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
161
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
162
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/lib/telapi.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'telapi/version'
|
2
|
+
|
3
|
+
require 'telapi/error'
|
4
|
+
require 'telapi/configuration'
|
5
|
+
require 'telapi/network'
|
6
|
+
|
7
|
+
require 'telapi/resource'
|
8
|
+
require 'telapi/resource_collection'
|
9
|
+
|
10
|
+
require 'telapi/account'
|
11
|
+
require 'telapi/application'
|
12
|
+
require 'telapi/available_phone_number'
|
13
|
+
require 'telapi/call'
|
14
|
+
require 'telapi/caller_id'
|
15
|
+
require 'telapi/carrier'
|
16
|
+
require 'telapi/conference'
|
17
|
+
require 'telapi/fraud'
|
18
|
+
require 'telapi/incoming_phone_number'
|
19
|
+
require 'telapi/message'
|
20
|
+
require 'telapi/notification'
|
21
|
+
require 'telapi/recording'
|
22
|
+
require 'telapi/transcription'
|
23
|
+
|
24
|
+
require 'telapi/inbound_xml'
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Telapi
|
2
|
+
# Wraps TelAPI Account functionality
|
3
|
+
class Account < Resource
|
4
|
+
class << self
|
5
|
+
|
6
|
+
# Gets current Telapi account as a Telapi::Account object
|
7
|
+
# See http://www.telapi.com/docs/api/rest/accounts/view/
|
8
|
+
def get
|
9
|
+
Account.new(Network.get)
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
module Telapi
|
2
|
+
# Wraps TelAPI Application functionality
|
3
|
+
class Application < Resource
|
4
|
+
class << self
|
5
|
+
|
6
|
+
# Returns a resource collection containing Telapi::Application objects
|
7
|
+
# See http://www.telapi.com/docs/api/rest/applications/list/
|
8
|
+
#
|
9
|
+
# Optional params is a hash containing:
|
10
|
+
# +FriendlyName+:: string
|
11
|
+
# +Page+:: integer greater than 0
|
12
|
+
# +PageSize+:: integer greater than 0
|
13
|
+
def list(optional_params = {})
|
14
|
+
response = Network.get(['Applications'], optional_params)
|
15
|
+
ResourceCollection.new(response, 'applications', self)
|
16
|
+
end
|
17
|
+
|
18
|
+
# Returns a Telapi::Application object given its id
|
19
|
+
# See http://www.telapi.com/docs/api/rest/applications/view/
|
20
|
+
def get(id)
|
21
|
+
response = Network.get(['Applications', id])
|
22
|
+
Application.new(response)
|
23
|
+
end
|
24
|
+
|
25
|
+
# Creates an application, returning a Telapi::Application object
|
26
|
+
# See http://www.telapi.com/docs/api/rest/applications/create/
|
27
|
+
#
|
28
|
+
# Required params:
|
29
|
+
# +name+:: string
|
30
|
+
#
|
31
|
+
# Optional params is a hash containing:
|
32
|
+
# +VoiceUrl+:: valid URL
|
33
|
+
# +VoiceMethod+:: (POST) or GET
|
34
|
+
# +VoiceFallbackUrl+:: valid URL
|
35
|
+
# +VoiceFallbackMethod+:: (POST) or GET
|
36
|
+
# +VoiceCallerIdLookup+:: true or (false)
|
37
|
+
# +SmsUrl+:: valid URL
|
38
|
+
# +SmsMethod+:: (POST) or GET
|
39
|
+
# +SmsFallbackUrl+:: valid URL
|
40
|
+
# +SmsFallbackMethod+:: (POST) or GET
|
41
|
+
# +HeartbeatUrl+:: valid URL
|
42
|
+
# +HeartbeatMethod+:: (POST) or GET
|
43
|
+
# +StatusCallback+:: valid URL
|
44
|
+
# +StatusCallbackMethod+:: (POST) or GET
|
45
|
+
def create(name, optional_params = {})
|
46
|
+
opts = { :FriendlyName => name }.merge(optional_params)
|
47
|
+
response = Network.post(['Applications'], opts)
|
48
|
+
Application.new(response)
|
49
|
+
end
|
50
|
+
|
51
|
+
# Updates an application, returning a Telapi::Application object
|
52
|
+
# See http://www.telapi.com/docs/api/rest/applications/update/
|
53
|
+
#
|
54
|
+
# Required params:
|
55
|
+
# +id+:: application id
|
56
|
+
#
|
57
|
+
# Optional params is a hash supporting same options under ::create
|
58
|
+
# in addition to:
|
59
|
+
# +FriendlyName+:: string
|
60
|
+
def update(id, optional_params = {})
|
61
|
+
response = Network.post(['Applications', id], optional_params)
|
62
|
+
Application.new(response)
|
63
|
+
end
|
64
|
+
|
65
|
+
# Deletes an application, returning a Telapi::Application object
|
66
|
+
# See http://www.telapi.com/docs/api/rest/applications/delete/
|
67
|
+
#
|
68
|
+
# Required params:
|
69
|
+
# +id+:: application id
|
70
|
+
def delete(id)
|
71
|
+
response = Network.delete(['Applications', id])
|
72
|
+
Application.new(response)
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
|
77
|
+
# See ::update
|
78
|
+
def update(optional_params = {})
|
79
|
+
self.class.update(self.sid, optional_params)
|
80
|
+
end
|
81
|
+
|
82
|
+
# See ::delete
|
83
|
+
def delete(optional_params = {})
|
84
|
+
self.class.delete(self.sid)
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
88
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Telapi
|
2
|
+
# Wraps TelAPI Available Phone Number functionality
|
3
|
+
class AvailablePhoneNumber < Resource
|
4
|
+
class << self
|
5
|
+
|
6
|
+
# Returns a resource collection containing Telapi::AvailablePhoneNumber objects
|
7
|
+
# See http://www.telapi.com/docs/api/rest/available-phone-numbers/list/
|
8
|
+
#
|
9
|
+
# Required params:
|
10
|
+
# +country_code_iso+:: country code (ISO), see http://en.wikipedia.org/wiki/ISO_3166-1_alpha-2
|
11
|
+
#
|
12
|
+
# Optional params is a hash containing:
|
13
|
+
# +AreaCode+:: valid area code, e.g. 415
|
14
|
+
# +Contains+:: 0-9, lower and upper case letters of the alphabet (Aa-Zz), or *
|
15
|
+
# +InRegion+:: valid region (state or province) abbreviation
|
16
|
+
# +InPostalCode+:: valid postal code
|
17
|
+
def list(country_code_iso, optional_params = {})
|
18
|
+
response = Network.get(['AvailablePhoneNumbers', country_code_iso, 'Local'], optional_params)
|
19
|
+
ResourceCollection.new(response, 'available_phone_numbers', self)
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/lib/telapi/call.rb
ADDED
@@ -0,0 +1,214 @@
|
|
1
|
+
module Telapi
|
2
|
+
# Wraps TelAPI Call functionality
|
3
|
+
class Call < Resource
|
4
|
+
class << self
|
5
|
+
|
6
|
+
# Returns a resource collection containing Telapi::Call objects
|
7
|
+
# See http://www.telapi.com/docs/api/rest/calls/list/
|
8
|
+
#
|
9
|
+
# Optional params is a hash containing:
|
10
|
+
# +To+:: phone number, e.g. 7325551234
|
11
|
+
# +From+:: phone number, e.g. 7325551234
|
12
|
+
# +Status+:: ringing, in-progress, queued, busy, no-answer, or failed
|
13
|
+
# +StartTime+:: date in the following format: YYYY-MM-DD
|
14
|
+
# +Page+:: integer greater than 0
|
15
|
+
# +PageSize+:: integer greater than 0
|
16
|
+
def list(optional_params = {})
|
17
|
+
response = Network.get(['Calls'], optional_params)
|
18
|
+
ResourceCollection.new(response, 'calls', self)
|
19
|
+
end
|
20
|
+
|
21
|
+
# Returns a Telapi::Call object given its id
|
22
|
+
# See http://www.telapi.com/docs/api/rest/calls/view/
|
23
|
+
def get(id)
|
24
|
+
response = Network.get(['Calls', id])
|
25
|
+
Call.new(response)
|
26
|
+
end
|
27
|
+
|
28
|
+
# Creates a call, returning a Telapi::Call object
|
29
|
+
# See http://www.telapi.com/docs/api/rest/calls/make/
|
30
|
+
#
|
31
|
+
# Required params:
|
32
|
+
# +to+:: phone number, e.g. 7325551234
|
33
|
+
# +from+:: phone number, e.g. 7325551234
|
34
|
+
# +url+:: valid url
|
35
|
+
#
|
36
|
+
# Optional params is a hash containing:
|
37
|
+
# +ForwardedFrom+:: phone number, e.g. 7325551234
|
38
|
+
# +Method+:: (POST) or GET
|
39
|
+
# +FallbackUrl+:: valid URL
|
40
|
+
# +FallbackMethod+:: (POST) or GET
|
41
|
+
# +StatusCallback+:: valid URL
|
42
|
+
# +StatusCallbackMethod+:: (POST) or GET
|
43
|
+
# +SendDigits+:: 0-9, #, or *
|
44
|
+
# +Timeout+:: integer greater than or equal to 0 (default: 60)
|
45
|
+
# +HideCallerId+:: true or (false)
|
46
|
+
def make(to, from, url, optional_params = {})
|
47
|
+
opts = { :To => to, :From => from, :Url => url }.merge(optional_params)
|
48
|
+
response = Network.post(['Calls'], opts)
|
49
|
+
Call.new(response)
|
50
|
+
end
|
51
|
+
|
52
|
+
# Interrupts a call, returning a Telapi::Call object
|
53
|
+
# See http://www.telapi.com/docs/api/rest/calls/interrupt/
|
54
|
+
#
|
55
|
+
# Required params:
|
56
|
+
# +id+:: call id
|
57
|
+
# +url+:: valid url
|
58
|
+
# +method+:: (POST) or GET
|
59
|
+
# +status+:: canceled or (completed)
|
60
|
+
def interrupt(id, url, method = 'POST', status = 'completed')
|
61
|
+
opts = { :Url => url, :Method => method, :Status => status }
|
62
|
+
response = Network.post(['Calls', id], opts)
|
63
|
+
Call.new(response)
|
64
|
+
end
|
65
|
+
|
66
|
+
# Hangs up a call, returning a Telapi::Call object
|
67
|
+
# See http://www.telapi.com/docs/api/rest/calls/hangup/
|
68
|
+
#
|
69
|
+
# Required params:
|
70
|
+
# +id+:: call id
|
71
|
+
# +status+:: completed
|
72
|
+
def hangup(id, status = 'completed')
|
73
|
+
opts = { :Status => status }
|
74
|
+
response = Network.post(['Calls', id], opts)
|
75
|
+
Call.new(response)
|
76
|
+
end
|
77
|
+
|
78
|
+
# Sends touch tones during call, returning a Telapi::Call object
|
79
|
+
# See http://www.telapi.com/docs/api/rest/calls/send-digits/
|
80
|
+
#
|
81
|
+
# Required params:
|
82
|
+
# +id+:: call id
|
83
|
+
# +play_dtmf+:: 0-9, W, or w
|
84
|
+
# +play_dtmf_leg+:: aleg or bleg
|
85
|
+
def send_digits(id, play_dtmf, play_dtmf_leg = 'aleg')
|
86
|
+
opts = { :PlayDtmf => play_dtmf, :PlayDtmfLeg => play_dtmf_leg }
|
87
|
+
response = Network.post(['Calls', id], opts)
|
88
|
+
Call.new(response)
|
89
|
+
end
|
90
|
+
|
91
|
+
# Play audio file during call, returning a Telapi::Call object
|
92
|
+
# See http://www.telapi.com/docs/api/rest/calls/play-audio/
|
93
|
+
#
|
94
|
+
# Required params:
|
95
|
+
# +id+:: call id
|
96
|
+
# +sound_url+:: valid URL
|
97
|
+
#
|
98
|
+
# Optional params is a hash containing:
|
99
|
+
# +Length+:: integer greater than or equal to 0
|
100
|
+
# +Legs+:: aleg, bleg, or (both)
|
101
|
+
# +Loop+:: true or (false)
|
102
|
+
# +Mix+:: true or (false)
|
103
|
+
def play_audio(id, sound_url, optional_params = {})
|
104
|
+
opts = { :Sounds => sound_url }.merge(optional_params)
|
105
|
+
response = Network.post(['Calls', id, 'Play'], opts)
|
106
|
+
Call.new(response)
|
107
|
+
end
|
108
|
+
|
109
|
+
# Change caller's voice via speed and pitch of audio, returning a Telapi::Call object
|
110
|
+
# See http://www.telapi.com/docs/api/rest/calls/voice-effects/
|
111
|
+
#
|
112
|
+
# Required params:
|
113
|
+
# +id+:: call id
|
114
|
+
#
|
115
|
+
# Optional params is a hash containing:
|
116
|
+
# +AudioDirection+:: in or (out)
|
117
|
+
# +Pitch+:: value between -1 and 1, including 0
|
118
|
+
# +PitchSemiTones+:: value between -14 and 14, including 0
|
119
|
+
# +PitchOctaves+:: value between -1 and 1, including 0
|
120
|
+
# +Rate+:: value between -1 and 1, including 0
|
121
|
+
def voice_effect(id, optional_params = {})
|
122
|
+
response = Network.post(['Calls', id, 'Effect'], optional_params)
|
123
|
+
Call.new(response)
|
124
|
+
end
|
125
|
+
|
126
|
+
# Initiate or end a call recording, returning a Telapi::Call object
|
127
|
+
# See http://www.telapi.com/docs/api/rest/calls/record/
|
128
|
+
#
|
129
|
+
# Required params:
|
130
|
+
# +id+:: call id
|
131
|
+
# +record+:: (true) or false
|
132
|
+
#
|
133
|
+
# Optional params is a hash containing:
|
134
|
+
# +TimeLimit+:: integer greater than or equal to 0
|
135
|
+
# +CallbackUrl+:: valid URL
|
136
|
+
def record(id, record = true, optional_params = {})
|
137
|
+
opts = { :Record => record }.merge(optional_params)
|
138
|
+
response = Network.post(['Calls', id, 'Recordings'], opts)
|
139
|
+
Call.new(response)
|
140
|
+
end
|
141
|
+
|
142
|
+
# Returns a resource collection containing Telapi::Recording objects
|
143
|
+
# See http://www.telapi.com/docs/api/rest/recordings/list/
|
144
|
+
#
|
145
|
+
# Required params:
|
146
|
+
# +id+:: call id
|
147
|
+
#
|
148
|
+
# Optional params is a hash containing:
|
149
|
+
# +DateCreated+:: date in the following format: YYYY-MM-DD
|
150
|
+
# +Page+:: integer greater than 0
|
151
|
+
# +PageSize+:: integer greater than 0
|
152
|
+
def recordings(id, optional_params = {})
|
153
|
+
response = Network.get(['Calls', id, 'Recordings'], optional_params)
|
154
|
+
ResourceCollection.new(response, 'recordings', Recording)
|
155
|
+
end
|
156
|
+
|
157
|
+
# Returns a resource collection containing Telapi::Notification objects
|
158
|
+
# See http://www.telapi.com/docs/api/rest/notifications/list/
|
159
|
+
#
|
160
|
+
# Required params:
|
161
|
+
# +id+:: call id
|
162
|
+
#
|
163
|
+
# Optional params is a hash containing:
|
164
|
+
# +Log+:: 0 (error), 1 (warning), or 2 (info)
|
165
|
+
# +Page+:: integer greater than 0
|
166
|
+
# +PageSize+:: integer greater than 0
|
167
|
+
def notifications(id, optional_params = {})
|
168
|
+
response = Network.get(['Calls', id, 'Notifications'], optional_params)
|
169
|
+
ResourceCollection.new(response, 'notifications', Notification)
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
# See ::interrupt
|
174
|
+
def interrupt(url, method = 'POST', status = 'completed')
|
175
|
+
self.class.interrupt(self.sid, url, method, status)
|
176
|
+
end
|
177
|
+
|
178
|
+
# See ::hangup
|
179
|
+
def hangup(status = 'completed')
|
180
|
+
self.class.hangup(self.sid, status)
|
181
|
+
end
|
182
|
+
|
183
|
+
# See ::send_digits
|
184
|
+
def send_digits(play_dtmf, play_dtmf_leg = 'aleg')
|
185
|
+
self.class.send_digits(self.sid, play_dtmf, play_dtmf_leg)
|
186
|
+
end
|
187
|
+
|
188
|
+
# See ::play_audio
|
189
|
+
def play_audio(sound_url, optional_params = {})
|
190
|
+
self.class.play_audio(self.sid, sound_url, optional_params)
|
191
|
+
end
|
192
|
+
|
193
|
+
# See ::voice_effect
|
194
|
+
def voice_effect(optional_params = {})
|
195
|
+
self.class.voice_effect(self.sid, optional_params)
|
196
|
+
end
|
197
|
+
|
198
|
+
# See ::record
|
199
|
+
def record(record = true, optional_params = {})
|
200
|
+
self.class.record(self.sid, record, optional_params)
|
201
|
+
end
|
202
|
+
|
203
|
+
# See ::recordings
|
204
|
+
def recordings(optional_params = {})
|
205
|
+
self.class.recordings(self.sid, optional_params)
|
206
|
+
end
|
207
|
+
|
208
|
+
# See ::notifications
|
209
|
+
def notifications(optional_params = {})
|
210
|
+
self.class.notifications(self.sid, optional_params)
|
211
|
+
end
|
212
|
+
|
213
|
+
end
|
214
|
+
end
|