Class: Twitter::Config::YAMLConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/twitter/config.rb

Class Method Summary collapse

Class Method Details

.for_user(username, options = {}) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/twitter/config.rb', line 15

def self.for_user(username, options = {})
	path = options[:path] || "#{ENV['HOME']}/.trc"
	config_data = YAML.load_file path
	user_config = {}

	# we want to be able to handle two different formats - the simple one
	# with just a list of usernames, and the more complicated .trc format
	# that has the app ids in it etc
	if config_data['profiles'].nil?
		user_config = config_data[username]
	else
		user_config = config_data['profiles'][username].values.first
	end

	raise "no config found for #{username} in file #{path}" if user_config.nil?
	return {
		:consumer_key => user_config['consumer_key'],
		:consumer_secret => user_config['consumer_secret'],
		:access_token => user_config['token'] || user_config['access_token'],
		:access_token_secret => user_config['secret'] || user_config['access_token_secret']
	}
end