class Twitter::Config::YAMLConfig

Public Class Methods

for_user(username, options = {}) click to toggle source
# 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 = nil

        # 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]
        elsif !config_data['profiles'][username].nil?
                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