Module: Card::Set::Right::ApiKey

Extended by:
Card::Set
Defined in:
platypus/tmp/set/gem-defaults/mod021-api_key/right/api_key.rb

Overview

Set: All “+ApiKey” cards

Defined Under Namespace

Modules: HtmlFormat, JsonFormat

Constant Summary

Constants included from Helpers

Helpers::SET_PATTERN_TEST_REGEXP

Constants included from Event::Api

Event::Api::OPTIONS

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Card::Set

reset

Methods included from I18nScope

#mod_name, #scope

Methods included from Card::Set::Registrar

#extended, #finalize_load, #process_base_modules, #register_set

Methods included from Helpers

#format_module, #format_modules, #method_missing, #modules, #pattern_code, #respond_to_missing?, #set_name_parts, #shortname, #underscored_name

Methods included from AdvancedApi

#assign_type, #attachment, #define_set_from_error, #ensure_set, #setting_opts, #stage_method

Methods included from Format

#before, #format, layout_method_name, #view, view_method_name, view_setting_method_name, wrapper_method_name

Methods included from Inheritance

#include_set, #include_set_formats

Methods included from Trait

#card_accessor, #card_reader, #card_writer, #require_field

Methods included from Event::Api

#event

Class Method Details

.source_locationObject

[View source]

7
# File 'platypus/tmp/set/gem-defaults/mod021-api_key/right/api_key.rb', line 7

def self.source_location; "/Users/ethan/dev/decko/gem/mod/api_key/set/right/api_key.rb"; end

Instance Method Details

#api_key_taken?Boolean

checks availability of API key

Returns:

  • (Boolean)
[View source]

21
22
23
24
25
# File 'platypus/tmp/set/gem-defaults/mod021-api_key/right/api_key.rb', line 21

def api_key_taken?
  return false unless (acct = Card::Auth. content)

  acct.id != left_id
end

#authenticate_api_key(api_key) ⇒ True/False

Returns checks whether key matches content.

Returns:

  • (True/False)

    checks whether key matches content

[View source]

40
41
42
43
44
45
# File 'platypus/tmp/set/gem-defaults/mod021-api_key/right/api_key.rb', line 40

def authenticate_api_key api_key
  return true unless (error = api_key_validation_error api_key)

  errors.add error, t(error)
  false
end

#event: generate_api_keyObject

triggerable event to generate new API Key

[View source]

11
12
13
# File 'platypus/tmp/set/gem-defaults/mod021-api_key/right/api_key.rb', line 11

event :generate_api_key, :prepare_to_validate, trigger: :required do
  generate
end

#event: validate_api_keyObject

[View source]

15
16
17
18
# File 'platypus/tmp/set/gem-defaults/mod021-api_key/right/api_key.rb', line 15

event :validate_api_key, :validate, on: :save, changed: :content do
  errors.add :content, t(:api_key_invalid) unless content.match?(/^\w{20,}$/)
  errors.add :content, t(:api_key_taken) if api_key_taken?
end

#generateObject

[View source]

47
48
49
# File 'platypus/tmp/set/gem-defaults/mod021-api_key/right/api_key.rb', line 47

def generate
  self.content = SecureRandom.base64.tr "+/=", "Qrt"
end

#generate!Object

[View source]

51
52
53
# File 'platypus/tmp/set/gem-defaults/mod021-api_key/right/api_key.rb', line 51

def generate!
  generate.tap { save! }
end

#history?Boolean

Returns:

  • (Boolean)
[View source]

27
28
29
# File 'platypus/tmp/set/gem-defaults/mod021-api_key/right/api_key.rb', line 27

def history?
  false
end

#ok_to_create?Boolean

Returns:

  • (Boolean)
[View source]

35
36
37
# File 'platypus/tmp/set/gem-defaults/mod021-api_key/right/api_key.rb', line 35

def ok_to_create?
  own_account? || super
end

#ok_to_read?Boolean

Returns:

  • (Boolean)
[View source]

31
32
33
# File 'platypus/tmp/set/gem-defaults/mod021-api_key/right/api_key.rb', line 31

def ok_to_read?
  own_account? || super
end

#simple_tokenObject

[View source]

55
56
57
# File 'platypus/tmp/set/gem-defaults/mod021-api_key/right/api_key.rb', line 55

def simple_token
  Card::Auth::Token.encode accounted.id
end