nexmo 6.3.0 → 7.2.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.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +28 -9
  3. data/lib/nexmo.rb +1 -1
  4. data/lib/nexmo/abstract_authentication.rb +0 -2
  5. data/lib/nexmo/account.rb +5 -1
  6. data/lib/nexmo/alerts.rb +5 -1
  7. data/lib/nexmo/applications.rb +24 -4
  8. data/lib/nexmo/client.rb +45 -24
  9. data/lib/nexmo/config.rb +43 -10
  10. data/lib/nexmo/conversations.rb +24 -1
  11. data/lib/nexmo/conversations/events.rb +1 -1
  12. data/lib/nexmo/conversations/legs.rb +1 -1
  13. data/lib/nexmo/conversations/members.rb +1 -1
  14. data/lib/nexmo/conversations/users.rb +1 -1
  15. data/lib/nexmo/conversions.rb +4 -1
  16. data/lib/nexmo/entity.rb +2 -2
  17. data/lib/nexmo/errors.rb +8 -1
  18. data/lib/nexmo/files.rb +7 -3
  19. data/lib/nexmo/gsm7.rb +0 -2
  20. data/lib/nexmo/http.rb +12 -4
  21. data/lib/nexmo/json.rb +4 -1
  22. data/lib/nexmo/jwt.rb +11 -12
  23. data/lib/nexmo/key_secret_params.rb +9 -3
  24. data/lib/nexmo/keys.rb +24 -3
  25. data/lib/nexmo/logger.rb +14 -5
  26. data/lib/nexmo/messages.rb +6 -1
  27. data/lib/nexmo/namespace.rb +2 -10
  28. data/lib/nexmo/number_insight.rb +21 -7
  29. data/lib/nexmo/numbers.rb +1 -1
  30. data/lib/nexmo/pricing.rb +1 -1
  31. data/lib/nexmo/pricing_types.rb +1 -1
  32. data/lib/nexmo/redact.rb +4 -1
  33. data/lib/nexmo/response.rb +1 -1
  34. data/lib/nexmo/secrets.rb +1 -1
  35. data/lib/nexmo/signature.rb +1 -1
  36. data/lib/nexmo/sms.rb +10 -8
  37. data/lib/nexmo/tfa.rb +1 -1
  38. data/lib/nexmo/verify.rb +93 -18
  39. data/lib/nexmo/version.rb +1 -1
  40. data/lib/nexmo/{calls.rb → voice.rb} +12 -12
  41. data/lib/nexmo/{calls → voice}/dtmf.rb +2 -2
  42. data/lib/nexmo/{calls → voice}/list_response.rb +1 -1
  43. data/lib/nexmo/{calls → voice}/stream.rb +2 -2
  44. data/lib/nexmo/{calls → voice}/talk.rb +2 -2
  45. data/nexmo.gemspec +2 -1
  46. metadata +25 -14
  47. data/lib/nexmo/number_insight/response.rb +0 -7
  48. data/lib/nexmo/sms/response.rb +0 -8
  49. data/lib/nexmo/verify/response.rb +0 -7
@@ -1,18 +1,23 @@
1
- # typed: false
1
+ # typed: strict
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module Nexmo
5
5
  class Messages < Namespace
6
+ extend T::Sig
7
+
6
8
  self.host = :rest_host
7
9
 
10
+ sig { params(id: String).returns(Nexmo::Response) }
8
11
  def get(id)
9
12
  request('/search/message', params: {id: id})
10
13
  end
11
14
 
15
+ sig { params(params: T::Hash[Symbol, T.untyped]).returns(Nexmo::Response) }
12
16
  def search(params)
13
17
  request('/search/messages', params: params)
14
18
  end
15
19
 
20
+ sig { params(params: T::Hash[Symbol, T.untyped]).returns(Nexmo::Response) }
16
21
  def rejections(params)
17
22
  request('/search/rejections', params: params)
18
23
  end
@@ -46,14 +46,6 @@ module Nexmo
46
46
  @request_headers ||= {}
47
47
  end
48
48
 
49
- def self.response_class
50
- @response_class ||= Response
51
- end
52
-
53
- def self.response_class=(response_class)
54
- @response_class = response_class
55
- end
56
-
57
49
  protected
58
50
 
59
51
  Get = Net::HTTP::Get
@@ -61,7 +53,7 @@ module Nexmo
61
53
  Post = Net::HTTP::Post
62
54
  Delete = Net::HTTP::Delete
63
55
 
64
- def request(path, params: nil, type: Get, response_class: nil, &block)
56
+ def request(path, params: nil, type: Get, response_class: Response, &block)
65
57
  uri = URI('https://' + @host + path)
66
58
 
67
59
  params ||= {}
@@ -97,7 +89,7 @@ module Nexmo
97
89
 
98
90
  logger.debug(response.body) if response.body
99
91
 
100
- parse(response, response_class || self.class.response_class)
92
+ parse(response, response_class)
101
93
  end
102
94
 
103
95
  def parse(response, response_class)
@@ -1,10 +1,8 @@
1
- # typed: false
1
+ # typed: true
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module Nexmo
5
5
  class NumberInsight < Namespace
6
- self.response_class = Response
7
-
8
6
  # Provides basic number insight information about a number.
9
7
  #
10
8
  # @example
@@ -25,7 +23,11 @@ module Nexmo
25
23
  # @see https://developer.nexmo.com/api/number-insight#getNumberInsightBasic
26
24
  #
27
25
  def basic(params)
28
- request('/ni/basic/json', params: params)
26
+ response = request('/ni/basic/json', params: params)
27
+
28
+ raise Error, response[:status_message] unless response.status.zero?
29
+
30
+ response
29
31
  end
30
32
 
31
33
  # Provides standard number insight information about a number.
@@ -53,7 +55,11 @@ module Nexmo
53
55
  # @see https://developer.nexmo.com/api/number-insight#getNumberInsightStandard
54
56
  #
55
57
  def standard(params)
56
- request('/ni/standard/json', params: params)
58
+ response = request('/ni/standard/json', params: params)
59
+
60
+ raise Error, response[:status_message] unless response.status.zero?
61
+
62
+ response
57
63
  end
58
64
 
59
65
  # Provides advanced number insight information about a number synchronously.
@@ -85,7 +91,11 @@ module Nexmo
85
91
  # @see https://developer.nexmo.com/api/number-insight#getNumberInsightAdvanced
86
92
  #
87
93
  def advanced(params)
88
- request('/ni/advanced/json', params: params)
94
+ response = request('/ni/advanced/json', params: params)
95
+
96
+ raise Error, response[:status_message] unless response.status.zero?
97
+
98
+ response
89
99
  end
90
100
 
91
101
  # Provides advanced number insight number information *asynchronously* using the URL specified in the callback parameter.
@@ -120,7 +130,11 @@ module Nexmo
120
130
  # @see https://developer.nexmo.com/api/number-insight#getNumberInsightAsync
121
131
  #
122
132
  def advanced_async(params)
123
- request('/ni/advanced/async/json', params: params)
133
+ response = request('/ni/advanced/async/json', params: params)
134
+
135
+ raise Error, response[:status_message] unless response.status.zero?
136
+
137
+ response
124
138
  end
125
139
  end
126
140
  end
@@ -1,4 +1,4 @@
1
- # typed: false
1
+ # typed: true
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module Nexmo
@@ -1,4 +1,4 @@
1
- # typed: false
1
+ # typed: true
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module Nexmo
@@ -1,4 +1,4 @@
1
- # typed: false
1
+ # typed: true
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module Nexmo
@@ -1,8 +1,10 @@
1
- # typed: false
1
+ # typed: strict
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module Nexmo
5
5
  class Redact < Namespace
6
+ extend T::Sig
7
+
6
8
  self.authentication = Basic
7
9
 
8
10
  self.request_body = JSON
@@ -27,6 +29,7 @@ module Nexmo
27
29
  #
28
30
  # @see https://developer.nexmo.com/api/redact#redact-message
29
31
  #
32
+ sig { params(params: T::Hash[Symbol, T.untyped]).returns(Nexmo::Response) }
30
33
  def transaction(params)
31
34
  request('/v1/redact/transaction', params: params, type: Post)
32
35
  end
@@ -1,4 +1,4 @@
1
- # typed: false
1
+ # typed: true
2
2
 
3
3
  module Nexmo
4
4
  class Response
@@ -1,4 +1,4 @@
1
- # typed: false
1
+ # typed: true
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module Nexmo
@@ -1,4 +1,4 @@
1
- # typed: false
1
+ # typed: true
2
2
  # frozen_string_literal: true
3
3
  require 'openssl'
4
4
  require 'digest/md5'
@@ -13,11 +13,7 @@ module Nexmo
13
13
  # @example
14
14
  # response = client.sms.send(from: 'Ruby', to: '447700900000', text: 'Hello world')
15
15
  #
16
- # if response.success?
17
- # puts "Sent message id=#{response.messages.first.message_id}"
18
- # else
19
- # puts "Error: #{response.messages.first.error_text}"
20
- # end
16
+ # puts "Sent message id=#{response.messages.first.message_id}"
21
17
  #
22
18
  # @option params [required, String] :from
23
19
  # The name or number the message should be sent from.
@@ -96,7 +92,7 @@ module Nexmo
96
92
  #
97
93
  # @see https://developer.nexmo.com/api/sms#send-an-sms
98
94
  #
99
- sig { params(params: T::Hash[Symbol, T.untyped]).returns(Nexmo::SMS::Response) }
95
+ sig { params(params: T::Hash[Symbol, T.untyped]).returns(Nexmo::Response) }
100
96
  def send(params)
101
97
  if unicode?(params.fetch(:text)) && params[:type] != 'unicode'
102
98
  message = 'Sending unicode text SMS without setting the type parameter to "unicode". ' \
@@ -106,14 +102,20 @@ module Nexmo
106
102
  logger.warn(message)
107
103
  end
108
104
 
109
- request('/sms/json', params: hyphenate(params), type: Post, response_class: Response)
105
+ response = request('/sms/json', params: hyphenate(params), type: Post)
106
+
107
+ unless response.messages.first.status == '0'
108
+ raise Error, response.messages.first[:error_text]
109
+ end
110
+
111
+ response
110
112
  end
111
113
 
112
114
  private
113
115
 
114
116
  sig { params(text: String).returns(T::Boolean) }
115
117
  def unicode?(text)
116
- !GSM7.encoded?(text)
118
+ !Nexmo::GSM7.encoded?(text)
117
119
  end
118
120
  end
119
121
  end
@@ -1,4 +1,4 @@
1
- # typed: false
1
+ # typed: true
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module Nexmo
@@ -1,14 +1,13 @@
1
- # typed: false
1
+ # typed: strict
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module Nexmo
5
5
  class Verify < Namespace
6
+ extend T::Sig
6
7
  alias_method :http_request, :request
7
8
 
8
9
  private :http_request
9
10
 
10
- self.response_class = Response
11
-
12
11
  # Generate and send a PIN to your user.
13
12
  #
14
13
  # @note You can make a maximum of one Verify request per second.
@@ -16,11 +15,7 @@ module Nexmo
16
15
  # @example
17
16
  # response = client.verify.request(number: '447700900000', brand: 'Acme Inc')
18
17
  #
19
- # if response.success?
20
- # puts "Started verification request_id=#{response.request_id}"
21
- # else
22
- # puts "Error: #{response.error_text}"
23
- # end
18
+ # puts "Started verification request_id=#{response.request_id}"
24
19
  #
25
20
  # @option params [required, String] :number
26
21
  # The mobile or landline phone number to verify.
@@ -65,8 +60,13 @@ module Nexmo
65
60
  #
66
61
  # @see https://developer.nexmo.com/api/verify#verifyRequest
67
62
  #
68
- def request(params)
69
- http_request('/verify/json', params: params, type: Post)
63
+ sig { params(params: T.untyped, uri: T.untyped).returns(T.untyped) }
64
+ def request(params, uri = '/verify/json')
65
+ response = http_request(uri, params: params, type: Post)
66
+
67
+ raise Error, response[:error_text] if error?(response)
68
+
69
+ response
70
70
  end
71
71
 
72
72
  # Confirm that the PIN you received from your user matches the one sent by Nexmo in your verification request.
@@ -74,11 +74,7 @@ module Nexmo
74
74
  # @example
75
75
  # response = client.verify.check(request_id: request_id, code: '1234')
76
76
  #
77
- # if response.success?
78
- # puts "Verification complete, event_id=#{response.event_id}"
79
- # else
80
- # puts "Error: #{response.error_text}"
81
- # end
77
+ # puts "Verification complete, event_id=#{response.event_id}"
82
78
  #
83
79
  # @option params [required, String] :request_id
84
80
  # The Verify request to check.
@@ -97,8 +93,13 @@ module Nexmo
97
93
  #
98
94
  # @see https://developer.nexmo.com/api/verify#verifyCheck
99
95
  #
96
+ sig { params(params: T::Hash[Symbol, T.untyped]).returns(Nexmo::Response) }
100
97
  def check(params)
101
- http_request('/verify/check/json', params: params, type: Post)
98
+ response = http_request('/verify/check/json', params: params, type: Post)
99
+
100
+ raise Error, response[:error_text] if error?(response)
101
+
102
+ response
102
103
  end
103
104
 
104
105
  # Check the status of past or current verification requests.
@@ -119,8 +120,13 @@ module Nexmo
119
120
  #
120
121
  # @see https://developer.nexmo.com/api/verify#verifySearch
121
122
  #
123
+ sig { params(params: T::Hash[Symbol, T.untyped]).returns(T.any(T::Hash[Symbol, T.untyped], Nexmo::Response)) }
122
124
  def search(params)
123
- http_request('/verify/search/json', params: params)
125
+ response = http_request('/verify/search/json', params: params)
126
+
127
+ raise Error, response[:error_text] if error?(response)
128
+
129
+ response
124
130
  end
125
131
 
126
132
  # Control the progress of your verification requests.
@@ -141,8 +147,13 @@ module Nexmo
141
147
  #
142
148
  # @see https://developer.nexmo.com/api/verify#verifyControl
143
149
  #
150
+ sig { params(params: T::Hash[Symbol, T.untyped]).returns(T.untyped) }
144
151
  def control(params)
145
- http_request('/verify/control/json', params: params, type: Post)
152
+ response = http_request('/verify/control/json', params: params, type: Post)
153
+
154
+ raise Error, response[:error_text] if error?(response)
155
+
156
+ response
146
157
  end
147
158
 
148
159
  # Cancel an existing verification request.
@@ -156,6 +167,7 @@ module Nexmo
156
167
  #
157
168
  # @see https://developer.nexmo.com/api/verify#verifyControl
158
169
  #
170
+ sig { params(id: String).returns(Nexmo::Response) }
159
171
  def cancel(id)
160
172
  control(request_id: id, cmd: 'cancel')
161
173
  end
@@ -171,8 +183,71 @@ module Nexmo
171
183
  #
172
184
  # @see https://developer.nexmo.com/api/verify#verifyControl
173
185
  #
186
+ sig { params(id: String).returns(Nexmo::Response) }
174
187
  def trigger_next_event(id)
175
188
  control(request_id: id, cmd: 'trigger_next_event')
176
189
  end
190
+
191
+ # Send a PSD2-compliant payment token to a user for payment authorization
192
+ #
193
+ # @example
194
+ # response = client.verify.psd2(number: '447700900000', payee: 'Acme Inc', amount: 48.00)
195
+ #
196
+ # @option params [required, String] :number
197
+ # The mobile or landline phone number to verify.
198
+ # Unless you are setting **:country** explicitly, this number must be in E.164 format.
199
+ #
200
+ # @option params [String] :country
201
+ # If you do not provide **:number** in international format or you are not sure if **:number** is correctly formatted, specify the two-character country code in **:country**.
202
+ # Verify will then format the number for you.
203
+ #
204
+ # @option params [required, String] :payee
205
+ # An alphanumeric string to indicate to the user the name of the recipient that they are confirming a payment to.
206
+ #
207
+ # @option params [required, Float] :amount
208
+ # The decimal amount of the payment to be confirmed, in Euros
209
+ #
210
+ # @option params [Integer] :code_length
211
+ # The length of the verification code.
212
+ #
213
+ # @option params [String] :lg
214
+ # By default, the SMS or text-to-speech (TTS) message is generated in the locale that matches the **:number**.
215
+ # For example, the text message or TTS message for a `33*` number is sent in French.
216
+ # Use this parameter to explicitly control the language, accent and gender used for the Verify request.
217
+ #
218
+ # @option params [Integer] :pin_expiry
219
+ # How log the generated verification code is valid for, in seconds.
220
+ # When you specify both **:pin_expiry** and **:next_event_wait** then **:pin_expiry** must be an integer multiple of **:next_event_wait** otherwise **:pin_expiry** is defaulted to equal **:next_event_wait**.
221
+ # See [changing the event timings](https://developer.nexmo.com/verify/guides/changing-default-timings).
222
+ #
223
+ # @option params [Integer] :next_event_wait
224
+ # Specifies the wait time in seconds between attempts to deliver the verification code.
225
+ #
226
+ # @option params [Integer] :workflow_id
227
+ # Selects the predefined sequence of SMS and TTS (Text To Speech) actions to use in order to convey the PIN to your user.
228
+ # For example, an id of 1 identifies the workflow SMS - TTS - TTS.
229
+ # For a list of all workflows and their associated ids, please visit the [developer portal](https://developer.nexmo.com/verify/guides/workflows-and-events).
230
+ #
231
+ # @param [Hash] params
232
+ #
233
+ # @return [Response]
234
+ #
235
+ # @see https://developer.nexmo.com/api/verify#verifyRequestWithPSD2
236
+ #
237
+ sig { params(params: T.untyped, uri: T.untyped).returns(T.any(Nexmo::Error, Nexmo::Response)) }
238
+ def psd2(params, uri = '/verify/psd2/json')
239
+ response = http_request(uri, params: params, type: Post)
240
+
241
+ raise Error, response[:error_text] if error?(response)
242
+
243
+ response
244
+ end
245
+
246
+ private
247
+
248
+ sig { params(response: T.untyped).returns(T::Boolean) }
249
+ def error?(response)
250
+ response.respond_to?(:error_text)
251
+ end
177
252
  end
178
253
  end
@@ -1,5 +1,5 @@
1
1
  # typed: strong
2
2
 
3
3
  module Nexmo
4
- VERSION = '6.3.0'
4
+ VERSION = '7.2.0'
5
5
  end
@@ -1,8 +1,8 @@
1
- # typed: false
1
+ # typed: true
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module Nexmo
5
- class Calls < Namespace
5
+ class Voice < Namespace
6
6
  self.authentication = BearerToken
7
7
 
8
8
  self.request_body = JSON
@@ -10,7 +10,7 @@ module Nexmo
10
10
  # Create an outbound Call.
11
11
  #
12
12
  # @example
13
- # response = client.calls.create({
13
+ # response = client.voice.create({
14
14
  # to: [{type: 'phone', number: '14843331234'}],
15
15
  # from: {type: 'phone', number: '14843335555'},
16
16
  # answer_url: ['https://example.com/answer']
@@ -61,7 +61,7 @@ module Nexmo
61
61
  # Get details of your calls.
62
62
  #
63
63
  # @example
64
- # response = client.calls.list
64
+ # response = client.voice.list
65
65
  # response.each do |item|
66
66
  # puts "#{item.uuid} #{item.direction} #{item.status}"
67
67
  # end
@@ -100,7 +100,7 @@ module Nexmo
100
100
  # Get detail of a specific call.
101
101
  #
102
102
  # @example
103
- # response = client.calls.get(id)
103
+ # response = client.voice.get(id)
104
104
  #
105
105
  # @param [String] id
106
106
  #
@@ -115,7 +115,7 @@ module Nexmo
115
115
  # Modify an in progress call.
116
116
  #
117
117
  # @example
118
- # response = client.calls.update(id, action: 'hangup')
118
+ # response = client.voice.update(id, action: 'hangup')
119
119
  #
120
120
  # @option params [required, String] :action
121
121
  #
@@ -136,7 +136,7 @@ module Nexmo
136
136
  # Hangup an in progress call.
137
137
  #
138
138
  # @example
139
- # response = client.calls.hangup(id)
139
+ # response = client.voice.hangup(id)
140
140
  #
141
141
  # @param [String] id
142
142
  #
@@ -151,7 +151,7 @@ module Nexmo
151
151
  # Mute an in progress call.
152
152
  #
153
153
  # @example
154
- # response = client.calls.mute(id)
154
+ # response = client.voice.mute(id)
155
155
  #
156
156
  # @param [String] id
157
157
  #
@@ -166,7 +166,7 @@ module Nexmo
166
166
  # Unmute an in progress call.
167
167
  #
168
168
  # @example
169
- # response = client.calls.unmute(id)
169
+ # response = client.voice.unmute(id)
170
170
  #
171
171
  # @param [String] id
172
172
  #
@@ -181,7 +181,7 @@ module Nexmo
181
181
  # Earmuff an in progress call.
182
182
  #
183
183
  # @example
184
- # response = client.calls.earmuff(id)
184
+ # response = client.voice.earmuff(id)
185
185
  #
186
186
  # @param [String] id
187
187
  #
@@ -196,7 +196,7 @@ module Nexmo
196
196
  # Unearmuff an in progress call.
197
197
  #
198
198
  # @example
199
- # response = client.calls.unearmuff(id)
199
+ # response = client.voice.unearmuff(id)
200
200
  #
201
201
  # @param [String] id
202
202
  #
@@ -216,7 +216,7 @@ module Nexmo
216
216
  # url: ['https://example.com/ncco.json']
217
217
  # }
218
218
  #
219
- # response = client.calls.transfer(id, destination: destination)
219
+ # response = client.voice.transfer(id, destination: destination)
220
220
  #
221
221
  # @param [String] id
222
222
  # @param [Hash] destination