Class: Vonage::Config

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/vonage/config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/vonage/config.rb', line 10

def initialize
  self.api_host = 'api.nexmo.com'
  self.api_key = T.let(ENV['VONAGE_API_KEY'], T.nilable(String))
  self.api_secret = T.let(ENV['VONAGE_API_SECRET'], T.nilable(String))
  self.application_id = ENV['VONAGE_APPLICATION_ID']
  self.logger = (defined?(::Rails.logger) && ::Rails.logger) || Vonage::Logger.new(nil)
  self.private_key = ENV['VONAGE_PRIVATE_KEY_PATH'] ? File.read(T.must(ENV['VONAGE_PRIVATE_KEY_PATH'])) : ENV['VONAGE_PRIVATE_KEY']
  self.rest_host = 'rest.nexmo.com'
  self.signature_secret = ENV['VONAGE_SIGNATURE_SECRET']
  self.signature_method = ENV['VONAGE_SIGNATURE_METHOD'] || 'md5hash'
  self.token = T.let(nil, T.nilable(String))
  self.vonage_host = 'api-eu.vonage.com'
end

Instance Attribute Details

#api_hostObject

Returns the value of attribute api_host.



38
39
40
# File 'lib/vonage/config.rb', line 38

def api_host
  @api_host
end

#api_keyObject



47
48
49
50
51
52
53
54
55
56
# File 'lib/vonage/config.rb', line 47

def api_key
  @api_key = T.let(@api_key, T.nilable(String))
  unless @api_key
    raise AuthenticationError.new('No API key provided. ' \
      'See https://developer.nexmo.com/concepts/guides/authentication for details, ' \
      'or email [email protected] if you have any questions.')
  end

  @api_key
end

#api_secretObject



68
69
70
71
72
73
74
75
76
77
# File 'lib/vonage/config.rb', line 68

def api_secret
  @api_secret = T.let(@api_secret, T.nilable(String))
  unless @api_secret
    raise AuthenticationError.new('No API secret provided. ' \
      'See https://developer.nexmo.com/concepts/guides/authentication for details, ' \
      'or email [email protected] if you have any questions.')
  end

  @api_secret
end

#app_nameObject

Returns the value of attribute app_name.



106
107
108
# File 'lib/vonage/config.rb', line 106

def app_name
  @app_name
end

#app_versionObject

Returns the value of attribute app_version.



109
110
111
# File 'lib/vonage/config.rb', line 109

def app_version
  @app_version
end

#application_idObject



89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/vonage/config.rb', line 89

def application_id
  @application_id = T.let(@application_id, T.nilable(String))
  unless @application_id
    raise AuthenticationError.new('No application_id provided. ' \
      'Either provide an application_id, or set an auth token. ' \
      'You can add new applications from the Vonage dashboard. ' \
      'See https://developer.nexmo.com/concepts/guides/applications for details, ' \
      'or email [email protected] if you have any questions.')
  end

  @application_id
end

#httpObject

Returns the value of attribute http.



116
117
118
# File 'lib/vonage/config.rb', line 116

def http
  @http
end

#loggerObject

Returns the value of attribute logger.



129
130
131
# File 'lib/vonage/config.rb', line 129

def logger
  @logger
end

#private_keyObject



149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/vonage/config.rb', line 149

def private_key
  @private_key = T.let(@private_key, T.nilable(String))
  unless @private_key
    raise AuthenticationError.new('No private_key provided. ' \
      'Either provide a private_key, or set an auth token. ' \
      'You can add new applications from the Vonage dashboard. ' \
      'See https://developer.nexmo.com/concepts/guides/applications for details, ' \
      'or email [email protected] if you have any questions.')
  end

  @private_key
end

#rest_hostObject

Returns the value of attribute rest_host.



166
167
168
# File 'lib/vonage/config.rb', line 166

def rest_host
  @rest_host
end

#signature_methodObject

Returns the value of attribute signature_method.



191
192
193
# File 'lib/vonage/config.rb', line 191

def signature_method
  @signature_method
end

#signature_secretObject



175
176
177
178
179
180
181
182
183
184
185
# File 'lib/vonage/config.rb', line 175

def signature_secret
  @signature_secret = T.let(@signature_secret, T.nilable(String))
  unless @signature_secret
    raise AuthenticationError.new('No signature_secret provided. ' \
      'You can find your signature secret in the Vonage dashboard. ' \
      'See https://developer.nexmo.com/concepts/guides/signing-messages for details, ' \
      'or email [email protected] if you have any questions.')
  end

  @signature_secret
end

#tokenObject



198
199
200
201
# File 'lib/vonage/config.rb', line 198

def token
  @token = T.let(@token, T.nilable(String))
  @token || JWT.generate({application_id: application_id}, T.must(private_key))
end

#vonage_hostObject

Returns the value of attribute vonage_host.



207
208
209
# File 'lib/vonage/config.rb', line 207

def vonage_host
  @vonage_host
end

Instance Method Details

#merge(options) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/vonage/config.rb', line 29

def merge(options)
  return self if options.nil? || options.empty?

  options.each_with_object(dup) do |(name, value), config|
    config.write_attribute(name, value)
  end
end