Class: Retjilp::Retweeter

Inherits:
Object
  • Object
show all
Defined in:
lib/retjilp/retweeter.rb

Instance Method Summary collapse

Constructor Details

#initialize(twitter, options) ⇒ Retweeter

Returns a new instance of Retweeter.


9
10
11
12
13
# File 'lib/retjilp/retweeter.rb', line 9

def initialize(twitter, options)
	@twitter = twitter
	@retweet_from_list = options[:retweet_from_list]
	@match = options[:match]
end

Instance Method Details

#runObject


15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/retjilp/retweeter.rb', line 15

def run
	@twitter.

	# Fetch own tweets
	user_timeline = @twitter.user_timeline.select {|x| x.has_key? 'retweeted_status'}
	retweeted_ids = user_timeline.map { |status| status['retweeted_status']['id'] }.sort

	# Fetch timeline tweets
	statuses_options = {}
	statuses_options[:since_id] = retweeted_ids[0] unless retweeted_ids.empty?
	if @retweet_from_list
		statuses = @twitter.list_statuses(@retweet_from_list, statuses_options)
	else
		statuses = @twitter.home_timeline(statuses_options)
	end

	# Retweet statuses
	statuses.each do |status|
		if should_retweet? status['text']
			id_to_retweet = status.has_key?('retweeted_status') ? status['retweeted_status']['id'] : status['id']
			if retweeted_ids.include? id_to_retweet
				Retjilp::log.debug("Already retweeted: #{status['text']}")
			else
				Retjilp::log.info("Retweeting: #{status['text']}")
				@twitter.retweet id_to_retweet
			end
		end
	end
end