1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-12-11 22:24:21 +01:00
fab-manager/app/models/open_api/client.rb

28 lines
603 B
Ruby
Raw Normal View History

# frozen_string_literal: true
# OpenAPI::Client keeps track of the authorized accesses to the 3-rd party API (aka. OpenAPI)
2020-03-25 10:16:47 +01:00
class OpenAPI::Client < ApplicationRecord
validates :name, presence: true
validates_uniqueness_of :token
before_create :set_initial_token
def increment_calls_count
update_column(:calls_count, calls_count+1)
end
def regenerate_token
update_attributes(token: generate_unique_secure_token)
end
private
def set_initial_token
self.token = generate_unique_secure_token
end
def generate_unique_secure_token
SecureRandom.base58(24)
end
end