nexmo 6.3.0 → 7.2.0

Sign up to get free protection for your applications and to get access to all the features.
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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 431850b9568a3bacf15de1cf1f31883616451e0fdd49283e9f78deb76cf74ba9
4
- data.tar.gz: 8d3c2e1314efd2235abb2e3b243367fa715eb9d568048178f8d86e7455ed2abd
3
+ metadata.gz: ad124eb0e0e93884dc48ed8257b977c2cc365b19668326751d0fa9c0dd843696
4
+ data.tar.gz: a7e1dae46b7e4c9d86b49fa51f6e74679ec1df56d55961e81e1a8d12b1831f29
5
5
  SHA512:
6
- metadata.gz: c27cf8e95a1793a0c16f5787a9c9fe0063dfdd245e1bb8f162c8195f051f7b3ccbdec407f879e0ff7084c55f7a46ccf8932249255edfa4bb22c30384380cf587
7
- data.tar.gz: e5d15599fb9f691337d053f76d2c74e498744787e98890256fab12bfa4f681105e9ca932397af14cb034b33cd379065a66d0f80f1ce23a4c2d1bc1fe4df63db3
6
+ metadata.gz: 4de53e3319290efe704e16603a09aa79af15cc47aaf75f539e1e442b040d6e86f7427e6a412702c0557cd1d43c1ee8b31b38e71646ac615766277ed63caa590c
7
+ data.tar.gz: 57c846af9f53f5537a6aeda3d588e36c6ef41c273f18640fe2214e37428ecd8d5ba7cfe91b619fc5035c43b0847a9507d97b9b036aa3fc1d6bb6b67bf975601f
data/README.md CHANGED
@@ -1,6 +1,8 @@
1
1
  # Nexmo Client Library for Ruby
2
2
 
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)
3
+ [![Gem Version](https://badge.fury.io/rb/nexmo.svg)](https://badge.fury.io/rb/nexmo) [![Coverage Status](https://github.com/nexmo/nexmo-ruby/workflows/CI/badge.svg) [![Coverage Status](https://coveralls.io/repos/github/Nexmo/nexmo-ruby/badge.svg?branch=coveralls)](https://coveralls.io/github/Nexmo/nexmo-ruby?branch=master)
4
+
5
+ <img src="https://developer.nexmo.com/assets/images/Vonage_Nexmo.svg" height="48px" alt="Nexmo is now known as Vonage" />
4
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].
@@ -8,9 +10,10 @@ need a Nexmo account. Sign up [for free at nexmo.com][signup].
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
@@ -94,18 +112,19 @@ the token option. For example:
94
112
  ```ruby
95
113
  claims = {
96
114
  application_id: application_id,
115
+ private_key: 'path/to/private.key',
97
116
  nbf: 1483315200,
98
- exp: 1514764800,
99
- iat: 1483228800
117
+ ttl: 800
100
118
  }
101
119
 
102
- private_key = File.read('path/to/private.key')
103
-
104
- token = Nexmo::JWT.generate(claims, private_key)
120
+ token = Nexmo::JWT.generate(claims)
105
121
 
106
122
  client = Nexmo::Client.new(token: token)
107
123
  ````
108
124
 
125
+ Documentation for the Nexmo Ruby JWT generator gem can be found at
126
+ [https://www.rubydoc.info/github/nexmo/nexmo-jwt-ruby](https://www.rubydoc.info/github/nexmo/nexmo-jwt-ruby).
127
+ The documentation outlines all the possible parameters you can use to customize and build a token with.
109
128
 
110
129
  ## Webhook signatures
111
130
 
@@ -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'
@@ -6,6 +6,4 @@ module Nexmo
6
6
  @config = config
7
7
  end
8
8
  end
9
-
10
- private_constant :AbstractAuthentication
11
9
  end
@@ -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 Account < Namespace
6
+ extend T::Sig
6
7
  include Keys
7
8
 
8
9
  self.host = :rest_host
@@ -13,6 +14,7 @@ module Nexmo
13
14
  #
14
15
  # @see https://developer.nexmo.com/api/developer/account#get-balance
15
16
  #
17
+ sig { returns(Nexmo::Response) }
16
18
  def balance
17
19
  request('/account/get-balance')
18
20
  end
@@ -35,6 +37,7 @@ module Nexmo
35
37
  #
36
38
  # @see https://developer.nexmo.com/api/developer/account#settings
37
39
  #
40
+ sig { params(params: T::Hash[Symbol, T.untyped]).returns(Nexmo::Response) }
38
41
  def update(params)
39
42
  request('/account/settings', params: camelcase(params), type: Post)
40
43
  end
@@ -50,6 +53,7 @@ module Nexmo
50
53
  #
51
54
  # @see https://developer.nexmo.com/api/developer/account#top-up
52
55
  #
56
+ sig { params(params: T::Hash[Symbol, T.untyped]).returns(Nexmo::Response) }
53
57
  def topup(params)
54
58
  request('/account/top-up', params: params, type: Post)
55
59
  end
@@ -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 Alerts < Namespace
6
+ extend T::Sig
6
7
  self.host = :rest_host
7
8
 
8
9
  # Request the list of phone numbers opted out from your campaign.
@@ -11,6 +12,7 @@ module Nexmo
11
12
  #
12
13
  # @return [Response]
13
14
  #
15
+ sig { returns(Nexmo::Response) }
14
16
  def list
15
17
  request('/sc/us/alert/opt-in/query/json')
16
18
  end
@@ -26,6 +28,7 @@ module Nexmo
26
28
  #
27
29
  # @see https://developer.nexmo.com/api/sms/us-short-codes/alerts/subscription
28
30
  #
31
+ sig { params(params: T::Hash[Symbol, T.untyped]).returns(Nexmo::Response) }
29
32
  def remove(params)
30
33
  request('/sc/us/alert/opt-in/manage/json', params: params, type: Post)
31
34
  end
@@ -61,6 +64,7 @@ module Nexmo
61
64
  #
62
65
  # @see https://developer.nexmo.com/api/sms/us-short-codes/alerts/sending
63
66
  #
67
+ sig { params(params: T::Hash[Symbol, T.untyped]).returns(Nexmo::Response) }
64
68
  def send(params)
65
69
  request('/sc/us/alert/json', params: params, type: Post)
66
70
  end
@@ -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)
33
- end
34
-
35
- # @return [Calls]
36
- #
37
- def calls
38
- @calls ||= Calls.new(config)
40
+ @applications ||= T.let(Applications.new(config), T.nilable(Nexmo::Applications))
39
41
  end
40
42
 
41
43
  # @return [Conversations]
42
44
  #
45
+ sig { returns(T.nilable(Nexmo::Conversations)) }
43
46
  def conversations
44
- @conversations ||= Conversations.new(config)
47
+ @conversations ||= T.let(Conversations.new(config), T.nilable(Nexmo::Conversations))
45
48
  end
46
49
 
47
50
  # @return [Conversions]
48
51
  #
52
+ sig { returns(T.nilable(Nexmo::Conversions)) }
49
53
  def conversions
50
- @conversions ||= Conversions.new(config)
54
+ @conversions ||= T.let(Conversions.new(config), T.nilable(Nexmo::Conversions))
51
55
  end
52
56
 
53
57
  # @return [Files]
54
58
  #
59
+ sig { returns(T.nilable(Nexmo::Files)) }
55
60
  def files
56
- @files ||= Files.new(config)
61
+ @files ||= T.let(Files.new(config), T.nilable(Nexmo::Files))
57
62
  end
58
63
 
59
64
  # @return [Messages]
60
65
  #
66
+ sig { returns(T.nilable(Nexmo::Messages)) }
61
67
  def messages
62
- @messages ||= Messages.new(config)
68
+ @messages ||= T.let(Messages.new(config), T.nilable(Nexmo::Messages))
63
69
  end
64
70
 
65
71
  # @return [NumberInsight]
66
72
  #
73
+ sig { returns(T.nilable(Nexmo::NumberInsight)) }
67
74
  def number_insight
68
- @number_insight ||= NumberInsight.new(config)
75
+ @number_insight ||= T.let(NumberInsight.new(config), T.nilable(Nexmo::NumberInsight))
69
76
  end
70
77
 
71
78
  # @return [Numbers]
72
79
  #
80
+ sig { returns(T.nilable(Nexmo::Numbers)) }
73
81
  def numbers
74
- @numbers ||= Numbers.new(config)
82
+ @numbers ||= T.let(Numbers.new(config), T.nilable(Nexmo::Numbers))
75
83
  end
76
84
 
77
85
  # @return [PricingTypes]
78
86
  #
87
+ sig { returns(T.nilable(Nexmo::PricingTypes)) }
79
88
  def pricing
80
- @pricing ||= PricingTypes.new(config)
89
+ @pricing ||= T.let(PricingTypes.new(config), T.nilable(Nexmo::PricingTypes))
81
90
  end
82
91
 
83
92
  # @return [Redact]
84
93
  #
94
+ sig { returns(T.nilable(Nexmo::Redact)) }
85
95
  def redact
86
- @redact ||= Redact.new(config)
96
+ @redact ||= T.let(Redact.new(config), T.nilable(Nexmo::Redact))
87
97
  end
88
98
 
89
99
  # @return [Secrets]
90
100
  #
101
+ sig { returns(T.nilable(Nexmo::Secrets)) }
91
102
  def secrets
92
- @secrets ||= Secrets.new(config)
103
+ @secrets ||= T.let(Secrets.new(config), T.nilable(Nexmo::Secrets))
93
104
  end
94
105
 
95
106
  # @return [SMS]
96
107
  #
108
+ sig { returns(T.nilable(Nexmo::SMS)) }
97
109
  def sms
98
- @sms ||= SMS.new(config)
110
+ @sms ||= T.let(SMS.new(config), T.nilable(Nexmo::SMS))
99
111
  end
100
112
 
101
113
  # @return [TFA]
102
114
  #
115
+ sig { returns(T.nilable(Nexmo::TFA)) }
103
116
  def tfa
104
- @tfa ||= TFA.new(config)
117
+ @tfa ||= T.let(TFA.new(config), T.nilable(Nexmo::TFA))
105
118
  end
106
119
 
107
120
  # @return [Verify]
108
121
  #
122
+ sig { returns(T.nilable(Nexmo::Verify)) }
109
123
  def verify
110
- @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))
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']
11
- self.application_id = nil
12
- self.logger = (defined?(Rails.logger) && Rails.logger) || ::Logger.new(nil)
13
- self.private_key = nil
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))
14
+ self.application_id = ENV['NEXMO_APPLICATION_ID']
15
+ self.logger = (defined?(::Rails.logger) && ::Rails.logger) || 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