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
# 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))
end

Instance Attribute Details

#api_hostObject

Returns the value of attribute api_host


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

def api_host
  @api_host
end

#api_keyObject


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

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


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

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


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

def app_name
  @app_name
end

#app_versionObject

Returns the value of attribute app_version


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

def app_version
  @app_version
end

#application_idObject


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

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


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

def http
  @http
end

#loggerObject

Returns the value of attribute logger


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

def logger
  @logger
end

#private_keyObject


144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/vonage/config.rb', line 144

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


161
162
163
# File 'lib/vonage/config.rb', line 161

def rest_host
  @rest_host
end

#signature_methodObject

Returns the value of attribute signature_method


186
187
188
# File 'lib/vonage/config.rb', line 186

def signature_method
  @signature_method
end

#signature_secretObject


170
171
172
173
174
175
176
177
178
179
180
# File 'lib/vonage/config.rb', line 170

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


193
194
195
196
# File 'lib/vonage/config.rb', line 193

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

Instance Method Details

#merge(options) ⇒ Object


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

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