Class: Vonage::Config
- Inherits:
-
Object
- Object
- Vonage::Config
- Extended by:
- T::Sig
- Defined in:
- lib/vonage/config.rb
Instance Attribute Summary collapse
-
#api_host ⇒ Object
Returns the value of attribute api_host.
- #api_key ⇒ Object
- #api_secret ⇒ Object
-
#app_name ⇒ Object
Returns the value of attribute app_name.
-
#app_version ⇒ Object
Returns the value of attribute app_version.
- #application_id ⇒ Object
-
#http ⇒ Object
Returns the value of attribute http.
-
#logger ⇒ Object
Returns the value of attribute logger.
- #private_key ⇒ Object
-
#rest_host ⇒ Object
Returns the value of attribute rest_host.
-
#signature_method ⇒ Object
Returns the value of attribute signature_method.
- #signature_secret ⇒ Object
- #token ⇒ Object
-
#video_host ⇒ Object
Returns the value of attribute video_host.
-
#vonage_host ⇒ Object
Returns the value of attribute vonage_host.
Instance Method Summary collapse
-
#initialize ⇒ Config
constructor
A new instance of Config.
- #merge(options) ⇒ Object
Constructor Details
#initialize ⇒ Config
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_host ⇒ Object
Returns the value of attribute api_host.
39 40 41 |
# File 'lib/vonage/config.rb', line 39 def api_host @api_host end |
#api_key ⇒ Object
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_secret ⇒ Object
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_name ⇒ Object
Returns the value of attribute app_name.
107 108 109 |
# File 'lib/vonage/config.rb', line 107 def app_name @app_name end |
#app_version ⇒ Object
Returns the value of attribute app_version.
110 111 112 |
# File 'lib/vonage/config.rb', line 110 def app_version @app_version end |
#application_id ⇒ Object
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 |
#http ⇒ Object
Returns the value of attribute http.
117 118 119 |
# File 'lib/vonage/config.rb', line 117 def http @http end |
#logger ⇒ Object
Returns the value of attribute logger.
130 131 132 |
# File 'lib/vonage/config.rb', line 130 def logger @logger end |
#private_key ⇒ Object
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_host ⇒ Object
Returns the value of attribute rest_host.
167 168 169 |
# File 'lib/vonage/config.rb', line 167 def rest_host @rest_host end |
#signature_method ⇒ Object
Returns the value of attribute signature_method.
192 193 194 |
# File 'lib/vonage/config.rb', line 192 def signature_method @signature_method end |
#signature_secret ⇒ Object
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 |
#token ⇒ Object
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_host ⇒ Object
Returns the value of attribute video_host.
208 209 210 |
# File 'lib/vonage/config.rb', line 208 def video_host @video_host end |
#vonage_host ⇒ Object
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() return self if .nil? || .empty? .each_with_object(dup) do |(name, value), config| config.write_attribute(name, value) end end |