Class: Marty::ApiAuth

Inherits:
Base show all
Defined in:
app/models/marty/api_auth.rb

Defined Under Namespace

Classes: ApiAuthValidator

Constant Summary collapse

KEY_SIZE =
19

Constants inherited from Base

Base::COUNT_SIG, Base::DISTINCT_SIG, Base::FIRST_SIG, Base::GROUP_SIG, Base::JOINS_SIG, Base::LAST_SIG, Base::LIMIT_SIG, Base::MCFLY_PT_SIG, Base::NOT_SIG, Base::ORDER_SIG, Base::PLUCK_SIG, Base::SELECT_SIG, Base::WHERE_SIG

Class Method Summary collapse

Methods inherited from Base

mcfly_pt

Methods inherited from ActiveRecord::Base

joins, old_joins

Class Method Details

.authorized?(script_name, api_key) ⇒ Boolean

Returns:

  • (Boolean)


37
38
39
40
41
42
43
# File 'app/models/marty/api_auth.rb', line 37

def self.authorized?(script_name, api_key)
  is_secured = where(script_name: script_name,
                     obsoleted_dt: 'infinity').exists?
  !is_secured || where(api_key: api_key,
                       script_name: script_name,
                       obsoleted_dt: 'infinity').pluck(:app_name).first
end

.generate_keyObject



6
7
8
# File 'app/models/marty/api_auth.rb', line 6

def self.generate_key
  SecureRandom.hex(KEY_SIZE)
end