class Auth

Attributes

api_key[RW]

API KEY

api_secret[RW]

API SECRET KEY

salt[RW]

Salt

timestamp[RW]

Time Default : now

Public Class Methods

new() click to toggle source
# File lib/coolsms/auth.rb, line 15
def initialize
  self.api_key ||= ENV['COOLSMS_KEY']
  self.api_secret ||= ENV['COOLSMS_SECRET_KEY']
end

Public Instance Methods

auth() click to toggle source
# File lib/coolsms/auth.rb, line 27
def auth
  { api_key: self.api_key, signature: self.signature, timestamp: self.timestamp, salt: self.salt }
end
signature() click to toggle source
# 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