Skip to content

Commit

Permalink
Remove duplication in Twitter::API::Timelines
Browse files Browse the repository at this point in the history
  • Loading branch information
sferik committed Nov 20, 2012
1 parent 5e8938f commit 5fe1da8
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions lib/twitter/api/timelines.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,8 @@ def retweeted_by_user(user, options={})
# @example Return the 20 most recent retweets posted by the authenticating user
# Twitter.retweeted_by_me
def retweeted_by_me(options={})
options[:include_rts] = true
count = options[:count] || DEFAULT_TWEETS_PER_REQUEST
collect_with_count(count) do |count_options|
select_retweets(user_timeline(options.merge(count_options)))
retweets_from_timeline(options) do |options|
user_timeline(options)
end
end

Expand Down Expand Up @@ -148,10 +146,8 @@ def home_timeline(options={})
# @example Return the 20 most recent retweets posted by users followed by the authenticating user
# Twitter.retweeted_to_me
def retweeted_to_me(options={})
options[:include_rts] = true
count = options[:count] || DEFAULT_TWEETS_PER_REQUEST
collect_with_count(count) do |count_options|
select_retweets(home_timeline(options.merge(count_options)))
retweets_from_timeline(options) do |options|
home_timeline(options)
end
end

Expand Down Expand Up @@ -202,6 +198,14 @@ def collect_with_count(count, &block)
end.flatten.compact[0...count]
end

def retweets_from_timeline(options)
options[:include_rts] = true
count = options[:count] || DEFAULT_TWEETS_PER_REQUEST
collect_with_count(count) do |count_options|
select_retweets(yield(options.merge(count_options)))
end
end

# @param tweets [Array]
# @return [Array]
def select_retweets(tweets)
Expand Down

0 comments on commit 5fe1da8

Please sign in to comment.