nexmo 6.1.0 → 7.1.1

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 (64) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE.txt +1 -1
  3. data/README.md +24 -4
  4. data/lib/nexmo.rb +12 -14
  5. data/lib/nexmo/abstract_authentication.rb +2 -0
  6. data/lib/nexmo/account.rb +6 -1
  7. data/lib/nexmo/alerts.rb +6 -1
  8. data/lib/nexmo/applications.rb +24 -3
  9. data/lib/nexmo/applications/list_response.rb +2 -0
  10. data/lib/nexmo/authentication_error.rb +2 -0
  11. data/lib/nexmo/basic.rb +2 -0
  12. data/lib/nexmo/bearer_token.rb +1 -0
  13. data/lib/nexmo/client.rb +46 -23
  14. data/lib/nexmo/client_error.rb +2 -0
  15. data/lib/nexmo/config.rb +49 -9
  16. data/lib/nexmo/conversations.rb +24 -0
  17. data/lib/nexmo/conversations/events.rb +1 -0
  18. data/lib/nexmo/conversations/legs.rb +1 -0
  19. data/lib/nexmo/conversations/members.rb +1 -0
  20. data/lib/nexmo/conversations/users.rb +1 -0
  21. data/lib/nexmo/conversions.rb +4 -0
  22. data/lib/nexmo/entity.rb +5 -3
  23. data/lib/nexmo/error.rb +2 -0
  24. data/lib/nexmo/errors.rb +8 -0
  25. data/lib/nexmo/files.rb +7 -2
  26. data/lib/nexmo/form_data.rb +2 -0
  27. data/lib/nexmo/gsm7.rb +2 -0
  28. data/lib/nexmo/http.rb +12 -3
  29. data/lib/nexmo/json.rb +4 -0
  30. data/lib/nexmo/jwt.rb +5 -1
  31. data/lib/nexmo/key_secret_params.rb +10 -2
  32. data/lib/nexmo/keys.rb +7 -1
  33. data/lib/nexmo/logger.rb +14 -4
  34. data/lib/nexmo/messages.rb +7 -1
  35. data/lib/nexmo/namespace.rb +15 -18
  36. data/lib/nexmo/number_insight.rb +21 -6
  37. data/lib/nexmo/numbers.rb +24 -20
  38. data/lib/nexmo/numbers/list_response.rb +2 -0
  39. data/lib/nexmo/numbers/response.rb +1 -0
  40. data/lib/nexmo/params.rb +1 -0
  41. data/lib/nexmo/pricing.rb +2 -1
  42. data/lib/nexmo/pricing_types.rb +1 -0
  43. data/lib/nexmo/redact.rb +2 -1
  44. data/lib/nexmo/response.rb +2 -0
  45. data/lib/nexmo/secrets.rb +1 -0
  46. data/lib/nexmo/secrets/list_response.rb +2 -0
  47. data/lib/nexmo/server_error.rb +2 -0
  48. data/lib/nexmo/signature.rb +1 -0
  49. data/lib/nexmo/sms.rb +16 -10
  50. data/lib/nexmo/tfa.rb +2 -1
  51. data/lib/nexmo/user_agent.rb +1 -0
  52. data/lib/nexmo/verify.rb +93 -17
  53. data/lib/nexmo/version.rb +3 -1
  54. data/lib/nexmo/{calls.rb → voice.rb} +12 -11
  55. data/lib/nexmo/{calls → voice}/dtmf.rb +2 -1
  56. data/lib/nexmo/{calls → voice}/list_response.rb +3 -1
  57. data/lib/nexmo/{calls → voice}/stream.rb +2 -1
  58. data/lib/nexmo/{calls → voice}/talk.rb +2 -1
  59. data/nexmo.gemspec +2 -7
  60. metadata +17 -85
  61. data/lib/nexmo/key_secret_query.rb +0 -20
  62. data/lib/nexmo/number_insight/response.rb +0 -5
  63. data/lib/nexmo/sms/response.rb +0 -7
  64. data/lib/nexmo/verify/response.rb +0 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 991aaf647a8a483780486cdf6ad8393305d9e597aeeda649c404e8ce4ba4f858
4
- data.tar.gz: 5849c75718751dc5b4c6d7fc0c205b224e19a5527ca536176bbd30956a916fda
3
+ metadata.gz: 30bb0f469e9a1f2f85455d1ac2e0524bbc29a95589d4a87cb61a71b2667fe939
4
+ data.tar.gz: 92790dada4fd50a470e97214d0b0aa3584ac6d0e75fcc350ed912c3b7fc79886
5
5
  SHA512:
6
- metadata.gz: 2ad6c409666f784c59656bb55c793ea5e1885c6bee593fb866259edbfecd178b62d89214946ba4ab2bce1c6a36a71f2149a584b8d0781de0978eab2e498a9cbc
7
- data.tar.gz: f91e6bbcbf7de8a41a88411d47c58529b0c204780a25c5f827cac682cfe17e162c33193c86928f6ba39b4cf452f0303c7d75ded9281ddbf41b4cf2892a2f5d0f
6
+ metadata.gz: ff3fcd89549bfcd1c98db024e2bace02b2b2e63780a3171dd2a31af84db1ea5e6e4efe7e1ac361f488d1f2964a3fc11a0e20b575cbef76e0b92a44d97ee15b6b
7
+ data.tar.gz: ae131dac65585a7544770b4f7d68b002605273a3e79b2293f7f9885049872ccfdb13a48328aa284df07dae1c2862655bb5b3e818abd8a22cc14fd5c0d8e93db9
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2016-2019 Nexmo Inc
3
+ Copyright (c) 2016-2020 Nexmo Inc
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person
6
6
  obtaining a copy of this software and associated documentation
data/README.md CHANGED
@@ -2,15 +2,18 @@
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/nexmo.svg)](https://badge.fury.io/rb/nexmo) [![Build Status](https://api.travis-ci.org/Nexmo/nexmo-ruby.svg?branch=master)](https://travis-ci.org/Nexmo/nexmo-ruby) [![Coverage Status](https://coveralls.io/repos/github/Nexmo/nexmo-ruby/badge.svg?branch=coveralls)](https://coveralls.io/github/Nexmo/nexmo-ruby?branch=master)
4
4
 
5
+ <img src="https://developer.nexmo.com/assets/images/Vonage_Nexmo.svg" height="48px" alt="Nexmo is now known as Vonage" />
6
+
5
7
  This is the Ruby client library for Nexmo's API. To use it you'll
6
8
  need a Nexmo account. Sign up [for free at nexmo.com][signup].
7
9
 
8
10
  * [Requirements](#requirements)
9
11
  * [Installation](#installation)
10
12
  * [Usage](#usage)
11
- * [Logging](#logging)
12
- * [JWT authentication](#jwt-authentication)
13
- * [Webhook signatures](#webhook-signatures)
13
+ * [Logging](#logging)
14
+ * [Overriding the default hosts](#overriding-the-default-hosts)
15
+ * [JWT authentication](#jwt-authentication)
16
+ * [Webhook signatures](#webhook-signatures)
14
17
  * [Documentation](#documentation)
15
18
  * [License](#license)
16
19
 
@@ -73,6 +76,21 @@ By default the library sets the logger to `Rails.logger` if it is defined.
73
76
  To disable logging set the logger to `nil`.
74
77
 
75
78
 
79
+ ## Overriding the default hosts
80
+
81
+ To override the default hosts that the SDK uses for HTTP requests, you need to
82
+ specify the `api_host`, `rest_host` or both in the client configuration. For example:
83
+
84
+ ```ruby
85
+ client = Nexmo::Client.new(
86
+ api_host: 'api-sg-1.nexmo.com',
87
+ rest_host: 'rest-sg-1.nexmo.com'
88
+ )
89
+ ```
90
+
91
+ By default the hosts are set to `api.nexmo.com` and `rest.nexmo.com`, respectively.
92
+
93
+
76
94
  ## JWT authentication
77
95
 
78
96
  To call newer endpoints that support JWT authentication such as the Voice API you'll
@@ -112,7 +130,9 @@ client = Nexmo::Client.new(token: token)
112
130
  To check webhook signatures you'll also need to specify the `signature_secret` option. For example:
113
131
 
114
132
  ```ruby
115
- client = Nexmo::Client.new(signature_secret: 'secret')
133
+ client = Nexmo::Client.new
134
+ client.config.signature_secret = 'secret'
135
+ client.config.signature_method = 'sha512'
116
136
 
117
137
  if client.signature.check(request.GET)
118
138
  # valid signature
@@ -1,23 +1,21 @@
1
+ # typed: true
1
2
  # frozen_string_literal: true
2
3
  require 'zeitwerk'
4
+ require 'sorbet-runtime'
3
5
 
4
6
  module Nexmo
5
- class ZeitwerkInflector < Zeitwerk::Inflector
6
- def camelize(basename, _abspath)
7
- case basename
8
- when 'http', 'json', 'jwt', 'sms', 'tfa', 'gsm7', 'dtmf', 'version'
9
- basename.upcase
10
- else
11
- super
12
- end
13
- end
14
- end
15
-
16
- private_constant :ZeitwerkInflector
17
-
18
7
  loader = Zeitwerk::Loader.new
19
8
  loader.tag = File.basename(__FILE__, '.rb')
20
- loader.inflector = ZeitwerkInflector.new
9
+ loader.inflector.inflect({
10
+ 'dtmf' => 'DTMF',
11
+ 'gsm7' => 'GSM7',
12
+ 'http' => 'HTTP',
13
+ 'json' => 'JSON',
14
+ 'jwt' => 'JWT',
15
+ 'sms' => 'SMS',
16
+ 'tfa' => 'TFA',
17
+ 'version' => 'VERSION',
18
+ })
21
19
  loader.push_dir(__dir__)
22
20
  loader.setup
23
21
 
@@ -1,3 +1,5 @@
1
+ # typed: ignore
2
+
1
3
  module Nexmo
2
4
  class AbstractAuthentication
3
5
  def initialize(config)
@@ -1,10 +1,12 @@
1
+ # typed: strict
1
2
  # frozen_string_literal: true
2
3
 
3
4
  module Nexmo
4
5
  class Account < Namespace
6
+ extend T::Sig
5
7
  include Keys
6
8
 
7
- self.host = 'rest.nexmo.com'
9
+ self.host = :rest_host
8
10
 
9
11
  # Retrieve your account balance.
10
12
  #
@@ -12,6 +14,7 @@ module Nexmo
12
14
  #
13
15
  # @see https://developer.nexmo.com/api/developer/account#get-balance
14
16
  #
17
+ sig { returns(Nexmo::Response) }
15
18
  def balance
16
19
  request('/account/get-balance')
17
20
  end
@@ -34,6 +37,7 @@ module Nexmo
34
37
  #
35
38
  # @see https://developer.nexmo.com/api/developer/account#settings
36
39
  #
40
+ sig { params(params: T::Hash[Symbol, T.untyped]).returns(Nexmo::Response) }
37
41
  def update(params)
38
42
  request('/account/settings', params: camelcase(params), type: Post)
39
43
  end
@@ -49,6 +53,7 @@ module Nexmo
49
53
  #
50
54
  # @see https://developer.nexmo.com/api/developer/account#top-up
51
55
  #
56
+ sig { params(params: T::Hash[Symbol, T.untyped]).returns(Nexmo::Response) }
52
57
  def topup(params)
53
58
  request('/account/top-up', params: params, type: Post)
54
59
  end
@@ -1,8 +1,10 @@
1
+ # typed: strict
1
2
  # frozen_string_literal: true
2
3
 
3
4
  module Nexmo
4
5
  class Alerts < Namespace
5
- self.host = 'rest.nexmo.com'
6
+ extend T::Sig
7
+ self.host = :rest_host
6
8
 
7
9
  # Request the list of phone numbers opted out from your campaign.
8
10
  #
@@ -10,6 +12,7 @@ module Nexmo
10
12
  #
11
13
  # @return [Response]
12
14
  #
15
+ sig { returns(Nexmo::Response) }
13
16
  def list
14
17
  request('/sc/us/alert/opt-in/query/json')
15
18
  end
@@ -25,6 +28,7 @@ module Nexmo
25
28
  #
26
29
  # @see https://developer.nexmo.com/api/sms/us-short-codes/alerts/subscription
27
30
  #
31
+ sig { params(params: T::Hash[Symbol, T.untyped]).returns(Nexmo::Response) }
28
32
  def remove(params)
29
33
  request('/sc/us/alert/opt-in/manage/json', params: params, type: Post)
30
34
  end
@@ -60,6 +64,7 @@ module Nexmo
60
64
  #
61
65
  # @see https://developer.nexmo.com/api/sms/us-short-codes/alerts/sending
62
66
  #
67
+ sig { params(params: T::Hash[Symbol, T.untyped]).returns(Nexmo::Response) }
63
68
  def send(params)
64
69
  request('/sc/us/alert/json', params: params, type: Post)
65
70
  end
@@ -1,7 +1,9 @@
1
+ # typed: strict
1
2
  # frozen_string_literal: true
2
3
 
3
4
  module Nexmo
4
5
  class Applications < Namespace
6
+ extend T::Sig
5
7
  self.authentication = Basic
6
8
 
7
9
  self.request_body = JSON
@@ -13,9 +15,20 @@ module Nexmo
13
15
  # @example
14
16
  # params = {
15
17
  # name: 'Example App',
16
- # type: 'voice',
17
- # answer_url: answer_url,
18
- # 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
+ # }
19
32
  # }
20
33
  #
21
34
  # response = client.applications.create(params)
@@ -37,6 +50,7 @@ module Nexmo
37
50
  #
38
51
  # @see https://developer.nexmo.com/api/application.v2#createApplication
39
52
  #
53
+ sig { params(params: T::Hash[Symbol, T.untyped]).returns(Nexmo::Response) }
40
54
  def create(params)
41
55
  request('/v2/applications', params: params, type: Post)
42
56
  end
@@ -61,6 +75,7 @@ module Nexmo
61
75
  #
62
76
  # @see https://developer.nexmo.com/api/application.v2#listApplication
63
77
  #
78
+ sig { params(params: T.nilable(T::Hash[Symbol, Integer])).returns(Nexmo::Response) }
64
79
  def list(params = nil)
65
80
  request('/v2/applications', params: params, response_class: ListResponse)
66
81
  end
@@ -76,6 +91,7 @@ module Nexmo
76
91
  #
77
92
  # @see https://developer.nexmo.com/api/application.v2#getApplication
78
93
  #
94
+ sig { params(id: String).returns(Nexmo::Response) }
79
95
  def get(id)
80
96
  request('/v2/applications/' + id)
81
97
  end
@@ -103,6 +119,10 @@ module Nexmo
103
119
  #
104
120
  # @see https://developer.nexmo.com/api/application.v2#updateApplication
105
121
  #
122
+ sig { params(
123
+ id: String,
124
+ params: T::Hash[Symbol, T.untyped]
125
+ ).returns(Nexmo::Response) }
106
126
  def update(id, params)
107
127
  request('/v2/applications/' + id, params: params, type: Put)
108
128
  end
@@ -120,6 +140,7 @@ module Nexmo
120
140
  #
121
141
  # @see https://developer.nexmo.com/api/application.v2#deleteApplication
122
142
  #
143
+ sig { params(id: String).returns(Nexmo::Response) }
123
144
  def delete(id)
124
145
  request('/v2/applications/' + id, type: Delete)
125
146
  end
@@ -1,3 +1,5 @@
1
+ # typed: ignore
2
+
1
3
  class Nexmo::Applications::ListResponse < Nexmo::Response
2
4
  include Enumerable
3
5
 
@@ -1,3 +1,5 @@
1
+ # typed: strong
2
+
1
3
  module Nexmo
2
4
  class AuthenticationError < ClientError
3
5
  end
@@ -1,3 +1,5 @@
1
+ # typed: ignore
2
+
1
3
  module Nexmo
2
4
  class Basic < AbstractAuthentication
3
5
  def update(object)
@@ -1,3 +1,4 @@
1
+ # typed: ignore
1
2
  # frozen_string_literal: true
2
3
 
3
4
  module Nexmo
@@ -1,111 +1,134 @@
1
+ # typed: strict
2
+
1
3
  module Nexmo
2
4
  class Client
5
+ extend T::Sig
6
+
7
+ sig { returns(Nexmo::Config) }
3
8
  attr_reader :config
4
9
 
10
+ sig { params(options: T.nilable(T::Hash[Symbol, T.untyped])).void }
5
11
  def initialize(options = nil)
6
- @config = Nexmo.config.merge(options)
12
+ @config = T.let(Nexmo.config.merge(options), Nexmo::Config)
7
13
  end
8
14
 
9
15
  # @return [Signature]
10
16
  #
17
+ sig { returns(T.nilable(Nexmo::Signature)) }
11
18
  def signature
12
- @signature ||= Signature.new(config)
19
+ @signature ||= T.let(Signature.new(config), T.nilable(Nexmo::Signature))
13
20
  end
14
21
 
15
22
  # @return [Account]
16
23
  #
24
+ sig { returns(T.nilable(Nexmo::Account)) }
17
25
  def account
18
- @account ||= Account.new(config)
26
+ @account ||= T.let(Account.new(config), T.nilable(Nexmo::Account))
19
27
  end
20
28
 
21
29
  # @return [Alerts]
22
30
  #
31
+ sig { returns(T.nilable(Nexmo::Alerts)) }
23
32
  def alerts
24
- @alerts ||= Alerts.new(config)
33
+ @alerts ||= T.let(Alerts.new(config), T.nilable(Nexmo::Alerts))
25
34
  end
26
35
 
27
36
  # @return [Applications]
28
37
  #
38
+ sig { returns(T.nilable(Nexmo::Applications)) }
29
39
  def applications
30
- @applications ||= Applications.new(config)
31
- end
32
-
33
- # @return [Calls]
34
- #
35
- def calls
36
- @calls ||= Calls.new(config)
40
+ @applications ||= T.let(Applications.new(config), T.nilable(Nexmo::Applications))
37
41
  end
38
42
 
39
43
  # @return [Conversations]
40
44
  #
45
+ sig { returns(T.nilable(Nexmo::Conversations)) }
41
46
  def conversations
42
- @conversations ||= Conversations.new(config)
47
+ @conversations ||= T.let(Conversations.new(config), T.nilable(Nexmo::Conversations))
43
48
  end
44
49
 
45
50
  # @return [Conversions]
46
51
  #
52
+ sig { returns(T.nilable(Nexmo::Conversions)) }
47
53
  def conversions
48
- @conversions ||= Conversions.new(config)
54
+ @conversions ||= T.let(Conversions.new(config), T.nilable(Nexmo::Conversions))
49
55
  end
50
56
 
51
57
  # @return [Files]
52
58
  #
59
+ sig { returns(T.nilable(Nexmo::Files)) }
53
60
  def files
54
- @files ||= Files.new(config)
61
+ @files ||= T.let(Files.new(config), T.nilable(Nexmo::Files))
55
62
  end
56
63
 
57
64
  # @return [Messages]
58
65
  #
66
+ sig { returns(T.nilable(Nexmo::Messages)) }
59
67
  def messages
60
- @messages ||= Messages.new(config)
68
+ @messages ||= T.let(Messages.new(config), T.nilable(Nexmo::Messages))
61
69
  end
62
70
 
63
71
  # @return [NumberInsight]
64
72
  #
73
+ sig { returns(T.nilable(Nexmo::NumberInsight)) }
65
74
  def number_insight
66
- @number_insight ||= NumberInsight.new(config)
75
+ @number_insight ||= T.let(NumberInsight.new(config), T.nilable(Nexmo::NumberInsight))
67
76
  end
68
77
 
69
78
  # @return [Numbers]
70
79
  #
80
+ sig { returns(T.nilable(Nexmo::Numbers)) }
71
81
  def numbers
72
- @numbers ||= Numbers.new(config)
82
+ @numbers ||= T.let(Numbers.new(config), T.nilable(Nexmo::Numbers))
73
83
  end
74
84
 
75
85
  # @return [PricingTypes]
76
86
  #
87
+ sig { returns(T.nilable(Nexmo::PricingTypes)) }
77
88
  def pricing
78
- @pricing ||= PricingTypes.new(config)
89
+ @pricing ||= T.let(PricingTypes.new(config), T.nilable(Nexmo::PricingTypes))
79
90
  end
80
91
 
81
92
  # @return [Redact]
82
93
  #
94
+ sig { returns(T.nilable(Nexmo::Redact)) }
83
95
  def redact
84
- @redact ||= Redact.new(config)
96
+ @redact ||= T.let(Redact.new(config), T.nilable(Nexmo::Redact))
85
97
  end
86
98
 
87
99
  # @return [Secrets]
88
100
  #
101
+ sig { returns(T.nilable(Nexmo::Secrets)) }
89
102
  def secrets
90
- @secrets ||= Secrets.new(config)
103
+ @secrets ||= T.let(Secrets.new(config), T.nilable(Nexmo::Secrets))
91
104
  end
92
105
 
93
106
  # @return [SMS]
94
107
  #
108
+ sig { returns(T.nilable(Nexmo::SMS)) }
95
109
  def sms
96
- @sms ||= SMS.new(config)
110
+ @sms ||= T.let(SMS.new(config), T.nilable(Nexmo::SMS))
97
111
  end
98
112
 
99
113
  # @return [TFA]
100
114
  #
115
+ sig { returns(T.nilable(Nexmo::TFA)) }
101
116
  def tfa
102
- @tfa ||= TFA.new(config)
117
+ @tfa ||= T.let(TFA.new(config), T.nilable(Nexmo::TFA))
103
118
  end
104
119
 
105
120
  # @return [Verify]
106
121
  #
122
+ sig { returns(T.nilable(Nexmo::Verify)) }
107
123
  def verify
108
- @verify ||= Verify.new(config)
124
+ @verify ||= T.let(Verify.new(config), T.nilable(Nexmo::Verify))
125
+ end
126
+
127
+ # @return [Voice]
128
+ #
129
+ sig { returns(T.nilable(Nexmo::Voice)) }
130
+ def voice
131
+ @voice ||= T.let(Voice.new(config), T.nilable(Nexmo::Voice))
109
132
  end
110
133
  end
111
134
  end