Module: ExTwitter::ExistingApi

Included in:
Client
Defined in:
lib/ex_twitter/existing_api.rb

Instance Method Summary collapse

Instance Method Details

#favorites(*args) ⇒ Object



111
112
113
114
115
116
117
# File 'lib/ex_twitter/existing_api.rb', line 111

def favorites(*args)
  options = {count: 100, call_count: 1}.merge(args.extract_options!)
  args[0] = verify_credentials(skip_status: true).id if args.empty?
  fetch_cache_or_call_api(__method__, args[0], options) {
    collect_with_max_id("old_#{__method__}", *args, options)
  }
end

#follower_ids(*args) ⇒ Object



41
42
43
44
45
46
47
# File 'lib/ex_twitter/existing_api.rb', line 41

def follower_ids(*args)
  options = {count: 5000, cursor: -1}.merge(args.extract_options!)
  args[0] = verify_credentials(skip_status: true).id if args.empty?
  fetch_cache_or_call_api(__method__, args[0], options) {
    collect_with_cursor("old_#{__method__}", *args, options)
  }
end

#followers(*args) ⇒ Object

specify reduce: false to use tweet for inactive_*



60
61
62
63
64
65
66
67
# File 'lib/ex_twitter/existing_api.rb', line 60

def followers(*args)
  options = {count: 200, include_user_entities: true, cursor: -1}.merge(args.extract_options!)
  options[:reduce] = false unless options.has_key?(:reduce)
  args[0] = verify_credentials(skip_status: true).id if args.empty?
  fetch_cache_or_call_api(__method__, args[0], options) {
    collect_with_cursor("old_#{__method__}", *args, options)
  }
end

#friend_ids(*args) ⇒ Object



33
34
35
36
37
38
39
# File 'lib/ex_twitter/existing_api.rb', line 33

def friend_ids(*args)
  options = {count: 5000, cursor: -1}.merge(args.extract_options!)
  args[0] = verify_credentials(skip_status: true).id if args.empty?
  fetch_cache_or_call_api(__method__, args[0], options) {
    collect_with_cursor("old_#{__method__}", *args, options)
  }
end

#friends(*args) ⇒ Object

specify reduce: false to use tweet for inactive_*



50
51
52
53
54
55
56
57
# File 'lib/ex_twitter/existing_api.rb', line 50

def friends(*args)
  options = {count: 200, include_user_entities: true, cursor: -1}.merge(args.extract_options!)
  options[:reduce] = false unless options.has_key?(:reduce)
  args[0] = verify_credentials(skip_status: true).id if args.empty?
  fetch_cache_or_call_api(__method__, args[0], options) {
    collect_with_cursor("old_#{__method__}", *args, options)
  }
end

#friendship?(*args) ⇒ Boolean

Returns:

  • (Boolean)


10
11
12
13
14
15
# File 'lib/ex_twitter/existing_api.rb', line 10

def friendship?(*args)
  options = args.extract_options!
  fetch_cache_or_call_api(__method__, args) {
    call_old_method("old_#{__method__}", *args, options)
  }
end

#home_timeline(*args) ⇒ Object



89
90
91
92
93
94
# File 'lib/ex_twitter/existing_api.rb', line 89

def home_timeline(*args)
  options = {count: 200, include_rts: true, call_limit: 3}.merge(args.extract_options!)
  fetch_cache_or_call_api(__method__, user.id, options) {
    collect_with_max_id("old_#{__method__}", options)
  }
end

#mentions_timeline(*args) ⇒ Object



104
105
106
107
108
109
# File 'lib/ex_twitter/existing_api.rb', line 104

def mentions_timeline(*args)
  options = {count: 200, include_rts: true, call_limit: 1}.merge(args.extract_options!)
  fetch_cache_or_call_api(__method__, user.id, options) {
    collect_with_max_id("old_#{__method__}", options)
  }
end

#search(*args) ⇒ Object



119
120
121
122
123
124
125
# File 'lib/ex_twitter/existing_api.rb', line 119

def search(*args)
  options = {count: 100, result_type: :recent, call_limit: 1}.merge(args.extract_options!)
  options[:reduce] = false
  fetch_cache_or_call_api(__method__, args[0], options) {
    collect_with_max_id("old_#{__method__}", *args, options) { |response| response.attrs[:statuses] }
  }
end

#user(*args) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/ex_twitter/existing_api.rb', line 25

def user(*args)
  options = args.extract_options!
  args[0] = verify_credentials(skip_status: true).id if args.empty?
  fetch_cache_or_call_api(__method__, args[0], options) {
    call_old_method("old_#{__method__}", args[0], options)
  }
end

#user?(*args) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
20
21
22
23
# File 'lib/ex_twitter/existing_api.rb', line 17

def user?(*args)
  options = args.extract_options!
  args[0] = verify_credentials(skip_status: true).id if args.empty?
  fetch_cache_or_call_api(__method__, args[0], options) {
    call_old_method("old_#{__method__}", args[0], options)
  }
end

#user_timeline(*args) ⇒ Object



96
97
98
99
100
101
102
# File 'lib/ex_twitter/existing_api.rb', line 96

def user_timeline(*args)
  options = {count: 200, include_rts: true, call_limit: 3}.merge(args.extract_options!)
  args[0] = verify_credentials(skip_status: true).id if args.empty?
  fetch_cache_or_call_api(__method__, args[0], options) {
    collect_with_max_id("old_#{__method__}", *args, options)
  }
end

#users(*args) ⇒ Object

use compact, not use sort and uniq specify reduce: false to use tweet for inactive_* TODO Perhaps ‘old_users` automatically merges result…



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/ex_twitter/existing_api.rb', line 72

def users(*args)
  options = args.extract_options!
  options[:reduce] = false
  users_per_workers = args.first.compact.each_slice(100).to_a
  processed_users = []

  Parallel.each_with_index(users_per_workers, in_threads: [users_per_workers.size, 10].min) do |users_per_worker, i|
    _users = fetch_cache_or_call_api(__method__, users_per_worker, options) {
      call_old_method("old_#{__method__}", users_per_worker, options)
    }

    processed_users << {i: i, users: _users}
  end

  processed_users.sort_by{|p| p[:i] }.map{|p| p[:users] }.flatten.compact
end

#verify_credentials(*args) ⇒ Object



3
4
5
6
7
8
# File 'lib/ex_twitter/existing_api.rb', line 3

def verify_credentials(*args)
  options = {skip_status: true}.merge(args.extract_options!)
  fetch_cache_or_call_api(__method__, args) {
    call_old_method("old_#{__method__}", *args, options)
  }
end