0.0
No commit activity in last 3 years
No release in over 3 years
Entitlements in Redis
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0
>= 0

Runtime

>= 0
 Project Readme

SilverSpoon

Entitlements in Redis. A simple semantic wrapper around Redis hashes for adding, removing, retrieving and checking existence of entitlements.

Installation

Add this line to your application's Gemfile:

gem 'silver_spoon'

And then execute:

$ bundle

Or install it yourself as:

$ gem install silver_spoon

Usage

Configuration:

SilverSpoon.configure do |configuration|
  configuration.redis = Redis.new
  configuration.namespace = 'silver_spoon'
  configuration.default_scope = 'entitlements'
end

The hash key used in looking up entitlements for a given id is as follows:

"#{SilverSpoon.namespace}:#{scope}:#{id}"

You can use the scope property in the various calls to retrieve entitlement data in another context. This may be useful if you want to allow, for example, entitlements for multiple games or different membership products.

Adding entitlements:

add_entitlement(id, entitlement_key, entitlement_value, scope = SilverSpoon.default_scope)
add_entitlements(id, entitlement_keys, entitlement_values, scope = SilverSpoon.default_scope)

Removing entitlements:

remove_entitlement(id, entitlement_key, scope = SilverSpoon.default_scope)
remove_entitlements(id, entitlement_keys, scope = SilverSpoon.default_scope)

Checking entitlements:

has_entitlement?(id, entitlement_key, scope = SilverSpoon.default_scope)
has_entitlements?(id, entitlement_keys, scope = SilverSpoon.default_scope)

Retrieving entitlements:

retrieve_entitlement(id, entitlement_key, scope = SilverSpoon.default_scope)
retrieve_entitlements(id, entitlement_keys, scope = SilverSpoon.default_scope)

Complete example:

require 'silver_spoon'
 => true
SilverSpoon.configure do |configuration|
  configuration.redis = Redis.new
  configuration.namespace = 'silver_spoon'
  configuration.default_scope = 'entitlements'
end
 => "entitlements"
SilverSpoon.has_entitlement?('david', 'an_entitlement')
 => false
SilverSpoon.add_entitlement('david', 'an_entitlement', 'an_entitlement_value')
 => "OK"
SilverSpoon.add_entitlement('david', 'another_entitlement', 'another_entitlement_value')
 => "OK"
SilverSpoon.has_entitlements?('david', ['an_entitlement', 'another_entitlement'])
 => [true, true]
SilverSpoon.has_entitlement?('david', 'unknown_entitlement')
 => false
SilverSpoon.retrieve_entitlements('david', ['an_entitlement', 'another_entitlement'])
 => {"an_entitlement"=>"an_entitlement_value", "another_entitlement"=>"another_entitlement_value"}

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Added some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Copyright

Copyright (c) 2012-2014 David Czarnecki. See LICENSE for further details.