plivo 4.1.8 → 4.2.0.pre.beta1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/examples/conference_bridge.rb +108 -0
- data/examples/multi_party_call.rb +295 -0
- data/examples/phlos.rb +55 -0
- data/lib/plivo.rb +2 -0
- data/lib/plivo/base.rb +1 -0
- data/lib/plivo/base/resource.rb +7 -1
- data/lib/plivo/base/resource_interface.rb +2 -2
- data/lib/plivo/base_client.rb +213 -0
- data/lib/plivo/phlo_client.rb +29 -0
- data/lib/plivo/resources.rb +3 -0
- data/lib/plivo/resources/member.rb +64 -0
- data/lib/plivo/resources/nodes.rb +83 -0
- data/lib/plivo/resources/phlos.rb +55 -0
- data/lib/plivo/rest_client.rb +6 -200
- data/lib/plivo/version.rb +1 -1
- metadata +12 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 0e970e643746294ea9ebe794b56cf0edf400fb42af33a1226acd34c0442610fb
|
|
4
|
+
data.tar.gz: b044649e4a950a6c4ce1b85aca66484617e9603c16938d89693cef9f85def37f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 42f91ffb699716db5081a1fc74d76dedd0a4f8a3276bed27aeeccfe02202609554100e133f2ca2eeaa32c1db206c80fea69022dd9ccc9956e5c9c8ab04c8b9bc
|
|
7
|
+
data.tar.gz: 87a9e46d8248347f9c2ed28c1d5cbe2488634e173f911a58b5d40e392719edec3694c79c87142e7e3de23f122ac1aa39d13460e4ac5dfaf31e68a6272014ed56
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
+
## [4.2-beta1](https://github.com/plivo/plivo-ruby/releases/tag/v4.2-beta1) (2019-03-11)
|
|
4
|
+
- Add PHLO support
|
|
5
|
+
- Add Multi-Party Call triggers
|
|
6
|
+
|
|
3
7
|
## [4.1.8](https://github.com/plivo/plivo-ruby/releases/tag/v4.1.8) (2019-02-27)
|
|
4
8
|
- Fix log_incoming_messages having no effect while application creation
|
|
5
9
|
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
require 'rubygems'
|
|
2
|
+
require 'plivo'
|
|
3
|
+
|
|
4
|
+
include Plivo
|
|
5
|
+
|
|
6
|
+
AUTH_ID = 'AUTH_ID'
|
|
7
|
+
AUTH_TOKEN = 'AUTH_TOKEN'
|
|
8
|
+
|
|
9
|
+
client = Phlo.new(AUTH_ID, AUTH_TOKEN)
|
|
10
|
+
|
|
11
|
+
# if credentials are stored in the PLIVO_AUTH_ID and the PLIVO_AUTH_TOKEN environment variables
|
|
12
|
+
# then initialize client as:
|
|
13
|
+
# client = Phlo.new
|
|
14
|
+
#
|
|
15
|
+
|
|
16
|
+
# provide the phlo_id in params
|
|
17
|
+
begin
|
|
18
|
+
phlo = client.phlo.get('11a5f5cf-b6cd-419b-8ada-e41ef073de74')
|
|
19
|
+
conference_bridge = phlo.conference_bridge('b24d49ea-fb62-4612-9d98-4565c67f0bdc')
|
|
20
|
+
puts conference_bridge
|
|
21
|
+
rescue PlivoRESTError => e
|
|
22
|
+
puts 'Exception: ' + e.message
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
# Response:
|
|
26
|
+
# {
|
|
27
|
+
# "api_id"=>"1bcee5a2-f2db-47c3-b424-49f09bc9c62a",
|
|
28
|
+
# "node_id"=>"b24d49ea-fb62-4612-9d98-4565c67f0bdc",
|
|
29
|
+
# "phlo_id"=>"11a5f5cf-b6cd-419b-8ada-e41ef073de74",
|
|
30
|
+
# "name"=>"Conference_1",
|
|
31
|
+
# "node_type"=>"conference",
|
|
32
|
+
# "created_on"=>"2018-12-04 13:51:22.796041+00:00"
|
|
33
|
+
# }
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
# 1. member leaves the call [HANGUP]:
|
|
38
|
+
#
|
|
39
|
+
# member_address => phone number of the member
|
|
40
|
+
#
|
|
41
|
+
# conference_bridge.member(<member_address>).hangup
|
|
42
|
+
|
|
43
|
+
begin
|
|
44
|
+
response = conference_bridge.member('0000000000').hangup
|
|
45
|
+
puts response
|
|
46
|
+
rescue PlivoRESTError => e
|
|
47
|
+
puts 'Exception: ' + e.message
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
# Response:
|
|
51
|
+
# {
|
|
52
|
+
# "api_id"=>"1bcee5a2-f2db-47c3-b424-49f09bc9c62a",
|
|
53
|
+
# "node_id"=>"b24d49ea-fb62-4612-9d98-4565c67f0bdc",
|
|
54
|
+
# "phlo_id"=>"11a5f5cf-b6cd-419b-8ada-e41ef073de74",
|
|
55
|
+
# "member_address"=>"0000000000",
|
|
56
|
+
# "node_type"=>"conference",
|
|
57
|
+
# "created_on"=>"2018-12-04 13:51:22.796041+00:00"
|
|
58
|
+
# }
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
# 2. Mute a member in the conference bridge:
|
|
63
|
+
#
|
|
64
|
+
# member_address => phone number of the member
|
|
65
|
+
#
|
|
66
|
+
# conference_bridge.member(<member_address>).mute
|
|
67
|
+
|
|
68
|
+
begin
|
|
69
|
+
response = conference_bridge.member('0000000000').mute
|
|
70
|
+
puts response
|
|
71
|
+
rescue PlivoRESTError => e
|
|
72
|
+
puts 'Exception: ' + e.message
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
# Response:
|
|
76
|
+
# {
|
|
77
|
+
# "api_id"=>"1bcee5a2-f2db-47c3-b424-49f09bc9c62a",
|
|
78
|
+
# "node_id"=>"b24d49ea-fb62-4612-9d98-4565c67f0bdc",
|
|
79
|
+
# "phlo_id"=>"11a5f5cf-b6cd-419b-8ada-e41ef073de74",
|
|
80
|
+
# "member_address"=>"0000000000",
|
|
81
|
+
# "node_type"=>"conference",
|
|
82
|
+
# "created_on"=>"2018-12-04 13:51:22.796041+00:00"
|
|
83
|
+
# }
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
# 3. Unmute a member in the conference bridge:
|
|
88
|
+
#
|
|
89
|
+
# member_address => phone number of the member
|
|
90
|
+
#
|
|
91
|
+
# conference_bridge.member(<member_address>).unmute
|
|
92
|
+
|
|
93
|
+
begin
|
|
94
|
+
response = conference_bridge.member('0000000000').unmute
|
|
95
|
+
puts response
|
|
96
|
+
rescue PlivoRESTError => e
|
|
97
|
+
puts 'Exception: ' + e.message
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
# Response:
|
|
101
|
+
# {
|
|
102
|
+
# "api_id"=>"1bcee5a2-f2db-47c3-b424-49f09bc9c62a",
|
|
103
|
+
# "node_id"=>"b24d49ea-fb62-4612-9d98-4565c67f0bdc",
|
|
104
|
+
# "phlo_id"=>"11a5f5cf-b6cd-419b-8ada-e41ef073de74",
|
|
105
|
+
# "member_address"=>"0000000000",
|
|
106
|
+
# "node_type"=>"conference",
|
|
107
|
+
# "created_on"=>"2018-12-04 13:51:22.796041+00:00"
|
|
108
|
+
# }
|
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
require 'rubygems'
|
|
2
|
+
require 'plivo'
|
|
3
|
+
|
|
4
|
+
include Plivo
|
|
5
|
+
|
|
6
|
+
AUTH_ID = 'AUTH_ID'
|
|
7
|
+
AUTH_TOKEN = 'AUTH_TOKEN'
|
|
8
|
+
|
|
9
|
+
client = Phlo.new(AUTH_ID, AUTH_TOKEN)
|
|
10
|
+
|
|
11
|
+
# if credentials are stored in the PLIVO_AUTH_ID and the PLIVO_AUTH_TOKEN environment variables
|
|
12
|
+
# then initialize client as:
|
|
13
|
+
# client = Phlo.new
|
|
14
|
+
|
|
15
|
+
# provide the phlo_id in params
|
|
16
|
+
phlo = client.phlo.get('phlo_id')
|
|
17
|
+
|
|
18
|
+
# provide multi_party_call node id in params:
|
|
19
|
+
begin
|
|
20
|
+
multi_party_call = phlo.multi_party_call('node_id')
|
|
21
|
+
puts multi_party_call
|
|
22
|
+
rescue PlivoRESTError => e
|
|
23
|
+
puts 'Exception: ' + e.message
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# Response:
|
|
27
|
+
# {
|
|
28
|
+
# "api_id": "36989807-a76f-4555-84d1-9dfdccca7a80",
|
|
29
|
+
# "node_id": "36989807-a76f-4555-84d1-9dfdccca7a80",
|
|
30
|
+
# "name": "Multi-Party Call_1",
|
|
31
|
+
# "node_type": "multi_party_call",
|
|
32
|
+
# "phlo_id": 'e564a84a-7910-4447-b16f-65c541dd552c',
|
|
33
|
+
# "created_on": '2018-11-03 19:32:33.240504+00:00'
|
|
34
|
+
# }
|
|
35
|
+
#------------------------------------------------------------------------
|
|
36
|
+
|
|
37
|
+
# 1. Agent makes outbound call to customer:
|
|
38
|
+
#
|
|
39
|
+
# 'trigger_source' => Caller Id to be set when an outbound call is made to the users to be added to the multi-party call
|
|
40
|
+
# 'to' => 'phone number/SIP endpoint to which an outbound call should be initiated'
|
|
41
|
+
# 'role' => 'customer'/'agent'/'supervisor'
|
|
42
|
+
# multi_party_call.call(<trigger_source>, <to>, <role>)
|
|
43
|
+
|
|
44
|
+
begin
|
|
45
|
+
response = multi_party_call.call('9999999999', '0000000000', 'customer')
|
|
46
|
+
puts response
|
|
47
|
+
rescue PlivoRESTError => e
|
|
48
|
+
puts 'Exception: ' + e.message
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
# Response:
|
|
52
|
+
# {
|
|
53
|
+
# "api_id": "36989807-a76f-4555-84d1-9dfdccca7a80",
|
|
54
|
+
# "node_id": "36989807-a76f-4555-84d1-9dfdccca7a80",
|
|
55
|
+
# "name": "Multi-Party Call_1",
|
|
56
|
+
# "node_type": "multi_party_call",
|
|
57
|
+
# "phlo_id": 'e564a84a-7910-4447-b16f-65c541dd552c',
|
|
58
|
+
# "created_on": '2018-11-03 19:32:33.240504+00:00'
|
|
59
|
+
# }
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
# 2. Agent initiates warm transfer:
|
|
63
|
+
#
|
|
64
|
+
# 'trigger_source' => number of the agent initiating warm transfer
|
|
65
|
+
# 'to' => number of another agent to be added to the multi-party call
|
|
66
|
+
#
|
|
67
|
+
# multi_party_call.warm_transfer(<trigger_source>, <to>)
|
|
68
|
+
|
|
69
|
+
begin
|
|
70
|
+
response = multi_party_call.warm_transfer('9999999999', '0000000000')
|
|
71
|
+
puts response
|
|
72
|
+
rescue PlivoRESTError => e
|
|
73
|
+
puts 'Exception: ' + e.message
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
# Response:
|
|
77
|
+
# {
|
|
78
|
+
# "api_id": "36989807-a76f-4555-84d1-9dfdccca7a80",
|
|
79
|
+
# "node_id": "36989807-a76f-4555-84d1-9dfdccca7a80",
|
|
80
|
+
# "name": "Multi-Party Call_1",
|
|
81
|
+
# "node_type": "multi_party_call",
|
|
82
|
+
# "phlo_id": 'e564a84a-7910-4447-b16f-65c541dd552c',
|
|
83
|
+
# "created_on": '2018-11-03 19:32:33.240504+00:00'
|
|
84
|
+
# }
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
# 3. Agent initiates cold transfer:
|
|
88
|
+
#
|
|
89
|
+
# 'trigger_source' => number of the agent initiating cold transfer
|
|
90
|
+
# 'to' => number of another agent to be added to the multi-party call
|
|
91
|
+
#
|
|
92
|
+
# multi_party_call.cold_transfer(<trigger_source>, <to>)
|
|
93
|
+
|
|
94
|
+
begin
|
|
95
|
+
response = multi_party_call.cold_transfer('9999999999', '0000000000')
|
|
96
|
+
puts response
|
|
97
|
+
rescue PlivoRESTError => e
|
|
98
|
+
puts 'Exception: ' + e.message
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
# Response:
|
|
102
|
+
# {
|
|
103
|
+
# "api_id": "36989807-a76f-4555-84d1-9dfdccca7a80",
|
|
104
|
+
# "node_id": "36989807-a76f-4555-84d1-9dfdccca7a80",
|
|
105
|
+
# "name": "Multi-Party Call_1",
|
|
106
|
+
# "node_type": "multi_party_call",
|
|
107
|
+
# "phlo_id": 'e564a84a-7910-4447-b16f-65c541dd552c',
|
|
108
|
+
# "created_on": '2018-11-03 19:32:33.240504+00:00'
|
|
109
|
+
# }
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
# 4. Agent abort transfer:
|
|
113
|
+
#
|
|
114
|
+
# agent_address => number of the agent
|
|
115
|
+
#
|
|
116
|
+
# multi_party_call.member(<agent_address>).abort_transfer
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
begin
|
|
120
|
+
response = multi_party_call.member('0000000000').abort_transfer
|
|
121
|
+
puts response
|
|
122
|
+
rescue PlivoRESTError => e
|
|
123
|
+
puts 'Exception: ' + e.message
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
# Response:
|
|
127
|
+
# {
|
|
128
|
+
# "api_id": "36989807-a76f-4555-84d1-9dfdccca7a80",
|
|
129
|
+
# "node_id": "36989807-a76f-4555-84d1-9dfdccca7a80",
|
|
130
|
+
# "node_type": "multi_party_call",
|
|
131
|
+
# "phlo_id": 'e564a84a-7910-4447-b16f-65c541dd552c',
|
|
132
|
+
# "member_address": '0000000000',
|
|
133
|
+
# "created_on": '2018-11-03 19:32:33.240504+00:00'
|
|
134
|
+
# }
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
# 5. Agent places customer on hold:
|
|
138
|
+
#
|
|
139
|
+
# member_address => phone number of the member who is being put on hold
|
|
140
|
+
#
|
|
141
|
+
# multi_party_call.member(<member_address>).hold
|
|
142
|
+
|
|
143
|
+
begin
|
|
144
|
+
response = multi_party_call.member('9999999999').hold
|
|
145
|
+
puts response
|
|
146
|
+
rescue PlivoRESTError => e
|
|
147
|
+
puts 'Exception: ' + e.message
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
# Response:
|
|
151
|
+
# {
|
|
152
|
+
# "api_id": "36989807-a76f-4555-84d1-9dfdccca7a80",
|
|
153
|
+
# "node_id": "36989807-a76f-4555-84d1-9dfdccca7a80",
|
|
154
|
+
# "node_type": "multi_party_call",
|
|
155
|
+
# "phlo_id": 'e564a84a-7910-4447-b16f-65c541dd552c',
|
|
156
|
+
# "member_address": '9999999999',
|
|
157
|
+
# "created_on": '2018-11-03 19:32:33.240504+00:00'
|
|
158
|
+
# }
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
# 6. Resume call after hold:
|
|
162
|
+
#
|
|
163
|
+
# member_address => phone number of the member
|
|
164
|
+
#
|
|
165
|
+
# multi_party_call.member(<member_address>).unhold
|
|
166
|
+
|
|
167
|
+
begin
|
|
168
|
+
response = multi_party_call.member('9999999999').unhold
|
|
169
|
+
puts response
|
|
170
|
+
rescue PlivoRESTError => e
|
|
171
|
+
puts 'Exception: ' + e.message
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
# Response:
|
|
176
|
+
# {
|
|
177
|
+
# "api_id": "36989807-a76f-4555-84d1-9dfdccca7a80",
|
|
178
|
+
# "node_id": "36989807-a76f-4555-84d1-9dfdccca7a80",
|
|
179
|
+
# "node_type": "multi_party_call",
|
|
180
|
+
# "phlo_id": 'e564a84a-7910-4447-b16f-65c541dd552c',
|
|
181
|
+
# "member_address": '9999999999',
|
|
182
|
+
# "created_on": '2018-11-03 19:32:33.240504+00:00'
|
|
183
|
+
# }
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
# 7. Agent initiates voicemail drop:
|
|
187
|
+
#
|
|
188
|
+
# member_address => customer's number/endpoint
|
|
189
|
+
#
|
|
190
|
+
# multi_party_call.member(<member_address>).voicemail_drop
|
|
191
|
+
|
|
192
|
+
begin
|
|
193
|
+
response = multi_party_call.member('9999999999').voicemail_drop
|
|
194
|
+
puts response
|
|
195
|
+
rescue PlivoRESTError => e
|
|
196
|
+
puts 'Exception: ' + e.message
|
|
197
|
+
end
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
# Response:
|
|
201
|
+
# {
|
|
202
|
+
# "api_id": "36989807-a76f-4555-84d1-9dfdccca7a80",
|
|
203
|
+
# "node_id": "36989807-a76f-4555-84d1-9dfdccca7a80",
|
|
204
|
+
# "node_type": "multi_party_call",
|
|
205
|
+
# "phlo_id": 'e564a84a-7910-4447-b16f-65c541dd552c',
|
|
206
|
+
# "member_address": '9999999999',
|
|
207
|
+
# "created_on": '2018-11-03 19:32:33.240504+00:00'
|
|
208
|
+
# }
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
# 8. Rejoin call on warm transfer:
|
|
212
|
+
#
|
|
213
|
+
# agent_address => number of the agent to be added to the original conference on completion of call between agents
|
|
214
|
+
#
|
|
215
|
+
# multi_party_call.member(<agent_address>).resume_call
|
|
216
|
+
|
|
217
|
+
begin
|
|
218
|
+
response = multi_party_call.member('0000000000').resume_call
|
|
219
|
+
puts response
|
|
220
|
+
rescue PlivoRESTError => e
|
|
221
|
+
puts 'Exception: ' + e.message
|
|
222
|
+
end
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
# Response:
|
|
226
|
+
# {
|
|
227
|
+
# "api_id": "36989807-a76f-4555-84d1-9dfdccca7a80",
|
|
228
|
+
# "node_id": "36989807-a76f-4555-84d1-9dfdccca7a80",
|
|
229
|
+
# "node_type": "multi_party_call",
|
|
230
|
+
# "phlo_id": 'e564a84a-7910-4447-b16f-65c541dd552c',
|
|
231
|
+
# "member_address": '9999999999',
|
|
232
|
+
# "created_on": '2018-11-03 19:32:33.240504+00:00'
|
|
233
|
+
# }
|
|
234
|
+
|
|
235
|
+
|
|
236
|
+
# 9. Agent leaves of the call [HANGUP]:
|
|
237
|
+
#
|
|
238
|
+
# agent_address => phone number of the agent
|
|
239
|
+
#
|
|
240
|
+
# multi_party_call.member(<agent_address>).hangup
|
|
241
|
+
|
|
242
|
+
begin
|
|
243
|
+
response = multi_party_call.member('0000000000').hangup
|
|
244
|
+
puts response
|
|
245
|
+
rescue PlivoRESTError => e
|
|
246
|
+
puts 'Exception: ' + e.message
|
|
247
|
+
end
|
|
248
|
+
|
|
249
|
+
|
|
250
|
+
# Response:
|
|
251
|
+
# {
|
|
252
|
+
# "api_id": "36989807-a76f-4555-84d1-9dfdccca7a80",
|
|
253
|
+
# "node_id": "36989807-a76f-4555-84d1-9dfdccca7a80",
|
|
254
|
+
# "node_type": "multi_party_call",
|
|
255
|
+
# "phlo_id": 'e564a84a-7910-4447-b16f-65c541dd552c',
|
|
256
|
+
# "member_address": '9999999999',
|
|
257
|
+
# "created_on": '2018-11-03 19:32:33.240504+00:00'
|
|
258
|
+
# }
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
# 10. Customer is removed from the conference call [HANGUP]:
|
|
262
|
+
#
|
|
263
|
+
# customer_address => phone number of the customer
|
|
264
|
+
#
|
|
265
|
+
# multi_party_call.member(<customer_address>).hangup
|
|
266
|
+
|
|
267
|
+
# Response:
|
|
268
|
+
# {
|
|
269
|
+
# "api_id": "36989807-a76f-4555-84d1-9dfdccca7a80",
|
|
270
|
+
# "node_id": "36989807-a76f-4555-84d1-9dfdccca7a80",
|
|
271
|
+
# "node_type": "multi_party_call",
|
|
272
|
+
# "phlo_id": 'e564a84a-7910-4447-b16f-65c541dd552c',
|
|
273
|
+
# "member_address": '9999999999',
|
|
274
|
+
# "created_on": '2018-11-03 19:32:33.240504+00:00'
|
|
275
|
+
# }
|
|
276
|
+
|
|
277
|
+
|
|
278
|
+
# 11. Remove a member from the multi-party call:
|
|
279
|
+
#
|
|
280
|
+
# member_address => phone number of the member
|
|
281
|
+
#
|
|
282
|
+
# multi_party_call.member(<member_address>).remove
|
|
283
|
+
|
|
284
|
+
begin
|
|
285
|
+
response = multi_party_call.member('9999999999').remove
|
|
286
|
+
puts response
|
|
287
|
+
rescue PlivoRESTError => e
|
|
288
|
+
puts 'Exception: ' + e.message
|
|
289
|
+
end
|
|
290
|
+
|
|
291
|
+
# Response:
|
|
292
|
+
# {
|
|
293
|
+
# "api_id": "36989807-a76f-4555-84d1-9dfdccca7a80",
|
|
294
|
+
# "id": "9999999999"
|
|
295
|
+
# }
|
data/examples/phlos.rb
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
require 'rubygems'
|
|
2
|
+
require 'plivo'
|
|
3
|
+
|
|
4
|
+
include Plivo
|
|
5
|
+
|
|
6
|
+
AUTH_ID = 'AUTH_ID'
|
|
7
|
+
AUTH_TOKEN = 'AUTH_TOKEN'
|
|
8
|
+
|
|
9
|
+
client = Phlo.new(AUTH_ID, AUTH_TOKEN)
|
|
10
|
+
|
|
11
|
+
# if credentials are stored in the PLIVO_AUTH_ID and the PLIVO_AUTH_TOKEN environment variables
|
|
12
|
+
# then initialize client as:
|
|
13
|
+
# client = Phlo.new
|
|
14
|
+
#
|
|
15
|
+
|
|
16
|
+
# provide the phlo_id in params
|
|
17
|
+
begin
|
|
18
|
+
phlo = client.phlo.get('phlo_id')
|
|
19
|
+
puts phlo
|
|
20
|
+
rescue PlivoRESTError => e
|
|
21
|
+
puts 'Exception: ' + e.message
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
# Sample Response:
|
|
26
|
+
# {
|
|
27
|
+
# "api_id": '36989807-a76f-4555-84d1-9dfdccca7a80',
|
|
28
|
+
# "phlo_id": 'e564a84a-7910-4447-b16f-65c541dd552c',
|
|
29
|
+
# "name": 'assignment_mpc',
|
|
30
|
+
# "created_on": '2018-11-03 19:32:33.240504+00:00'
|
|
31
|
+
# }
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
# initiate phlo via API request:
|
|
35
|
+
begin
|
|
36
|
+
#optional parameter - params
|
|
37
|
+
params = {
|
|
38
|
+
from: '9999999999',
|
|
39
|
+
to: '0000000000'
|
|
40
|
+
}
|
|
41
|
+
response = phlo.run(params)
|
|
42
|
+
puts response
|
|
43
|
+
rescue PlivoRESTError => e
|
|
44
|
+
puts 'Exception: ' + e.message
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
# Sample Response:
|
|
49
|
+
# {
|
|
50
|
+
# :api_id=>"ff25223a-1c9f-11e4-80aa-12313f048015",
|
|
51
|
+
# :phlo_id=>"ff25223a-1c9f-11e4-80aa-12313f048015",
|
|
52
|
+
# :name=>"assignment_mpc",
|
|
53
|
+
# :created_on=>"2018-11-03 19:32:33.210714+00:00",
|
|
54
|
+
# :phlo_run_id=>"ff25223a-1c9f-11e4-80aa-12313f048015"
|
|
55
|
+
# }
|
data/lib/plivo.rb
CHANGED
data/lib/plivo/base.rb
CHANGED
data/lib/plivo/base/resource.rb
CHANGED
|
@@ -13,7 +13,7 @@ module Plivo
|
|
|
13
13
|
private
|
|
14
14
|
|
|
15
15
|
def configure_client(client)
|
|
16
|
-
valid_param?(:client, client, RestClient, true)
|
|
16
|
+
valid_param?(:client, client, [RestClient, Phlo], true)
|
|
17
17
|
@_client = client
|
|
18
18
|
end
|
|
19
19
|
|
|
@@ -80,6 +80,12 @@ module Plivo
|
|
|
80
80
|
Response.new(@_client.send_request(@_resource_uri, 'DELETE', params),
|
|
81
81
|
@_identifier_string)
|
|
82
82
|
end
|
|
83
|
+
|
|
84
|
+
def perform_run(params)
|
|
85
|
+
response_json = @_client.send_request(@_resource_uri, 'POST', params, nil)
|
|
86
|
+
parse_and_set(response_json)
|
|
87
|
+
Response.new(response_json, @_identifier_string)
|
|
88
|
+
end
|
|
83
89
|
end
|
|
84
90
|
end
|
|
85
91
|
end
|
|
@@ -11,14 +11,14 @@ module Plivo
|
|
|
11
11
|
private
|
|
12
12
|
|
|
13
13
|
def configure_client(client)
|
|
14
|
-
valid_param?(:client, client, RestClient, true)
|
|
14
|
+
valid_param?(:client, client, [RestClient, Phlo], true)
|
|
15
15
|
@_client = client
|
|
16
16
|
end
|
|
17
17
|
|
|
18
18
|
def configure_resource_uri
|
|
19
19
|
to_join = ['', 'v1', 'Account', @_client.auth_id, @_name, '']
|
|
20
20
|
to_join = ['', 'v1', 'Account', ''] if @_name == 'Account'
|
|
21
|
-
|
|
21
|
+
to_join = ['', 'v1', @_name, ''] if @_name == 'phlo'
|
|
22
22
|
@_resource_uri = to_join.join('/')
|
|
23
23
|
end
|
|
24
24
|
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
require 'json'
|
|
2
|
+
require 'faraday'
|
|
3
|
+
require 'faraday_middleware'
|
|
4
|
+
|
|
5
|
+
require_relative 'exceptions'
|
|
6
|
+
require_relative 'utils'
|
|
7
|
+
require_relative 'resources'
|
|
8
|
+
require_relative 'base'
|
|
9
|
+
|
|
10
|
+
module Plivo
|
|
11
|
+
# Core client, used for all API requests
|
|
12
|
+
include Utils
|
|
13
|
+
class BaseClient
|
|
14
|
+
# Base stuff
|
|
15
|
+
attr_reader :headers, :auth_credentials
|
|
16
|
+
|
|
17
|
+
def initialize(auth_id = nil, auth_token = nil, proxy_options = nil, timeout=5)
|
|
18
|
+
configure_credentials(auth_id, auth_token)
|
|
19
|
+
configure_proxies(proxy_options)
|
|
20
|
+
configure_timeout(timeout)
|
|
21
|
+
configure_headers
|
|
22
|
+
configure_connection
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def auth_id
|
|
26
|
+
@auth_credentials[:auth_id]
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def process_response(method, response)
|
|
30
|
+
handle_response_exceptions(response)
|
|
31
|
+
if method == 'DELETE'
|
|
32
|
+
if response[:status] != 204
|
|
33
|
+
raise Exceptions::PlivoRESTError, "Resource at #{response[:url]} "\
|
|
34
|
+
'couldn\'t be deleted'
|
|
35
|
+
end
|
|
36
|
+
elsif !([200, 201, 202].include? response[:status])
|
|
37
|
+
raise Exceptions::PlivoRESTError, "Received #{response[:status]} for #{method}"
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
response[:body]
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def send_request(resource_path, method = 'GET', data = {}, timeout = nil, use_multipart_conn = false)
|
|
44
|
+
timeout ||= @timeout
|
|
45
|
+
|
|
46
|
+
response = case method
|
|
47
|
+
when 'GET' then send_get(resource_path, data, timeout)
|
|
48
|
+
when 'POST' then send_post(resource_path, data, timeout, use_multipart_conn)
|
|
49
|
+
when 'DELETE' then send_delete(resource_path, timeout)
|
|
50
|
+
else raise_invalid_request("#{method} not supported by Plivo, yet")
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
process_response(method, response.to_hash)
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
private
|
|
57
|
+
|
|
58
|
+
def auth_token
|
|
59
|
+
@auth_credentials[:auth_token]
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def configure_credentials(auth_id, auth_token)
|
|
63
|
+
# Fetches and sets the right credentials
|
|
64
|
+
auth_id ||= ENV['PLIVO_AUTH_ID']
|
|
65
|
+
auth_token ||= ENV['PLIVO_AUTH_TOKEN']
|
|
66
|
+
|
|
67
|
+
raise Exceptions::AuthenticationError, 'Couldn\'t find auth credentials' unless
|
|
68
|
+
auth_id && auth_token
|
|
69
|
+
|
|
70
|
+
raise Exceptions::AuthenticationError, "Invalid auth_id: '#{auth_id}'" unless
|
|
71
|
+
Utils.valid_account?(auth_id)
|
|
72
|
+
|
|
73
|
+
@auth_credentials = {
|
|
74
|
+
auth_id: auth_id,
|
|
75
|
+
auth_token: auth_token
|
|
76
|
+
}
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def configure_proxies(proxy_dict)
|
|
80
|
+
@proxy_hash = nil
|
|
81
|
+
return unless proxy_dict
|
|
82
|
+
|
|
83
|
+
@proxy_hash = {
|
|
84
|
+
uri: "#{proxy_dict[:proxy_host]}:#{proxy_dict[:proxy_port]}",
|
|
85
|
+
user: proxy_dict[:proxy_user],
|
|
86
|
+
password: proxy_dict[:proxy_pass]
|
|
87
|
+
}
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
def configure_timeout(timeout)
|
|
91
|
+
@timeout = timeout
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
def user_agent
|
|
95
|
+
"plivo-ruby/#{Plivo::VERSION} (Ruby #{RUBY_VERSION})"
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
def configure_headers
|
|
99
|
+
@headers = {
|
|
100
|
+
'User-Agent' => user_agent,
|
|
101
|
+
'Content-Type' => 'application/json',
|
|
102
|
+
'Accept' => 'application/json'
|
|
103
|
+
}
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
def configure_connection
|
|
108
|
+
@conn = Faraday.new(@base_uri) do |faraday|
|
|
109
|
+
faraday.headers = @headers
|
|
110
|
+
|
|
111
|
+
# DANGER: Basic auth should always come after headers, else
|
|
112
|
+
# The headers will replace the basic_auth
|
|
113
|
+
|
|
114
|
+
faraday.basic_auth(auth_id, auth_token)
|
|
115
|
+
|
|
116
|
+
faraday.proxy=@proxy_hash if @proxy_hash
|
|
117
|
+
faraday.response :json, content_type: /\bjson$/
|
|
118
|
+
faraday.adapter Faraday.default_adapter
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
def send_get(resource_path, data, timeout)
|
|
123
|
+
response = @conn.get do |req|
|
|
124
|
+
req.url resource_path, data
|
|
125
|
+
req.options.timeout = timeout if timeout
|
|
126
|
+
end
|
|
127
|
+
response
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
def send_post(resource_path, data, timeout, use_multipart_conn)
|
|
131
|
+
if use_multipart_conn
|
|
132
|
+
multipart_conn = Faraday.new(@base_uri) do |faraday|
|
|
133
|
+
faraday.headers = {
|
|
134
|
+
'User-Agent' => @headers['User-Agent'],
|
|
135
|
+
'Accept' => @headers['Accept']
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
# DANGER: Basic auth should always come after headers, else
|
|
139
|
+
# The headers will replace the basic_auth
|
|
140
|
+
|
|
141
|
+
faraday.request :multipart
|
|
142
|
+
faraday.request :url_encoded
|
|
143
|
+
faraday.basic_auth(auth_id, auth_token)
|
|
144
|
+
|
|
145
|
+
faraday.proxy=@proxy_hash if @proxy_hash
|
|
146
|
+
faraday.response :json, content_type: /\bjson$/
|
|
147
|
+
faraday.adapter Faraday.default_adapter
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
response = multipart_conn.post do |req|
|
|
151
|
+
req.url resource_path
|
|
152
|
+
req.options.timeout = timeout if timeout
|
|
153
|
+
req.body = data
|
|
154
|
+
end
|
|
155
|
+
else
|
|
156
|
+
response = @conn.post do |req|
|
|
157
|
+
req.url resource_path
|
|
158
|
+
req.options.timeout = timeout if timeout
|
|
159
|
+
req.body = JSON.generate(data) if data
|
|
160
|
+
end
|
|
161
|
+
end
|
|
162
|
+
response
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
def send_delete(resource_path, timeout)
|
|
166
|
+
response = @conn.delete do |req|
|
|
167
|
+
req.url resource_path
|
|
168
|
+
req.options.timeout = timeout if timeout
|
|
169
|
+
end
|
|
170
|
+
response
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
def handle_response_exceptions(response)
|
|
174
|
+
exception_mapping = {
|
|
175
|
+
400 => [
|
|
176
|
+
Exceptions::ValidationError,
|
|
177
|
+
'A parameter is missing or is invalid while accessing resource'
|
|
178
|
+
],
|
|
179
|
+
401 => [
|
|
180
|
+
Exceptions::AuthenticationError,
|
|
181
|
+
'Failed to authenticate while accessing resource'
|
|
182
|
+
],
|
|
183
|
+
404 => [
|
|
184
|
+
Exceptions::ResourceNotFoundError,
|
|
185
|
+
'Resource not found'
|
|
186
|
+
],
|
|
187
|
+
405 => [
|
|
188
|
+
Exceptions::InvalidRequestError,
|
|
189
|
+
'HTTP method used is not allowed to access resource'
|
|
190
|
+
],
|
|
191
|
+
500 => [
|
|
192
|
+
Exceptions::PlivoServerError,
|
|
193
|
+
'A server error occurred while accessing resource'
|
|
194
|
+
]
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
response_json = response[:body]
|
|
198
|
+
return unless exception_mapping.key? response[:status]
|
|
199
|
+
|
|
200
|
+
exception_now = exception_mapping[response[:status]]
|
|
201
|
+
error_message = if (response_json.is_a? Hash) && (response_json.key? 'error')
|
|
202
|
+
response_json['error']
|
|
203
|
+
else
|
|
204
|
+
exception_now[1] + " at: #{response[:url]}"
|
|
205
|
+
end
|
|
206
|
+
if error_message.is_a?(Hash) && error_message.key?('error')
|
|
207
|
+
error_message = error_message['error']
|
|
208
|
+
end
|
|
209
|
+
|
|
210
|
+
raise exception_now[0], error_message.to_s
|
|
211
|
+
end
|
|
212
|
+
end
|
|
213
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
require_relative 'resources'
|
|
2
|
+
require_relative 'base_client'
|
|
3
|
+
require_relative 'base'
|
|
4
|
+
|
|
5
|
+
module Plivo
|
|
6
|
+
|
|
7
|
+
class Phlo < BaseClient
|
|
8
|
+
|
|
9
|
+
# Resources
|
|
10
|
+
attr_reader :phlo
|
|
11
|
+
|
|
12
|
+
def initialize(auth_id = nil, auth_token = nil, proxy_options = nil, timeout=5)
|
|
13
|
+
configure_base_uri
|
|
14
|
+
super
|
|
15
|
+
configure_interfaces
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
private
|
|
19
|
+
|
|
20
|
+
def configure_base_uri
|
|
21
|
+
@base_uri = Base::PHLO_API_URL
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def configure_interfaces
|
|
25
|
+
@phlo = Resources::PhloInterface.new(self)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
end
|
|
29
|
+
end
|
data/lib/plivo/resources.rb
CHANGED
|
@@ -9,6 +9,9 @@ require_relative 'resources/calls'
|
|
|
9
9
|
require_relative 'resources/endpoints'
|
|
10
10
|
require_relative 'resources/addresses'
|
|
11
11
|
require_relative 'resources/identities'
|
|
12
|
+
require_relative 'resources/phlos'
|
|
13
|
+
require_relative 'resources/nodes'
|
|
14
|
+
require_relative 'resources/member'
|
|
12
15
|
|
|
13
16
|
module Plivo
|
|
14
17
|
module Resources
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
module Plivo
|
|
2
|
+
module Resources
|
|
3
|
+
class Member < Base::Resource
|
|
4
|
+
def initialize(client, options)
|
|
5
|
+
@_name = 'member'
|
|
6
|
+
@_identifier_string = 'member_address'
|
|
7
|
+
super
|
|
8
|
+
configure_resource_uri
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def to_s
|
|
12
|
+
{
|
|
13
|
+
api_id: @api_id,
|
|
14
|
+
node_id: @node_id,
|
|
15
|
+
phlo_id: @phlo_id,
|
|
16
|
+
node_type: @node_type,
|
|
17
|
+
member_address: @member_address,
|
|
18
|
+
created_on: @created_on
|
|
19
|
+
}.to_s
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def hold
|
|
23
|
+
perform_update({action: 'hold'})
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def unhold
|
|
27
|
+
perform_update({action: 'unhold'})
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def voicemail_drop
|
|
31
|
+
perform_update({action: 'voicemail_drop'})
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def resume_call
|
|
35
|
+
perform_update({action: 'resume_call'})
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def hangup
|
|
39
|
+
perform_update({action: 'hangup'})
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# def remove
|
|
43
|
+
# perform_delete
|
|
44
|
+
# end
|
|
45
|
+
|
|
46
|
+
def mute
|
|
47
|
+
perform_update({action: 'mute'})
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def unmute
|
|
51
|
+
perform_update({action: 'unmute'})
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def abort_transfer
|
|
55
|
+
perform_update({action: 'abort_transfer'})
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
private
|
|
59
|
+
def configure_resource_uri
|
|
60
|
+
@_resource_uri = ['', 'v1', 'phlo', @phlo_id, @node_type, @node_id, 'members', @id, ''].join('/')
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
end
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
module Plivo
|
|
2
|
+
module Resources
|
|
3
|
+
class NodeInterface < Base::ResourceInterface
|
|
4
|
+
def initialize(client, resource_list_json=nil)
|
|
5
|
+
super
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def getNode(node_id, node_type)
|
|
9
|
+
@_resource_uri = ['', 'v1', 'phlo', @_phlo_id, node_type, ''].join('/')
|
|
10
|
+
@_resource_type = configure_node_type(node_type)
|
|
11
|
+
perform_get(node_id)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
private
|
|
15
|
+
def configure_node_type(node_type)
|
|
16
|
+
case node_type
|
|
17
|
+
when 'multi_party_call'
|
|
18
|
+
MultiPartyCall
|
|
19
|
+
# when 'conference_bridge'
|
|
20
|
+
# ConferenceBridge
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
class Node < Base::Resource
|
|
26
|
+
def initialize(client,options=nil)
|
|
27
|
+
@_identifier_string = 'node_id'
|
|
28
|
+
super
|
|
29
|
+
configure_resource_uri
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def to_s
|
|
33
|
+
{
|
|
34
|
+
api_id: @api_id,
|
|
35
|
+
node_id: @node_id,
|
|
36
|
+
phlo_id: @phlo_id,
|
|
37
|
+
name: @name,
|
|
38
|
+
node_type: @node_type,
|
|
39
|
+
created_on: @created_on
|
|
40
|
+
}.to_s
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def member(member_address)
|
|
44
|
+
options = {'member_address' => member_address, 'node_id' => @id, 'phlo_id' => @phlo_id, 'node_type' => @node_type}
|
|
45
|
+
Member.new(@_client, {resource_json: options})
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
private
|
|
49
|
+
def configure_resource_uri
|
|
50
|
+
@_resource_uri = ['', 'v1', 'phlo', @phlo_id, @node_type, @id, ''].join('/')
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
class MultiPartyCall < Node
|
|
55
|
+
def initialize(client,options=nil)
|
|
56
|
+
@_name = 'multi_party_call'
|
|
57
|
+
super
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def call(trigger_source, to, role)
|
|
61
|
+
payload = {action: 'call', trigger_source: trigger_source, to: to, role: role}
|
|
62
|
+
perform_update(payload)
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def warm_transfer(trigger_source, to, role='agent')
|
|
66
|
+
payload = {action: 'warm_transfer', trigger_source: trigger_source, to: to, role: role}
|
|
67
|
+
perform_update(payload)
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def cold_transfer(trigger_source, to, role='agent')
|
|
71
|
+
payload = {action: 'cold_transfer', trigger_source: trigger_source, to: to, role: role}
|
|
72
|
+
perform_update(payload)
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
# class ConferenceBridge < Node
|
|
77
|
+
# def initialize(client,options=nil)
|
|
78
|
+
# @_name = 'conference_bridge'
|
|
79
|
+
# super
|
|
80
|
+
# end
|
|
81
|
+
# end
|
|
82
|
+
end
|
|
83
|
+
end
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
module Plivo
|
|
2
|
+
module Resources
|
|
3
|
+
include Plivo::Utils
|
|
4
|
+
|
|
5
|
+
class Phlo < Base::Resource
|
|
6
|
+
|
|
7
|
+
def initialize(client, options = nil)
|
|
8
|
+
@_name = 'phlo'
|
|
9
|
+
@_identifier_string = 'phlo_id'
|
|
10
|
+
super
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def to_s
|
|
14
|
+
{
|
|
15
|
+
api_id: @api_id,
|
|
16
|
+
phlo_id: @phlo_id,
|
|
17
|
+
name: @name,
|
|
18
|
+
created_on: @created_on,
|
|
19
|
+
phlo_run_id: @phlo_run_id
|
|
20
|
+
}.to_s
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def multi_party_call(node_id)
|
|
24
|
+
nodeInterface = NodeInterface.new(@_client, {_phlo_id: @id})
|
|
25
|
+
nodeInterface.getNode(node_id, 'multi_party_call')
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# def conference_bridge(node_id)
|
|
29
|
+
# nodeInterface = NodeInterface.new(@_client, {_phlo_id: @id})
|
|
30
|
+
# nodeInterface.getNode(node_id, 'conference_bridge')
|
|
31
|
+
# end
|
|
32
|
+
|
|
33
|
+
def run(params=nil)
|
|
34
|
+
@_resource_uri = ['', 'v1', 'account', @_client.auth_id, @_name, @id, ''].join('/')
|
|
35
|
+
perform_run(params)
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
class PhloInterface < Base::ResourceInterface
|
|
41
|
+
|
|
42
|
+
def initialize(client, resource_list_json = nil)
|
|
43
|
+
@_name = 'phlo'
|
|
44
|
+
@_resource_type = Phlo
|
|
45
|
+
super
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def get(phlo_id)
|
|
49
|
+
perform_get(phlo_id)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
end
|
|
55
|
+
end
|
data/lib/plivo/rest_client.rb
CHANGED
|
@@ -1,18 +1,9 @@
|
|
|
1
|
-
require 'json'
|
|
2
|
-
require 'faraday'
|
|
3
|
-
require 'faraday_middleware'
|
|
4
|
-
|
|
5
|
-
require_relative 'exceptions'
|
|
6
|
-
require_relative 'utils'
|
|
7
1
|
require_relative 'resources'
|
|
2
|
+
require_relative 'base_client'
|
|
8
3
|
require_relative 'base'
|
|
9
4
|
|
|
10
5
|
module Plivo
|
|
11
|
-
|
|
12
|
-
include Utils
|
|
13
|
-
class RestClient
|
|
14
|
-
# Base stuff
|
|
15
|
-
attr_reader :headers, :auth_credentials
|
|
6
|
+
class RestClient < BaseClient
|
|
16
7
|
|
|
17
8
|
# Resources
|
|
18
9
|
attr_reader :messages, :account, :subaccounts, :recordings
|
|
@@ -21,93 +12,15 @@ module Plivo
|
|
|
21
12
|
attr_reader :addresses, :identities
|
|
22
13
|
|
|
23
14
|
def initialize(auth_id = nil, auth_token = nil, proxy_options = nil, timeout=5)
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
configure_timeout(timeout)
|
|
27
|
-
configure_headers
|
|
28
|
-
configure_connection
|
|
15
|
+
configure_base_uri
|
|
16
|
+
super
|
|
29
17
|
configure_interfaces
|
|
30
18
|
end
|
|
31
19
|
|
|
32
|
-
def auth_id
|
|
33
|
-
@auth_credentials[:auth_id]
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
def process_response(method, response)
|
|
37
|
-
handle_response_exceptions(response)
|
|
38
|
-
if method == 'DELETE'
|
|
39
|
-
if response[:status] != 204
|
|
40
|
-
raise Exceptions::PlivoRESTError, "Resource at #{response[:url]} "\
|
|
41
|
-
'couldn\'t be deleted'
|
|
42
|
-
end
|
|
43
|
-
elsif !([200, 201, 202].include? response[:status])
|
|
44
|
-
raise Exceptions::PlivoRESTError, "Received #{response[:status]} for #{method}"
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
response[:body]
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
def send_request(resource_path, method = 'GET', data = {}, timeout = nil, use_multipart_conn = false)
|
|
51
|
-
timeout ||= @timeout
|
|
52
|
-
|
|
53
|
-
response = case method
|
|
54
|
-
when 'GET' then send_get(resource_path, data, timeout)
|
|
55
|
-
when 'POST' then send_post(resource_path, data, timeout, use_multipart_conn)
|
|
56
|
-
when 'DELETE' then send_delete(resource_path, data, timeout)
|
|
57
|
-
else raise_invalid_request("#{method} not supported by Plivo, yet")
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
process_response(method, response.to_hash)
|
|
61
|
-
end
|
|
62
|
-
|
|
63
20
|
private
|
|
64
21
|
|
|
65
|
-
def
|
|
66
|
-
@
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
def configure_credentials(auth_id, auth_token)
|
|
70
|
-
# Fetches and sets the right credentials
|
|
71
|
-
auth_id ||= ENV['PLIVO_AUTH_ID']
|
|
72
|
-
auth_token ||= ENV['PLIVO_AUTH_TOKEN']
|
|
73
|
-
|
|
74
|
-
raise Exceptions::AuthenticationError, 'Couldn\'t find auth credentials' unless
|
|
75
|
-
auth_id && auth_token
|
|
76
|
-
|
|
77
|
-
raise Exceptions::AuthenticationError, "Invalid auth_id: '#{auth_id}'" unless
|
|
78
|
-
Utils.valid_account?(auth_id)
|
|
79
|
-
|
|
80
|
-
@auth_credentials = {
|
|
81
|
-
auth_id: auth_id,
|
|
82
|
-
auth_token: auth_token
|
|
83
|
-
}
|
|
84
|
-
end
|
|
85
|
-
|
|
86
|
-
def configure_proxies(proxy_dict)
|
|
87
|
-
@proxy_hash = nil
|
|
88
|
-
return unless proxy_dict
|
|
89
|
-
|
|
90
|
-
@proxy_hash = {
|
|
91
|
-
uri: "#{proxy_dict[:proxy_host]}:#{proxy_dict[:proxy_port]}",
|
|
92
|
-
user: proxy_dict[:proxy_user],
|
|
93
|
-
password: proxy_dict[:proxy_pass]
|
|
94
|
-
}
|
|
95
|
-
end
|
|
96
|
-
|
|
97
|
-
def configure_timeout(timeout)
|
|
98
|
-
@timeout = timeout
|
|
99
|
-
end
|
|
100
|
-
|
|
101
|
-
def user_agent
|
|
102
|
-
"plivo-ruby/#{Plivo::VERSION} (Ruby #{RUBY_VERSION})"
|
|
103
|
-
end
|
|
104
|
-
|
|
105
|
-
def configure_headers
|
|
106
|
-
@headers = {
|
|
107
|
-
'User-Agent' => user_agent,
|
|
108
|
-
'Content-Type' => 'application/json',
|
|
109
|
-
'Accept' => 'application/json'
|
|
110
|
-
}
|
|
22
|
+
def configure_base_uri
|
|
23
|
+
@base_uri = Base::PLIVO_API_URL
|
|
111
24
|
end
|
|
112
25
|
|
|
113
26
|
def configure_interfaces
|
|
@@ -125,112 +38,5 @@ module Plivo
|
|
|
125
38
|
@addresses = Resources::AddressInterface.new(self)
|
|
126
39
|
@identities = Resources::IdentityInterface.new(self)
|
|
127
40
|
end
|
|
128
|
-
|
|
129
|
-
def configure_connection
|
|
130
|
-
@conn = Faraday.new(Base::PLIVO_API_URL) do |faraday|
|
|
131
|
-
faraday.headers = @headers
|
|
132
|
-
|
|
133
|
-
# DANGER: Basic auth should always come after headers, else
|
|
134
|
-
# The headers will replace the basic_auth
|
|
135
|
-
|
|
136
|
-
faraday.basic_auth(auth_id, auth_token)
|
|
137
|
-
|
|
138
|
-
faraday.proxy=@proxy_hash if @proxy_hash
|
|
139
|
-
faraday.response :json, content_type: /\bjson$/
|
|
140
|
-
faraday.adapter Faraday.default_adapter
|
|
141
|
-
end
|
|
142
|
-
end
|
|
143
|
-
|
|
144
|
-
def send_get(resource_path, data, timeout)
|
|
145
|
-
response = @conn.get do |req|
|
|
146
|
-
req.url resource_path, data
|
|
147
|
-
req.options.timeout = timeout if timeout
|
|
148
|
-
end
|
|
149
|
-
response
|
|
150
|
-
end
|
|
151
|
-
|
|
152
|
-
def send_post(resource_path, data, timeout, use_multipart_conn)
|
|
153
|
-
if use_multipart_conn
|
|
154
|
-
multipart_conn = Faraday.new(Base::PLIVO_API_URL) do |faraday|
|
|
155
|
-
faraday.headers = {
|
|
156
|
-
'User-Agent' => @headers['User-Agent'],
|
|
157
|
-
'Accept' => @headers['Accept']
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
# DANGER: Basic auth should always come after headers, else
|
|
161
|
-
# The headers will replace the basic_auth
|
|
162
|
-
|
|
163
|
-
faraday.request :multipart
|
|
164
|
-
faraday.request :url_encoded
|
|
165
|
-
faraday.basic_auth(auth_id, auth_token)
|
|
166
|
-
|
|
167
|
-
faraday.proxy=@proxy_hash if @proxy_hash
|
|
168
|
-
faraday.response :json, content_type: /\bjson$/
|
|
169
|
-
faraday.adapter Faraday.default_adapter
|
|
170
|
-
end
|
|
171
|
-
|
|
172
|
-
response = multipart_conn.post do |req|
|
|
173
|
-
req.url resource_path
|
|
174
|
-
req.options.timeout = timeout if timeout
|
|
175
|
-
req.body = data
|
|
176
|
-
end
|
|
177
|
-
else
|
|
178
|
-
response = @conn.post do |req|
|
|
179
|
-
req.url resource_path
|
|
180
|
-
req.options.timeout = timeout if timeout
|
|
181
|
-
req.body = JSON.generate(data) if data
|
|
182
|
-
end
|
|
183
|
-
end
|
|
184
|
-
response
|
|
185
|
-
end
|
|
186
|
-
|
|
187
|
-
def send_delete(resource_path, data, timeout)
|
|
188
|
-
response = @conn.delete do |req|
|
|
189
|
-
req.url resource_path
|
|
190
|
-
req.options.timeout = timeout if timeout
|
|
191
|
-
req.body = JSON.generate(data) if data
|
|
192
|
-
end
|
|
193
|
-
response
|
|
194
|
-
end
|
|
195
|
-
|
|
196
|
-
def handle_response_exceptions(response)
|
|
197
|
-
exception_mapping = {
|
|
198
|
-
400 => [
|
|
199
|
-
Exceptions::ValidationError,
|
|
200
|
-
'A parameter is missing or is invalid while accessing resource'
|
|
201
|
-
],
|
|
202
|
-
401 => [
|
|
203
|
-
Exceptions::AuthenticationError,
|
|
204
|
-
'Failed to authenticate while accessing resource'
|
|
205
|
-
],
|
|
206
|
-
404 => [
|
|
207
|
-
Exceptions::ResourceNotFoundError,
|
|
208
|
-
'Resource not found'
|
|
209
|
-
],
|
|
210
|
-
405 => [
|
|
211
|
-
Exceptions::InvalidRequestError,
|
|
212
|
-
'HTTP method used is not allowed to access resource'
|
|
213
|
-
],
|
|
214
|
-
500 => [
|
|
215
|
-
Exceptions::PlivoServerError,
|
|
216
|
-
'A server error occurred while accessing resource'
|
|
217
|
-
]
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
response_json = response[:body]
|
|
221
|
-
return unless exception_mapping.key? response[:status]
|
|
222
|
-
|
|
223
|
-
exception_now = exception_mapping[response[:status]]
|
|
224
|
-
error_message = if (response_json.is_a? Hash) && (response_json.key? 'error')
|
|
225
|
-
response_json['error']
|
|
226
|
-
else
|
|
227
|
-
exception_now[1] + " at: #{response[:url]}"
|
|
228
|
-
end
|
|
229
|
-
if error_message.is_a?(Hash) && error_message.key?('error')
|
|
230
|
-
error_message = error_message['error']
|
|
231
|
-
end
|
|
232
|
-
|
|
233
|
-
raise exception_now[0], error_message.to_s
|
|
234
|
-
end
|
|
235
41
|
end
|
|
236
42
|
end
|
data/lib/plivo/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: plivo
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 4.
|
|
4
|
+
version: 4.2.0.pre.beta1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- The Plivo SDKs Team
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2019-
|
|
11
|
+
date: 2019-03-11 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: faraday
|
|
@@ -147,12 +147,17 @@ files:
|
|
|
147
147
|
- LICENSE.txt
|
|
148
148
|
- README.md
|
|
149
149
|
- Rakefile
|
|
150
|
+
- examples/conference_bridge.rb
|
|
151
|
+
- examples/multi_party_call.rb
|
|
152
|
+
- examples/phlos.rb
|
|
150
153
|
- lib/plivo.rb
|
|
151
154
|
- lib/plivo/base.rb
|
|
152
155
|
- lib/plivo/base/resource.rb
|
|
153
156
|
- lib/plivo/base/resource_interface.rb
|
|
154
157
|
- lib/plivo/base/response.rb
|
|
158
|
+
- lib/plivo/base_client.rb
|
|
155
159
|
- lib/plivo/exceptions.rb
|
|
160
|
+
- lib/plivo/phlo_client.rb
|
|
156
161
|
- lib/plivo/resources.rb
|
|
157
162
|
- lib/plivo/resources/accounts.rb
|
|
158
163
|
- lib/plivo/resources/addresses.rb
|
|
@@ -161,8 +166,11 @@ files:
|
|
|
161
166
|
- lib/plivo/resources/conferences.rb
|
|
162
167
|
- lib/plivo/resources/endpoints.rb
|
|
163
168
|
- lib/plivo/resources/identities.rb
|
|
169
|
+
- lib/plivo/resources/member.rb
|
|
164
170
|
- lib/plivo/resources/messages.rb
|
|
171
|
+
- lib/plivo/resources/nodes.rb
|
|
165
172
|
- lib/plivo/resources/numbers.rb
|
|
173
|
+
- lib/plivo/resources/phlos.rb
|
|
166
174
|
- lib/plivo/resources/pricings.rb
|
|
167
175
|
- lib/plivo/resources/recordings.rb
|
|
168
176
|
- lib/plivo/rest_client.rb
|
|
@@ -202,9 +210,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
202
210
|
version: 2.0.0
|
|
203
211
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
204
212
|
requirements:
|
|
205
|
-
- - "
|
|
213
|
+
- - ">"
|
|
206
214
|
- !ruby/object:Gem::Version
|
|
207
|
-
version:
|
|
215
|
+
version: 1.3.1
|
|
208
216
|
requirements: []
|
|
209
217
|
rubyforge_project:
|
|
210
218
|
rubygems_version: 2.7.8
|