Class: Google::APIClient::RedisStore

Inherits:
Object
  • Object
show all
Defined in:
lib/google/api_client/auth/storages/redis_store.rb

Constant Summary collapse

DEFAULT_REDIS_CREDENTIALS_KEY =
"google_api_credentials"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(redis, key = nil) ⇒ RedisStore

Initializes the RedisStore object.



29
30
31
32
# File 'lib/google/api_client/auth/storages/redis_store.rb', line 29

def initialize(redis, key = nil)
  @redis= redis
  @redis_credentials_key = key
end

Instance Attribute Details

#redisObject

Returns the value of attribute redis.



23
24
25
# File 'lib/google/api_client/auth/storages/redis_store.rb', line 23

def redis
  @redis
end

Instance Method Details

#load_credentialsObject

Attempt to read in credentials from redis.



36
37
38
39
# File 'lib/google/api_client/auth/storages/redis_store.rb', line 36

def load_credentials
  credentials = redis.get redis_credentials_key
  JSON.parse(credentials) if credentials
end

#redis_credentials_keyObject



41
42
43
# File 'lib/google/api_client/auth/storages/redis_store.rb', line 41

def redis_credentials_key
  @redis_credentials_key || DEFAULT_REDIS_CREDENTIALS_KEY
end

#write_credentials(credentials_hash) ⇒ Object

Write the credentials to redis.



49
50
51
# File 'lib/google/api_client/auth/storages/redis_store.rb', line 49

def write_credentials(credentials_hash)
  redis.set(redis_credentials_key, credentials_hash.to_json)
end