nexmo 7.0.0 → 7.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c11d202ac7a62f8ee5ae904f0a3c3edfd92d9d04899b747f8369811ca140d6d3
4
- data.tar.gz: 595afbed12c7c0e2bda951059beac3f904ded148a229b2d1eec84996c5a9c736
3
+ metadata.gz: 041a5d88df4780900cec2813647b6cfb45c71031374a824905cc2839cb9e46dd
4
+ data.tar.gz: c5fb8b4dc6f75c19a55ff1005364eff154b326bb0bbff82cc7874127a37da1e0
5
5
  SHA512:
6
- metadata.gz: c0bb244ff331d3faa4eec0b79b173e8829aead849682ad508bb9c152be677276387db0d602a801f09c7c5237699d00c43ac65021ba2b9f8d8ee0f5c096c9b5d1
7
- data.tar.gz: 527352b2f4a00c318a39f234182f240b7955018b75882ed084809ef5b3a245b202036d94dad8c210e50512f7a08b6b71fd41faec3fa9f8ee2b7e830ee9a4c265
6
+ metadata.gz: 9c923d6ca80704f3e6fd68f8311ff2e7d737a75d6892ba24866a8d2e82e6db566ad8c8cb84335302830ec71fe1a1e6e1466ab890fd1746e5d25a4b6c0f4de789
7
+ data.tar.gz: af9df8e503ea622f9221f9c8c8bf6414e03d6c806b4648829093ff80155f0e05bb32c678795d1e750f2edc4b0c0c11681a318bed9eb0b6edcec1c8fbb5f7e70c
@@ -1,4 +1,4 @@
1
- # typed: false
1
+ # typed: true
2
2
  # frozen_string_literal: true
3
3
  require 'zeitwerk'
4
4
  require 'sorbet-runtime'
@@ -1,8 +1,9 @@
1
- # typed: false
1
+ # typed: strict
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module Nexmo
5
5
  class Applications < Namespace
6
+ extend T::Sig
6
7
  self.authentication = Basic
7
8
 
8
9
  self.request_body = JSON
@@ -14,9 +15,20 @@ module Nexmo
14
15
  # @example
15
16
  # params = {
16
17
  # name: 'Example App',
17
- # type: 'voice',
18
- # answer_url: answer_url,
19
- # event_url: event_url
18
+ # capabilities: {
19
+ # 'messages': {
20
+ # 'webhooks': {
21
+ # 'inbound_url': {
22
+ # 'address': 'https://example.com/webhooks/inbound',
23
+ # 'http_method': 'POST'
24
+ # },
25
+ # 'status_url': {
26
+ # 'address': 'https://example.com/webhooks/status',
27
+ # 'http_method': 'POST'
28
+ # }
29
+ # }
30
+ # }
31
+ # }
20
32
  # }
21
33
  #
22
34
  # response = client.applications.create(params)
@@ -38,6 +50,7 @@ module Nexmo
38
50
  #
39
51
  # @see https://developer.nexmo.com/api/application.v2#createApplication
40
52
  #
53
+ sig { params(params: T::Hash[Symbol, T.untyped]).returns(Nexmo::Response) }
41
54
  def create(params)
42
55
  request('/v2/applications', params: params, type: Post)
43
56
  end
@@ -62,6 +75,7 @@ module Nexmo
62
75
  #
63
76
  # @see https://developer.nexmo.com/api/application.v2#listApplication
64
77
  #
78
+ sig { params(params: T.nilable(T::Hash[Symbol, Integer])).returns(Nexmo::Response) }
65
79
  def list(params = nil)
66
80
  request('/v2/applications', params: params, response_class: ListResponse)
67
81
  end
@@ -77,6 +91,7 @@ module Nexmo
77
91
  #
78
92
  # @see https://developer.nexmo.com/api/application.v2#getApplication
79
93
  #
94
+ sig { params(id: String).returns(Nexmo::Response) }
80
95
  def get(id)
81
96
  request('/v2/applications/' + id)
82
97
  end
@@ -104,6 +119,10 @@ module Nexmo
104
119
  #
105
120
  # @see https://developer.nexmo.com/api/application.v2#updateApplication
106
121
  #
122
+ sig { params(
123
+ id: String,
124
+ params: T::Hash[Symbol, T.untyped]
125
+ ).returns(Nexmo::Response) }
107
126
  def update(id, params)
108
127
  request('/v2/applications/' + id, params: params, type: Put)
109
128
  end
@@ -121,6 +140,7 @@ module Nexmo
121
140
  #
122
141
  # @see https://developer.nexmo.com/api/application.v2#deleteApplication
123
142
  #
143
+ sig { params(id: String).returns(Nexmo::Response) }
124
144
  def delete(id)
125
145
  request('/v2/applications/' + id, type: Delete)
126
146
  end
@@ -1,113 +1,134 @@
1
- # typed: false
1
+ # typed: strict
2
2
 
3
3
  module Nexmo
4
4
  class Client
5
+ extend T::Sig
6
+
7
+ sig { returns(Nexmo::Config) }
5
8
  attr_reader :config
6
9
 
10
+ sig { params(options: T.nilable(T::Hash[Symbol, T.untyped])).void }
7
11
  def initialize(options = nil)
8
- @config = Nexmo.config.merge(options)
12
+ @config = T.let(Nexmo.config.merge(options), Nexmo::Config)
9
13
  end
10
14
 
11
15
  # @return [Signature]
12
16
  #
17
+ sig { returns(T.nilable(Nexmo::Signature)) }
13
18
  def signature
14
- @signature ||= Signature.new(config)
19
+ @signature ||= T.let(Signature.new(config), T.nilable(Nexmo::Signature))
15
20
  end
16
21
 
17
22
  # @return [Account]
18
23
  #
24
+ sig { returns(T.nilable(Nexmo::Account)) }
19
25
  def account
20
- @account ||= Account.new(config)
26
+ @account ||= T.let(Account.new(config), T.nilable(Nexmo::Account))
21
27
  end
22
28
 
23
29
  # @return [Alerts]
24
30
  #
31
+ sig { returns(T.nilable(Nexmo::Alerts)) }
25
32
  def alerts
26
- @alerts ||= Alerts.new(config)
33
+ @alerts ||= T.let(Alerts.new(config), T.nilable(Nexmo::Alerts))
27
34
  end
28
35
 
29
36
  # @return [Applications]
30
37
  #
38
+ sig { returns(T.nilable(Nexmo::Applications)) }
31
39
  def applications
32
- @applications ||= Applications.new(config)
40
+ @applications ||= T.let(Applications.new(config), T.nilable(Nexmo::Applications))
33
41
  end
34
42
 
35
43
  # @return [Conversations]
36
44
  #
45
+ sig { returns(T.nilable(Nexmo::Conversations)) }
37
46
  def conversations
38
- @conversations ||= Conversations.new(config)
47
+ @conversations ||= T.let(Conversations.new(config), T.nilable(Nexmo::Conversations))
39
48
  end
40
49
 
41
50
  # @return [Conversions]
42
51
  #
52
+ sig { returns(T.nilable(Nexmo::Conversions)) }
43
53
  def conversions
44
- @conversions ||= Conversions.new(config)
54
+ @conversions ||= T.let(Conversions.new(config), T.nilable(Nexmo::Conversions))
45
55
  end
46
56
 
47
57
  # @return [Files]
48
58
  #
59
+ sig { returns(T.nilable(Nexmo::Files)) }
49
60
  def files
50
- @files ||= Files.new(config)
61
+ @files ||= T.let(Files.new(config), T.nilable(Nexmo::Files))
51
62
  end
52
63
 
53
64
  # @return [Messages]
54
65
  #
66
+ sig { returns(T.nilable(Nexmo::Messages)) }
55
67
  def messages
56
- @messages ||= Messages.new(config)
68
+ @messages ||= T.let(Messages.new(config), T.nilable(Nexmo::Messages))
57
69
  end
58
70
 
59
71
  # @return [NumberInsight]
60
72
  #
73
+ sig { returns(T.nilable(Nexmo::NumberInsight)) }
61
74
  def number_insight
62
- @number_insight ||= NumberInsight.new(config)
75
+ @number_insight ||= T.let(NumberInsight.new(config), T.nilable(Nexmo::NumberInsight))
63
76
  end
64
77
 
65
78
  # @return [Numbers]
66
79
  #
80
+ sig { returns(T.nilable(Nexmo::Numbers)) }
67
81
  def numbers
68
- @numbers ||= Numbers.new(config)
82
+ @numbers ||= T.let(Numbers.new(config), T.nilable(Nexmo::Numbers))
69
83
  end
70
84
 
71
85
  # @return [PricingTypes]
72
86
  #
87
+ sig { returns(T.nilable(Nexmo::PricingTypes)) }
73
88
  def pricing
74
- @pricing ||= PricingTypes.new(config)
89
+ @pricing ||= T.let(PricingTypes.new(config), T.nilable(Nexmo::PricingTypes))
75
90
  end
76
91
 
77
92
  # @return [Redact]
78
93
  #
94
+ sig { returns(T.nilable(Nexmo::Redact)) }
79
95
  def redact
80
- @redact ||= Redact.new(config)
96
+ @redact ||= T.let(Redact.new(config), T.nilable(Nexmo::Redact))
81
97
  end
82
98
 
83
99
  # @return [Secrets]
84
100
  #
101
+ sig { returns(T.nilable(Nexmo::Secrets)) }
85
102
  def secrets
86
- @secrets ||= Secrets.new(config)
103
+ @secrets ||= T.let(Secrets.new(config), T.nilable(Nexmo::Secrets))
87
104
  end
88
105
 
89
106
  # @return [SMS]
90
107
  #
108
+ sig { returns(T.nilable(Nexmo::SMS)) }
91
109
  def sms
92
- @sms ||= SMS.new(config)
110
+ @sms ||= T.let(SMS.new(config), T.nilable(Nexmo::SMS))
93
111
  end
94
112
 
95
113
  # @return [TFA]
96
114
  #
115
+ sig { returns(T.nilable(Nexmo::TFA)) }
97
116
  def tfa
98
- @tfa ||= TFA.new(config)
117
+ @tfa ||= T.let(TFA.new(config), T.nilable(Nexmo::TFA))
99
118
  end
100
119
 
101
120
  # @return [Verify]
102
121
  #
122
+ sig { returns(T.nilable(Nexmo::Verify)) }
103
123
  def verify
104
- @verify ||= Verify.new(config)
124
+ @verify ||= T.let(Verify.new(config), T.nilable(Nexmo::Verify))
105
125
  end
106
126
 
107
127
  # @return [Voice]
108
128
  #
129
+ sig { returns(T.nilable(Nexmo::Voice)) }
109
130
  def voice
110
- @voice ||= Voice.new(config)
131
+ @voice ||= T.let(Voice.new(config), T.nilable(Nexmo::Voice))
111
132
  end
112
133
  end
113
134
  end
@@ -1,26 +1,30 @@
1
- # typed: false
1
+ # typed: true
2
2
  # frozen_string_literal: true
3
3
  require 'logger'
4
4
 
5
5
  module Nexmo
6
6
  class Config
7
+ extend T::Sig
8
+
9
+ sig { void }
7
10
  def initialize
8
11
  self.api_host = 'api.nexmo.com'
9
- self.api_key = ENV['NEXMO_API_KEY']
10
- self.api_secret = ENV['NEXMO_API_SECRET']
12
+ self.api_key = T.let(ENV['NEXMO_API_KEY'], T.nilable(String))
13
+ self.api_secret = T.let(ENV['NEXMO_API_SECRET'], T.nilable(String))
11
14
  self.application_id = ENV['NEXMO_APPLICATION_ID']
12
- self.logger = (defined?(Rails.logger) && Rails.logger) || ::Logger.new(nil)
13
- self.private_key = ENV['NEXMO_PRIVATE_KEY_PATH'] ? File.read(ENV['NEXMO_PRIVATE_KEY_PATH']) : ENV['NEXMO_PRIVATE_KEY']
15
+ self.logger = (defined?(Rails.logger) && Rails.log) || Nexmo::Logger.new(nil)
16
+ self.private_key = ENV['NEXMO_PRIVATE_KEY_PATH'] ? File.read(T.must(ENV['NEXMO_PRIVATE_KEY_PATH'])) : ENV['NEXMO_PRIVATE_KEY']
14
17
  self.rest_host = 'rest.nexmo.com'
15
18
  self.signature_secret = ENV['NEXMO_SIGNATURE_SECRET']
16
19
  self.signature_method = ENV['NEXMO_SIGNATURE_METHOD'] || 'md5hash'
17
- self.token = nil
20
+ self.token = T.let(nil, T.nilable(String))
18
21
  end
19
22
 
20
23
  # Merges the config with the given options hash.
21
24
  #
22
25
  # @return [Nexmo::Config]
23
26
  #
27
+ sig { params(options: T.nilable(T::Hash[Symbol, T.untyped])).returns(Nexmo::Config) }
24
28
  def merge(options)
25
29
  return self if options.nil? || options.empty?
26
30
 
@@ -29,6 +33,7 @@ module Nexmo
29
33
  end
30
34
  end
31
35
 
36
+ sig { returns(String) }
32
37
  attr_accessor :api_host
33
38
 
34
39
  # Returns the value of attribute api_key.
@@ -37,7 +42,9 @@ module Nexmo
37
42
  #
38
43
  # @raise [AuthenticationError]
39
44
  #
45
+ sig { returns(T.nilable(String)) }
40
46
  def api_key
47
+ @api_key = T.let(@api_key, T.nilable(String))
41
48
  unless @api_key
42
49
  raise AuthenticationError.new('No API key provided. ' \
43
50
  'See https://developer.nexmo.com/concepts/guides/authentication for details, ' \
@@ -47,6 +54,7 @@ module Nexmo
47
54
  @api_key
48
55
  end
49
56
 
57
+ sig { params(api_key: T.nilable(String)).returns(T.nilable(String)) }
50
58
  attr_writer :api_key
51
59
 
52
60
  # Returns the value of attribute api_secret.
@@ -55,7 +63,9 @@ module Nexmo
55
63
  #
56
64
  # @raise [AuthenticationError]
57
65
  #
66
+ sig { returns(T.nilable(String)) }
58
67
  def api_secret
68
+ @api_secret = T.let(@api_secret, T.nilable(String))
59
69
  unless @api_secret
60
70
  raise AuthenticationError.new('No API secret provided. ' \
61
71
  'See https://developer.nexmo.com/concepts/guides/authentication for details, ' \
@@ -65,6 +75,7 @@ module Nexmo
65
75
  @api_secret
66
76
  end
67
77
 
78
+ sig { params(api_secret: T.nilable(String)).returns(T.nilable(String)) }
68
79
  attr_writer :api_secret
69
80
 
70
81
  # Returns the value of attribute application_id.
@@ -73,7 +84,9 @@ module Nexmo
73
84
  #
74
85
  # @raise [AuthenticationError]
75
86
  #
87
+ sig { returns(T.nilable(String)) }
76
88
  def application_id
89
+ @application_id = T.let(@application_id, T.nilable(String))
77
90
  unless @application_id
78
91
  raise AuthenticationError.new('No application_id provided. ' \
79
92
  'Either provide an application_id, or set an auth token. ' \
@@ -85,32 +98,40 @@ module Nexmo
85
98
  @application_id
86
99
  end
87
100
 
101
+ sig { params(application_id: T.nilable(String)).returns(T.nilable(String)) }
88
102
  attr_writer :application_id
89
103
 
104
+ sig { returns(T.nilable(String)) }
90
105
  attr_accessor :app_name
91
106
 
107
+ sig { returns(T.nilable(String)) }
92
108
  attr_accessor :app_version
93
109
 
94
110
  # Returns the value of attribute http.
95
111
  #
96
112
  # @return [Nexmo::HTTP::Options]
97
113
  #
114
+ sig { returns(T.nilable(Nexmo::HTTP::Options)) }
98
115
  attr_reader :http
99
116
 
117
+ sig { params(hash: T::Hash[T.untyped, T.untyped]).returns(T.nilable(Nexmo::HTTP::Options)) }
100
118
  def http=(hash)
101
- @http = HTTP::Options.new(hash)
119
+ @http = T.let(nil, T.nilable(Nexmo::HTTP::Options))
120
+ @http = Nexmo::HTTP::Options.new(hash)
102
121
  end
103
122
 
104
123
  # Returns the value of attribute logger.
105
124
  #
106
125
  # @return [Nexmo::Logger]
107
126
  #
127
+ sig { returns(T.nilable(Nexmo::Logger)) }
108
128
  attr_reader :logger
109
129
 
110
130
  # @return [Nexmo::Logger]
111
131
  #
132
+ sig { params(logger: T.nilable(T.any(::Logger, Nexmo::Logger))).returns(T.nilable(Nexmo::Logger)) }
112
133
  def logger=(logger)
113
- @logger = Logger.new(logger)
134
+ @logger = T.let(Logger.new(logger), T.nilable(Nexmo::Logger))
114
135
  end
115
136
 
116
137
  # Returns the value of attribute private_key.
@@ -119,7 +140,9 @@ module Nexmo
119
140
  #
120
141
  # @raise [AuthenticationError]
121
142
  #
143
+ sig { returns(T.nilable(String)) }
122
144
  def private_key
145
+ @private_key = T.let(@private_key, T.nilable(String))
123
146
  unless @private_key
124
147
  raise AuthenticationError.new('No private_key provided. ' \
125
148
  'Either provide a private_key, or set an auth token. ' \
@@ -131,8 +154,10 @@ module Nexmo
131
154
  @private_key
132
155
  end
133
156
 
157
+ sig { params(private_key: T.nilable(String)).returns(T.nilable(String)) }
134
158
  attr_writer :private_key
135
159
 
160
+ sig { returns(String) }
136
161
  attr_accessor :rest_host
137
162
 
138
163
  # Returns the value of attribute signature_secret.
@@ -141,7 +166,9 @@ module Nexmo
141
166
  #
142
167
  # @raise [AuthenticationError]
143
168
  #
169
+ sig { returns(T.nilable(String)) }
144
170
  def signature_secret
171
+ @signature_secret = T.let(@signature_secret, T.nilable(String))
145
172
  unless @signature_secret
146
173
  raise AuthenticationError.new('No signature_secret provided. ' \
147
174
  'You can find your signature secret in the Nexmo dashboard. ' \
@@ -152,22 +179,28 @@ module Nexmo
152
179
  @signature_secret
153
180
  end
154
181
 
182
+ sig { params(signature_secret: T.nilable(String)).returns(T.nilable(String)) }
155
183
  attr_writer :signature_secret
156
184
 
185
+ sig { returns(String) }
157
186
  attr_accessor :signature_method
158
187
 
159
188
  # Returns the value of attribute token, or a temporary short lived token.
160
189
  #
161
190
  # @return [String]
162
191
  #
192
+ sig { returns(T.nilable(String)) }
163
193
  def token
164
- @token || JWT.generate({application_id: application_id}, private_key)
194
+ @token = T.let(nil, T.nilable(String))
195
+ @token || JWT.generate({application_id: application_id}, T.must(private_key))
165
196
  end
166
197
 
198
+ sig { params(token: T.nilable(String)).returns(T.nilable(String)) }
167
199
  attr_writer :token
168
200
 
169
201
  protected
170
202
 
203
+ sig { params(name: Symbol, value: T.nilable(T.untyped)).void }
171
204
  def write_attribute(name, value)
172
205
  public_send(:"#{name}=", value)
173
206
  end
@@ -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 Conversations < Namespace
6
+ extend T::Sig
7
+
6
8
  self.authentication = BearerToken
7
9
 
8
10
  self.request_body = JSON
@@ -33,6 +35,7 @@ module Nexmo
33
35
  #
34
36
  # @see https://developer.nexmo.com/api/conversation#createConversation
35
37
  #
38
+ sig { params(params: T::Hash[Symbol, T.untyped]).returns(Nexmo::Response) }
36
39
  def create(params)
37
40
  request('/beta/conversations', params: params, type: Post)
38
41
  end
@@ -63,6 +66,7 @@ module Nexmo
63
66
  #
64
67
  # @see https://developer.nexmo.com/api/conversation#replaceConversation
65
68
  #
69
+ sig { params(params: T.nilable(T::Hash[Symbol, T.untyped])).returns(Nexmo::Response) }
66
70
  def list(params = nil)
67
71
  request('/beta/conversations', params: params)
68
72
  end
@@ -78,6 +82,7 @@ module Nexmo
78
82
  #
79
83
  # @see https://developer.nexmo.com/api/conversation#retrieveConversation
80
84
  #
85
+ sig { params(id: String).returns(Nexmo::Response) }
81
86
  def get(id)
82
87
  request('/beta/conversations/' + id)
83
88
  end
@@ -110,6 +115,10 @@ module Nexmo
110
115
  #
111
116
  # @see https://developer.nexmo.com/api/conversation#replaceConversation
112
117
  #
118
+ sig { params(
119
+ id: String,
120
+ params: T::Hash[Symbol, T.untyped]
121
+ ).returns(Nexmo::Response) }
113
122
  def update(id, params)
114
123
  request('/beta/conversations/' + id, params: params, type: Put)
115
124
  end
@@ -125,6 +134,7 @@ module Nexmo
125
134
  #
126
135
  # @see https://developer.nexmo.com/api/conversation#deleteConversation
127
136
  #
137
+ sig { params(id: String).returns(Nexmo::Response) }
128
138
  def delete(id)
129
139
  request('/beta/conversations/' + id, type: Delete)
130
140
  end
@@ -156,31 +166,44 @@ module Nexmo
156
166
  #
157
167
  # @see https://developer.nexmo.com/api/conversation#recordConversation
158
168
  #
169
+ sig { params(
170
+ id: String,
171
+ params: T::Hash[Symbol, T.untyped]
172
+ ).returns(Nexmo::Response) }
159
173
  def record(id, params)
160
174
  request('/v1/conversations/' + id + '/record', params: params, type: Put)
161
175
  end
162
176
 
163
177
  # @return [Events]
164
178
  #
179
+ sig { returns(T.nilable(Nexmo::Conversations::Events)) }
165
180
  def events
181
+ @events = T.let(@events, T.nilable(Nexmo::Conversations::Events))
182
+ @config = T.let(@config, T.nilable(Nexmo::Config))
166
183
  @events ||= Events.new(@config)
167
184
  end
168
185
 
169
186
  # @return [Legs]
170
187
  #
188
+ sig { returns(T.nilable(Nexmo::Conversations::Legs)) }
171
189
  def legs
190
+ @legs = T.let(@legs, T.nilable(Nexmo::Conversations::Legs))
172
191
  @legs ||= Legs.new(@config)
173
192
  end
174
193
 
175
194
  # @return [Members]
176
195
  #
196
+ sig { returns(T.nilable(Nexmo::Conversations::Members)) }
177
197
  def members
198
+ @members = T.let(@members, T.nilable(Nexmo::Conversations::Members))
178
199
  @members ||= Members.new(@config)
179
200
  end
180
201
 
181
202
  # @return [Users]
182
203
  #
204
+ sig { returns(T.nilable(Nexmo::Conversations::Users)) }
183
205
  def users
206
+ @users = T.let(@users, T.nilable(Nexmo::Conversations::Users))
184
207
  @users ||= Users.new(@config)
185
208
  end
186
209
  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,4 +1,4 @@
1
- # typed: false
1
+ # typed: true
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module Nexmo
@@ -1,14 +1,17 @@
1
- # typed: false
1
+ # typed: strict
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module Nexmo
5
5
  class Conversions < Namespace
6
+ extend T::Sig
6
7
  include Keys
7
8
 
9
+ sig { params(params: T::Hash[Symbol, T.untyped]).returns(Nexmo::Response) }
8
10
  def track_sms(params)
9
11
  request('/conversions/sms', params: hyphenate(params), type: Post)
10
12
  end
11
13
 
14
+ sig { params(params: T::Hash[Symbol, T.untyped]).returns(Nexmo::Response) }
12
15
  def track_voice(params)
13
16
  request('/conversions/voice', params: hyphenate(params), type: Post)
14
17
  end
@@ -1,4 +1,4 @@
1
- # typed: false
1
+ # typed: true
2
2
 
3
3
  module Nexmo
4
4
  class Entity
@@ -48,4 +48,4 @@ module Nexmo
48
48
 
49
49
  include Enumerable
50
50
  end
51
- end
51
+ end
@@ -1,9 +1,12 @@
1
- # typed: ignore
1
+ # typed: strict
2
2
  # frozen_string_literal: true
3
3
  require 'json'
4
4
 
5
5
  module Nexmo
6
6
  module Errors
7
+ extend T::Sig
8
+
9
+ sig {params(response: T.any(Net::HTTPUnauthorized, Net::HTTPClientError, Net::HTTPServerError, T.untyped)).returns(Nexmo::Error)}
7
10
  def self.parse(response)
8
11
  exception_class = case response
9
12
  when Net::HTTPUnauthorized
@@ -33,10 +36,12 @@ module Nexmo
33
36
  exception_class.new(message)
34
37
  end
35
38
 
39
+ sig { params(hash: T::Hash[String, T.untyped]).returns(T::Boolean) }
36
40
  def self.problem_details?(hash)
37
41
  hash.key?('title') && hash.key?('detail') && hash.key?('type')
38
42
  end
39
43
 
44
+ sig { params(hash: T::Hash[String, T.untyped]).returns(String) }
40
45
  def self.problem_details_message(hash)
41
46
  "#{hash['title']}. #{hash['detail']} See #{hash['type']} for more info, or email support@nexmo.com if you have any questions."
42
47
  end
@@ -1,16 +1,20 @@
1
- # typed: false
1
+ # typed: strict
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module Nexmo
5
5
  class Files < Namespace
6
+ extend T::Sig
7
+
6
8
  self.authentication = BearerToken
7
9
 
10
+ sig { params(id: String).returns(T.nilable(Nexmo::Response)) }
8
11
  def get(id)
9
- request('/v1/files/' + id.split('/').last)
12
+ request('/v1/files/' + T.must(id.split('/').last))
10
13
  end
11
14
 
15
+ sig { params(id: String, filename: String).returns(T.nilable(Nexmo::Response)) }
12
16
  def save(id, filename)
13
- request('/v1/files/' + id.split('/').last) do |response|
17
+ request('/v1/files/' + T.must(id.split('/').last)) do |response|
14
18
  File.open(filename, 'wb') do |file|
15
19
  response.read_body do |chunk|
16
20
  file.write(chunk)
@@ -1,12 +1,18 @@
1
- # typed: ignore
1
+ # typed: strict
2
2
  # frozen_string_literal: true
3
3
  require 'net/http'
4
4
 
5
5
  module Nexmo
6
6
  module HTTP
7
7
  class Options
8
+ extend T::Sig
9
+
10
+ sig { params(hash: T::Hash[Symbol, T.untyped]).void }
8
11
  def initialize(hash)
9
- @hash = hash || {}
12
+ raise ArgumentError, 'hash parameter cannot be empty or nil' if hash == {} || hash.nil?
13
+
14
+ @hash = T.let(@hash, T::Hash[Symbol, T.untyped]) if defined? @hash
15
+ @hash = hash
10
16
 
11
17
  @hash.each_key do |name|
12
18
  next if defined_options.key?(name)
@@ -15,6 +21,7 @@ module Nexmo
15
21
  end
16
22
  end
17
23
 
24
+ sig { params(http: Net::HTTP).returns(T::Hash[Symbol, T.untyped]) }
18
25
  def set(http)
19
26
  @hash.each do |name, value|
20
27
  http.public_send(defined_options.fetch(name), value)
@@ -23,13 +30,14 @@ module Nexmo
23
30
 
24
31
  private
25
32
 
33
+ sig { returns(T::Hash[Symbol, T.untyped]) }
26
34
  def defined_options
35
+ @defined_options = T.let(@defined_options, T.nilable(T::Hash[Symbol, T.untyped]))
36
+
27
37
  @defined_options ||= Net::HTTP.instance_methods.grep(/\w=\z/).each_with_object({}) do |name, hash|
28
38
  hash[name.to_s.chomp('=').to_sym] = name
29
39
  end
30
40
  end
31
41
  end
32
42
  end
33
-
34
- private_constant :HTTP
35
43
  end
@@ -1,9 +1,12 @@
1
- # typed: ignore
1
+ # typed: strict
2
2
  # frozen_string_literal: true
3
3
  require 'json'
4
4
 
5
5
  module Nexmo
6
6
  module JSON
7
+ extend T::Sig
8
+
9
+ sig { params(http_request: T.any(Net::HTTP::Put, Net::HTTP::Post), params: T::Hash[Symbol, T.untyped]).void }
7
10
  def self.update(http_request, params)
8
11
  http_request['Content-Type'] = 'application/json'
9
12
  http_request.body = ::JSON.generate(params)
@@ -1,4 +1,4 @@
1
- # typed: false
1
+ # typed: strict
2
2
  # frozen_string_literal: true
3
3
  require 'securerandom'
4
4
  require 'openssl'
@@ -6,6 +6,8 @@ require 'jwt'
6
6
 
7
7
  module Nexmo
8
8
  module JWT
9
+ extend T::Sig
10
+
9
11
  # Generate an encoded JSON Web Token.
10
12
  #
11
13
  # By default the Nexmo Ruby SDK generates a short lived JWT per request.
@@ -31,9 +33,10 @@ module Nexmo
31
33
  #
32
34
  # @return [String]
33
35
  #
36
+ sig { params(payload: T::Hash[T.any(Symbol, String), T.any(String, Integer)], private_key: T.any(OpenSSL::PKey::RSA, String)).returns(String) }
34
37
  def self.generate(payload, private_key)
35
38
  payload[:iat] = iat = Time.now.to_i unless payload.key?(:iat) || payload.key?('iat')
36
- payload[:exp] = iat + 60 unless payload.key?(:exp) || payload.key?('exp')
39
+ payload[:exp] = T.must(iat) + 60 unless payload.key?(:exp) || payload.key?('exp')
37
40
  payload[:jti] = SecureRandom.uuid unless payload.key?(:jti) || payload.key?('jti')
38
41
 
39
42
  private_key = OpenSSL::PKey::RSA.new(private_key) unless private_key.respond_to?(:sign)
@@ -1,12 +1,18 @@
1
- # typed: ignore
1
+ # typed: strict
2
2
 
3
3
  module Nexmo
4
4
  class KeySecretParams < AbstractAuthentication
5
+ extend T::Sig
6
+
7
+ sig { params(
8
+ object: T.any(T::Hash[T.untyped, T.untyped], URI::HTTPS, Net::HTTP::Post, Net::HTTP::Get)
9
+ ).void }
5
10
  def update(object)
6
11
  return unless object.is_a?(Hash)
7
12
 
8
- object[:api_key] = @config.api_key
9
- object[:api_secret] = @config.api_secret
13
+ @config = T.let(@config, T.nilable(Nexmo::Config))
14
+ object[:api_key] = T.must(@config).api_key
15
+ object[:api_secret] = T.must(@config).api_secret
10
16
  end
11
17
  end
12
18
 
@@ -1,17 +1,21 @@
1
- # typed: ignore
1
+ # typed: strict
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module Nexmo
5
5
  module Keys
6
+ extend T::Sig
7
+
8
+ sig { params(hash: T::Hash[T.untyped, T.untyped]).returns(T::Hash[String, T.untyped]) }
6
9
  def hyphenate(hash)
7
10
  hash.transform_keys { |k| k.to_s.tr('_', '-') }
8
11
  end
9
12
 
13
+ sig { params(hash: T::Hash[T.untyped, T.untyped]).returns(T::Hash[String, T.untyped]) }
10
14
  def camelcase(hash)
11
15
  hash.transform_keys { |k| k.to_s.gsub(/_(\w)/) { $1.upcase } }
12
16
  end
13
17
 
14
- ATTRIBUTE_KEYS = Hash.new { |h, k| h[k] = k.split(PATTERN).join('_').downcase.to_sym }
18
+ ATTRIBUTE_KEYS = T.let(Hash.new { |h, k| h[k] = k.split(PATTERN).join('_').downcase.to_sym }, T::Hash[T.untyped, T.untyped])
15
19
 
16
20
  PATTERN = /[\-_]|(?<=\w)(?=[A-Z])/
17
21
 
@@ -19,6 +23,7 @@ module Nexmo
19
23
 
20
24
  private_constant :PATTERN
21
25
 
26
+ sig { params(k: T.any(Symbol, String)).returns(Symbol) }
22
27
  def attribute_key(k)
23
28
  return k if k.is_a?(Symbol)
24
29
 
@@ -1,10 +1,13 @@
1
- # typed: ignore
1
+ # typed: false
2
2
  # frozen_string_literal: true
3
3
  require 'logger'
4
4
  require 'forwardable'
5
5
 
6
6
  module Nexmo
7
7
  class Logger
8
+ extend T::Sig
9
+
10
+ sig { params(logger: T.nilable(T.any(::Logger, Nexmo::Logger))).void }
8
11
  def initialize(logger)
9
12
  @logger = logger || ::Logger.new(nil)
10
13
  end
@@ -15,8 +18,11 @@ module Nexmo
15
18
  def_delegator :@logger, name, name
16
19
  end
17
20
 
21
+ sig { params(request: T.any(Net::HTTP::Post, Net::HTTP::Get, Net::HTTP::Delete, Net::HTTP::Put)).void }
18
22
  def log_request_info(request)
19
- @logger.info do
23
+ @logger = T.let(@logger, T.nilable(T.any(::Logger, Nexmo::Logger)))
24
+
25
+ T.must(@logger).info do
20
26
  format('Nexmo API request', {
21
27
  method: request.method,
22
28
  path: request.uri.path
@@ -24,8 +30,12 @@ module Nexmo
24
30
  end
25
31
  end
26
32
 
33
+ sig { params(
34
+ response: T.any(Net::HTTPOK, Net::HTTPNoContent, Net::HTTPBadRequest, Net::HTTPInternalServerError, Net::HTTPResponse),
35
+ host: String
36
+ ).void }
27
37
  def log_response_info(response, host)
28
- @logger.info do
38
+ T.must(@logger).info do
29
39
  format('Nexmo API response', {
30
40
  host: host,
31
41
  status: response.code,
@@ -38,6 +48,7 @@ module Nexmo
38
48
 
39
49
  private
40
50
 
51
+ sig { params(message: String, hash: T::Hash[Symbol, T.untyped]).returns(String) }
41
52
  def format(message, hash)
42
53
  return message if hash.nil?
43
54
 
@@ -46,6 +57,4 @@ module Nexmo
46
57
  fields.join(' ')
47
58
  end
48
59
  end
49
-
50
- private_constant :Logger
51
60
  end
@@ -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
@@ -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,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
 
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'
@@ -115,7 +115,7 @@ module Nexmo
115
115
 
116
116
  sig { params(text: String).returns(T::Boolean) }
117
117
  def unicode?(text)
118
- !GSM7.encoded?(text)
118
+ !Nexmo::GSM7Test::GSM7.encoded?(text)
119
119
  end
120
120
  end
121
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,8 +1,9 @@
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
@@ -59,8 +60,9 @@ module Nexmo
59
60
  #
60
61
  # @see https://developer.nexmo.com/api/verify#verifyRequest
61
62
  #
62
- def request(params)
63
- response = 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)
64
66
 
65
67
  raise Error, response[:error_text] if error?(response)
66
68
 
@@ -91,6 +93,7 @@ module Nexmo
91
93
  #
92
94
  # @see https://developer.nexmo.com/api/verify#verifyCheck
93
95
  #
96
+ sig { params(params: T::Hash[Symbol, T.untyped]).returns(Nexmo::Response) }
94
97
  def check(params)
95
98
  response = http_request('/verify/check/json', params: params, type: Post)
96
99
 
@@ -117,6 +120,7 @@ module Nexmo
117
120
  #
118
121
  # @see https://developer.nexmo.com/api/verify#verifySearch
119
122
  #
123
+ sig { params(params: T::Hash[Symbol, T.untyped]).returns(T.any(T::Hash[Symbol, T.untyped], Nexmo::Response)) }
120
124
  def search(params)
121
125
  response = http_request('/verify/search/json', params: params)
122
126
 
@@ -143,6 +147,7 @@ module Nexmo
143
147
  #
144
148
  # @see https://developer.nexmo.com/api/verify#verifyControl
145
149
  #
150
+ sig { params(params: T::Hash[Symbol, T.untyped]).returns(T.untyped) }
146
151
  def control(params)
147
152
  response = http_request('/verify/control/json', params: params, type: Post)
148
153
 
@@ -162,6 +167,7 @@ module Nexmo
162
167
  #
163
168
  # @see https://developer.nexmo.com/api/verify#verifyControl
164
169
  #
170
+ sig { params(id: String).returns(Nexmo::Response) }
165
171
  def cancel(id)
166
172
  control(request_id: id, cmd: 'cancel')
167
173
  end
@@ -177,12 +183,69 @@ module Nexmo
177
183
  #
178
184
  # @see https://developer.nexmo.com/api/verify#verifyControl
179
185
  #
186
+ sig { params(id: String).returns(Nexmo::Response) }
180
187
  def trigger_next_event(id)
181
188
  control(request_id: id, cmd: 'trigger_next_event')
182
189
  end
183
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
+
184
246
  private
185
247
 
248
+ sig { params(response: T.untyped).returns(T::Boolean) }
186
249
  def error?(response)
187
250
  response.respond_to?(:error_text)
188
251
  end
@@ -1,5 +1,5 @@
1
1
  # typed: strong
2
2
 
3
3
  module Nexmo
4
- VERSION = '7.0.0'
4
+ VERSION = '7.1.0'
5
5
  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,4 +1,4 @@
1
- # typed: false
1
+ # typed: true
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module Nexmo
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nexmo
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.0.0
4
+ version: 7.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nexmo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-04-06 00:00:00.000000000 Z
11
+ date: 2020-06-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jwt