plivo 0.3.19 → 4.0.0.beta.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +14 -0
- data/.rspec +2 -0
- data/.travis.yml +10 -0
- data/AUTHORS.md +4 -0
- data/CHANGELOG.md +19 -0
- data/Gemfile +3 -0
- data/LICENSE.txt +19 -0
- data/README.md +105 -24
- data/Rakefile +7 -0
- data/lib/plivo.rb +9 -815
- data/lib/plivo/base.rb +9 -0
- data/lib/plivo/base/resource.rb +85 -0
- data/lib/plivo/base/resource_interface.rb +93 -0
- data/lib/plivo/base/response.rb +29 -0
- data/lib/plivo/exceptions.rb +50 -0
- data/lib/plivo/resources.rb +14 -0
- data/lib/plivo/resources/accounts.rb +174 -0
- data/lib/plivo/resources/applications.rb +233 -0
- data/lib/plivo/resources/calls.rb +492 -0
- data/lib/plivo/resources/conferences.rb +371 -0
- data/lib/plivo/resources/endpoints.rb +130 -0
- data/lib/plivo/resources/messages.rb +178 -0
- data/lib/plivo/resources/numbers.rb +302 -0
- data/lib/plivo/resources/pricings.rb +43 -0
- data/lib/plivo/resources/recordings.rb +114 -0
- data/lib/plivo/rest_client.rb +199 -0
- data/lib/plivo/utils.rb +107 -0
- data/lib/plivo/version.rb +3 -0
- data/lib/plivo/xml.rb +27 -0
- data/lib/plivo/xml/conference.rb +20 -0
- data/lib/plivo/xml/dial.rb +16 -0
- data/lib/plivo/xml/dtmf.rb +13 -0
- data/lib/plivo/xml/element.rb +83 -0
- data/lib/plivo/xml/get_digits.rb +15 -0
- data/lib/plivo/xml/hangup.rb +12 -0
- data/lib/plivo/xml/message.rb +13 -0
- data/lib/plivo/xml/number.rb +13 -0
- data/lib/plivo/xml/play.rb +13 -0
- data/lib/plivo/xml/plivo_xml.rb +19 -0
- data/lib/plivo/xml/pre_answer.rb +12 -0
- data/lib/plivo/xml/record.rb +17 -0
- data/lib/plivo/xml/redirect.rb +13 -0
- data/lib/plivo/xml/response.rb +21 -0
- data/lib/plivo/xml/speak.rb +17 -0
- data/lib/plivo/xml/user.rb +13 -0
- data/lib/plivo/xml/wait.rb +12 -0
- data/plivo.gemspec +44 -0
- metadata +134 -45
- data/ext/mkrf_conf.rb +0 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4b3769ca665c441fa19c2ac4aac8844876e6625a
|
4
|
+
data.tar.gz: 5478cb00e8c5c79760447aabc913a7e64f9b9596
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 56dab2850afb6b10de0bb5ee58270cbb5495db06b46bff6eade3ea739798d19e83843fe0b2a19736199ca4a9fbf1333180a416d1943f227f3810c57d11652c8c
|
7
|
+
data.tar.gz: 61496cb4d40060e34e635cbacfa1bb7e95a6fc2a5d4ec01b36c9187fd21b3785970178bfff456ba8781140b4c68103d406033d74cb2360092533b8718c91c354
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/AUTHORS.md
ADDED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# Change Log
|
2
|
+
## [v0.3.19](https://github.com/plivo/plivo-ruby/tree/v0.3.19) (2015-11-24)
|
3
|
+
- Add `modify_number` function
|
4
|
+
|
5
|
+
## [0.3.17](https://github.com/plivo/plivo-ruby/tree/v0.3.17) (2015-07-21)
|
6
|
+
- Add support for `digitsMatchBLeg` in Dial XML
|
7
|
+
- `stop_speak_member` function added
|
8
|
+
|
9
|
+
## Other changes
|
10
|
+
- 2013-10-23 Added `stop_speak()`
|
11
|
+
- 2013-09-25 Added `relayDTMF` to `<Conference>` and `async` to `<DTMF>`
|
12
|
+
- 2013-08-17 Fix unicode characters only for speak element.
|
13
|
+
- 2013-08-12 Fix unicode characters only for speak APIs.
|
14
|
+
- 2013-07-26 Added `XPlivoSignature` header validation.
|
15
|
+
- 2013-07-21 Added outgoing carrier and carrier routing apis.
|
16
|
+
- 2013-07-20 Added `recordWhenAlone` to `<Conference>`.
|
17
|
+
- 2013-07-14 Unicode character support in XML and API.
|
18
|
+
- 2013-03-15 Added `min_silence` to `<Wait>`.
|
19
|
+
- 2013-02-23 Pricing API added.
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (C) 2017, Plivo Inc.
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
4
|
+
this software and associated documentation files (the "Software"), to deal in
|
5
|
+
the Software without restriction, including without limitation the rights to
|
6
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
7
|
+
of the Software, and to permit persons to whom the Software is furnished to do
|
8
|
+
so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in all
|
11
|
+
copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
19
|
+
SOFTWARE.
|
data/README.md
CHANGED
@@ -1,48 +1,129 @@
|
|
1
|
-
#
|
1
|
+
# plivo-ruby
|
2
|
+
The Plivo Ruby SDK makes it simpler to integrate communications into your Ruby applications using the Plivo REST API. Using the SDK, you will be able to make voice calls, send SMS and generate Plivo XML to control your call flows.
|
2
3
|
|
3
|
-
|
4
|
-
|
4
|
+
## Installation
|
5
|
+
Add this line to your application's Gemfile:
|
5
6
|
|
6
|
-
|
7
|
+
```ruby
|
8
|
+
gem 'plivo', '>= 4.0.0.beta.1'
|
9
|
+
```
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
7
14
|
|
8
|
-
|
15
|
+
Or install it yourself as:
|
9
16
|
|
10
|
-
|
17
|
+
$ gem install plivo --pre
|
11
18
|
|
19
|
+
If you have the `0.3.19` version (a.k.a legacy) already installed, you may have to first uninstall it before installing the new version.
|
12
20
|
|
13
|
-
##
|
21
|
+
## Getting started
|
14
22
|
|
15
|
-
|
23
|
+
### Authentication
|
24
|
+
To make the API requests, you need create a `RestClient` and provide it with authentication credentials (which can be found at [https://manage.plivo.com/dashboard/](https://manage.plivo.com/dashboard/)).
|
16
25
|
|
26
|
+
We recommend that you store your credentials in the `PLIVO_AUTH_ID` and the `PLIVO_AUTH_TOKEN` environment variables, so as to avoid the possibility of accidentally committing them to source control. If you do this, you can initialise the client with no arguments and it will automatically fetch them from the environment variables:
|
17
27
|
|
18
|
-
|
28
|
+
```ruby
|
29
|
+
client = RestClient.new;
|
30
|
+
```
|
31
|
+
|
32
|
+
Alternatively, you can specifiy the authentication credentials while initializing the `RestClient`.
|
19
33
|
|
20
|
-
|
34
|
+
```ruby
|
35
|
+
client = RestClient.new('your_auth_id', 'your_auth_token');
|
36
|
+
```
|
21
37
|
|
22
|
-
|
23
|
-
|
38
|
+
### The basics
|
39
|
+
The SDK uses consistent interfaces to create, retrieve, update, delete and list resources. The pattern followed is as follows:
|
24
40
|
|
25
|
-
|
41
|
+
```ruby
|
42
|
+
client.resources.create(params); # Create
|
43
|
+
client.resources.get(resource_identifier); # Get
|
44
|
+
client.resources.update(resource_identifier, params); # Update
|
45
|
+
client.resources.delete(resource_identifier); # Delete
|
46
|
+
client.resources.list; # List all resources, max 20 at a time
|
47
|
+
```
|
26
48
|
|
27
|
-
|
49
|
+
You can also use the `resource` directly to update and delete it. For example,
|
28
50
|
|
51
|
+
```ruby
|
52
|
+
resource = client.resources.get(resource_identifier);
|
53
|
+
resource.update(params); # update the resource
|
54
|
+
resource.delete(); # Delete the resource
|
29
55
|
```
|
30
|
-
|
31
|
-
|
32
|
-
|
56
|
+
|
57
|
+
Also, using `client.resources.list` would list the first 20 resources by default (which is the first page, with `limit` as 20, and `offset` as 0). To get more, you will have to use `limit` and `offset` to get the second page of resources.
|
58
|
+
|
59
|
+
To list all resources, you can simply use the following pattern that will handle the pagination for you automatically, so you won't have to worry about passing the right `limit` and `offset` values.
|
60
|
+
|
61
|
+
```ruby
|
62
|
+
client.resources.each do |resource|
|
63
|
+
puts resource.id
|
64
|
+
end
|
33
65
|
```
|
34
66
|
|
35
|
-
##
|
67
|
+
## Examples
|
68
|
+
|
69
|
+
### Send a message
|
36
70
|
|
37
|
-
|
71
|
+
```ruby
|
72
|
+
require 'rubygems'
|
73
|
+
require 'plivo'
|
38
74
|
|
39
|
-
|
75
|
+
include Plivo
|
40
76
|
|
41
|
-
|
77
|
+
client = RestClient.new
|
78
|
+
message_created = client.messages.create(
|
79
|
+
'your_source_number',
|
80
|
+
%w[your_destination_number_1 your_destination_number_2],
|
81
|
+
'Hello, world!'
|
82
|
+
)
|
83
|
+
```
|
42
84
|
|
43
|
-
|
85
|
+
### Make a call
|
44
86
|
|
45
|
-
|
87
|
+
```ruby
|
88
|
+
require 'rubygems'
|
89
|
+
require 'plivo'
|
90
|
+
|
91
|
+
include Plivo
|
92
|
+
|
93
|
+
client = RestClient.new
|
94
|
+
call_made = client.calls.create(
|
95
|
+
'your_source_number',
|
96
|
+
['your_destination_number'],
|
97
|
+
'https://answer.url'
|
98
|
+
)
|
99
|
+
```
|
100
|
+
|
101
|
+
### Generate Plivo XML
|
102
|
+
|
103
|
+
```ruby
|
104
|
+
require 'rubygems'
|
105
|
+
require 'plivo'
|
106
|
+
|
107
|
+
include Plivo::XML
|
108
|
+
|
109
|
+
response = Response.new
|
110
|
+
response.addSpeak('Hello, world!')
|
111
|
+
puts response.to_xml # Prints the XML string
|
112
|
+
|
113
|
+
xml_response = PlivoXML.new(response)
|
114
|
+
puts xml_response.to_xml # Prints XML along with XML version & encoding details
|
115
|
+
```
|
116
|
+
This generates the following XML:
|
117
|
+
|
118
|
+
```xml
|
119
|
+
<?xml version="1.0" encoding="utf-8" ?>
|
120
|
+
<Response>
|
121
|
+
<Speak>Hello, world!</Speak>
|
122
|
+
</Response>
|
123
|
+
```
|
46
124
|
|
125
|
+
### More examples
|
126
|
+
Refer to the [Ruby API Reference](https://api-reference.plivo.com/latest/ruby/introduction/overview) for more examples. Also refer to the [guide to setting up dev environment](https://developers.plivo.com/getting-started/setting-up-dev-environment/) on [Plivo Developers Portal](https://developers.plivo.com) to setup a Sinatra server & use it to test out your integration in under 5 minutes.
|
47
127
|
|
48
|
-
|
128
|
+
## Reporting issues
|
129
|
+
Report any feedback or problems with this beta version by [opening an issue on Github](https://github.com/plivo/plivo-ruby/issues).
|
data/Rakefile
ADDED
data/lib/plivo.rb
CHANGED
@@ -1,815 +1,9 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
module Plivo
|
10
|
-
class PlivoError < StandardError
|
11
|
-
end
|
12
|
-
|
13
|
-
class XPlivoSignature
|
14
|
-
attr_accessor :signature, :uri, :post_params, :auth_token
|
15
|
-
|
16
|
-
def initialize(signature, uri, post_params, auth_token)
|
17
|
-
@signature = signature
|
18
|
-
@uri = uri
|
19
|
-
@post_params = post_params
|
20
|
-
@auth_token = auth_token
|
21
|
-
end
|
22
|
-
|
23
|
-
def is_valid?
|
24
|
-
uri = @post_params.sort.reduce(@uri) {|_, (key, val)| _ += key + val}
|
25
|
-
return Base64.encode64(OpenSSL::HMAC.digest('sha1', @auth_token, uri)).chomp.eql? @signature
|
26
|
-
end
|
27
|
-
|
28
|
-
end
|
29
|
-
|
30
|
-
class RestAPI
|
31
|
-
attr_accessor :auth_id, :auth_token, :url, :version, :api, :headers, :rest
|
32
|
-
|
33
|
-
def initialize(auth_id, auth_token, url="https://api.plivo.com", version="v1")
|
34
|
-
@auth_id = auth_id
|
35
|
-
@auth_token = auth_token
|
36
|
-
@url = url.chomp('/')
|
37
|
-
@version = version
|
38
|
-
@api = @url + '/' + @version + '/Account/' + @auth_id
|
39
|
-
@headers = {"User-Agent" => "RubyPlivo"}
|
40
|
-
@rest = RestClient::Resource.new(@api, @auth_id, @auth_token)
|
41
|
-
end
|
42
|
-
|
43
|
-
def hash_to_params(myhash)
|
44
|
-
return myhash.map { |k, v| "#{CGI.escape(k.to_s)}=#{CGI.escape(v.to_s)}" }.join("&")
|
45
|
-
end
|
46
|
-
|
47
|
-
def request(method, path, params=nil)
|
48
|
-
if method == "POST"
|
49
|
-
if not params
|
50
|
-
params = {}
|
51
|
-
end
|
52
|
-
begin
|
53
|
-
r = @rest[path].post params.to_json, :content_type => 'application/json'
|
54
|
-
rescue => e
|
55
|
-
response = e
|
56
|
-
end
|
57
|
-
if not response
|
58
|
-
code = r.code
|
59
|
-
raw = r.to_str
|
60
|
-
response = JSON.parse(raw)
|
61
|
-
else
|
62
|
-
code = response.http_code
|
63
|
-
response = JSON.parse(response.response.to_s)
|
64
|
-
end
|
65
|
-
return [code, response]
|
66
|
-
elsif method == "GET"
|
67
|
-
if params
|
68
|
-
path = path + '?' + hash_to_params(params)
|
69
|
-
end
|
70
|
-
|
71
|
-
begin
|
72
|
-
r = @rest[path].get
|
73
|
-
rescue => e
|
74
|
-
response = e
|
75
|
-
end
|
76
|
-
if not response
|
77
|
-
code = r.code
|
78
|
-
raw = r.to_str
|
79
|
-
response = JSON.parse(raw)
|
80
|
-
else
|
81
|
-
code = response.http_code
|
82
|
-
response = JSON.parse(response.response.to_s)
|
83
|
-
end
|
84
|
-
return [code, response]
|
85
|
-
elsif method == "DELETE"
|
86
|
-
if params
|
87
|
-
path = path + '?' + hash_to_params(params)
|
88
|
-
end
|
89
|
-
begin
|
90
|
-
r = @rest[path].delete
|
91
|
-
rescue => e
|
92
|
-
response = e
|
93
|
-
end
|
94
|
-
if not response
|
95
|
-
code = r.code
|
96
|
-
else
|
97
|
-
code = response.http_code
|
98
|
-
response = JSON.parse(response.response.to_s)
|
99
|
-
end
|
100
|
-
return [code, ""]
|
101
|
-
end
|
102
|
-
return [405, 'Method Not Supported']
|
103
|
-
end
|
104
|
-
|
105
|
-
## Accounts ##
|
106
|
-
def get_account(params={})
|
107
|
-
return request('GET', "/", params)
|
108
|
-
end
|
109
|
-
|
110
|
-
def modify_account(params={})
|
111
|
-
return request('POST', "/", params)
|
112
|
-
end
|
113
|
-
|
114
|
-
def get_subaccounts(params={})
|
115
|
-
return request('GET', "/Subaccount/", params)
|
116
|
-
end
|
117
|
-
|
118
|
-
def create_subaccount(params={})
|
119
|
-
return request('POST', "/Subaccount/", params)
|
120
|
-
end
|
121
|
-
|
122
|
-
def get_subaccount(params={})
|
123
|
-
subauth_id = params.delete("subauth_id") || params.delete(:subauth_id)
|
124
|
-
return request('GET', "/Subaccount/#{subauth_id}/", params)
|
125
|
-
end
|
126
|
-
|
127
|
-
def modify_subaccount(params={})
|
128
|
-
subauth_id = params.delete("subauth_id") || params.delete(:subauth_id)
|
129
|
-
return request('POST', "/Subaccount/#{subauth_id}/", params)
|
130
|
-
end
|
131
|
-
|
132
|
-
def delete_subaccount(params={})
|
133
|
-
subauth_id = params.delete("subauth_id") || params.delete(:subauth_id)
|
134
|
-
return request('DELETE', "/Subaccount/#{subauth_id}/", params)
|
135
|
-
end
|
136
|
-
|
137
|
-
## Applications ##
|
138
|
-
def get_applications(params={})
|
139
|
-
return request('GET', "/Application/", params)
|
140
|
-
end
|
141
|
-
|
142
|
-
def create_application(params={})
|
143
|
-
return request('POST', "/Application/", params)
|
144
|
-
end
|
145
|
-
|
146
|
-
def get_application(params={})
|
147
|
-
app_id = params.delete("app_id")
|
148
|
-
return request('GET', "/Application/#{app_id}/", params)
|
149
|
-
end
|
150
|
-
|
151
|
-
def modify_application(params={})
|
152
|
-
app_id = params.delete("app_id")
|
153
|
-
return request('POST', "/Application/#{app_id}/", params)
|
154
|
-
end
|
155
|
-
|
156
|
-
def delete_application(params={})
|
157
|
-
app_id = params.delete("app_id")
|
158
|
-
return request('DELETE', "/Application/#{app_id}/", params)
|
159
|
-
end
|
160
|
-
|
161
|
-
## Numbers ##
|
162
|
-
def search_phone_number(params={})
|
163
|
-
return request('GET', "/PhoneNumber/", params)
|
164
|
-
end
|
165
|
-
|
166
|
-
def buy_phone_number(params={})
|
167
|
-
number = params.delete("number")
|
168
|
-
return request('POST', "/PhoneNumber/#{number}/", params)
|
169
|
-
end
|
170
|
-
|
171
|
-
def get_numbers(params={})
|
172
|
-
return request('GET', "/Number/", params)
|
173
|
-
end
|
174
|
-
|
175
|
-
def modify_number(params={})
|
176
|
-
number = params.delete("number")
|
177
|
-
return request('POST', "/Number/#{number}/", params)
|
178
|
-
end
|
179
|
-
|
180
|
-
def search_numbers(params={})
|
181
|
-
return request('GET', "/AvailableNumber/", params)
|
182
|
-
end
|
183
|
-
|
184
|
-
def get_number(params={})
|
185
|
-
number = params.delete("number")
|
186
|
-
return request('GET', "/Number/#{number}/", params)
|
187
|
-
end
|
188
|
-
|
189
|
-
def rent_number(params={})
|
190
|
-
number = params.delete("number")
|
191
|
-
return request('POST', "/AvailableNumber/#{number}/", params)
|
192
|
-
end
|
193
|
-
|
194
|
-
def unrent_number(params={})
|
195
|
-
number = params.delete("number")
|
196
|
-
return request('DELETE', "/Number/#{number}/", params)
|
197
|
-
end
|
198
|
-
|
199
|
-
def link_application_number(params={})
|
200
|
-
number = params.delete("number")
|
201
|
-
return request('POST', "/Number/#{number}/", params)
|
202
|
-
end
|
203
|
-
|
204
|
-
def unlink_application_number(params={})
|
205
|
-
number = params.delete("number")
|
206
|
-
params = {"app_id" => ""}
|
207
|
-
return request('POST', "/Number/#{number}/", params)
|
208
|
-
end
|
209
|
-
|
210
|
-
def get_number_group(params={})
|
211
|
-
return request('GET', "/AvailableNumberGroup/", params)
|
212
|
-
end
|
213
|
-
|
214
|
-
def get_number_group_details(params={})
|
215
|
-
group_id = params.delete('group_id')
|
216
|
-
return request('GET', "/AvailableNumberGroup/#{group_id}/", params)
|
217
|
-
end
|
218
|
-
|
219
|
-
def rent_from_number_group(params={})
|
220
|
-
group_id = params.delete('group_id')
|
221
|
-
return request('POST', "/AvailableNumberGroup/#{group_id}/", params)
|
222
|
-
end
|
223
|
-
|
224
|
-
## Calls ##
|
225
|
-
def get_cdrs(params={})
|
226
|
-
return request('GET', "/Call/", params)
|
227
|
-
end
|
228
|
-
|
229
|
-
def get_cdr(params={})
|
230
|
-
record_id = params.delete('record_id')
|
231
|
-
return request('GET', "/Call/#{record_id}/", params)
|
232
|
-
end
|
233
|
-
|
234
|
-
def get_live_calls(params={})
|
235
|
-
params["status"] = "live"
|
236
|
-
return request('GET', "/Call/", params)
|
237
|
-
end
|
238
|
-
|
239
|
-
def get_live_call(params={})
|
240
|
-
call_uuid = params.delete('call_uuid')
|
241
|
-
params["status"] = "live"
|
242
|
-
return request('GET', "/Call/#{call_uuid}/", params)
|
243
|
-
end
|
244
|
-
|
245
|
-
def make_call(params={})
|
246
|
-
return request('POST', "/Call/", params)
|
247
|
-
end
|
248
|
-
|
249
|
-
def hangup_all_calls(params={})
|
250
|
-
return request('DELETE', "/Call/", params)
|
251
|
-
end
|
252
|
-
|
253
|
-
def transfer_call(params={})
|
254
|
-
call_uuid = params.delete('call_uuid')
|
255
|
-
return request('POST', "/Call/#{call_uuid}/", params)
|
256
|
-
end
|
257
|
-
|
258
|
-
def hangup_call(params={})
|
259
|
-
call_uuid = params.delete('call_uuid')
|
260
|
-
return request('DELETE', "/Call/#{call_uuid}/", params)
|
261
|
-
end
|
262
|
-
|
263
|
-
def record(params={})
|
264
|
-
call_uuid = params.delete('call_uuid')
|
265
|
-
return request('POST', "/Call/#{call_uuid}/Record/", params)
|
266
|
-
end
|
267
|
-
|
268
|
-
def stop_record(params={})
|
269
|
-
call_uuid = params.delete('call_uuid')
|
270
|
-
return request('DELETE', "/Call/#{call_uuid}/Record/", params)
|
271
|
-
end
|
272
|
-
|
273
|
-
def play(params={})
|
274
|
-
call_uuid = params.delete('call_uuid')
|
275
|
-
return request('POST', "/Call/#{call_uuid}/Play/", params)
|
276
|
-
end
|
277
|
-
|
278
|
-
def stop_play(params={})
|
279
|
-
call_uuid = params.delete('call_uuid')
|
280
|
-
return request('DELETE', "/Call/#{call_uuid}/Play/", params)
|
281
|
-
end
|
282
|
-
|
283
|
-
def speak(params={})
|
284
|
-
call_uuid = params.delete('call_uuid')
|
285
|
-
params.update({"text" => HTMLEntities.new(:html4).encode(params['text'], :decimal)})
|
286
|
-
return request('POST', "/Call/#{call_uuid}/Speak/", params)
|
287
|
-
end
|
288
|
-
|
289
|
-
def stop_speak(params={})
|
290
|
-
call_uuid = params.delete('call_uuid')
|
291
|
-
return request('DELETE', "/Call/#{call_uuid}/Speak/", params)
|
292
|
-
end
|
293
|
-
|
294
|
-
def send_digits(params={})
|
295
|
-
call_uuid = params.delete('call_uuid')
|
296
|
-
return request('POST', "/Call/#{call_uuid}/DTMF/", params)
|
297
|
-
end
|
298
|
-
|
299
|
-
## Calls requests ##
|
300
|
-
def hangup_request(params={})
|
301
|
-
request_uuid = params.delete('request_uuid')
|
302
|
-
return request('DELETE', "/Request/#{request_uuid}/", params)
|
303
|
-
end
|
304
|
-
|
305
|
-
## Conferences ##
|
306
|
-
def get_live_conferences(params={})
|
307
|
-
return request('GET', "/Conference/", params)
|
308
|
-
end
|
309
|
-
|
310
|
-
def hangup_all_conferences(params={})
|
311
|
-
return request('DELETE', "/Conference/", params)
|
312
|
-
end
|
313
|
-
|
314
|
-
def get_live_conference(params={})
|
315
|
-
conference_name = params.delete('conference_name')
|
316
|
-
return request('GET', "/Conference/#{conference_name}/", params)
|
317
|
-
end
|
318
|
-
|
319
|
-
def hangup_conference(params={})
|
320
|
-
conference_name = params.delete('conference_name')
|
321
|
-
return request('DELETE', "/Conference/#{conference_name}/", params)
|
322
|
-
end
|
323
|
-
|
324
|
-
def hangup_member(params={})
|
325
|
-
conference_name = params.delete('conference_name')
|
326
|
-
member_id = params.delete('member_id')
|
327
|
-
return request('DELETE', "/Conference/#{conference_name}/Member/#{member_id}/", params)
|
328
|
-
end
|
329
|
-
|
330
|
-
def play_member(params={})
|
331
|
-
conference_name = params.delete('conference_name')
|
332
|
-
member_id = params.delete('member_id')
|
333
|
-
return request('POST', "/Conference/#{conference_name}/Member/#{member_id}/Play/", params)
|
334
|
-
end
|
335
|
-
|
336
|
-
def stop_play_member(params={})
|
337
|
-
conference_name = params.delete('conference_name')
|
338
|
-
member_id = params.delete('member_id')
|
339
|
-
return request('DELETE', "/Conference/#{conference_name}/Member/#{member_id}/Play/", params)
|
340
|
-
end
|
341
|
-
|
342
|
-
def speak_member(params={})
|
343
|
-
conference_name = params.delete('conference_name')
|
344
|
-
member_id = params.delete('member_id')
|
345
|
-
params.update({"text" => HTMLEntities.new(:html4).encode(params['text'], :decimal)})
|
346
|
-
return request('POST', "/Conference/#{conference_name}/Member/#{member_id}/Speak/", params)
|
347
|
-
end
|
348
|
-
|
349
|
-
def stop_speak_member(params={})
|
350
|
-
conference_name = params.delete('conference_name')
|
351
|
-
member_id = params.delete('member_id')
|
352
|
-
return request('DELETE', "/Conference/#{conference_name}/Member/#{member_id}/Speak/", params)
|
353
|
-
end
|
354
|
-
|
355
|
-
def deaf_member(params={})
|
356
|
-
conference_name = params.delete('conference_name')
|
357
|
-
member_id = params.delete('member_id')
|
358
|
-
return request('POST', "/Conference/#{conference_name}/Member/#{member_id}/Deaf/", params)
|
359
|
-
end
|
360
|
-
|
361
|
-
def undeaf_member(params={})
|
362
|
-
conference_name = params.delete('conference_name')
|
363
|
-
member_id = params.delete('member_id')
|
364
|
-
return request('DELETE', "/Conference/#{conference_name}/Member/#{member_id}/Deaf/", params)
|
365
|
-
end
|
366
|
-
|
367
|
-
def mute_member(params={})
|
368
|
-
conference_name = params.delete('conference_name')
|
369
|
-
member_id = params.delete('member_id')
|
370
|
-
return request('POST', "/Conference/#{conference_name}/Member/#{member_id}/Mute/", params)
|
371
|
-
end
|
372
|
-
|
373
|
-
def unmute_member(params={})
|
374
|
-
conference_name = params.delete('conference_name')
|
375
|
-
member_id = params.delete('member_id')
|
376
|
-
return request('DELETE', "/Conference/#{conference_name}/Member/#{member_id}/Mute/", params)
|
377
|
-
end
|
378
|
-
|
379
|
-
def kick_member(params={})
|
380
|
-
conference_name = params.delete('conference_name')
|
381
|
-
member_id = params.delete('member_id')
|
382
|
-
return request('POST', "/Conference/#{conference_name}/Member/#{member_id}/Kick/", params)
|
383
|
-
end
|
384
|
-
|
385
|
-
def record_conference(params={})
|
386
|
-
conference_name = params.delete('conference_name')
|
387
|
-
return request('POST', "/Conference/#{conference_name}/Record/", params)
|
388
|
-
end
|
389
|
-
|
390
|
-
def stop_record_conference(params={})
|
391
|
-
conference_name = params.delete('conference_name')
|
392
|
-
return request('DELETE', "/Conference/#{conference_name}/Record/", params)
|
393
|
-
end
|
394
|
-
|
395
|
-
## Recordings ##
|
396
|
-
def get_recordings(params={})
|
397
|
-
return request('GET', "/Recording/", params)
|
398
|
-
end
|
399
|
-
|
400
|
-
def get_recording(params={})
|
401
|
-
recording_id = params.delete('recording_id')
|
402
|
-
return request('GET', "/Recording/#{recording_id}/", params)
|
403
|
-
end
|
404
|
-
|
405
|
-
def delete_recording(params={})
|
406
|
-
recording_id = params.delete('recording_id')
|
407
|
-
return request('DELETE', "/Recording/#{recording_id}/", params)
|
408
|
-
end
|
409
|
-
|
410
|
-
## Endpoints ##
|
411
|
-
def get_endpoints(params={})
|
412
|
-
return request('GET', "/Endpoint/", params)
|
413
|
-
end
|
414
|
-
|
415
|
-
def create_endpoint(params={})
|
416
|
-
return request('POST', "/Endpoint/", params)
|
417
|
-
end
|
418
|
-
|
419
|
-
def get_endpoint(params={})
|
420
|
-
endpoint_id = params.delete('endpoint_id')
|
421
|
-
return request('GET', "/Endpoint/#{endpoint_id}/", params)
|
422
|
-
end
|
423
|
-
|
424
|
-
def modify_endpoint(params={})
|
425
|
-
endpoint_id = params.delete('endpoint_id')
|
426
|
-
return request('POST', "/Endpoint/#{endpoint_id}/", params)
|
427
|
-
end
|
428
|
-
|
429
|
-
def delete_endpoint(params={})
|
430
|
-
endpoint_id = params.delete('endpoint_id')
|
431
|
-
return request('DELETE', "/Endpoint/#{endpoint_id}/", params)
|
432
|
-
end
|
433
|
-
|
434
|
-
## Incoming Carriers ##
|
435
|
-
def get_incoming_carriers(params={})
|
436
|
-
return request('GET', "/IncomingCarrier/", params)
|
437
|
-
end
|
438
|
-
|
439
|
-
def create_incoming_carrier(params={})
|
440
|
-
return request('POST', "/IncomingCarrier/", params)
|
441
|
-
end
|
442
|
-
|
443
|
-
def get_incoming_carrier(params={})
|
444
|
-
carrier_id = params.delete('carrier_id')
|
445
|
-
return request('GET', "/IncomingCarrier/#{carrier_id}/", params)
|
446
|
-
end
|
447
|
-
|
448
|
-
def modify_incoming_carrier(params={})
|
449
|
-
carrier_id = params.delete('carrier_id')
|
450
|
-
return request('POST', "/IncomingCarrier/#{carrier_id}/", params)
|
451
|
-
end
|
452
|
-
|
453
|
-
def delete_incoming_carrier(params={})
|
454
|
-
carrier_id = params.delete('carrier_id')
|
455
|
-
return request('DELETE', "/IncomingCarrier/#{carrier_id}/", params)
|
456
|
-
end
|
457
|
-
|
458
|
-
## Outgoing Carriers ##
|
459
|
-
def get_outgoing_carriers(params={})
|
460
|
-
return request('GET', "/OutgoingCarrier/", params)
|
461
|
-
end
|
462
|
-
|
463
|
-
def create_outgoing_carrier(params={})
|
464
|
-
return request('POST', "/OutgoingCarrier/", params)
|
465
|
-
end
|
466
|
-
|
467
|
-
def get_outgoing_carrier(params={})
|
468
|
-
carrier_id = params.delete('carrier_id')
|
469
|
-
return request('GET', "/OutgoingCarrier/#{carrier_id}/", params)
|
470
|
-
end
|
471
|
-
|
472
|
-
def modify_outgoing_carrier(params={})
|
473
|
-
carrier_id = params.delete('carrier_id')
|
474
|
-
return request('POST', "/OutgoingCarrier/#{carrier_id}/", params)
|
475
|
-
end
|
476
|
-
|
477
|
-
def delete_outgoing_carrier(params={})
|
478
|
-
carrier_id = params.delete('carrier_id')
|
479
|
-
return request('DELETE', "/OutgoingCarrier/#{carrier_id}/", params)
|
480
|
-
end
|
481
|
-
|
482
|
-
## Outgoing Carrier Routings ##
|
483
|
-
def get_outgoing_carrier_routings(params={})
|
484
|
-
return request('GET', "/OutgoingCarrierRouting/", params)
|
485
|
-
end
|
486
|
-
|
487
|
-
def create_outgoing_carrier_routing(params={})
|
488
|
-
return request('POST', "/OutgoingCarrierRouting/", params)
|
489
|
-
end
|
490
|
-
|
491
|
-
def get_outgoing_carrier_routing(params={})
|
492
|
-
routing_id = params.delete('routing_id')
|
493
|
-
return request('GET', "/OutgoingCarrierRouting/#{routing_id}/", params)
|
494
|
-
end
|
495
|
-
|
496
|
-
def modify_outgoing_carrier_routing(params={})
|
497
|
-
routing_id = params.delete('routing_id')
|
498
|
-
return request('POST', "/OutgoingCarrierRouting/#{routing_id}/", params)
|
499
|
-
end
|
500
|
-
|
501
|
-
def delete_outgoing_carrier_routing(params={})
|
502
|
-
routing_id = params.delete('routing_id')
|
503
|
-
return request('DELETE', "/OutgoingCarrierRouting/#{routing_id}/", params)
|
504
|
-
end
|
505
|
-
|
506
|
-
## Pricing ##
|
507
|
-
def pricing(params={})
|
508
|
-
return request('GET', "/Pricing/", params)
|
509
|
-
end
|
510
|
-
|
511
|
-
## Outgoing Carrier ##
|
512
|
-
|
513
|
-
## To be added here ##
|
514
|
-
|
515
|
-
## Message ##
|
516
|
-
def send_message(params={})
|
517
|
-
return request('POST', "/Message/", params)
|
518
|
-
end
|
519
|
-
|
520
|
-
def get_messages(params={})
|
521
|
-
return request('GET', "/Message/", params)
|
522
|
-
end
|
523
|
-
|
524
|
-
def get_message(params={})
|
525
|
-
record_id = params.delete('record_id')
|
526
|
-
return request('GET', "/Message/#{record_id}/", params)
|
527
|
-
end
|
528
|
-
end
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
class Element
|
533
|
-
class << self
|
534
|
-
attr_accessor :valid_attributes, :nestables
|
535
|
-
end
|
536
|
-
@nestables = []
|
537
|
-
@valid_attributes = []
|
538
|
-
|
539
|
-
attr_accessor :node, :name
|
540
|
-
|
541
|
-
def initialize(body=nil, attributes={}, &block)
|
542
|
-
@name = self.class.name.split('::')[1]
|
543
|
-
@body = body
|
544
|
-
@node = REXML::Element.new @name
|
545
|
-
attributes.each do |k, v|
|
546
|
-
if self.class.valid_attributes.include?(k.to_s)
|
547
|
-
@node.attributes[k.to_s] = convert_value(v)
|
548
|
-
else
|
549
|
-
raise PlivoError, "invalid attribute #{k.to_s} for #{@name}"
|
550
|
-
end
|
551
|
-
end
|
552
|
-
|
553
|
-
if @body
|
554
|
-
@node.text = @body
|
555
|
-
end
|
556
|
-
|
557
|
-
# Allow for nested "nestable" elements using a code block
|
558
|
-
# ie
|
559
|
-
# Plivo::Response.new do |r|
|
560
|
-
# r.Dial do |n|
|
561
|
-
# n.Number '+15557779999'
|
562
|
-
# end
|
563
|
-
# end
|
564
|
-
yield(self) if block_given?
|
565
|
-
end
|
566
|
-
|
567
|
-
def method_missing(method, *args, &block)
|
568
|
-
# Handle the addElement methods
|
569
|
-
method = $1.to_sym if method.to_s =~ /^add(.*)/
|
570
|
-
# Add the element
|
571
|
-
add(Plivo.const_get(method).new(*args, &block))
|
572
|
-
end
|
573
|
-
|
574
|
-
|
575
|
-
def convert_value(v)
|
576
|
-
if v == true
|
577
|
-
return "true"
|
578
|
-
elsif v == false
|
579
|
-
return "false"
|
580
|
-
elsif v == nil
|
581
|
-
return "none"
|
582
|
-
elsif v == "get"
|
583
|
-
return "GET"
|
584
|
-
elsif v == "post"
|
585
|
-
return "POST"
|
586
|
-
else
|
587
|
-
return v
|
588
|
-
end
|
589
|
-
end
|
590
|
-
|
591
|
-
def add(element)
|
592
|
-
if not element
|
593
|
-
raise PlivoError, "invalid element"
|
594
|
-
end
|
595
|
-
if self.class.nestables.include?(element.name)
|
596
|
-
@node.elements << element.node
|
597
|
-
return element
|
598
|
-
else
|
599
|
-
raise PlivoError, "#{element.name} not nestable in #{@name}"
|
600
|
-
end
|
601
|
-
end
|
602
|
-
|
603
|
-
def to_xml
|
604
|
-
return @node.to_s
|
605
|
-
end
|
606
|
-
|
607
|
-
def to_s
|
608
|
-
return @node.to_s
|
609
|
-
end
|
610
|
-
end
|
611
|
-
|
612
|
-
|
613
|
-
class Response < Element
|
614
|
-
@nestables = ['Speak', 'Play', 'GetDigits', 'Record', 'Dial', 'Message',
|
615
|
-
'Redirect', 'Wait', 'Hangup', 'PreAnswer', 'Conference', 'DTMF']
|
616
|
-
@valid_attributes = []
|
617
|
-
|
618
|
-
def initialize()
|
619
|
-
super(nil, {})
|
620
|
-
end
|
621
|
-
|
622
|
-
def to_xml()
|
623
|
-
return '<?xml version="1.0" encoding="utf-8" ?>' + super()
|
624
|
-
end
|
625
|
-
|
626
|
-
def to_s()
|
627
|
-
return '<?xml version="1.0" encoding="utf-8" ?>' + super()
|
628
|
-
end
|
629
|
-
end
|
630
|
-
|
631
|
-
|
632
|
-
class Speak < Element
|
633
|
-
@nestables = []
|
634
|
-
@valid_attributes = ['voice', 'language', 'loop']
|
635
|
-
|
636
|
-
def initialize(body, attributes={})
|
637
|
-
if not body
|
638
|
-
raise PlivoError, 'No text set for Speak'
|
639
|
-
else
|
640
|
-
body = HTMLEntities.new(:html4).encode(body, :decimal)
|
641
|
-
end
|
642
|
-
super(body, attributes)
|
643
|
-
end
|
644
|
-
end
|
645
|
-
|
646
|
-
|
647
|
-
class Play < Element
|
648
|
-
@nestables = []
|
649
|
-
@valid_attributes = ['loop']
|
650
|
-
|
651
|
-
def initialize(body, attributes={})
|
652
|
-
if not body
|
653
|
-
raise PlivoError 'No url set for Play'
|
654
|
-
end
|
655
|
-
super(body, attributes)
|
656
|
-
end
|
657
|
-
end
|
658
|
-
|
659
|
-
|
660
|
-
class Wait < Element
|
661
|
-
@nestables = []
|
662
|
-
@valid_attributes = ['length', 'silence', 'min_silence', 'beep']
|
663
|
-
|
664
|
-
def initialize(attributes={})
|
665
|
-
super(nil, attributes)
|
666
|
-
end
|
667
|
-
end
|
668
|
-
|
669
|
-
|
670
|
-
class Redirect < Element
|
671
|
-
@nestables = []
|
672
|
-
@valid_attributes = ['method']
|
673
|
-
|
674
|
-
def initialize(body, attributes={})
|
675
|
-
if not body
|
676
|
-
raise PlivoError 'No url set for Redirect'
|
677
|
-
end
|
678
|
-
super(body, attributes)
|
679
|
-
end
|
680
|
-
end
|
681
|
-
|
682
|
-
|
683
|
-
class Hangup < Element
|
684
|
-
@nestables = []
|
685
|
-
@valid_attributes = ['schedule', 'reason']
|
686
|
-
|
687
|
-
def initialize(attributes={})
|
688
|
-
super(nil, attributes)
|
689
|
-
end
|
690
|
-
end
|
691
|
-
|
692
|
-
|
693
|
-
class GetDigits < Element
|
694
|
-
@nestables = ['Speak', 'Play', 'Wait']
|
695
|
-
@valid_attributes = ['action', 'method', 'timeout', 'digitTimeout',
|
696
|
-
'numDigits', 'retries', 'invalidDigitsSound',
|
697
|
-
'validDigits', 'playBeep', 'redirect', "finishOnKey",
|
698
|
-
'digitTimeout', 'log']
|
699
|
-
|
700
|
-
def initialize(attributes={}, &block)
|
701
|
-
super(nil, attributes, &block)
|
702
|
-
end
|
703
|
-
end
|
704
|
-
|
705
|
-
|
706
|
-
class Number < Element
|
707
|
-
@nestables = []
|
708
|
-
@valid_attributes = ['sendDigits', 'sendOnPreanswer']
|
709
|
-
|
710
|
-
def initialize(body, attributes={})
|
711
|
-
if not body
|
712
|
-
raise PlivoError, 'No number set for Number'
|
713
|
-
end
|
714
|
-
super(body, attributes)
|
715
|
-
end
|
716
|
-
end
|
717
|
-
|
718
|
-
|
719
|
-
class User < Element
|
720
|
-
@nestables = []
|
721
|
-
@valid_attributes = ['sendDigits', 'sendOnPreanswer', 'sipHeaders']
|
722
|
-
|
723
|
-
def initialize(body, attributes={})
|
724
|
-
if not body
|
725
|
-
raise PlivoError, 'No user set for User'
|
726
|
-
end
|
727
|
-
super(body, attributes)
|
728
|
-
end
|
729
|
-
end
|
730
|
-
|
731
|
-
|
732
|
-
class Dial < Element
|
733
|
-
@nestables = ['Number', 'User']
|
734
|
-
@valid_attributes = ['action','method','timeout','hangupOnStar',
|
735
|
-
'timeLimit','callerId', 'callerName', 'confirmSound',
|
736
|
-
'dialMusic', 'confirmKey', 'redirect',
|
737
|
-
'callbackUrl', 'callbackMethod', 'digitsMatch', 'digitsMatchBLeg',
|
738
|
-
'sipHeaders']
|
739
|
-
|
740
|
-
def initialize(attributes={}, &block)
|
741
|
-
super(nil, attributes, &block)
|
742
|
-
end
|
743
|
-
end
|
744
|
-
|
745
|
-
|
746
|
-
class Conference < Element
|
747
|
-
@nestables = []
|
748
|
-
@valid_attributes = ['muted','beep','startConferenceOnEnter',
|
749
|
-
'endConferenceOnExit','waitSound','enterSound', 'exitSound',
|
750
|
-
'timeLimit', 'hangupOnStar', 'maxMembers',
|
751
|
-
'record', 'recordFileFormat', 'action', 'method', 'redirect',
|
752
|
-
'digitsMatch', 'callbackUrl', 'callbackMethod',
|
753
|
-
'stayAlone', 'floorEvent',
|
754
|
-
'transcriptionType', 'transcriptionUrl',
|
755
|
-
'transcriptionMethod', 'recordWhenAlone', 'relayDTMF']
|
756
|
-
|
757
|
-
def initialize(body, attributes={})
|
758
|
-
if not body
|
759
|
-
raise PlivoError, 'No conference name set for Conference'
|
760
|
-
end
|
761
|
-
super(body, attributes)
|
762
|
-
end
|
763
|
-
end
|
764
|
-
|
765
|
-
|
766
|
-
class Record < Element
|
767
|
-
@nestables = []
|
768
|
-
@valid_attributes = ['action', 'method', 'timeout','finishOnKey',
|
769
|
-
'maxLength', 'playBeep', 'recordSession',
|
770
|
-
'startOnDialAnswer', 'redirect', 'fileFormat',
|
771
|
-
'callbackUrl', 'callbackMethod',
|
772
|
-
'transcriptionType', 'transcriptionUrl',
|
773
|
-
'transcriptionMethod']
|
774
|
-
|
775
|
-
def initialize(attributes={})
|
776
|
-
super(nil, attributes)
|
777
|
-
end
|
778
|
-
end
|
779
|
-
|
780
|
-
|
781
|
-
class PreAnswer < Element
|
782
|
-
@nestables = ['Play', 'Speak', 'GetDigits', 'Wait', 'Redirect', 'Message', 'DTMF']
|
783
|
-
@valid_attributes = []
|
784
|
-
|
785
|
-
def initialize(attributes={}, &block)
|
786
|
-
super(nil, attributes, &block)
|
787
|
-
end
|
788
|
-
end
|
789
|
-
|
790
|
-
|
791
|
-
class Message < Element
|
792
|
-
@nestables = []
|
793
|
-
@valid_attributes = ['src', 'dst', 'type', 'callbackUrl', 'callbackMethod']
|
794
|
-
|
795
|
-
def initialize(body, attributes={})
|
796
|
-
if not body
|
797
|
-
raise PlivoError, 'No text set for Message'
|
798
|
-
end
|
799
|
-
super(body, attributes)
|
800
|
-
end
|
801
|
-
end
|
802
|
-
|
803
|
-
class DTMF < Element
|
804
|
-
@nestables = []
|
805
|
-
@valid_attributes = ['async']
|
806
|
-
|
807
|
-
def initialize(body, attributes={})
|
808
|
-
if not body
|
809
|
-
raise PlivoError, 'No digits set for DTMF'
|
810
|
-
end
|
811
|
-
super(body, attributes)
|
812
|
-
end
|
813
|
-
end
|
814
|
-
|
815
|
-
end
|
1
|
+
require_relative 'plivo/version'
|
2
|
+
require_relative 'plivo/exceptions'
|
3
|
+
require_relative 'plivo/utils'
|
4
|
+
require_relative 'plivo/base'
|
5
|
+
require_relative 'plivo/resources'
|
6
|
+
require_relative 'plivo/rest_client'
|
7
|
+
require_relative 'plivo/xml'
|
8
|
+
|
9
|
+
module Plivo; end
|