plivo 4.7.1 → 4.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +16 -0
- data/README.md +1 -1
- data/examples/jwt.rb +32 -0
- data/lib/plivo.rb +1 -0
- data/lib/plivo/base.rb +5 -0
- data/lib/plivo/base/resource.rb +8 -7
- data/lib/plivo/base/resource_interface.rb +8 -7
- data/lib/plivo/base_client.rb +141 -21
- data/lib/plivo/jwt.rb +120 -0
- data/lib/plivo/resources.rb +1 -1
- data/lib/plivo/resources/applications.rb +2 -0
- data/lib/plivo/resources/calls.rb +8 -4
- data/lib/plivo/resources/conferences.rb +7 -11
- data/lib/plivo/resources/endpoints.rb +2 -0
- data/lib/plivo/resources/nodes.rb +3 -3
- data/lib/plivo/resources/{member.rb → phlo_member.rb} +1 -1
- data/lib/plivo/resources/recordings.rb +2 -0
- data/lib/plivo/rest_client.rb +3 -0
- data/lib/plivo/version.rb +1 -1
- data/plivo.gemspec +3 -2
- metadata +23 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c368bc21255a5a1cef319179fbf0bf066375b1f6
|
4
|
+
data.tar.gz: 929a607f7200f8060263b697680dcb610471632d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 718383feb89c897a7a3d0d91094ab09d4885b9d0054b05983b63d507678bcf152247fcfbe04ef69ecbcf8c6f3c59807240cf32a3616991c6175f35643ef0c2d8
|
7
|
+
data.tar.gz: 6f8b7b343a0b26f7b59259d8eea063ec1e15a41c2283316342d204a4f341cc5757e38a8f50ba78daa6515ab38972731f976a8779ab537b1e9db2ab7826f1eb48
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,21 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
+
## [4.10.0](https://github.com/plivo/plivo-ruby/releases/tag/v4.10.0) (2020-09-04)
|
4
|
+
- Add ConferenceUuid & CallState for Get Details of a Call API
|
5
|
+
- Upgrade faraday & faraday_middleware dependencies
|
6
|
+
|
7
|
+
## [4.9.1](https://github.com/plivo/plivo-ruby/releases/tag/v4.9.1) (2020-08-19)
|
8
|
+
- Internal changes in Phlo for MultiPartyCall component
|
9
|
+
|
10
|
+
## [4.9.0](https://github.com/plivo/plivo-ruby/releases/tag/v4.9.0) (2020-07-23)
|
11
|
+
- Add retries to multiple regions for voice requests.
|
12
|
+
|
13
|
+
## [4.8.1](https://github.com/plivo/plivo-ruby/releases/tag/v4.8.1) (2020-06-05)
|
14
|
+
- Fix Record a Conference API response.
|
15
|
+
|
16
|
+
## [4.8.0](https://github.com/plivo/plivo-ruby/releases/tag/v4.8.0) (2020-05-28)
|
17
|
+
- Add JWT helper functions.
|
18
|
+
|
3
19
|
## [4.7.1](https://github.com/plivo/plivo-ruby/releases/tag/v4.7.1) (2020-05-06)
|
4
20
|
- Fix Send MMS with existing media_ids.
|
5
21
|
|
data/README.md
CHANGED
data/examples/jwt.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'plivo'
|
3
|
+
|
4
|
+
include Plivo
|
5
|
+
|
6
|
+
AUTH_ID = 'MADADADADADADADADADA'
|
7
|
+
AUTH_TOKEN = 'AUTH_TOKEN'
|
8
|
+
|
9
|
+
begin
|
10
|
+
acctkn = Plivo::Token::AccessToken.new(
|
11
|
+
AUTH_ID,
|
12
|
+
AUTH_TOKEN,
|
13
|
+
'{username}',
|
14
|
+
'{uid}'
|
15
|
+
)
|
16
|
+
# update token validity (from, lifetime)
|
17
|
+
acctkn.update_validity(Time.now, 300)
|
18
|
+
# add voice grants (incoming, outgoing)
|
19
|
+
acctkn.add_voice_grants(Plivo::Token::VoiceGrants.new(true, true))
|
20
|
+
puts acctkn.to_jwt
|
21
|
+
|
22
|
+
# update token validity (from, nil, till)
|
23
|
+
acctkn.update_validity(Time.now, nil, Time.now + 300)
|
24
|
+
# add voice grants (incoming, outgoing)
|
25
|
+
acctkn.add_voice_grants(Plivo::Token::VoiceGrants.new(true, true))
|
26
|
+
puts acctkn.to_jwt
|
27
|
+
rescue ValidationError => e
|
28
|
+
puts 'Exception: ' + e.message
|
29
|
+
end
|
30
|
+
|
31
|
+
# Sample Response:
|
32
|
+
#
|
data/lib/plivo.rb
CHANGED
data/lib/plivo/base.rb
CHANGED
@@ -5,6 +5,11 @@ require_relative 'base/response'
|
|
5
5
|
module Plivo
|
6
6
|
module Base
|
7
7
|
PLIVO_API_URL = 'https://api.plivo.com'.freeze
|
8
|
+
|
9
|
+
API_VOICE = 'https://voice.plivo.com'.freeze
|
10
|
+
API_VOICE_FALLBACK_1 = 'https://voice-usw1.plivo.com'.freeze
|
11
|
+
API_VOICE_FALLBACK_2 = 'https://voice-use1.plivo.com'.freeze
|
12
|
+
|
8
13
|
CALLINSIGHTS_API_URL = 'https://stats.plivo.com'.freeze
|
9
14
|
PHLO_API_URL = 'https://phlorunner.plivo.com'.freeze
|
10
15
|
end
|
data/lib/plivo/base/resource.rb
CHANGED
@@ -8,6 +8,7 @@ module Plivo
|
|
8
8
|
configure_client(client)
|
9
9
|
configure_options(options) if options
|
10
10
|
configure_resource_uri
|
11
|
+
@_is_voice_request = false
|
11
12
|
end
|
12
13
|
|
13
14
|
private
|
@@ -56,7 +57,7 @@ module Plivo
|
|
56
57
|
'without an identifier')
|
57
58
|
end
|
58
59
|
|
59
|
-
response_json = @_client.send_request(@_resource_uri, 'POST', params, nil, use_multipart_conn)
|
60
|
+
response_json = @_client.send_request(@_resource_uri, 'POST', params, nil, use_multipart_conn, is_voice_request: @_is_voice_request)
|
60
61
|
|
61
62
|
parse_and_set(params)
|
62
63
|
parse_and_set(response_json)
|
@@ -65,7 +66,7 @@ module Plivo
|
|
65
66
|
|
66
67
|
def perform_action(action = nil, method = 'GET', params = nil, parse = false)
|
67
68
|
resource_path = action ? @_resource_uri + action + '/' : @_resource_uri
|
68
|
-
response = @_client.send_request(resource_path, method, params)
|
69
|
+
response = @_client.send_request(resource_path, method, params,nil,false,is_voice_request: @_is_voice_request)
|
69
70
|
parse ? parse_and_set(response) : self
|
70
71
|
method == 'POST' ? parse_and_set(params) : self
|
71
72
|
self
|
@@ -73,7 +74,7 @@ module Plivo
|
|
73
74
|
|
74
75
|
def perform_custome_action(action = nil, method = 'GET', params = nil, parse = false)
|
75
76
|
resource_path = action ? @_resource_uri + action + '/' : @_resource_uri
|
76
|
-
response = @_client.send_request(resource_path, method, params)
|
77
|
+
response = @_client.send_request(resource_path, method, params,nil,false,is_voice_request: @_is_voice_request)
|
77
78
|
parse ? parse_and_set(response) : self
|
78
79
|
method == 'POST' ? parse_and_set(params) : self
|
79
80
|
self
|
@@ -81,7 +82,7 @@ module Plivo
|
|
81
82
|
|
82
83
|
def perform_action_apiresponse(action = nil, method = 'GET', params = nil, parse = false)
|
83
84
|
resource_path = action ? @_resource_uri + action + '/' : @_resource_uri
|
84
|
-
response = @_client.send_request(resource_path, method, params)
|
85
|
+
response = @_client.send_request(resource_path, method, params,nil,false,is_voice_request: @_is_voice_request)
|
85
86
|
parse ? parse_and_set(response) : self
|
86
87
|
method == 'POST' ? parse_and_set(params) : self
|
87
88
|
method == 'DELETE' ? parse_and_set(params) : self
|
@@ -90,7 +91,7 @@ module Plivo
|
|
90
91
|
|
91
92
|
def perform_custom_action_apiresponse(action = nil, method = 'GET', params = nil, parse = false)
|
92
93
|
resource_path = action ? '/v1/Account/' + @_client.auth_id + '/'+ action + '/' : @_resource_uri
|
93
|
-
response = @_client.send_request(resource_path, method, params)
|
94
|
+
response = @_client.send_request(resource_path, method, params,nil,false,is_voice_request: @_is_voice_request)
|
94
95
|
parse ? parse_and_set(response) : self
|
95
96
|
method == 'POST' ? parse_and_set(params) : self
|
96
97
|
method == 'DELETE' ? parse_and_set(params) : self
|
@@ -103,12 +104,12 @@ module Plivo
|
|
103
104
|
'without an identifier')
|
104
105
|
end
|
105
106
|
|
106
|
-
Response.new(@_client.send_request(@_resource_uri, 'DELETE', params),
|
107
|
+
Response.new(@_client.send_request(@_resource_uri, 'DELETE', params, nil, false, is_voice_request: @_is_voice_request),
|
107
108
|
@_identifier_string)
|
108
109
|
end
|
109
110
|
|
110
111
|
def perform_run(params)
|
111
|
-
response_json = @_client.send_request(@_resource_uri, 'POST', params, nil)
|
112
|
+
response_json = @_client.send_request(@_resource_uri, 'POST', params, nil,false,is_voice_request: @_is_voice_request)
|
112
113
|
parse_and_set(response_json)
|
113
114
|
Response.new(response_json, @_identifier_string)
|
114
115
|
end
|
@@ -6,6 +6,7 @@ module Plivo
|
|
6
6
|
configure_client(client)
|
7
7
|
configure_resource_uri
|
8
8
|
parse_and_set(resource_list_json) if resource_list_json
|
9
|
+
@_is_voice_request = false
|
9
10
|
end
|
10
11
|
|
11
12
|
private
|
@@ -41,25 +42,25 @@ module Plivo
|
|
41
42
|
|
42
43
|
def perform_get(identifier, params = nil)
|
43
44
|
valid_param?(:identifier, identifier, [String, Symbol], true)
|
44
|
-
response_json = @_client.send_request(@_resource_uri + identifier.to_s + '/', 'GET', params)
|
45
|
+
response_json = @_client.send_request(@_resource_uri + identifier.to_s + '/', 'GET', params, nil, false, is_voice_request: @_is_voice_request)
|
45
46
|
@_resource_type.new(@_client, resource_json: response_json)
|
46
47
|
end
|
47
48
|
|
48
49
|
def perform_get_without_identifier(params)
|
49
50
|
valid_param?(:params, params, Hash, true)
|
50
|
-
response_json = @_client.send_request(@_resource_uri, 'GET', params)
|
51
|
+
response_json = @_client.send_request(@_resource_uri, 'GET', params, nil, false, is_voice_request: @_is_voice_request)
|
51
52
|
@_resource_type.new(@_client, resource_json: response_json)
|
52
53
|
end
|
53
54
|
|
54
55
|
def perform_create(params, use_multipart_conn=false)
|
55
56
|
Response.new(
|
56
|
-
@_client.send_request(@_resource_uri, 'POST', params, nil, use_multipart_conn),
|
57
|
+
@_client.send_request(@_resource_uri, 'POST', params, nil, use_multipart_conn, is_voice_request: @_is_voice_request),
|
57
58
|
@_identifier_string
|
58
59
|
)
|
59
60
|
end
|
60
61
|
|
61
62
|
def perform_post(params)
|
62
|
-
response_json = @_client.send_request(@_resource_uri, 'POST', params)
|
63
|
+
response_json = @_client.send_request(@_resource_uri, 'POST', params, nil, false, is_voice_request: @_is_voice_request)
|
63
64
|
|
64
65
|
parse_and_set(response_json)
|
65
66
|
self
|
@@ -74,7 +75,7 @@ module Plivo
|
|
74
75
|
end
|
75
76
|
|
76
77
|
def perform_list(params = nil)
|
77
|
-
response_json = @_client.send_request(@_resource_uri, 'GET', params)
|
78
|
+
response_json = @_client.send_request(@_resource_uri, 'GET', params, nil, false, is_voice_request: @_is_voice_request)
|
78
79
|
parse_and_set(response_json)
|
79
80
|
{
|
80
81
|
api_id: @api_id,
|
@@ -85,14 +86,14 @@ module Plivo
|
|
85
86
|
|
86
87
|
def perform_action(action = nil, method = 'GET', params = nil, parse = false)
|
87
88
|
resource_path = action ? @_resource_uri + action + '/' : @_resource_uri
|
88
|
-
response = @_client.send_request(resource_path, method, params)
|
89
|
+
response = @_client.send_request(resource_path, method, params, nil, false, is_voice_request: @_is_voice_request)
|
89
90
|
parse ? parse_and_set(response) : self
|
90
91
|
method == 'POST' ? parse_and_set(params) : self
|
91
92
|
self
|
92
93
|
end
|
93
94
|
|
94
95
|
def perform_list_without_object(params = nil)
|
95
|
-
response_json = @_client.send_request(@_resource_uri, 'GET', params)
|
96
|
+
response_json = @_client.send_request(@_resource_uri, 'GET', params, nil, false, is_voice_request: @_is_voice_request)
|
96
97
|
parse_and_set(response_json)
|
97
98
|
response_json
|
98
99
|
end
|
data/lib/plivo/base_client.rb
CHANGED
@@ -13,7 +13,7 @@ module Plivo
|
|
13
13
|
class BaseClient
|
14
14
|
# Base stuff
|
15
15
|
attr_reader :headers, :auth_credentials
|
16
|
-
|
16
|
+
@@voice_retry_count = 0
|
17
17
|
def initialize(auth_id = nil, auth_token = nil, proxy_options = nil, timeout=5)
|
18
18
|
configure_credentials(auth_id, auth_token)
|
19
19
|
configure_proxies(proxy_options)
|
@@ -36,21 +36,42 @@ module Plivo
|
|
36
36
|
elsif !([200, 201, 202, 207].include? response[:status])
|
37
37
|
raise Exceptions::PlivoRESTError, "Received #{response[:status]} for #{method}"
|
38
38
|
end
|
39
|
-
|
39
|
+
@@voice_retry_count = 0
|
40
40
|
response[:body]
|
41
41
|
end
|
42
42
|
|
43
|
-
def send_request(resource_path, method = 'GET', data = {}, timeout = nil, use_multipart_conn = false)
|
43
|
+
def send_request(resource_path, method = 'GET', data = {}, timeout = nil, use_multipart_conn = false, options = nil)
|
44
44
|
timeout ||= @timeout
|
45
45
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
46
|
+
if options[:is_voice_request] == true
|
47
|
+
response = case method
|
48
|
+
when 'GET' then send_get(resource_path, data, timeout, is_voice_request: options[:is_voice_request], voice_retry_count: @@voice_retry_count)
|
49
|
+
when 'POST' then send_post(resource_path, data, timeout, use_multipart_conn, is_voice_request: options[:is_voice_request], voice_retry_count: @@voice_retry_count)
|
50
|
+
when 'DELETE' then send_delete(resource_path, data, timeout, is_voice_request: options[:is_voice_request], voice_retry_count: @@voice_retry_count)
|
51
|
+
else raise_invalid_request("#{method} not supported by Plivo, yet")
|
52
|
+
end
|
53
|
+
|
54
|
+
if response.status >= 500
|
55
|
+
@@voice_retry_count += 1
|
56
|
+
if @@voice_retry_count > 2
|
57
|
+
return process_response(method, response.to_hash)
|
58
|
+
end
|
59
|
+
is_voice_request = true
|
60
|
+
send_request(resource_path, method, data, timeout, use_multipart_conn, is_voice_request: is_voice_request)
|
61
|
+
else
|
62
|
+
process_response(method, response.to_hash)
|
63
|
+
end
|
52
64
|
|
53
|
-
|
65
|
+
else
|
66
|
+
response = case method
|
67
|
+
when 'GET' then send_get(resource_path, data, timeout)
|
68
|
+
when 'POST' then send_post(resource_path, data, timeout, use_multipart_conn)
|
69
|
+
when 'DELETE' then send_delete(resource_path, data, timeout)
|
70
|
+
else raise_invalid_request("#{method} not supported by Plivo, yet")
|
71
|
+
end
|
72
|
+
|
73
|
+
process_response(method, response.to_hash)
|
74
|
+
end
|
54
75
|
end
|
55
76
|
|
56
77
|
private
|
@@ -118,6 +139,45 @@ module Plivo
|
|
118
139
|
faraday.adapter Faraday.default_adapter
|
119
140
|
end
|
120
141
|
|
142
|
+
@voice_conn_no_retry = Faraday.new(@voice_base_uri) do |faraday|
|
143
|
+
faraday.headers = @headers
|
144
|
+
|
145
|
+
# DANGER: Basic auth should always come after headers, else
|
146
|
+
# The headers will replace the basic_auth
|
147
|
+
|
148
|
+
faraday.basic_auth(auth_id, auth_token)
|
149
|
+
|
150
|
+
faraday.proxy=@proxy_hash if @proxy_hash
|
151
|
+
faraday.response :json, content_type: /\bjson$/
|
152
|
+
faraday.adapter Faraday.default_adapter
|
153
|
+
end
|
154
|
+
|
155
|
+
@voice_conn_retry_1 = Faraday.new(@voice_base_uri_fallback_1) do |faraday|
|
156
|
+
faraday.headers = @headers
|
157
|
+
|
158
|
+
# DANGER: Basic auth should always come after headers, else
|
159
|
+
# The headers will replace the basic_auth
|
160
|
+
|
161
|
+
faraday.basic_auth(auth_id, auth_token)
|
162
|
+
|
163
|
+
faraday.proxy=@proxy_hash if @proxy_hash
|
164
|
+
faraday.response :json, content_type: /\bjson$/
|
165
|
+
faraday.adapter Faraday.default_adapter
|
166
|
+
end
|
167
|
+
|
168
|
+
@voice_conn_retry_2 = Faraday.new(@voice_base_uri_fallback_2) do |faraday|
|
169
|
+
faraday.headers = @headers
|
170
|
+
|
171
|
+
# DANGER: Basic auth should always come after headers, else
|
172
|
+
# The headers will replace the basic_auth
|
173
|
+
|
174
|
+
faraday.basic_auth(auth_id, auth_token)
|
175
|
+
|
176
|
+
faraday.proxy=@proxy_hash if @proxy_hash
|
177
|
+
faraday.response :json, content_type: /\bjson$/
|
178
|
+
faraday.adapter Faraday.default_adapter
|
179
|
+
end
|
180
|
+
|
121
181
|
@callinsights_conn = Faraday.new(@callinsights_base_uri) do |faraday|
|
122
182
|
faraday.headers = @headers
|
123
183
|
|
@@ -133,15 +193,34 @@ module Plivo
|
|
133
193
|
|
134
194
|
end
|
135
195
|
|
136
|
-
def send_get(resource_path, data, timeout)
|
137
|
-
|
138
|
-
|
139
|
-
|
196
|
+
def send_get(resource_path, data, timeout, options = nil)
|
197
|
+
if options
|
198
|
+
if options[:voice_retry_count] == 0 and options[:is_voice_request] == true
|
199
|
+
response = @voice_conn_no_retry.get do |req|
|
200
|
+
req.url resource_path, data
|
201
|
+
req.options.timeout = timeout if timeout
|
202
|
+
end
|
203
|
+
elsif options[:voice_retry_count] == 1 and options[:is_voice_request] == true
|
204
|
+
response = @voice_conn_retry_1.get do |req|
|
205
|
+
req.url resource_path, data
|
206
|
+
req.options.timeout = timeout if timeout
|
207
|
+
end
|
208
|
+
elsif options[:voice_retry_count] == 2 and options[:is_voice_request] == true
|
209
|
+
response = @voice_conn_retry_2.get do |req|
|
210
|
+
req.url resource_path, data
|
211
|
+
req.options.timeout = timeout if timeout
|
212
|
+
end
|
213
|
+
end
|
214
|
+
else
|
215
|
+
response = @conn.get do |req|
|
216
|
+
req.url resource_path, data
|
217
|
+
req.options.timeout = timeout if timeout
|
218
|
+
end
|
140
219
|
end
|
141
220
|
response
|
142
221
|
end
|
143
222
|
|
144
|
-
def send_post(resource_path, data, timeout, use_multipart_conn)
|
223
|
+
def send_post(resource_path, data, timeout, use_multipart_conn, options = nil)
|
145
224
|
if use_multipart_conn
|
146
225
|
multipart_conn = Faraday.new(@base_uri) do |faraday|
|
147
226
|
faraday.headers = {
|
@@ -178,7 +257,26 @@ module Plivo
|
|
178
257
|
req.options.timeout = timeout if timeout
|
179
258
|
req.body = JSON.generate(data) if data
|
180
259
|
end
|
181
|
-
|
260
|
+
elsif options
|
261
|
+
if options[:voice_retry_count] == 0 and options[:is_voice_request] == true
|
262
|
+
response = @voice_conn_no_retry.post do |req|
|
263
|
+
req.url resource_path
|
264
|
+
req.options.timeout = timeout if timeout
|
265
|
+
req.body = JSON.generate(data) if data
|
266
|
+
end
|
267
|
+
elsif options[:voice_retry_count] == 1 and options[:is_voice_request] == true
|
268
|
+
response = @voice_conn_retry_1.post do |req|
|
269
|
+
req.url resource_path
|
270
|
+
req.options.timeout = timeout if timeout
|
271
|
+
req.body = JSON.generate(data) if data
|
272
|
+
end
|
273
|
+
elsif options[:voice_retry_count] == 2 and options[:is_voice_request] == true
|
274
|
+
response = @voice_conn_retry_2.post do |req|
|
275
|
+
req.url resource_path
|
276
|
+
req.options.timeout = timeout if timeout
|
277
|
+
req.body = JSON.generate(data) if data
|
278
|
+
end
|
279
|
+
end
|
182
280
|
else
|
183
281
|
response = @conn.post do |req|
|
184
282
|
req.url resource_path
|
@@ -190,11 +288,33 @@ module Plivo
|
|
190
288
|
response
|
191
289
|
end
|
192
290
|
|
193
|
-
def send_delete(resource_path, data, timeout)
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
291
|
+
def send_delete(resource_path, data, timeout, options = nil)
|
292
|
+
if options
|
293
|
+
if options[:voice_retry_count] == 0 and options[:is_voice_request] == true
|
294
|
+
response = @voice_conn_no_retry.delete do |req|
|
295
|
+
req.url resource_path
|
296
|
+
req.options.timeout = timeout if timeout
|
297
|
+
req.body = JSON.generate(data) if data
|
298
|
+
end
|
299
|
+
elsif options[:voice_retry_count] == 1 and options[:is_voice_request] == true
|
300
|
+
response = @voice_conn_retry_1.delete do |req|
|
301
|
+
req.url resource_path
|
302
|
+
req.options.timeout = timeout if timeout
|
303
|
+
req.body = JSON.generate(data) if data
|
304
|
+
end
|
305
|
+
elsif options[:voice_retry_count] == 2 and options[:is_voice_request] == true
|
306
|
+
response = @voice_conn_retry_2.delete do |req|
|
307
|
+
req.url resource_path
|
308
|
+
req.options.timeout = timeout if timeout
|
309
|
+
req.body = JSON.generate(data) if data
|
310
|
+
end
|
311
|
+
end
|
312
|
+
else
|
313
|
+
response = @conn.delete do |req|
|
314
|
+
req.url resource_path
|
315
|
+
req.options.timeout = timeout if timeout
|
316
|
+
req.body = JSON.generate(data) if data
|
317
|
+
end
|
198
318
|
end
|
199
319
|
response
|
200
320
|
end
|
data/lib/plivo/jwt.rb
ADDED
@@ -0,0 +1,120 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'openssl'
|
4
|
+
require 'uri'
|
5
|
+
require 'base64'
|
6
|
+
require 'date'
|
7
|
+
require 'jwt'
|
8
|
+
|
9
|
+
module Plivo
|
10
|
+
module Token
|
11
|
+
include Utils
|
12
|
+
|
13
|
+
class VoiceGrants
|
14
|
+
attr_reader :incoming_allow, :outgoing_allow
|
15
|
+
|
16
|
+
def initialize(incoming = nil, outgoing = nil)
|
17
|
+
Utils.valid_param?(:incoming, incoming, [TrueClass, FalseClass], false)
|
18
|
+
Utils.valid_param?(:outgoing, outgoing, [TrueClass, FalseClass], false)
|
19
|
+
@incoming_allow = incoming
|
20
|
+
@outgoing_allow = outgoing
|
21
|
+
end
|
22
|
+
|
23
|
+
def to_hash
|
24
|
+
hash = {}
|
25
|
+
instance_variables.each { |var| hash[var.to_s.delete('@')] = instance_variable_get(var) }
|
26
|
+
hash
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
class AccessToken
|
31
|
+
attr_reader :uid, :username, :valid_from, :lifetime, :grants
|
32
|
+
def initialize(auth_id = nil, auth_token = nil, username = nil, uid = nil)
|
33
|
+
configure_credentials(auth_id, auth_token)
|
34
|
+
Utils.valid_param?(:username, username, [String, Symbol], true)
|
35
|
+
@username = username
|
36
|
+
|
37
|
+
Utils.valid_param?(:uid, uid, [String, Symbol], false)
|
38
|
+
uid ||= username + '-' + Time.now.to_i
|
39
|
+
@uid = uid
|
40
|
+
update_validity
|
41
|
+
end
|
42
|
+
|
43
|
+
def update_validity(valid_from = nil, lifetime = nil, valid_till = nil)
|
44
|
+
Utils.valid_param?(:valid_from, valid_from, [Time, Integer], false)
|
45
|
+
Utils.valid_param?(:lifetime, lifetime, [Integer], false)
|
46
|
+
Utils.valid_param?(:valid_till, valid_till, [Time, Integer], false)
|
47
|
+
|
48
|
+
if valid_from.nil?
|
49
|
+
@lifetime = lifetime || 84_600
|
50
|
+
@valid_from = if valid_till.nil?
|
51
|
+
Time.now
|
52
|
+
else
|
53
|
+
Time.at(valid_till.to_i - @lifetime).utc
|
54
|
+
end
|
55
|
+
|
56
|
+
elsif valid_till.nil?
|
57
|
+
@lifetime = lifetime || 84_600
|
58
|
+
@valid_from = valid_from
|
59
|
+
else
|
60
|
+
unless lifetime.nil?
|
61
|
+
raise Exceptions::ValidationError, 'use any 2 of valid_from, lifetime and valid_till'
|
62
|
+
end
|
63
|
+
|
64
|
+
@valid_from = valid_from
|
65
|
+
@lifetime = valid_till.to_i - valid_from.to_i
|
66
|
+
end
|
67
|
+
|
68
|
+
return unless @lifetime < 180 || @lifetime > 84_600
|
69
|
+
|
70
|
+
raise Exceptions::ValidationError, 'validity out of [180, 84600] seconds'
|
71
|
+
end
|
72
|
+
|
73
|
+
def auth_id
|
74
|
+
@auth_credentials[:auth_id]
|
75
|
+
end
|
76
|
+
|
77
|
+
def add_voice_grants(grants)
|
78
|
+
Utils.valid_param?(:grants, grants, [VoiceGrants], true)
|
79
|
+
@grants = grants
|
80
|
+
end
|
81
|
+
|
82
|
+
def to_jwt
|
83
|
+
payload = {
|
84
|
+
jti: uid,
|
85
|
+
sub: username,
|
86
|
+
iss: auth_id,
|
87
|
+
nbf: valid_from.to_i,
|
88
|
+
exp: valid_from.to_i + lifetime,
|
89
|
+
grants: {
|
90
|
+
voice: grants.to_hash || {}
|
91
|
+
}
|
92
|
+
}
|
93
|
+
JWT.encode payload, key, 'HS256', {typ: 'JWT', cty: 'plivo;v=1'}
|
94
|
+
end
|
95
|
+
|
96
|
+
private
|
97
|
+
|
98
|
+
def key
|
99
|
+
@auth_credentials[:auth_token]
|
100
|
+
end
|
101
|
+
|
102
|
+
def configure_credentials(auth_id, auth_token)
|
103
|
+
# Fetches and sets the right credentials
|
104
|
+
auth_id ||= ENV['PLIVO_AUTH_ID']
|
105
|
+
auth_token ||= ENV['PLIVO_AUTH_TOKEN']
|
106
|
+
|
107
|
+
raise Exceptions::AuthenticationError, 'Couldn\'t find auth credentials' unless
|
108
|
+
auth_id && auth_token
|
109
|
+
|
110
|
+
raise Exceptions::AuthenticationError, "Invalid auth_id: '#{auth_id}'" unless
|
111
|
+
Utils.valid_account?(auth_id)
|
112
|
+
|
113
|
+
@auth_credentials = {
|
114
|
+
auth_id: auth_id,
|
115
|
+
auth_token: auth_token
|
116
|
+
}
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
data/lib/plivo/resources.rb
CHANGED
@@ -12,7 +12,7 @@ require_relative 'resources/addresses'
|
|
12
12
|
require_relative 'resources/identities'
|
13
13
|
require_relative 'resources/phlos'
|
14
14
|
require_relative 'resources/nodes'
|
15
|
-
require_relative 'resources/
|
15
|
+
require_relative 'resources/phlo_member'
|
16
16
|
require_relative 'resources/call_feedback'
|
17
17
|
require_relative 'resources/media'
|
18
18
|
|
@@ -8,6 +8,7 @@ module Plivo
|
|
8
8
|
@_name = 'Application'
|
9
9
|
@_identifier_string = 'app_id'
|
10
10
|
super
|
11
|
+
@_is_voice_request = true
|
11
12
|
end
|
12
13
|
|
13
14
|
# @param [Hash] options
|
@@ -109,6 +110,7 @@ module Plivo
|
|
109
110
|
@_resource_type = Application
|
110
111
|
@_identifier_string = 'app_id'
|
111
112
|
super
|
113
|
+
@_is_voice_request = true
|
112
114
|
end
|
113
115
|
|
114
116
|
# @param [String] app_id
|
@@ -6,6 +6,7 @@ module Plivo
|
|
6
6
|
@_name = 'Call'
|
7
7
|
@_identifier_string = 'call_uuid'
|
8
8
|
super
|
9
|
+
@_is_voice_request = true
|
9
10
|
end
|
10
11
|
|
11
12
|
def update(options)
|
@@ -199,7 +200,7 @@ module Plivo
|
|
199
200
|
|
200
201
|
def cancel_request
|
201
202
|
resource_path = @_resource_uri.sub('Call', 'Request')
|
202
|
-
@_client.send_request(resource_path, 'DELETE', nil)
|
203
|
+
@_client.send_request(resource_path, 'DELETE', nil, nil, false , is_voice_request: @_is_voice_request)
|
203
204
|
end
|
204
205
|
|
205
206
|
def to_s
|
@@ -211,7 +212,9 @@ module Plivo
|
|
211
212
|
call_direction: @call_direction,
|
212
213
|
call_duration: @call_duration,
|
213
214
|
call_status: @call_status,
|
215
|
+
call_state: @call_state,
|
214
216
|
call_uuid: @call_uuid,
|
217
|
+
conference_uuid: @conference_uuid,
|
215
218
|
end_time: @end_time,
|
216
219
|
from_number: @from_number,
|
217
220
|
initiation_time: @initiation_time,
|
@@ -240,6 +243,7 @@ module Plivo
|
|
240
243
|
@_resource_type = Call
|
241
244
|
@_identifier_string = 'call_uuid'
|
242
245
|
super
|
246
|
+
@_is_voice_request = true
|
243
247
|
end
|
244
248
|
|
245
249
|
##
|
@@ -288,9 +292,9 @@ module Plivo
|
|
288
292
|
answer_method: answer_method
|
289
293
|
}
|
290
294
|
|
291
|
-
return perform_create(params) if options.nil?
|
295
|
+
return perform_create(params, false) if options.nil?
|
292
296
|
|
293
|
-
perform_create(params.merge(options))
|
297
|
+
perform_create(params.merge(options), false)
|
294
298
|
end
|
295
299
|
|
296
300
|
##
|
@@ -397,7 +401,7 @@ module Plivo
|
|
397
401
|
# - To filter out those numbers that contain a particular number sequence, use to_number={ sequence}
|
398
402
|
# - To filter out a number that matches an exact number, use to_number={ exact_number}
|
399
403
|
def list_live(options = nil)
|
400
|
-
|
404
|
+
|
401
405
|
if options.nil?
|
402
406
|
options = {}
|
403
407
|
else
|
@@ -6,6 +6,7 @@ module Plivo
|
|
6
6
|
@_name = 'Conference'
|
7
7
|
@_identifier_string = 'conference_name'
|
8
8
|
super
|
9
|
+
@_is_voice_request = true
|
9
10
|
end
|
10
11
|
|
11
12
|
def delete
|
@@ -186,18 +187,12 @@ module Plivo
|
|
186
187
|
end
|
187
188
|
|
188
189
|
def to_s
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
190
|
+
response_json = {}
|
191
|
+
response_variables = self.instance_variables.drop(5)
|
192
|
+
response_variables.each do |variable|
|
193
|
+
response_json[variable.to_s[1..-1]] = self.instance_variable_get(variable)
|
193
194
|
end
|
194
|
-
|
195
|
-
conference_name: @conference_name,
|
196
|
-
conference_run_time: @conference_run_time,
|
197
|
-
conference_member_count: @conference_member_count,
|
198
|
-
members: members_json,
|
199
|
-
api_id: @api_id
|
200
|
-
}.to_s
|
195
|
+
return response_json.to_s
|
201
196
|
end
|
202
197
|
|
203
198
|
def to_json_member(member)
|
@@ -221,6 +216,7 @@ module Plivo
|
|
221
216
|
@_resource_type = Conference
|
222
217
|
@_identifier_string = 'conference_name'
|
223
218
|
super
|
219
|
+
@_is_voice_request = true
|
224
220
|
end
|
225
221
|
|
226
222
|
def get(conference_name)
|
@@ -6,6 +6,7 @@ module Plivo
|
|
6
6
|
@_name = 'Endpoint'
|
7
7
|
@_identifier_string = 'endpoint_id'
|
8
8
|
super
|
9
|
+
@_is_voice_request = true
|
9
10
|
end
|
10
11
|
|
11
12
|
# @param [Hash] options
|
@@ -71,6 +72,7 @@ module Plivo
|
|
71
72
|
@_resource_type = Endpoint
|
72
73
|
@_identifier_string = 'endpoint_id'
|
73
74
|
super
|
75
|
+
@_is_voice_request = true
|
74
76
|
end
|
75
77
|
|
76
78
|
# @param [String] endpoint_id
|
@@ -15,7 +15,7 @@ module Plivo
|
|
15
15
|
def configure_node_type(node_type)
|
16
16
|
case node_type
|
17
17
|
when 'multi_party_call'
|
18
|
-
|
18
|
+
PhloMultiPartyCall
|
19
19
|
# when 'conference_bridge'
|
20
20
|
# ConferenceBridge
|
21
21
|
end
|
@@ -42,7 +42,7 @@ module Plivo
|
|
42
42
|
|
43
43
|
def member(member_address)
|
44
44
|
options = {'member_address' => member_address, 'node_id' => @id, 'phlo_id' => @phlo_id, 'node_type' => @node_type}
|
45
|
-
|
45
|
+
PhloMember.new(@_client, {resource_json: options})
|
46
46
|
end
|
47
47
|
|
48
48
|
private
|
@@ -51,7 +51,7 @@ module Plivo
|
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
54
|
-
class
|
54
|
+
class PhloMultiPartyCall < Node
|
55
55
|
def initialize(client,options=nil)
|
56
56
|
@_name = 'multi_party_call'
|
57
57
|
super
|
@@ -6,6 +6,7 @@ module Plivo
|
|
6
6
|
@_name = 'Recording'
|
7
7
|
@_identifier_string = 'recording_id'
|
8
8
|
super
|
9
|
+
@_is_voice_request = true
|
9
10
|
end
|
10
11
|
|
11
12
|
def delete
|
@@ -36,6 +37,7 @@ module Plivo
|
|
36
37
|
@_resource_type = Recording
|
37
38
|
@_identifier_string = 'recording_id'
|
38
39
|
super
|
40
|
+
@_is_voice_request = true
|
39
41
|
end
|
40
42
|
|
41
43
|
# @param [Hash] options
|
data/lib/plivo/rest_client.rb
CHANGED
@@ -24,6 +24,9 @@ module Plivo
|
|
24
24
|
|
25
25
|
def configure_base_uri
|
26
26
|
@base_uri = Base::PLIVO_API_URL
|
27
|
+
@voice_base_uri = Base::API_VOICE
|
28
|
+
@voice_base_uri_fallback_1 = Base::API_VOICE_FALLBACK_1
|
29
|
+
@voice_base_uri_fallback_2 = Base::API_VOICE_FALLBACK_2
|
27
30
|
@callinsights_base_uri = Base::CALLINSIGHTS_API_URL
|
28
31
|
end
|
29
32
|
|
data/lib/plivo/version.rb
CHANGED
data/plivo.gemspec
CHANGED
@@ -31,9 +31,10 @@ Gem::Specification.new do |spec|
|
|
31
31
|
|
32
32
|
spec.required_ruby_version = '>= 2.0.0'
|
33
33
|
|
34
|
-
spec.add_dependency 'faraday', '~> 0.
|
35
|
-
spec.add_dependency 'faraday_middleware', '~> 0.
|
34
|
+
spec.add_dependency 'faraday', '~> 1.0.1'
|
35
|
+
spec.add_dependency 'faraday_middleware', '~> 1.0.0'
|
36
36
|
spec.add_dependency 'htmlentities'
|
37
|
+
spec.add_dependency 'jwt'
|
37
38
|
|
38
39
|
spec.add_development_dependency 'bundler', '>= 1.14', '<3.0'
|
39
40
|
spec.add_development_dependency 'rake', '~> 10.0'
|
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.10.0
|
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: 2020-
|
11
|
+
date: 2020-09-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -16,28 +16,28 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 1.0.1
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 1.0.1
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: faraday_middleware
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 0.
|
33
|
+
version: 1.0.0
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 0.
|
40
|
+
version: 1.0.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: htmlentities
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: jwt
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
70
|
name: bundler
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -150,6 +164,7 @@ files:
|
|
150
164
|
- Rakefile
|
151
165
|
- ci/config.yml
|
152
166
|
- examples/conference_bridge.rb
|
167
|
+
- examples/jwt.rb
|
153
168
|
- examples/multi_party_call.rb
|
154
169
|
- examples/phlos.rb
|
155
170
|
- lib/plivo.rb
|
@@ -159,6 +174,7 @@ files:
|
|
159
174
|
- lib/plivo/base/response.rb
|
160
175
|
- lib/plivo/base_client.rb
|
161
176
|
- lib/plivo/exceptions.rb
|
177
|
+
- lib/plivo/jwt.rb
|
162
178
|
- lib/plivo/phlo_client.rb
|
163
179
|
- lib/plivo/resources.rb
|
164
180
|
- lib/plivo/resources/accounts.rb
|
@@ -170,10 +186,10 @@ files:
|
|
170
186
|
- lib/plivo/resources/endpoints.rb
|
171
187
|
- lib/plivo/resources/identities.rb
|
172
188
|
- lib/plivo/resources/media.rb
|
173
|
-
- lib/plivo/resources/member.rb
|
174
189
|
- lib/plivo/resources/messages.rb
|
175
190
|
- lib/plivo/resources/nodes.rb
|
176
191
|
- lib/plivo/resources/numbers.rb
|
192
|
+
- lib/plivo/resources/phlo_member.rb
|
177
193
|
- lib/plivo/resources/phlos.rb
|
178
194
|
- lib/plivo/resources/powerpacks.rb
|
179
195
|
- lib/plivo/resources/pricings.rb
|