Class: Cadinsor::ApiKey

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/cadinsor/api_key.rb

Instance Method Summary collapse

Instance Method Details

#expired?Boolean

Returns:

  • (Boolean)


13
14
15
16
# File 'app/models/cadinsor/api_key.rb', line 13

def expired?
  return true if self.created_at < Cadinsor::Engine.config.key_expiry_time_in_mins.to_i.minutes.ago
  false
end

#generate_key!Object



6
7
8
9
10
11
# File 'app/models/cadinsor/api_key.rb', line 6

def generate_key!
  self.key = SecureRandom.urlsafe_base64(32)
  generate_key! if Cadinsor::ApiKey.find_by_key(self.key)
  # Return object for chaining requests
  self
end