Class: JsonCrudApi::AuthClient
- Inherits:
-
Object
- Object
- JsonCrudApi::AuthClient
- Defined in:
- lib/json-crud-api/auth_client.rb
Instance Attribute Summary collapse
-
#prefix ⇒ Object
Returns the value of attribute prefix.
-
#redis ⇒ Object
Returns the value of attribute redis.
-
#session_ttl ⇒ Object
Returns the value of attribute session_ttl.
Instance Method Summary collapse
- #delete(key) ⇒ Object
- #get(key) ⇒ Object
- #get_redis_key(key) ⇒ Object
-
#initialize(options) ⇒ AuthClient
constructor
A new instance of AuthClient.
- #touch(key) ⇒ Object
Constructor Details
#initialize(options) ⇒ AuthClient
Returns a new instance of AuthClient.
8 9 10 11 12 |
# File 'lib/json-crud-api/auth_client.rb', line 8 def initialize() @redis = [:redis_client] @session_ttl = [:session_ttl] @prefix = [:key_prefix] end |
Instance Attribute Details
#prefix ⇒ Object
Returns the value of attribute prefix.
6 7 8 |
# File 'lib/json-crud-api/auth_client.rb', line 6 def prefix @prefix end |
#redis ⇒ Object
Returns the value of attribute redis.
6 7 8 |
# File 'lib/json-crud-api/auth_client.rb', line 6 def redis @redis end |
#session_ttl ⇒ Object
Returns the value of attribute session_ttl.
6 7 8 |
# File 'lib/json-crud-api/auth_client.rb', line 6 def session_ttl @session_ttl end |
Instance Method Details
#delete(key) ⇒ Object
22 23 24 25 26 27 |
# File 'lib/json-crud-api/auth_client.rb', line 22 def delete(key) key = get_redis_key(key) return false unless @redis.exists(key) @redis.del(key) true end |
#get(key) ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/json-crud-api/auth_client.rb', line 14 def get(key) key = get_redis_key(key) data = @redis.get(key) return nil if data.nil? touch(key) JSON.parse(data, :symbolize_names => true) end |
#get_redis_key(key) ⇒ Object
36 37 38 39 |
# File 'lib/json-crud-api/auth_client.rb', line 36 def get_redis_key(key) return key.to_s if @prefix.nil? @prefix.to_s+key.to_s end |
#touch(key) ⇒ Object
29 30 31 32 33 34 |
# File 'lib/json-crud-api/auth_client.rb', line 29 def touch(key) key = get_redis_key(key) return false unless @redis.exists(key) @redis.expire(key, @session_ttl) true end |