Class: ThreeScale::Backend::ServiceToken

Inherits:
Object
  • Object
show all
Extended by:
Memoizer::Decorator, KeyHelpers
Includes:
KeyHelpers, Storable
Defined in:
lib/3scale/backend/service_token.rb

Defined Under Namespace

Modules: KeyHelpers Classes: InvalidServiceId, InvalidServiceToken

Constant Summary collapse

ValidationError =
Class.new(ThreeScale::Backend::Invalid)

Class Method Summary collapse

Methods included from Memoizer::Decorator

included

Methods included from KeyHelpers

key

Methods included from Storable

included, #initialize, #storage

Methods included from StorageKeyHelpers

#encode_key

Class Method Details

.delete(service_token, service_id) ⇒ Object



56
57
58
59
60
# File 'lib/3scale/backend/service_token.rb', line 56

def delete(service_token, service_id)
  res = storage.del(key(service_token, service_id))
  clear_cache(service_token, service_id)
  res
end

.exists?(service_token, service_id) ⇒ Boolean

Returns:

  • (Boolean)


62
63
64
# File 'lib/3scale/backend/service_token.rb', line 62

def exists?(service_token, service_id)
  storage.exists(key(service_token, service_id))
end

.save(service_token, service_id) ⇒ Object



40
41
42
43
# File 'lib/3scale/backend/service_token.rb', line 40

def save(service_token, service_id)
  validate_pairs([{ service_token: service_token, service_id: service_id }])
  storage.hset(key(service_token, service_id), PERMISSIONS_KEY_FIELD, ''.freeze)
end

.save_pairs(token_id_pairs) ⇒ Object

Saves a collection of (service_token, service_id) pairs only if all the pairs contain valid data, meaning that there are no null or empty strings.



48
49
50
51
52
53
54
# File 'lib/3scale/backend/service_token.rb', line 48

def save_pairs(token_id_pairs)
  validate_pairs(token_id_pairs)

  token_id_pairs.each do |pair|
    unchecked_save(pair[:service_token], pair[:service_id])
  end
end