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
23
# 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.video_host = 'video.api.vonage.com'
  self.vonage_host = 'api-eu.vonage.com'
end

Instance Attribute Details

#api_hostObject

Returns the value of attribute api_host.



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

def api_host
  @api_host
end

#api_keyObject



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

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



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

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.



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

def app_name
  @app_name
end

#app_versionObject

Returns the value of attribute app_version.



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

def app_version
  @app_version
end

#application_idObject



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

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.



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

def http
  @http
end

#loggerObject

Returns the value of attribute logger.



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

def logger
  @logger
end

#private_keyObject



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

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.



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

def rest_host
  @rest_host
end

#signature_methodObject

Returns the value of attribute signature_method.



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

def signature_method
  @signature_method
end

#signature_secretObject



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

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



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

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

#video_hostObject

Returns the value of attribute video_host.



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

def video_host
  @video_host
end

#vonage_hostObject

Returns the value of attribute vonage_host.



211
212
213
# File 'lib/vonage/config.rb', line 211

def vonage_host
  @vonage_host
end

Instance Method Details

#merge(options) ⇒ Object



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

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