lib/twitter_ebooks/archive.rb in twitter_ebooks-2.3.2 vs lib/twitter_ebooks/archive.rb in twitter_ebooks-3.0.0

- old
+ new

@@ -19,32 +19,35 @@ puts "As Twitter no longer allows anonymous API access, you'll need to enter the auth details of any account to use for archiving. These will be stored in #{CONFIG_PATH} if you need to change them later." print "Consumer key: " @config[:consumer_key] = STDIN.gets.chomp print "Consumer secret: " @config[:consumer_secret] = STDIN.gets.chomp - print "Oauth token: " + print "Access token: " @config[:oauth_token] = STDIN.gets.chomp - print "Oauth secret: " + print "Access secret: " @config[:oauth_token_secret] = STDIN.gets.chomp File.open(CONFIG_PATH, 'w') do |f| f.write(JSON.pretty_generate(@config)) end end - Twitter.configure do |config| + Twitter::REST::Client.new do |config| config.consumer_key = @config[:consumer_key] config.consumer_secret = @config[:consumer_secret] - config.oauth_token = @config[:oauth_token] - config.oauth_token_secret = @config[:oauth_token_secret] + config.access_token = @config[:oauth_token] + config.access_token_secret = @config[:oauth_token_secret] end - - Twitter::Client.new end - def initialize(username, path, client=nil) + def initialize(username, path=nil, client=nil) @username = username - @path = path || "#{username}.json" + @path = path || "corpus/#{username}.json" + + if File.directory?(@path) + @path = File.join(@path, "#{username}.json") + end + @client = client || make_client if File.exists?(@path) @tweets = JSON.parse(File.read(@path), symbolize_names: true) log "Currently #{@tweets.length} tweets for #{@username}"