nexmo 4.7.0 → 4.8.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b8c6620dc24f8cb8e4260f28df8d33775a796624
4
- data.tar.gz: f19674fb59e52953d0c690edba86fccc2e29a793
3
+ metadata.gz: fc7d3219d5a4d8671e83fa33eb807e317778b479
4
+ data.tar.gz: 51cec360405377fca50f586cc5fc5fb375a23409
5
5
  SHA512:
6
- metadata.gz: 441b7447fbe1e1a0452ed3f82cb531376b09e97e1c6241bfb5db59f2374f755db299ee56b41f475fa0d1f6ce13469c52a50c891a59e558d4818d4632764ec8f2
7
- data.tar.gz: c085d5cae72f90a22c6d8e7912d52e2e43a910b658282c770d9cb44e15e2586bc9fab6258ede4f2daa943458e2efa88aa1961bcc50c64bc34226fa9c09dc238c
6
+ metadata.gz: 781a072b8c216d96d000aec974974f648ca5375899380279d4ac8ddb55ca5824df744b4bdf1e959d19919bfb00125159f69d0e558706c7d187badbce70df1bc1
7
+ data.tar.gz: e540e6124bb1d17c166ca0ddf2ab166083869f5330f1285fa42f21f85ad3df1a09ae3c0f146cb3b64ba8982d58f6e6dd208e6bff2ad5cb595d87815588f54d25
@@ -6,9 +6,9 @@ module Nexmo
6
6
  attr_accessor :key, :secret, :auth_token
7
7
 
8
8
  def initialize(options = {})
9
- @key = options.fetch(:key) { ENV.fetch('NEXMO_API_KEY') }
9
+ @key = options.fetch(:key) { ENV['NEXMO_API_KEY'] }
10
10
 
11
- @secret = options.fetch(:secret) { ENV.fetch('NEXMO_API_SECRET') }
11
+ @secret = options.fetch(:secret) { ENV['NEXMO_API_SECRET'] }
12
12
 
13
13
  @signature_secret = options.fetch(:signature_secret) { ENV['NEXMO_SIGNATURE_SECRET'] }
14
14
 
@@ -20,8 +20,6 @@ module Nexmo
20
20
 
21
21
  @api_host = options.fetch(:api_host) { 'api.nexmo.com' }
22
22
 
23
- @sns_host = options.fetch(:sns_host) { 'sns.nexmo.com' }
24
-
25
23
  @user_agent = "nexmo-ruby/#{VERSION} ruby/#{RUBY_VERSION}"
26
24
 
27
25
  if options.key?(:app_name) && options.key?(:app_version)
@@ -101,14 +99,6 @@ module Nexmo
101
99
  get(@host, '/search/messages', Hash === params ? params : {ids: Array(params)})
102
100
  end
103
101
 
104
- def send_ussd_push_message(params)
105
- post(@host, '/ussd/json', params)
106
- end
107
-
108
- def send_ussd_prompt_message(params)
109
- post(@host, '/ussd-prompt/json', params)
110
- end
111
-
112
102
  def send_2fa_message(params)
113
103
  post(@host, '/sc/us/2fa/json', params)
114
104
  end
@@ -129,14 +119,6 @@ module Nexmo
129
119
  post(@host, '/sc/us/alert/opt-in/manage/json', params)
130
120
  end
131
121
 
132
- def sns_publish(message, params)
133
- post(@sns_host, '/sns/json', {cmd: 'publish', message: message}.merge(params))
134
- end
135
-
136
- def sns_subscribe(recipient, params)
137
- post(@sns_host, '/sns/json', {cmd: 'subscribe', to: recipient}.merge(params))
138
- end
139
-
140
122
  def initiate_call(params)
141
123
  Kernel.warn "#{self.class}##{__method__} is deprecated (use the Voice API instead)."
142
124
 
@@ -280,7 +262,7 @@ module Nexmo
280
262
 
281
263
  def get(host, request_uri, params = {})
282
264
  uri = URI('https://' + host + request_uri)
283
- uri.query = Params.encode(params.merge(api_key: @key, api_secret: @secret))
265
+ uri.query = Params.encode(params.merge(api_key_and_secret))
284
266
 
285
267
  message = Net::HTTP::Get.new(uri.request_uri)
286
268
 
@@ -291,7 +273,7 @@ module Nexmo
291
273
  uri = URI('https://' + host + request_uri)
292
274
 
293
275
  message = Net::HTTP::Post.new(uri.request_uri)
294
- message.form_data = params.merge(api_key: @key, api_secret: @secret)
276
+ message.form_data = params.merge(api_key_and_secret)
295
277
 
296
278
  request(uri, message)
297
279
  end
@@ -301,14 +283,14 @@ module Nexmo
301
283
 
302
284
  message = Net::HTTP::Put.new(uri.request_uri)
303
285
  message['Content-Type'] = 'application/json'
304
- message.body = JSON.generate(params.merge(api_key: @key, api_secret: @secret))
286
+ message.body = JSON.generate(params.merge(api_key_and_secret))
305
287
 
306
288
  request(uri, message)
307
289
  end
308
290
 
309
291
  def delete(host, request_uri)
310
292
  uri = URI('https://' + host + request_uri)
311
- uri.query = Params.encode({api_key: @key, api_secret: @secret})
293
+ uri.query = Params.encode(api_key_and_secret)
312
294
 
313
295
  message = Net::HTTP::Delete.new(uri.request_uri)
314
296
 
@@ -366,6 +348,22 @@ module Nexmo
366
348
  end
367
349
  end
368
350
 
351
+ def api_key_and_secret
352
+ unless @key
353
+ raise AuthenticationError.new('No API key provided. ' \
354
+ 'See https://developer.nexmo.com/concepts/guides/authentication for details, ' \
355
+ 'or email support@nexmo.com if you have any questions.')
356
+ end
357
+
358
+ unless @secret
359
+ raise AuthenticationError.new('No API secret provided. ' \
360
+ 'See https://developer.nexmo.com/concepts/guides/authentication for details, ' \
361
+ 'or email support@nexmo.com if you have any questions.')
362
+ end
363
+
364
+ {api_key: @key, api_secret: @secret}
365
+ end
366
+
369
367
  def generate_auth_token
370
368
  unless @application_id
371
369
  raise AuthenticationError.new('No application_id provided. ' \
@@ -8,11 +8,21 @@ module Nexmo
8
8
 
9
9
  signature = params.delete('sig')
10
10
 
11
- ::JWT.secure_compare(signature, digest(params, secret))
11
+ secure_compare(signature, digest(params, secret))
12
12
  end
13
13
 
14
14
  private
15
15
 
16
+ if defined?(::JWT::SecurityUtils) # ruby-jwt v2
17
+ def self.secure_compare(left, right)
18
+ ::JWT::SecurityUtils.secure_compare(left, right)
19
+ end
20
+ else
21
+ def self.secure_compare(left, right)
22
+ ::JWT.secure_compare(left, right)
23
+ end
24
+ end
25
+
16
26
  def self.digest(params, secret)
17
27
  md5 = Digest::MD5.new
18
28
 
@@ -1,3 +1,3 @@
1
1
  module Nexmo
2
- VERSION = '4.7.0'
2
+ VERSION = '4.8.0'
3
3
  end
@@ -12,14 +12,15 @@ Gem::Specification.new do |s|
12
12
  s.summary = 'This is the Ruby client library for Nexmo\'s API. To use it you\'ll need a Nexmo account. Sign up for free at https://www.nexmo.com'
13
13
  s.files = Dir.glob('{lib,spec}/**/*') + %w(LICENSE.txt README.md nexmo.gemspec)
14
14
  s.required_ruby_version = '>= 1.9.3'
15
- s.add_dependency('jwt')
16
15
  s.add_development_dependency('rake')
17
16
  s.add_development_dependency('minitest', '~> 5.0')
18
17
 
19
18
  if RUBY_VERSION == '1.9.3'
19
+ s.add_dependency('jwt', '< 2.0.0')
20
20
  s.add_development_dependency('addressable', '< 2.5.0')
21
21
  s.add_development_dependency('webmock', '~> 1.0')
22
22
  else
23
+ s.add_dependency('jwt')
23
24
  s.add_development_dependency('webmock', '~> 2.0')
24
25
  end
25
26
 
@@ -16,8 +16,6 @@ describe 'Nexmo::Client' do
16
16
 
17
17
  @api_base_url = 'https://api.nexmo.com'
18
18
 
19
- @sns_base_url = 'https://sns.nexmo.com'
20
-
21
19
  @response_body = {body: '{"key":"value"}', headers: {'Content-Type' => 'application/json;charset=utf-8'}}
22
20
 
23
21
  @response_object = {'key' => 'value'}
@@ -187,22 +185,6 @@ describe 'Nexmo::Client' do
187
185
  end
188
186
  end
189
187
 
190
- describe 'send_ussd_push_message method' do
191
- it 'posts to the ussd resource and returns the response object' do
192
- expect_post "#@base_url/ussd/json", "api_key=#@api_key&api_secret=#@api_secret&from=MyCompany20&to=447525856424&text=Hello"
193
-
194
- @client.send_ussd_push_message(from: 'MyCompany20', to: '447525856424', text: 'Hello').must_equal(@response_object)
195
- end
196
- end
197
-
198
- describe 'send_ussd_prompt_message method' do
199
- it 'posts to the ussd prompt resource and returns the response object' do
200
- expect_post "#@base_url/ussd-prompt/json", "api_key=#@api_key&api_secret=#@api_secret&from=virtual-number&to=447525856424&text=Hello"
201
-
202
- @client.send_ussd_prompt_message(from: 'virtual-number', to: '447525856424', text: 'Hello').must_equal(@response_object)
203
- end
204
- end
205
-
206
188
  describe 'send_2fa_message method' do
207
189
  it 'posts to the short code two factor authentication resource and returns the response object' do
208
190
  expect_post "#@base_url/sc/us/2fa/json", "api_key=#@api_key&api_secret=#@api_secret&to=16365553226&pin=1234"
@@ -243,22 +225,6 @@ describe 'Nexmo::Client' do
243
225
  end
244
226
  end
245
227
 
246
- describe 'sns_publish method' do
247
- it 'posts to the sns resource and returns the response object' do
248
- expect_post "#@sns_base_url/sns/json", "api_key=#@api_key&api_secret=#@api_secret&cmd=publish&message=Hello&topic=arn&from=MyCompany20"
249
-
250
- @client.sns_publish('Hello', topic: 'arn', from: 'MyCompany20').must_equal(@response_object)
251
- end
252
- end
253
-
254
- describe 'sns_subscribe method' do
255
- it 'posts to the sns resource and returns the response object' do
256
- expect_post "#@sns_base_url/sns/json", "api_key=#@api_key&api_secret=#@api_secret&cmd=subscribe&to=447525856424&topic=arn"
257
-
258
- @client.sns_subscribe('447525856424', topic: 'arn').must_equal(@response_object)
259
- end
260
- end
261
-
262
228
  describe 'initiate_call method' do
263
229
  it 'posts to the call resource and returns the response object' do
264
230
  expect_post "#@base_url/call/json", "api_key=#@api_key&api_secret=#@api_secret&to=16365553226&answer_url=http://example.com/answer"
@@ -533,24 +499,40 @@ describe 'Nexmo::Client' do
533
499
  it 'raises an authentication error exception if the signature secret was not provided' do
534
500
  client = Nexmo::Client.new(key: @api_key, secret: @api_secret)
535
501
 
536
- exception = proc { @client.check_signature({}) }.must_raise(Nexmo::AuthenticationError)
502
+ exception = proc { client.check_signature({}) }.must_raise(Nexmo::AuthenticationError)
537
503
 
538
504
  exception.message.must_include('No signature_secret provided.')
539
505
  end
540
506
  end
541
507
 
508
+ it 'raises an authentication error exception if the api key was not provided' do
509
+ client = Nexmo::Client.new(secret: @api_secret)
510
+
511
+ exception = proc { client.get_balance }.must_raise(Nexmo::AuthenticationError)
512
+
513
+ exception.message.must_include('No API key provided.')
514
+ end
515
+
516
+ it 'raises an authentication error exception if the api secret was not provided' do
517
+ client = Nexmo::Client.new(key: @api_key)
518
+
519
+ exception = proc { client.get_balance }.must_raise(Nexmo::AuthenticationError)
520
+
521
+ exception.message.must_include('No API secret provided.')
522
+ end
523
+
542
524
  it 'raises an authentication error exception if the application id was not provided' do
543
- @client = Nexmo::Client.new(key: @api_key, secret: @api_secret, private_key: @private_key)
525
+ client = Nexmo::Client.new(private_key: @private_key)
544
526
 
545
- exception = proc { @client.get_calls }.must_raise(Nexmo::AuthenticationError)
527
+ exception = proc { client.get_calls }.must_raise(Nexmo::AuthenticationError)
546
528
 
547
529
  exception.message.must_include('No application_id provided.')
548
530
  end
549
531
 
550
532
  it 'raises an authentication error exception if the private key was not provided' do
551
- @client = Nexmo::Client.new(key: @api_key, secret: @api_secret, application_id: @application_id)
533
+ client = Nexmo::Client.new(application_id: @application_id)
552
534
 
553
- exception = proc { @client.get_calls }.must_raise(Nexmo::AuthenticationError)
535
+ exception = proc { client.get_calls }.must_raise(Nexmo::AuthenticationError)
554
536
 
555
537
  exception.message.must_include('No private_key provided.')
556
538
  end
@@ -40,7 +40,7 @@ describe 'Nexmo::JWT' do
40
40
  private
41
41
 
42
42
  def decode(encoded_token)
43
- JWT.decode(encoded_token, private_key, 'RS256').first
43
+ JWT.decode(encoded_token, private_key, verify=true, {algorithm: 'RS256'}).first
44
44
  end
45
45
 
46
46
  def application_id
metadata CHANGED
@@ -1,23 +1,23 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nexmo
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.7.0
4
+ version: 4.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tim Craft
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-08-09 00:00:00.000000000 Z
11
+ date: 2017-11-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: jwt
14
+ name: rake
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
- type: :runtime
20
+ type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
@@ -25,33 +25,33 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: rake
28
+ name: minitest
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: '5.0'
34
34
  type: :development
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: '5.0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: minitest
42
+ name: jwt
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: '5.0'
48
- type: :development
47
+ version: '0'
48
+ type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: '5.0'
54
+ version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: webmock
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -110,7 +110,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
110
110
  version: '0'
111
111
  requirements: []
112
112
  rubyforge_project:
113
- rubygems_version: 2.6.11
113
+ rubygems_version: 2.6.13
114
114
  signing_key:
115
115
  specification_version: 4
116
116
  summary: This is the Ruby client library for Nexmo's API. To use it you'll need a