Class: Auth

Inherits:
Object
  • Object
show all
Defined in:
lib/coolsms/auth.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeAuth

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_keyObject

API KEY



10
11
12
# File 'lib/coolsms/auth.rb', line 10

def api_key
  @api_key
end

#api_secretObject

API SECRET KEY



13
14
15
# File 'lib/coolsms/auth.rb', line 13

def api_secret
  @api_secret
end

#saltObject

Salt



7
8
9
# File 'lib/coolsms/auth.rb', line 7

def salt
  @salt
end

#timestampObject

Time Default : now



4
5
6
# File 'lib/coolsms/auth.rb', line 4

def timestamp
  @timestamp
end

Instance Method Details

#authObject



27
28
29
# File 'lib/coolsms/auth.rb', line 27

def auth
  { api_key: self.api_key, signature: self.signature, timestamp: self.timestamp, salt: self.salt }
end

#signatureObject



20
21
22
23
24
25
# File 'lib/coolsms/auth.rb', line 20

def signature
  self.timestamp = Time.now.to_i
  self.salt = SecureRandom.hex
  hmac_data = self.timestamp.to_s + self.salt.to_s
  OpenSSL::HMAC.hexdigest( "md5", self.api_secret, hmac_data )
end