Module: TwitterWithAutoPagination::REST::Extension::Replying

Includes:
Utils
Defined in:
lib/twitter_with_auto_pagination/rest/extension/replying.rb

Constant Summary

Constants included from Utils

Utils::DEFAULT_CALL_LIMIT

Instance Method Summary collapse

Methods included from Collector

#collect_with_cursor, #collect_with_max_id

Instance Method Details

#_extract_screen_names(tweets) ⇒ Object



9
10
11
12
13
# File 'lib/twitter_with_auto_pagination/rest/extension/replying.rb', line 9

def _extract_screen_names(tweets)
  tweets.map do |t|
    $1 if t.text =~ /^(?:\.)?@(\w+)( |\W)/ # include statuses starts with .
  end.compact
end

#_extract_uids(tweets) ⇒ Object



51
52
53
54
55
# File 'lib/twitter_with_auto_pagination/rest/extension/replying.rb', line 51

def _extract_uids(tweets)
  tweets.map do |t|
    t.user.id.to_i if t.text =~ /^(?:\.)?@(\w+)( |\W)/ # include statuses starts with .
  end.compact
end

#_extract_users(tweets, uids) ⇒ Object



57
58
59
# File 'lib/twitter_with_auto_pagination/rest/extension/replying.rb', line 57

def _extract_users(tweets, uids)
  uids.map { |uid| tweets.find { |t| t.user.id.to_i == uid.to_i } }.map { |t| t.user }.compact
end

#_retrieve_user_timeline(*args) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/twitter_with_auto_pagination/rest/extension/replying.rb', line 15

def _retrieve_user_timeline(*args)
  options = args.extract_options!
  if args.empty?
    user_timeline(options)
  elsif uid_or_screen_name?(args[0])
    user_timeline(args[0], options)
  elsif args[0].kind_of?(Array) && args[0].all? { |t| t.respond_to?(:text) }
    args[0]
  else
    raise ArgumentError
  end
end

#_retrieve_users_from_mentions_timeline(*args) ⇒ Object



61
62
63
64
65
66
67
68
69
70
# File 'lib/twitter_with_auto_pagination/rest/extension/replying.rb', line 61

def _retrieve_users_from_mentions_timeline(*args)
  options = args.extract_options!
  if args.empty? || (uid_or_screen_name?(args[0]) && authenticating_user?(args[0]))
    mentions_timeline.map { |m| m.user }
  else
    searched_result = search('@' + user(args[0]).screen_name, options)
    uids = _extract_uids(searched_result)
    _extract_users(searched_result, uids)
  end
end

#users_which_you_replied_to(*args) ⇒ Object Also known as: replying

users which specified user is replying in_reply_to_user_id and in_reply_to_status_id is not used because of distinguishing mentions from replies



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/twitter_with_auto_pagination/rest/extension/replying.rb', line 30

def users_which_you_replied_to(*args)
  options = args.extract_options!
  instrument(__method__, nil, options) do
    tweets = _retrieve_user_timeline(*args, options)
    screen_names = _extract_screen_names(tweets)
    result = users(screen_names, {super_operation: __method__}.merge(options))
    if options.has_key?(:uniq) && !options[:uniq]
      screen_names.map { |sn| result.find { |u| u.screen_name == sn } }.compact
    else
      result.uniq { |u| u.id }
    end
  end
rescue Twitter::Error::NotFound => e
  e.message == 'No user matches for specified terms.' ? [] : (raise e)
rescue => e
  logger.warn "#{__method__}: #{e.class} #{e.message} #{args.inspect}"
  raise e
end

#users_who_replied_to_you(*args) ⇒ Object Also known as: replied

users which specified user is replied when user is login you had better to call mentions_timeline



74
75
76
77
78
79
80
81
82
83
84
# File 'lib/twitter_with_auto_pagination/rest/extension/replying.rb', line 74

def users_who_replied_to_you(*args)
  options = args.extract_options!
  instrument(__method__, nil, options) do
    result = _retrieve_users_from_mentions_timeline(*args, options)
    if options.has_key?(:uniq) && !options[:uniq]
      result
    else
      result.uniq { |r| r.id }
    end
  end
end