Class: Auth
- Inherits:
-
Object
- Object
- Auth
- Defined in:
- lib/coolsms/auth.rb
Instance Attribute Summary collapse
-
#api_key ⇒ Object
API KEY.
-
#api_secret ⇒ Object
API SECRET KEY.
-
#salt ⇒ Object
Salt.
-
#timestamp ⇒ Object
Time Default : now.
Instance Method Summary collapse
- #auth ⇒ Object
-
#initialize ⇒ Auth
constructor
A new instance of Auth.
- #signature ⇒ Object
Constructor Details
#initialize ⇒ Auth
Returns a new instance of Auth.
15 16 17 18 |
# File 'lib/coolsms/auth.rb', line 15 def initialize self.api_key ||= ENV['COOLSMS_KEY'] self.api_secret ||= ENV['COOLSMS_SECRET_KEY'] end |
Instance Attribute Details
#api_key ⇒ Object
API KEY
10 11 12 |
# File 'lib/coolsms/auth.rb', line 10 def api_key @api_key end |
#api_secret ⇒ Object
API SECRET KEY
13 14 15 |
# File 'lib/coolsms/auth.rb', line 13 def api_secret @api_secret end |
#salt ⇒ Object
Salt
7 8 9 |
# File 'lib/coolsms/auth.rb', line 7 def salt @salt end |
#timestamp ⇒ Object
Time Default : now
4 5 6 |
# File 'lib/coolsms/auth.rb', line 4 def @timestamp end |
Instance Method Details
#auth ⇒ Object
27 28 29 |
# File 'lib/coolsms/auth.rb', line 27 def auth { api_key: self.api_key, signature: self.signature, timestamp: self., salt: self.salt } end |
#signature ⇒ Object
20 21 22 23 24 25 |
# File 'lib/coolsms/auth.rb', line 20 def signature self. = Time.now.to_i self.salt = SecureRandom.hex hmac_data = self..to_s + self.salt.to_s OpenSSL::HMAC.hexdigest( "md5", self.api_secret, hmac_data ) end |