Class: Nexmo::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/nexmo/config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.


6
7
8
9
10
11
12
13
14
# File 'lib/nexmo/config.rb', line 6

def initialize
  self.api_key = ENV['NEXMO_API_KEY']
  self.api_secret = ENV['NEXMO_API_SECRET']
  self.application_id = nil
  self.logger = (defined?(Rails.logger) && Rails.logger) || ::Logger.new(nil)
  self.private_key = nil
  self.signature_secret = ENV['NEXMO_SIGNATURE_SECRET']
  self.token = nil
end

Instance Attribute Details

#api_keyString

Returns the value of attribute api_key.

Returns:

  • (String)

Raises:


34
35
36
37
38
39
40
41
42
# File 'lib/nexmo/config.rb', line 34

def api_key
  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_secretString

Returns the value of attribute api_secret.

Returns:

  • (String)

Raises:


52
53
54
55
56
57
58
59
60
# File 'lib/nexmo/config.rb', line 52

def api_secret
  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


84
85
86
# File 'lib/nexmo/config.rb', line 84

def app_name
  @app_name
end

#app_versionObject

Returns the value of attribute app_version


86
87
88
# File 'lib/nexmo/config.rb', line 86

def app_version
  @app_version
end

#application_idString

Returns the value of attribute application_id.

Returns:

  • (String)

Raises:


70
71
72
73
74
75
76
77
78
79
80
# File 'lib/nexmo/config.rb', line 70

def application_id
  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 Nexmo dashboard. ' \
      'See https://developer.nexmo.com/concepts/guides/applications for details, ' \
      'or email [email protected] if you have any questions.')
  end

  @application_id
end

#httpNexmo::HTTP::Options

Returns the value of attribute http.


92
93
94
# File 'lib/nexmo/config.rb', line 92

def http
  @http
end

#loggerNexmo::Logger

Returns the value of attribute logger.

Returns:

  • (Nexmo::Logger)

102
103
104
# File 'lib/nexmo/config.rb', line 102

def logger
  @logger
end

#private_keyString

Returns the value of attribute private_key.

Returns:

  • (String)

Raises:


116
117
118
119
120
121
122
123
124
125
126
# File 'lib/nexmo/config.rb', line 116

def private_key
  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 Nexmo dashboard. ' \
      'See https://developer.nexmo.com/concepts/guides/applications for details, ' \
      'or email [email protected] if you have any questions.')
  end

  @private_key
end

#signature_secretString

Returns the value of attribute signature_secret.

Returns:

  • (String)

Raises:


136
137
138
139
140
141
142
143
144
145
# File 'lib/nexmo/config.rb', line 136

def signature_secret
  unless @signature_secret
    raise AuthenticationError.new('No signature_secret provided. ' \
      'You can find your signature secret in the Nexmo 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

#tokenString

Returns the value of attribute token, or a temporary short lived token.

Returns:

  • (String)

153
154
155
# File 'lib/nexmo/config.rb', line 153

def token
  @token || JWT.generate({application_id: application_id}, private_key)
end

Instance Method Details

#merge(options) ⇒ Nexmo::Config

Merges the config with the given options hash.

Returns:


20
21
22
23
24
25
26
# File 'lib/nexmo/config.rb', line 20

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