nexmo 6.2.0 → 7.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +21 -3
  3. data/lib/nexmo.rb +2 -0
  4. data/lib/nexmo/abstract_authentication.rb +2 -2
  5. data/lib/nexmo/account.rb +6 -1
  6. data/lib/nexmo/alerts.rb +6 -1
  7. data/lib/nexmo/applications.rb +24 -3
  8. data/lib/nexmo/applications/list_response.rb +2 -0
  9. data/lib/nexmo/authentication_error.rb +2 -0
  10. data/lib/nexmo/basic.rb +2 -0
  11. data/lib/nexmo/bearer_token.rb +1 -0
  12. data/lib/nexmo/client.rb +46 -23
  13. data/lib/nexmo/client_error.rb +2 -0
  14. data/lib/nexmo/config.rb +49 -9
  15. data/lib/nexmo/conversations.rb +24 -0
  16. data/lib/nexmo/conversations/events.rb +1 -0
  17. data/lib/nexmo/conversations/legs.rb +1 -0
  18. data/lib/nexmo/conversations/members.rb +1 -0
  19. data/lib/nexmo/conversations/users.rb +1 -0
  20. data/lib/nexmo/conversions.rb +4 -0
  21. data/lib/nexmo/entity.rb +3 -1
  22. data/lib/nexmo/error.rb +2 -0
  23. data/lib/nexmo/errors.rb +8 -0
  24. data/lib/nexmo/files.rb +7 -2
  25. data/lib/nexmo/form_data.rb +2 -0
  26. data/lib/nexmo/gsm7.rb +2 -2
  27. data/lib/nexmo/http.rb +12 -3
  28. data/lib/nexmo/json.rb +4 -0
  29. data/lib/nexmo/jwt.rb +5 -1
  30. data/lib/nexmo/key_secret_params.rb +10 -2
  31. data/lib/nexmo/keys.rb +7 -1
  32. data/lib/nexmo/logger.rb +14 -4
  33. data/lib/nexmo/messages.rb +7 -1
  34. data/lib/nexmo/namespace.rb +15 -18
  35. data/lib/nexmo/number_insight.rb +21 -6
  36. data/lib/nexmo/numbers.rb +2 -1
  37. data/lib/nexmo/numbers/list_response.rb +2 -0
  38. data/lib/nexmo/numbers/response.rb +1 -0
  39. data/lib/nexmo/params.rb +1 -0
  40. data/lib/nexmo/pricing.rb +2 -1
  41. data/lib/nexmo/pricing_types.rb +1 -0
  42. data/lib/nexmo/redact.rb +1 -0
  43. data/lib/nexmo/response.rb +2 -0
  44. data/lib/nexmo/secrets.rb +1 -0
  45. data/lib/nexmo/secrets/list_response.rb +2 -0
  46. data/lib/nexmo/server_error.rb +2 -0
  47. data/lib/nexmo/signature.rb +1 -0
  48. data/lib/nexmo/sms.rb +16 -10
  49. data/lib/nexmo/tfa.rb +2 -1
  50. data/lib/nexmo/user_agent.rb +1 -0
  51. data/lib/nexmo/verify.rb +93 -17
  52. data/lib/nexmo/version.rb +3 -1
  53. data/lib/nexmo/{calls.rb → voice.rb} +12 -11
  54. data/lib/nexmo/{calls → voice}/dtmf.rb +2 -1
  55. data/lib/nexmo/{calls → voice}/list_response.rb +3 -1
  56. data/lib/nexmo/{calls → voice}/stream.rb +2 -1
  57. data/lib/nexmo/{calls → voice}/talk.rb +2 -1
  58. data/nexmo.gemspec +1 -0
  59. metadata +22 -11
  60. data/lib/nexmo/number_insight/response.rb +0 -5
  61. data/lib/nexmo/sms/response.rb +0 -7
  62. data/lib/nexmo/verify/response.rb +0 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 435a12da7a4fdd6a713aaf4660d5e7ae9e81013e7272df5d0bbbf9b2d5c6c9b8
4
- data.tar.gz: ed72a0177f94fdc83b592d86d2e7a198023e6b55511984ffe03a1c409d8947c4
3
+ metadata.gz: 964a347a61a516b4161b0110412b262ff82614b5c48cddb0d85ee6b9878854ee
4
+ data.tar.gz: 50edc921ee4c8a8e4f7172d5c1d8ec3efa195d04d9923efcd98c2f4f6623d145
5
5
  SHA512:
6
- metadata.gz: 662bf6adc6417ffad8ae5612297a1dce42be997a7a95c030c5b0630fdeff278e0bf09a26be88465827c1e7b69d6f0d4823ca9bbde77a79af132cacd7fe2fb998
7
- data.tar.gz: 0e739f013dc8f4b564a58f90b8aa1bd1ad61920a15825f4ea1b9a38c3b32dbcea3946ee4824eb1e4aae52a3cfbcac654759016c6eef6d32d41a63eaecb238d72
6
+ metadata.gz: 0b35dad79758fb59d4ef8662b6684afd655965ca402832c19b652c7985a4234ad3d815dbbbe190ccfda001901067918e3518fce6d3aa31c9f3ed88e09e8bfacb
7
+ data.tar.gz: 91b1f197f77d8cfd7fcabc3d35d69e6b9adbad8d1dd30c0f0e7f8d376bc7dc521dd519ab0184c79ec1d02fb879afaaf0c8c606fc6a13692c03ba8804e31d0f92
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
@@ -1,5 +1,7 @@
1
+ # typed: true
1
2
  # frozen_string_literal: true
2
3
  require 'zeitwerk'
4
+ require 'sorbet-runtime'
3
5
 
4
6
  module Nexmo
5
7
  loader = Zeitwerk::Loader.new
@@ -1,9 +1,9 @@
1
+ # typed: ignore
2
+
1
3
  module Nexmo
2
4
  class AbstractAuthentication
3
5
  def initialize(config)
4
6
  @config = config
5
7
  end
6
8
  end
7
-
8
- private_constant :AbstractAuthentication
9
9
  end
@@ -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
@@ -1,3 +1,5 @@
1
+ # typed: strong
2
+
1
3
  module Nexmo
2
4
  class ClientError < Error
3
5
  end
@@ -1,23 +1,30 @@
1
+ # typed: true
1
2
  # frozen_string_literal: true
2
3
  require 'logger'
3
4
 
4
5
  module Nexmo
5
6
  class Config
7
+ extend T::Sig
8
+
9
+ sig { void }
6
10
  def initialize
7
- self.api_key = ENV['NEXMO_API_KEY']
8
- self.api_secret = ENV['NEXMO_API_SECRET']
9
- self.application_id = nil
10
- self.logger = (defined?(Rails.logger) && Rails.logger) || ::Logger.new(nil)
11
- self.private_key = nil
11
+ self.api_host = 'api.nexmo.com'
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']
17
+ self.rest_host = 'rest.nexmo.com'
12
18
  self.signature_secret = ENV['NEXMO_SIGNATURE_SECRET']
13
19
  self.signature_method = ENV['NEXMO_SIGNATURE_METHOD'] || 'md5hash'
14
- self.token = nil
20
+ self.token = T.let(nil, T.nilable(String))
15
21
  end
16
22
 
17
23
  # Merges the config with the given options hash.
18
24
  #
19
25
  # @return [Nexmo::Config]
20
26
  #
27
+ sig { params(options: T.nilable(T::Hash[Symbol, T.untyped])).returns(Nexmo::Config) }
21
28
  def merge(options)
22
29
  return self if options.nil? || options.empty?
23
30
 
@@ -26,13 +33,18 @@ module Nexmo
26
33
  end
27
34
  end
28
35
 
36
+ sig { returns(String) }
37
+ attr_accessor :api_host
38
+
29
39
  # Returns the value of attribute api_key.
30
40
  #
31
41
  # @return [String]
32
42
  #
33
43
  # @raise [AuthenticationError]
34
44
  #
45
+ sig { returns(T.nilable(String)) }
35
46
  def api_key
47
+ @api_key = T.let(@api_key, T.nilable(String))
36
48
  unless @api_key
37
49
  raise AuthenticationError.new('No API key provided. ' \
38
50
  'See https://developer.nexmo.com/concepts/guides/authentication for details, ' \
@@ -42,6 +54,7 @@ module Nexmo
42
54
  @api_key
43
55
  end
44
56
 
57
+ sig { params(api_key: T.nilable(String)).returns(T.nilable(String)) }
45
58
  attr_writer :api_key
46
59
 
47
60
  # Returns the value of attribute api_secret.
@@ -50,7 +63,9 @@ module Nexmo
50
63
  #
51
64
  # @raise [AuthenticationError]
52
65
  #
66
+ sig { returns(T.nilable(String)) }
53
67
  def api_secret
68
+ @api_secret = T.let(@api_secret, T.nilable(String))
54
69
  unless @api_secret
55
70
  raise AuthenticationError.new('No API secret provided. ' \
56
71
  'See https://developer.nexmo.com/concepts/guides/authentication for details, ' \
@@ -60,6 +75,7 @@ module Nexmo
60
75
  @api_secret
61
76
  end
62
77
 
78
+ sig { params(api_secret: T.nilable(String)).returns(T.nilable(String)) }
63
79
  attr_writer :api_secret
64
80
 
65
81
  # Returns the value of attribute application_id.
@@ -68,7 +84,9 @@ module Nexmo
68
84
  #
69
85
  # @raise [AuthenticationError]
70
86
  #
87
+ sig { returns(T.nilable(String)) }
71
88
  def application_id
89
+ @application_id = T.let(@application_id, T.nilable(String))
72
90
  unless @application_id
73
91
  raise AuthenticationError.new('No application_id provided. ' \
74
92
  'Either provide an application_id, or set an auth token. ' \
@@ -80,32 +98,40 @@ module Nexmo
80
98
  @application_id
81
99
  end
82
100
 
101
+ sig { params(application_id: T.nilable(String)).returns(T.nilable(String)) }
83
102
  attr_writer :application_id
84
103
 
104
+ sig { returns(T.nilable(String)) }
85
105
  attr_accessor :app_name
86
106
 
107
+ sig { returns(T.nilable(String)) }
87
108
  attr_accessor :app_version
88
109
 
89
110
  # Returns the value of attribute http.
90
111
  #
91
112
  # @return [Nexmo::HTTP::Options]
92
113
  #
114
+ sig { returns(T.nilable(Nexmo::HTTP::Options)) }
93
115
  attr_reader :http
94
116
 
117
+ sig { params(hash: T::Hash[T.untyped, T.untyped]).returns(T.nilable(Nexmo::HTTP::Options)) }
95
118
  def http=(hash)
96
- @http = HTTP::Options.new(hash)
119
+ @http = T.let(nil, T.nilable(Nexmo::HTTP::Options))
120
+ @http = Nexmo::HTTP::Options.new(hash)
97
121
  end
98
122
 
99
123
  # Returns the value of attribute logger.
100
124
  #
101
125
  # @return [Nexmo::Logger]
102
126
  #
127
+ sig { returns(T.nilable(Nexmo::Logger)) }
103
128
  attr_reader :logger
104
129
 
105
130
  # @return [Nexmo::Logger]
106
131
  #
132
+ sig { params(logger: T.nilable(T.any(::Logger, Nexmo::Logger))).returns(T.nilable(Nexmo::Logger)) }
107
133
  def logger=(logger)
108
- @logger = Logger.new(logger)
134
+ @logger = T.let(Logger.new(logger), T.nilable(Nexmo::Logger))
109
135
  end
110
136
 
111
137
  # Returns the value of attribute private_key.
@@ -114,7 +140,9 @@ module Nexmo
114
140
  #
115
141
  # @raise [AuthenticationError]
116
142
  #
143
+ sig { returns(T.nilable(String)) }
117
144
  def private_key
145
+ @private_key = T.let(@private_key, T.nilable(String))
118
146
  unless @private_key
119
147
  raise AuthenticationError.new('No private_key provided. ' \
120
148
  'Either provide a private_key, or set an auth token. ' \
@@ -126,15 +154,21 @@ module Nexmo
126
154
  @private_key
127
155
  end
128
156
 
157
+ sig { params(private_key: T.nilable(String)).returns(T.nilable(String)) }
129
158
  attr_writer :private_key
130
159
 
160
+ sig { returns(String) }
161
+ attr_accessor :rest_host
162
+
131
163
  # Returns the value of attribute signature_secret.
132
164
  #
133
165
  # @return [String]
134
166
  #
135
167
  # @raise [AuthenticationError]
136
168
  #
169
+ sig { returns(T.nilable(String)) }
137
170
  def signature_secret
171
+ @signature_secret = T.let(@signature_secret, T.nilable(String))
138
172
  unless @signature_secret
139
173
  raise AuthenticationError.new('No signature_secret provided. ' \
140
174
  'You can find your signature secret in the Nexmo dashboard. ' \
@@ -145,22 +179,28 @@ module Nexmo
145
179
  @signature_secret
146
180
  end
147
181
 
182
+ sig { params(signature_secret: T.nilable(String)).returns(T.nilable(String)) }
148
183
  attr_writer :signature_secret
149
184
 
185
+ sig { returns(String) }
150
186
  attr_accessor :signature_method
151
187
 
152
188
  # Returns the value of attribute token, or a temporary short lived token.
153
189
  #
154
190
  # @return [String]
155
191
  #
192
+ sig { returns(T.nilable(String)) }
156
193
  def token
157
- @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))
158
196
  end
159
197
 
198
+ sig { params(token: T.nilable(String)).returns(T.nilable(String)) }
160
199
  attr_writer :token
161
200
 
162
201
  protected
163
202
 
203
+ sig { params(name: Symbol, value: T.nilable(T.untyped)).void }
164
204
  def write_attribute(name, value)
165
205
  public_send(:"#{name}=", value)
166
206
  end