twitter_with_auto_pagination 0.9.2 → 0.9.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 73b476c241a1ead8ec18d68ceccee2ca25d1a04f
4
- data.tar.gz: 90f9d722d8d41c04cc79995c0c603553e5eda950
3
+ metadata.gz: 8e6d62667d58aad44e53e4899aa19aefcfc9bd52
4
+ data.tar.gz: 30e641dc1fbae06370e82aae2194a350b9220f0f
5
5
  SHA512:
6
- metadata.gz: a33128d1fc01cfe4cd25266c4996b2f7cea639984c6dda91b11836ef0682151980a9fe8508cd98591b97ff782556b02b013de76d5c9ca4699275e0eef3cd0c43
7
- data.tar.gz: 425c05ee367fe15e668d1392c600efca5f684a8fac3486877a458f606de4741520ec6db25d45ba8f62b8fbf7ba3282da4f4a7edced5cf362cb46114d4f939f42
6
+ metadata.gz: 3834eb85fb20cb6967f82036605b7272d1f550d8d3f0399baa88fe361a487c3d3d7e1fea296fe3955fc8af8319cfe98b35bd1e2bf394c1a9f5ca38bbf1a4de93
7
+ data.tar.gz: 509bc8bfac522574b4fde7399970306bbc7124718973093400ee29dc563f867ca6d895f5b0236f796890a1b51f53f0104c3a3272c03590ffd2f2da206422e554
@@ -15,11 +15,30 @@ module TwitterWithAutoPagination
15
15
  end
16
16
 
17
17
  class Arguments < Array
18
- %i(users friend_ids follower_ids friends followers).each do |name|
18
+ %i(
19
+ users
20
+ friend_ids
21
+ follower_ids
22
+ friends
23
+ followers
24
+ home_timeline
25
+ user_timeline
26
+ mentions_timeline
27
+ search
28
+ favorites
29
+ ).each do |name|
19
30
  define_method(name) do |*args|
20
31
  send(:<< , [name, *args])
21
32
  end
22
33
  end
23
34
  end
35
+
36
+ # Deprecated
37
+ # [{method: :friends, args: ['ts_3156', ...], {...}]
38
+ def fetch_parallelly(signatures)
39
+ ::Parallel.map_with_index(signatures, in_threads: signatures.size) do |signature, i|
40
+ {i: i, result: send(signature[:method], *signature[:args])}
41
+ end.sort_by { |q| q[:i] }.map { |q| q[:result] }
42
+ end
24
43
  end
25
- end
44
+ end
@@ -5,9 +5,8 @@ require 'twitter_with_auto_pagination/rest/search'
5
5
  require 'twitter_with_auto_pagination/rest/timelines'
6
6
  require 'twitter_with_auto_pagination/rest/users'
7
7
 
8
- # require 'twitter_with_auto_pagination/rest/extension/clusters'
8
+ require 'twitter_with_auto_pagination/rest/extension/clusters'
9
9
  # require 'twitter_with_auto_pagination/rest/extension/favoriting'
10
- # require 'twitter_with_auto_pagination/rest/extension/friends_and_followers'
11
10
  # require 'twitter_with_auto_pagination/rest/extension/replying'
12
11
  # require 'twitter_with_auto_pagination/rest/extension/unfollowing'
13
12
  # require 'twitter_with_auto_pagination/rest/extension/users'
@@ -24,9 +23,8 @@ module TwitterWithAutoPagination
24
23
  include TwitterWithAutoPagination::REST::Timelines
25
24
  include TwitterWithAutoPagination::REST::Users
26
25
 
27
- # include TwitterWithAutoPagination::REST::Extension::Clusters
26
+ include TwitterWithAutoPagination::REST::Extension::Clusters
28
27
  # include TwitterWithAutoPagination::REST::Extension::Favoriting
29
- # include TwitterWithAutoPagination::REST::Extension::FriendsAndFollowers
30
28
  # include TwitterWithAutoPagination::REST::Extension::Replying
31
29
  # include TwitterWithAutoPagination::REST::Extension::Unfollowing
32
30
  # include TwitterWithAutoPagination::REST::Extension::Users
@@ -21,5 +21,5 @@ Gem::Specification.new do |spec|
21
21
  spec.required_ruby_version = '>= 2.3'
22
22
  spec.summary = spec.description
23
23
  spec.test_files = Dir.glob('spec/**/*')
24
- spec.version = '0.9.2'
24
+ spec.version = '0.9.3'
25
25
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: twitter_with_auto_pagination
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.2
4
+ version: 0.9.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shinohara Teruki
@@ -90,7 +90,6 @@ files:
90
90
  - lib/twitter_with_auto_pagination/rest/api.rb
91
91
  - lib/twitter_with_auto_pagination/rest/extension/clusters.rb
92
92
  - lib/twitter_with_auto_pagination/rest/extension/favoriting.rb
93
- - lib/twitter_with_auto_pagination/rest/extension/friends_and_followers.rb
94
93
  - lib/twitter_with_auto_pagination/rest/extension/replying.rb
95
94
  - lib/twitter_with_auto_pagination/rest/extension/unfollowing.rb
96
95
  - lib/twitter_with_auto_pagination/rest/extension/users.rb
@@ -1,124 +0,0 @@
1
- require 'twitter_with_auto_pagination/rest/utils'
2
- require 'parallel'
3
-
4
- module TwitterWithAutoPagination
5
- module REST
6
- module Extension
7
- module FriendsAndFollowers
8
- include TwitterWithAutoPagination::REST::Utils
9
-
10
- def _fetch_parallelly(signatures) # [{method: :friends, args: ['ts_3156', ...], {...}]
11
- result = Array.new(signatures.size)
12
-
13
- Parallel.each_with_index(signatures, in_threads: result.size) do |signature, i|
14
- result[i] = send(signature[:method], *signature[:args])
15
- end
16
-
17
- result
18
- end
19
-
20
- def friends_followers_and_statuses(*args)
21
- _fetch_parallelly(
22
- [
23
- {method: :friends, args: args},
24
- {method: :followers, args: args},
25
- {method: :user_timeline, args: args}])
26
- end
27
-
28
- def _retrieve_friends_and_followers(*args)
29
- obj = args[0]
30
- if obj.nil?
31
- friends_and_followers
32
- elsif uid_or_screen_name?(obj)
33
- friends_and_followers(obj)
34
- elsif obj.respond_to?(:friends) && obj.respond_to?(:followers)
35
- [obj.friends, obj.followers]
36
- else
37
- raise ArgumentError, args.inspect
38
- end
39
- end
40
-
41
- def one_sided_friends(me = nil)
42
- instrument(__method__, nil) do
43
- _friends, _followers = _retrieve_friends_and_followers(me)
44
- _friends.to_a - _followers.to_a
45
- end
46
- end
47
-
48
- def one_sided_followers(me = nil)
49
- instrument(__method__, nil) do
50
- _friends, _followers = _retrieve_friends_and_followers(me)
51
- _followers.to_a - _friends.to_a
52
- end
53
- end
54
-
55
- def mutual_friends(me = nil)
56
- instrument(__method__, nil) do
57
- _friends, _followers = _retrieve_friends_and_followers(me)
58
- _friends.to_a & _followers.to_a
59
- end
60
- end
61
-
62
- def _retrieve_friends(*args)
63
- if args.size == 1
64
- args[0].nil? ? friends : friends(args[0])
65
- elsif args.all? { |obj| uid_or_screen_name?(obj) }
66
- _fetch_parallelly(args.map { |obj| {method: :friends, args: [obj]} })
67
- elsif args.all? { |obj| obj.respond_to?(:friends) }
68
- args.map { |obj| obj.friends }
69
- else
70
- raise ArgumentError, args.inspect
71
- end
72
- end
73
-
74
- def common_friends(me, you)
75
- instrument(__method__, nil) do
76
- my_friends, your_friends = _retrieve_friends(me, you)
77
- my_friends.to_a & your_friends.to_a
78
- end
79
- end
80
-
81
- def _retrieve_followers(*args)
82
- if args.size == 1
83
- args[0].nil? ? followers : followers(args[0])
84
- elsif args.all? { |obj| uid_or_screen_name?(obj) }
85
- _fetch_parallelly(args.map { |obj| {method: :followers, args: [obj]} })
86
- elsif args.all? { |obj| obj.respond_to?(:followers) }
87
- args.map { |obj| obj.followers }
88
- else
89
- raise ArgumentError, args.inspect
90
- end
91
- end
92
-
93
- def common_followers(me, you)
94
- instrument(__method__, nil) do
95
- my_followers, your_followers = _retrieve_followers(me, you)
96
- my_followers.to_a & your_followers.to_a
97
- end
98
- end
99
-
100
- def _extract_inactive_users(users)
101
- two_weeks_ago = 2.weeks.ago.to_i
102
- users.select do |u|
103
- (Time.parse(u.status.created_at).to_i < two_weeks_ago) rescue false
104
- end
105
- end
106
-
107
- def inactive_friends(user = nil)
108
- instrument(__method__, nil) do
109
- _friends = _retrieve_friends(user)
110
- _extract_inactive_users(_friends)
111
- end
112
- end
113
-
114
- def inactive_followers(user = nil)
115
- instrument(__method__, nil) do
116
- _followers = _retrieve_followers(user)
117
- _extract_inactive_users(_followers)
118
- end
119
- end
120
- end
121
- end
122
- end
123
- end
124
-