Module: TwitterFriendly::REST::FriendsAndFollowers
- Included in:
- API
- Defined in:
- lib/twitter_friendly/rest/friends_and_followers.rb
Constant Summary collapse
- MAX_IDS_PER_REQUEST =
5000
Instance Method Summary collapse
- #follower_ids(*args) ⇒ Object
- #followers(*args) ⇒ Object
- #friend_ids(*args) ⇒ Hash
- #friend_ids_and_follower_ids(*args) ⇒ Object
- #friends(*args) ⇒ Hash
- #friends_and_followers(*args) ⇒ Object
- #friendship?(from, to, options = {}) ⇒ Boolean
Instance Method Details
#follower_ids(*args) ⇒ Object
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/twitter_friendly/rest/friends_and_followers.rb', line 31 def follower_ids(*args) = {count: MAX_IDS_PER_REQUEST}.merge(args.) args << if .has_key?(:cursor) @twitter.follower_ids(*args)&.attrs else fetch_resources_with_cursor(__method__, *args) end end |
#followers(*args) ⇒ Object
55 56 57 58 |
# File 'lib/twitter_friendly/rest/friends_and_followers.rb', line 55 def followers(*args) ids = follower_ids(*args) users(ids) end |
#friend_ids(options = {}) ⇒ Hash #friend_ids(user, options = {}) ⇒ Hash
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/twitter_friendly/rest/friends_and_followers.rb', line 20 def friend_ids(*args) = {count: MAX_IDS_PER_REQUEST}.merge(args.) args << if .has_key?(:cursor) @twitter.friend_ids(*args)&.attrs else fetch_resources_with_cursor(__method__, *args) end end |
#friend_ids_and_follower_ids(*args) ⇒ Object
60 61 62 63 64 65 |
# File 'lib/twitter_friendly/rest/friends_and_followers.rb', line 60 def friend_ids_and_follower_ids(*args) parallel(in_threads: 2) do |batch| batch.friend_ids(*args) batch.follower_ids(*args) end end |
#friends(options = {}) ⇒ Hash #friends(user, options = {}) ⇒ Hash
50 51 52 53 |
# File 'lib/twitter_friendly/rest/friends_and_followers.rb', line 50 def friends(*args) ids = friend_ids(*args) users(ids) end |
#friends_and_followers(*args) ⇒ Object
67 68 69 70 71 |
# File 'lib/twitter_friendly/rest/friends_and_followers.rb', line 67 def friends_and_followers(*args) following_ids, followed_ids = friend_ids_and_follower_ids(*args) people = users((following_ids + followed_ids).uniq).index_by { |u| u[:id] } [people.slice(*following_ids).values, people.slice(*followed_ids).values] end |
#friendship?(from, to, options = {}) ⇒ Boolean
6 7 8 |
# File 'lib/twitter_friendly/rest/friends_and_followers.rb', line 6 def friendship?(from, to, = {}) @twitter.send(__method__, from, to, ) end |