nexmo 5.9.0 → 6.0.0
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/README.md +35 -465
- data/lib/nexmo.rb +31 -48
- data/lib/nexmo/{authentication/abstract.rb → abstract_authentication.rb} +2 -2
- data/lib/nexmo/account.rb +4 -2
- data/lib/nexmo/alerts.rb +3 -3
- data/lib/nexmo/applications.rb +45 -63
- data/lib/nexmo/applications/list_response.rb +9 -0
- data/lib/nexmo/{errors/authentication_error.rb → authentication_error.rb} +0 -0
- data/lib/nexmo/{authentication/basic.rb → basic.rb} +1 -1
- data/lib/nexmo/{authentication/bearer_token.rb → bearer_token.rb} +1 -1
- data/lib/nexmo/calls.rb +18 -18
- data/lib/nexmo/{call_dtmf.rb → calls/dtmf.rb} +2 -2
- data/lib/nexmo/calls/list_response.rb +9 -0
- data/lib/nexmo/{call_stream.rb → calls/stream.rb} +3 -3
- data/lib/nexmo/{call_talk.rb → calls/talk.rb} +3 -3
- data/lib/nexmo/client.rb +20 -169
- data/lib/nexmo/{errors/client_error.rb → client_error.rb} +0 -0
- data/lib/nexmo/config.rb +165 -0
- data/lib/nexmo/conversations.rb +44 -13
- data/lib/nexmo/{conversation_events.rb → conversations/events.rb} +5 -5
- data/lib/nexmo/{conversation_legs.rb → conversations/legs.rb} +3 -3
- data/lib/nexmo/{conversation_members.rb → conversations/members.rb} +6 -6
- data/lib/nexmo/{conversation_users.rb → conversations/users.rb} +6 -6
- data/lib/nexmo/entity.rb +14 -0
- data/lib/nexmo/{errors/error.rb → error.rb} +0 -0
- data/lib/nexmo/files.rb +1 -2
- data/lib/nexmo/gsm7.rb +13 -0
- data/lib/nexmo/{authentication/key_secret_params.rb → key_secret_params.rb} +2 -2
- data/lib/nexmo/{authentication/key_secret_query.rb → key_secret_query.rb} +2 -2
- data/lib/nexmo/keys.rb +4 -22
- data/lib/nexmo/namespace.rb +22 -12
- data/lib/nexmo/number_insight.rb +6 -4
- data/lib/nexmo/number_insight/response.rb +5 -0
- data/lib/nexmo/numbers.rb +20 -12
- data/lib/nexmo/numbers/list_response.rb +9 -0
- data/lib/nexmo/numbers/response.rb +7 -0
- data/lib/nexmo/pricing.rb +2 -2
- data/lib/nexmo/pricing_types.rb +4 -4
- data/lib/nexmo/redact.rb +1 -1
- data/lib/nexmo/response.rb +23 -0
- data/lib/nexmo/secrets.rb +7 -7
- data/lib/nexmo/secrets/list_response.rb +9 -0
- data/lib/nexmo/{errors/server_error.rb → server_error.rb} +0 -0
- data/lib/nexmo/sms.rb +17 -3
- data/lib/nexmo/sms/response.rb +7 -0
- data/lib/nexmo/verify.rb +10 -8
- data/lib/nexmo/verify/response.rb +5 -0
- data/lib/nexmo/version.rb +1 -1
- data/nexmo.gemspec +4 -2
- metadata +45 -20
- data/lib/nexmo/applications_v2.rb +0 -102
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Nexmo
|
4
|
-
class
|
4
|
+
class Calls::DTMF < Namespace
|
5
5
|
self.authentication = BearerToken
|
6
6
|
|
7
7
|
self.request_body = JSON
|
@@ -14,7 +14,7 @@ module Nexmo
|
|
14
14
|
# @param [String] id
|
15
15
|
# @param [Hash] params
|
16
16
|
#
|
17
|
-
# @return [
|
17
|
+
# @return [Response]
|
18
18
|
#
|
19
19
|
# @see https://developer.nexmo.com/api/voice#startDTMF
|
20
20
|
#
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Nexmo
|
4
|
-
class
|
4
|
+
class Calls::Stream < Namespace
|
5
5
|
self.authentication = BearerToken
|
6
6
|
|
7
7
|
self.request_body = JSON
|
@@ -20,7 +20,7 @@ module Nexmo
|
|
20
20
|
# @param [String] id
|
21
21
|
# @param [Hash] params
|
22
22
|
#
|
23
|
-
# @return [
|
23
|
+
# @return [Response]
|
24
24
|
#
|
25
25
|
# @see https://developer.nexmo.com/api/voice#startStream
|
26
26
|
#
|
@@ -32,7 +32,7 @@ module Nexmo
|
|
32
32
|
#
|
33
33
|
# @param [String] id
|
34
34
|
#
|
35
|
-
# @return [
|
35
|
+
# @return [Response]
|
36
36
|
#
|
37
37
|
# @see https://developer.nexmo.com/api/voice#stopStream
|
38
38
|
#
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Nexmo
|
4
|
-
class
|
4
|
+
class Calls::Talk < Namespace
|
5
5
|
self.authentication = BearerToken
|
6
6
|
|
7
7
|
self.request_body = JSON
|
@@ -24,7 +24,7 @@ module Nexmo
|
|
24
24
|
# @param [String] id
|
25
25
|
# @param [Hash] params
|
26
26
|
#
|
27
|
-
# @return [
|
27
|
+
# @return [Response]
|
28
28
|
#
|
29
29
|
# @see https://developer.nexmo.com/api/voice#startTalk
|
30
30
|
#
|
@@ -36,7 +36,7 @@ module Nexmo
|
|
36
36
|
#
|
37
37
|
# @param [String] id
|
38
38
|
#
|
39
|
-
# @return [
|
39
|
+
# @return [Response]
|
40
40
|
#
|
41
41
|
# @see https://developer.nexmo.com/api/voice#stopTalk
|
42
42
|
#
|
data/lib/nexmo/client.rb
CHANGED
@@ -1,260 +1,111 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
1
|
module Nexmo
|
4
2
|
class Client
|
5
|
-
|
6
|
-
attr_writer :api_secret
|
7
|
-
attr_writer :signature_secret
|
8
|
-
attr_writer :application_id
|
9
|
-
attr_writer :private_key
|
10
|
-
attr_writer :token
|
11
|
-
attr_accessor :user_agent
|
12
|
-
|
13
|
-
def initialize(options = {})
|
14
|
-
@api_key = options[:api_key] || ENV['NEXMO_API_KEY']
|
15
|
-
|
16
|
-
@api_secret = options[:api_secret] || ENV['NEXMO_API_SECRET']
|
17
|
-
|
18
|
-
@signature_secret = options[:signature_secret] || ENV['NEXMO_SIGNATURE_SECRET']
|
19
|
-
|
20
|
-
@application_id = options[:application_id]
|
21
|
-
|
22
|
-
@private_key = options[:private_key]
|
23
|
-
|
24
|
-
@token = nil
|
25
|
-
|
26
|
-
@user_agent = UserAgent.string(options[:app_name], options[:app_version])
|
27
|
-
|
28
|
-
self.http_options = options[:http]
|
29
|
-
|
30
|
-
self.logger = options[:logger] || (defined?(Rails.logger) && Rails.logger)
|
31
|
-
end
|
32
|
-
|
33
|
-
attr_reader :http_options
|
34
|
-
|
35
|
-
def http_options=(hash)
|
36
|
-
@http_options = HTTP::Options.new(hash)
|
37
|
-
end
|
38
|
-
|
39
|
-
# @return [Nexmo::Logger]
|
40
|
-
#
|
41
|
-
def logger
|
42
|
-
@logger
|
43
|
-
end
|
44
|
-
|
45
|
-
# @return [Nexmo::Logger]
|
46
|
-
#
|
47
|
-
def logger=(logger)
|
48
|
-
@logger = Logger.new(logger)
|
49
|
-
end
|
3
|
+
attr_reader :config
|
50
4
|
|
51
|
-
|
52
|
-
|
53
|
-
# @return [String]
|
54
|
-
#
|
55
|
-
def token
|
56
|
-
@token || JWT.generate({application_id: application_id}, private_key)
|
57
|
-
end
|
58
|
-
|
59
|
-
# @deprecated Use {#token=} instead.
|
60
|
-
#
|
61
|
-
def auth_token=(auth_token)
|
62
|
-
Kernel.warn "#{self.class}##{__method__} is deprecated (use #token= instead)"
|
63
|
-
|
64
|
-
@token = auth_token
|
65
|
-
end
|
66
|
-
|
67
|
-
# Returns the value of attribute api_key.
|
68
|
-
#
|
69
|
-
# @return [String]
|
70
|
-
#
|
71
|
-
# @raise [AuthenticationError]
|
72
|
-
#
|
73
|
-
def api_key
|
74
|
-
unless @api_key
|
75
|
-
raise AuthenticationError.new('No API key provided. ' \
|
76
|
-
'See https://developer.nexmo.com/concepts/guides/authentication for details, ' \
|
77
|
-
'or email support@nexmo.com if you have any questions.')
|
78
|
-
end
|
79
|
-
|
80
|
-
@api_key
|
81
|
-
end
|
82
|
-
|
83
|
-
# Returns the value of attribute api_secret.
|
84
|
-
#
|
85
|
-
# @return [String]
|
86
|
-
#
|
87
|
-
# @raise [AuthenticationError]
|
88
|
-
#
|
89
|
-
def api_secret
|
90
|
-
unless @api_secret
|
91
|
-
raise AuthenticationError.new('No API secret provided. ' \
|
92
|
-
'See https://developer.nexmo.com/concepts/guides/authentication for details, ' \
|
93
|
-
'or email support@nexmo.com if you have any questions.')
|
94
|
-
end
|
95
|
-
|
96
|
-
@api_secret
|
97
|
-
end
|
98
|
-
|
99
|
-
# Returns the value of attribute signature_secret.
|
100
|
-
#
|
101
|
-
# @return [String]
|
102
|
-
#
|
103
|
-
# @raise [AuthenticationError]
|
104
|
-
#
|
105
|
-
def signature_secret
|
106
|
-
unless @signature_secret
|
107
|
-
raise AuthenticationError.new('No signature_secret provided. ' \
|
108
|
-
'You can find your signature secret in the Nexmo dashboard. ' \
|
109
|
-
'See https://developer.nexmo.com/concepts/guides/signing-messages for details, ' \
|
110
|
-
'or email support@nexmo.com if you have any questions.')
|
111
|
-
end
|
112
|
-
|
113
|
-
@signature_secret
|
114
|
-
end
|
115
|
-
|
116
|
-
# Returns the value of attribute application_id.
|
117
|
-
#
|
118
|
-
# @return [String]
|
119
|
-
#
|
120
|
-
# @raise [AuthenticationError]
|
121
|
-
#
|
122
|
-
def application_id
|
123
|
-
unless @application_id
|
124
|
-
raise AuthenticationError.new('No application_id provided. ' \
|
125
|
-
'Either provide an application_id, or set an auth token. ' \
|
126
|
-
'You can add new applications from the Nexmo dashboard. ' \
|
127
|
-
'See https://developer.nexmo.com/concepts/guides/applications for details, ' \
|
128
|
-
'or email support@nexmo.com if you have any questions.')
|
129
|
-
end
|
130
|
-
|
131
|
-
@application_id
|
132
|
-
end
|
133
|
-
|
134
|
-
# Returns the value of attribute private_key.
|
135
|
-
#
|
136
|
-
# @return [String]
|
137
|
-
#
|
138
|
-
# @raise [AuthenticationError]
|
139
|
-
#
|
140
|
-
def private_key
|
141
|
-
unless @private_key
|
142
|
-
raise AuthenticationError.new('No private_key provided. ' \
|
143
|
-
'Either provide a private_key, or set an auth token. ' \
|
144
|
-
'You can add new applications from the Nexmo dashboard. ' \
|
145
|
-
'See https://developer.nexmo.com/concepts/guides/applications for details, ' \
|
146
|
-
'or email support@nexmo.com if you have any questions.')
|
147
|
-
end
|
148
|
-
|
149
|
-
@private_key
|
5
|
+
def initialize(options = nil)
|
6
|
+
@config = Nexmo.config.merge(options)
|
150
7
|
end
|
151
8
|
|
152
9
|
# @return [Signature]
|
153
10
|
#
|
154
11
|
def signature
|
155
|
-
@signature ||= Signature.new(signature_secret)
|
12
|
+
@signature ||= Signature.new(config.signature_secret)
|
156
13
|
end
|
157
14
|
|
158
15
|
# @return [Account]
|
159
16
|
#
|
160
17
|
def account
|
161
|
-
@account ||= Account.new(
|
18
|
+
@account ||= Account.new(config)
|
162
19
|
end
|
163
20
|
|
164
21
|
# @return [Alerts]
|
165
22
|
#
|
166
23
|
def alerts
|
167
|
-
@alerts ||= Alerts.new(
|
24
|
+
@alerts ||= Alerts.new(config)
|
168
25
|
end
|
169
26
|
|
170
27
|
# @return [Applications]
|
171
28
|
#
|
172
29
|
def applications
|
173
|
-
@applications ||= Applications.new(
|
174
|
-
end
|
175
|
-
|
176
|
-
# @return [ApplicationsV2]
|
177
|
-
#
|
178
|
-
def applications_v2
|
179
|
-
@applications_v2 ||= ApplicationsV2.new(self)
|
30
|
+
@applications ||= Applications.new(config)
|
180
31
|
end
|
181
32
|
|
182
33
|
# @return [Calls]
|
183
34
|
#
|
184
35
|
def calls
|
185
|
-
@calls ||= Calls.new(
|
36
|
+
@calls ||= Calls.new(config)
|
186
37
|
end
|
187
38
|
|
188
39
|
# @return [Conversations]
|
189
40
|
#
|
190
41
|
def conversations
|
191
|
-
@conversations ||= Conversations.new(
|
42
|
+
@conversations ||= Conversations.new(config)
|
192
43
|
end
|
193
44
|
|
194
45
|
# @return [Conversions]
|
195
46
|
#
|
196
47
|
def conversions
|
197
|
-
@conversions ||= Conversions.new(
|
48
|
+
@conversions ||= Conversions.new(config)
|
198
49
|
end
|
199
50
|
|
200
51
|
# @return [Files]
|
201
52
|
#
|
202
53
|
def files
|
203
|
-
@files ||= Files.new(
|
54
|
+
@files ||= Files.new(config)
|
204
55
|
end
|
205
56
|
|
206
57
|
# @return [Messages]
|
207
58
|
#
|
208
59
|
def messages
|
209
|
-
@messages ||= Messages.new(
|
60
|
+
@messages ||= Messages.new(config)
|
210
61
|
end
|
211
62
|
|
212
63
|
# @return [NumberInsight]
|
213
64
|
#
|
214
65
|
def number_insight
|
215
|
-
@number_insight ||= NumberInsight.new(
|
66
|
+
@number_insight ||= NumberInsight.new(config)
|
216
67
|
end
|
217
68
|
|
218
69
|
# @return [Numbers]
|
219
70
|
#
|
220
71
|
def numbers
|
221
|
-
@numbers ||= Numbers.new(
|
72
|
+
@numbers ||= Numbers.new(config)
|
222
73
|
end
|
223
74
|
|
224
75
|
# @return [PricingTypes]
|
225
76
|
#
|
226
77
|
def pricing
|
227
|
-
@pricing ||= PricingTypes.new(
|
78
|
+
@pricing ||= PricingTypes.new(config)
|
228
79
|
end
|
229
80
|
|
230
81
|
# @return [Redact]
|
231
82
|
#
|
232
83
|
def redact
|
233
|
-
@redact ||= Redact.new(
|
84
|
+
@redact ||= Redact.new(config)
|
234
85
|
end
|
235
86
|
|
236
87
|
# @return [Secrets]
|
237
88
|
#
|
238
89
|
def secrets
|
239
|
-
@secrets ||= Secrets.new(
|
90
|
+
@secrets ||= Secrets.new(config)
|
240
91
|
end
|
241
92
|
|
242
93
|
# @return [SMS]
|
243
94
|
#
|
244
95
|
def sms
|
245
|
-
@sms ||= SMS.new(
|
96
|
+
@sms ||= SMS.new(config)
|
246
97
|
end
|
247
98
|
|
248
99
|
# @return [TFA]
|
249
100
|
#
|
250
101
|
def tfa
|
251
|
-
@tfa ||= TFA.new(
|
102
|
+
@tfa ||= TFA.new(config)
|
252
103
|
end
|
253
104
|
|
254
105
|
# @return [Verify]
|
255
106
|
#
|
256
107
|
def verify
|
257
|
-
@verify ||= Verify.new(
|
108
|
+
@verify ||= Verify.new(config)
|
258
109
|
end
|
259
110
|
end
|
260
111
|
end
|
File without changes
|
data/lib/nexmo/config.rb
ADDED
@@ -0,0 +1,165 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'logger'
|
3
|
+
|
4
|
+
module Nexmo
|
5
|
+
class Config
|
6
|
+
def initialize
|
7
|
+
self.api_key = ENV['NEXMO_API_KEY']
|
8
|
+
self.api_secret = ENV['NEXMO_API_SECRET']
|
9
|
+
self.application_id = nil
|
10
|
+
self.logger = (defined?(Rails.logger) && Rails.logger) || ::Logger.new(nil)
|
11
|
+
self.private_key = nil
|
12
|
+
self.signature_secret = ENV['NEXMO_SIGNATURE_SECRET']
|
13
|
+
self.token = nil
|
14
|
+
end
|
15
|
+
|
16
|
+
# Merges the config with the given options hash.
|
17
|
+
#
|
18
|
+
# @return [Nexmo::Config]
|
19
|
+
#
|
20
|
+
def merge(options)
|
21
|
+
return self if options.nil? || options.empty?
|
22
|
+
|
23
|
+
options.each_with_object(dup) do |(name, value), config|
|
24
|
+
config.write_attribute(name, value)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
# Returns the value of attribute api_key.
|
29
|
+
#
|
30
|
+
# @return [String]
|
31
|
+
#
|
32
|
+
# @raise [AuthenticationError]
|
33
|
+
#
|
34
|
+
def api_key
|
35
|
+
unless @api_key
|
36
|
+
raise AuthenticationError.new('No API key provided. ' \
|
37
|
+
'See https://developer.nexmo.com/concepts/guides/authentication for details, ' \
|
38
|
+
'or email support@nexmo.com if you have any questions.')
|
39
|
+
end
|
40
|
+
|
41
|
+
@api_key
|
42
|
+
end
|
43
|
+
|
44
|
+
attr_writer :api_key
|
45
|
+
|
46
|
+
# Returns the value of attribute api_secret.
|
47
|
+
#
|
48
|
+
# @return [String]
|
49
|
+
#
|
50
|
+
# @raise [AuthenticationError]
|
51
|
+
#
|
52
|
+
def api_secret
|
53
|
+
unless @api_secret
|
54
|
+
raise AuthenticationError.new('No API secret provided. ' \
|
55
|
+
'See https://developer.nexmo.com/concepts/guides/authentication for details, ' \
|
56
|
+
'or email support@nexmo.com if you have any questions.')
|
57
|
+
end
|
58
|
+
|
59
|
+
@api_secret
|
60
|
+
end
|
61
|
+
|
62
|
+
attr_writer :api_secret
|
63
|
+
|
64
|
+
# Returns the value of attribute application_id.
|
65
|
+
#
|
66
|
+
# @return [String]
|
67
|
+
#
|
68
|
+
# @raise [AuthenticationError]
|
69
|
+
#
|
70
|
+
def application_id
|
71
|
+
unless @application_id
|
72
|
+
raise AuthenticationError.new('No application_id provided. ' \
|
73
|
+
'Either provide an application_id, or set an auth token. ' \
|
74
|
+
'You can add new applications from the Nexmo dashboard. ' \
|
75
|
+
'See https://developer.nexmo.com/concepts/guides/applications for details, ' \
|
76
|
+
'or email support@nexmo.com if you have any questions.')
|
77
|
+
end
|
78
|
+
|
79
|
+
@application_id
|
80
|
+
end
|
81
|
+
|
82
|
+
attr_writer :application_id
|
83
|
+
|
84
|
+
attr_accessor :app_name
|
85
|
+
|
86
|
+
attr_accessor :app_version
|
87
|
+
|
88
|
+
# Returns the value of attribute http.
|
89
|
+
#
|
90
|
+
# @return [Nexmo::HTTP::Options]
|
91
|
+
#
|
92
|
+
attr_reader :http
|
93
|
+
|
94
|
+
def http=(hash)
|
95
|
+
@http = HTTP::Options.new(hash)
|
96
|
+
end
|
97
|
+
|
98
|
+
# Returns the value of attribute logger.
|
99
|
+
#
|
100
|
+
# @return [Nexmo::Logger]
|
101
|
+
#
|
102
|
+
attr_reader :logger
|
103
|
+
|
104
|
+
# @return [Nexmo::Logger]
|
105
|
+
#
|
106
|
+
def logger=(logger)
|
107
|
+
@logger = Logger.new(logger)
|
108
|
+
end
|
109
|
+
|
110
|
+
# Returns the value of attribute private_key.
|
111
|
+
#
|
112
|
+
# @return [String]
|
113
|
+
#
|
114
|
+
# @raise [AuthenticationError]
|
115
|
+
#
|
116
|
+
def private_key
|
117
|
+
unless @private_key
|
118
|
+
raise AuthenticationError.new('No private_key provided. ' \
|
119
|
+
'Either provide a private_key, or set an auth token. ' \
|
120
|
+
'You can add new applications from the Nexmo dashboard. ' \
|
121
|
+
'See https://developer.nexmo.com/concepts/guides/applications for details, ' \
|
122
|
+
'or email support@nexmo.com if you have any questions.')
|
123
|
+
end
|
124
|
+
|
125
|
+
@private_key
|
126
|
+
end
|
127
|
+
|
128
|
+
attr_writer :private_key
|
129
|
+
|
130
|
+
# Returns the value of attribute signature_secret.
|
131
|
+
#
|
132
|
+
# @return [String]
|
133
|
+
#
|
134
|
+
# @raise [AuthenticationError]
|
135
|
+
#
|
136
|
+
def signature_secret
|
137
|
+
unless @signature_secret
|
138
|
+
raise AuthenticationError.new('No signature_secret provided. ' \
|
139
|
+
'You can find your signature secret in the Nexmo dashboard. ' \
|
140
|
+
'See https://developer.nexmo.com/concepts/guides/signing-messages for details, ' \
|
141
|
+
'or email support@nexmo.com if you have any questions.')
|
142
|
+
end
|
143
|
+
|
144
|
+
@signature_secret
|
145
|
+
end
|
146
|
+
|
147
|
+
attr_writer :signature_secret
|
148
|
+
|
149
|
+
# Returns the value of attribute token, or a temporary short lived token.
|
150
|
+
#
|
151
|
+
# @return [String]
|
152
|
+
#
|
153
|
+
def token
|
154
|
+
@token || JWT.generate({application_id: application_id}, private_key)
|
155
|
+
end
|
156
|
+
|
157
|
+
attr_writer :token
|
158
|
+
|
159
|
+
protected
|
160
|
+
|
161
|
+
def write_attribute(name, value)
|
162
|
+
public_send(:"#{name}=", value)
|
163
|
+
end
|
164
|
+
end
|
165
|
+
end
|