Class: GoogleDirectory::YamlTokenStore

Inherits:
Object
  • Object
show all
Defined in:
lib/google-directory/config.rb

Instance Method Summary collapse

Constructor Details

#initialize(yaml_file) ⇒ YamlTokenStore

Returns a new instance of YamlTokenStore.



122
123
124
125
126
127
# File 'lib/google-directory/config.rb', line 122

def initialize(yaml_file)
	@yaml_file = yaml_file
	@yaml_data = YAML::load( yaml_file.open )
	@yaml_data = {} unless @yaml_data.is_a?(Hash)
	# @yaml_data[Rails.env.to_s] ||= {}
end

Instance Method Details

#load(scope_name) ⇒ Object



135
136
137
# File 'lib/google-directory/config.rb', line 135

def load( scope_name )
	data = @yaml_data[Rails.env.to_s] and data = data[scope_name.to_s] and data.slice('token_type', 'issued_at', 'access_token', 'expires_in')
end

#save(scope_name, token_hash) ⇒ Object



129
130
131
132
133
# File 'lib/google-directory/config.rb', line 129

def save( scope_name, token_hash )
	data = (@yaml_data[Rails.env.to_s] ||= {})
	data[scope_name.to_s] = token_hash
	File.open(@yaml_file, 'w') { |file| file.write( YAML::dump(@yaml_data) ) }
end