Sha256: 905ea2fa33a694b30319672716390bb40ba2b46121cfae4bd7c0defd21277c6a

Contents?: true

Size: 601 Bytes

Versions: 5

Compression:

Stored size: 601 Bytes

Contents

# frozen_string_literal: true

require 'securerandom'
module Apicasso
  # A model to abstract API access, with scope options, token generation, request limiting
  class Key < ApplicationRecord
    before_create :set_auth_token

    private

    # Method that generates `SecureRandom.uuid` as token until
    # an unique one has been acquired
    def set_auth_token
      loop do
        self.token = generate_auth_token
        break unless self.class.exists?(token: token)
      end
    end

    # RFC4122 style token
    def generate_auth_token
      SecureRandom.uuid.delete('-')
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
apicasso-0.2.16 app/models/apicasso/key.rb
apicasso-0.2.15 app/models/apicasso/key.rb
apicasso-0.1.5 app/models/apicasso/key.rb
apicasso-0.1.4 app/models/apicasso/key.rb
apicasso-0.1.3 app/models/apicasso/key.rb