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
Class Method Summary collapse
Instance Method Summary collapse
-
#api_key_taken? ⇒ Boolean
checks availability of API key.
-
#authenticate_api_key(api_key) ⇒ True/False
Checks whether key matches content.
-
#event: generate_api_key ⇒ Object
triggerable event to generate new API Key.
-
#event: validate_api_key ⇒ Object
-
#generate ⇒ Object
-
#generate! ⇒ Object
-
#history? ⇒ Boolean
-
#ok_to_create? ⇒ Boolean
-
#ok_to_read? ⇒ Boolean
-
#simple_token ⇒ Object
Methods included from Card::Set
Methods included from I18nScope
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
Class Method Details
.source_location ⇒ Object
[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
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.find_account_by_api_key content) acct.id != left_id end |
#authenticate_api_key(api_key) ⇒ True/False
Returns checks whether key matches content.
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_key ⇒ Object
triggerable event to generate new API Key
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_key ⇒ Object
[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 |
#generate ⇒ Object
[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
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
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
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 |