twitter_with_auto_pagination 0.4.0 → 0.5.0
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c3b148014f092aee0b2daa1893c109dbb8ae1b00
|
4
|
+
data.tar.gz: 5e1f994fa4185d4d6db93e81aef1c014aa1ae21a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c5852ccf3eed3bf1848abff90fecc408d157fce3d896b7e938b2a98f5289e4407fa79cc0372d15cad9989cc088864786d4d6dd8b2c3cc1d523eff0928a338d79
|
7
|
+
data.tar.gz: bb4230a5ae87e4cc12450febefa4c76d207f99def578cd49a164536f55e76512b73f4f6ec34a900270025d5201d453cada3b35b1f923956f2fe43a8b73abedc9
|
data/README.md
CHANGED
@@ -1,52 +1,151 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
twitter-with-auto-pagination
|
2
|
+
============================
|
3
3
|
|
4
|
-
[![Gem Version](https://badge.fury.io/rb/ex_twitter.png)](https://badge.fury.io/rb/
|
5
|
-
[![Build Status](https://travis-ci.org/ts-3156/ex-twitter.svg?branch=master)](https://travis-ci.org/ts-3156/
|
4
|
+
[![Gem Version](https://badge.fury.io/rb/ex_twitter.png)](https://badge.fury.io/rb/twitter_with_auto_pagination)
|
5
|
+
[![Build Status](https://travis-ci.org/ts-3156/ex-twitter.svg?branch=master)](https://travis-ci.org/ts-3156/twitter-with-auto-pagination)
|
6
6
|
|
7
|
-
Add auto
|
7
|
+
Add auto pagination, auto caching and parallelly fetching features to Twitter gem.
|
8
8
|
|
9
9
|
## Installation
|
10
10
|
|
11
11
|
### Gem
|
12
12
|
|
13
13
|
```
|
14
|
-
gem install
|
14
|
+
gem install twitter_with_auto_pagination
|
15
15
|
```
|
16
16
|
|
17
17
|
### Rails
|
18
18
|
|
19
|
-
Add
|
19
|
+
Add `twitter_with_auto_pagination` to your Gemfile, and bundle.
|
20
20
|
|
21
21
|
## Features
|
22
22
|
|
23
|
-
* Auto
|
23
|
+
* Auto pagination
|
24
|
+
* Auto caching
|
25
|
+
* Parallelly fetching
|
24
26
|
|
25
27
|
## Configuration
|
26
28
|
|
27
|
-
You can pass configuration options as a block to `
|
29
|
+
You can pass configuration options as a block to `TwitterWithAutoPagination::Client.new` just like `Twitter::REST::Client.new`.
|
28
30
|
|
29
31
|
```
|
30
|
-
client =
|
32
|
+
client = TwitterWithAutoPagination::Client.new do |config|
|
31
33
|
config.consumer_key = "YOUR_CONSUMER_KEY"
|
32
34
|
config.consumer_secret = "YOUR_CONSUMER_SECRET"
|
33
35
|
config.access_token = "YOUR_ACCESS_TOKEN"
|
34
36
|
config.access_token_secret = "YOUR_ACCESS_SECRET"
|
37
|
+
config.log_level = :debug # optional
|
38
|
+
config.logger = Logger.new(STDOUT) # optional
|
35
39
|
end
|
36
40
|
```
|
37
41
|
|
38
|
-
|
42
|
+
## Usage Examples
|
43
|
+
|
44
|
+
After configuring a `client`, you can do the following things.
|
45
|
+
|
46
|
+
### Pre-existing and enhanced APIs
|
47
|
+
|
48
|
+
Fetch the timeline of Tweets (by screen name or user ID, or by implicit authenticated user)
|
39
49
|
|
40
50
|
```
|
41
|
-
client
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
51
|
+
client.user_timeline('gem')
|
52
|
+
client.user_timeline(213747670)
|
53
|
+
client.user_timeline
|
54
|
+
|
55
|
+
result.size
|
56
|
+
# => 588
|
57
|
+
|
58
|
+
result.first.text
|
59
|
+
# => "Your tweet text..."
|
60
|
+
|
61
|
+
result.first.user.screen_name
|
62
|
+
# => "your_screen_name"
|
46
63
|
```
|
47
64
|
|
48
|
-
|
65
|
+
Fetch the timeline of Tweets from the authenticated user's home page
|
49
66
|
|
50
67
|
```
|
51
|
-
client.
|
68
|
+
client.home_timeline
|
69
|
+
```
|
70
|
+
|
71
|
+
Fetch the timeline of Tweets mentioning the authenticated user
|
72
|
+
|
73
|
+
```
|
74
|
+
client.mentions_timeline
|
75
|
+
```
|
76
|
+
|
77
|
+
Fetch all friends's user IDs (by screen name or user ID, or by implicit authenticated user)
|
78
|
+
|
79
|
+
```
|
80
|
+
client.friend_ids('gem')
|
81
|
+
client.friend_ids(213747670)
|
82
|
+
client.friend_ids
|
83
|
+
```
|
84
|
+
|
85
|
+
Fetch all followers's user IDs (by screen name or user ID, or by implicit authenticated user)
|
86
|
+
|
87
|
+
```
|
88
|
+
client.follower_ids('gem')
|
89
|
+
client.follower_ids(213747670)
|
90
|
+
client.follower_ids
|
91
|
+
```
|
92
|
+
|
93
|
+
Fetch all friends with profile details (by screen name or user ID, or by implicit authenticated user)
|
94
|
+
|
95
|
+
```
|
96
|
+
client.friends('gem')
|
97
|
+
client.friends(213747670)
|
98
|
+
client.friends
|
99
|
+
```
|
100
|
+
|
101
|
+
Fetch all followers with profile details (by screen name or user ID, or by implicit authenticated user)
|
102
|
+
|
103
|
+
```
|
104
|
+
client.followers('gem')
|
105
|
+
client.followers(213747670)
|
106
|
+
client.followers
|
107
|
+
```
|
108
|
+
|
109
|
+
Other APIs(e.g. `favorites`, `search`) also have auto pagination feature.
|
110
|
+
|
111
|
+
### New APIs
|
112
|
+
|
113
|
+
```
|
114
|
+
client.mutual_friends
|
115
|
+
```
|
116
|
+
|
117
|
+
```
|
118
|
+
client.one_sided_friends
|
119
|
+
```
|
120
|
+
|
121
|
+
```
|
122
|
+
client.one_sided_followers
|
123
|
+
```
|
124
|
+
|
125
|
+
```
|
126
|
+
client.common_friends(me, you)
|
127
|
+
```
|
128
|
+
|
129
|
+
```
|
130
|
+
client.common_followers(me, you)
|
131
|
+
```
|
132
|
+
|
133
|
+
```
|
134
|
+
client.close_friends
|
135
|
+
```
|
136
|
+
|
137
|
+
```
|
138
|
+
client.removed(pre_me, cur_me)
|
139
|
+
```
|
140
|
+
|
141
|
+
```
|
142
|
+
client.removed_by(pre_me, cur_me)
|
143
|
+
```
|
144
|
+
|
145
|
+
```
|
146
|
+
client.replied
|
147
|
+
```
|
148
|
+
|
149
|
+
```
|
150
|
+
client.replied_by
|
52
151
|
```
|
@@ -20,13 +20,15 @@ module TwitterWithAutoPagination
|
|
20
20
|
@uid = options.has_key?(:uid) ? options.delete(:uid).to_i : nil
|
21
21
|
@screen_name = options.has_key?(:screen_name) ? options.delete(:screen_name).to_s : nil
|
22
22
|
|
23
|
-
|
24
|
-
if options
|
23
|
+
logger =
|
24
|
+
if options.has_key?(:logger)
|
25
25
|
options.delete(:logger)
|
26
26
|
else
|
27
27
|
Dir.mkdir('log') unless File.exists?('log')
|
28
28
|
Logger.new('log/twitter_with_auto_pagination.log')
|
29
29
|
end
|
30
|
+
logger.level = options.has_key?(:log_level) ? options.delete(:log_level) : :debug
|
31
|
+
@@logger = @logger = logger
|
30
32
|
|
31
33
|
super
|
32
34
|
end
|
@@ -37,8 +37,10 @@ module TwitterWithAutoPagination
|
|
37
37
|
{method: :user_timeline, args: args}])
|
38
38
|
end
|
39
39
|
|
40
|
-
def
|
41
|
-
if
|
40
|
+
def one_sided_friends(me = nil)
|
41
|
+
if me.nil?
|
42
|
+
friends_parallelly.to_a - followers_parallelly.to_a
|
43
|
+
elsif uid_or_screen_name?(me)
|
42
44
|
# TODO use friends_and_followers
|
43
45
|
friends_parallelly(me).to_a - followers_parallelly(me).to_a
|
44
46
|
elsif me.respond_to?(:friends) && me.respond_to?(:followers)
|
@@ -48,8 +50,10 @@ module TwitterWithAutoPagination
|
|
48
50
|
end
|
49
51
|
end
|
50
52
|
|
51
|
-
def one_sided_followers(me)
|
52
|
-
if
|
53
|
+
def one_sided_followers(me = nil)
|
54
|
+
if me.nil?
|
55
|
+
followers_parallelly.to_a - friends_parallelly.to_a
|
56
|
+
elsif uid_or_screen_name?(me)
|
53
57
|
# TODO use friends_and_followers
|
54
58
|
followers_parallelly(me).to_a - friends_parallelly(me).to_a
|
55
59
|
elsif me.respond_to?(:friends) && me.respond_to?(:followers)
|
@@ -59,8 +63,10 @@ module TwitterWithAutoPagination
|
|
59
63
|
end
|
60
64
|
end
|
61
65
|
|
62
|
-
def mutual_friends(me)
|
63
|
-
if
|
66
|
+
def mutual_friends(me = nil)
|
67
|
+
if me.nil?
|
68
|
+
friends_parallelly.to_a & followers_parallelly.to_a
|
69
|
+
elsif uid_or_screen_name?(me)
|
64
70
|
# TODO use friends_and_followers
|
65
71
|
friends_parallelly(me).to_a & followers_parallelly(me).to_a
|
66
72
|
elsif me.respond_to?(:friends) && me.respond_to?(:followers)
|
@@ -90,7 +96,7 @@ module TwitterWithAutoPagination
|
|
90
96
|
end
|
91
97
|
end
|
92
98
|
|
93
|
-
def
|
99
|
+
def removed(pre_me, cur_me)
|
94
100
|
if uid_or_screen_name?(pre_me) && uid_or_screen_name?(cur_me)
|
95
101
|
friends_parallelly(pre_me).to_a - friends_parallelly(cur_me).to_a
|
96
102
|
elsif pre_me.respond_to?(:friends) && cur_me.respond_to?(:friends)
|
@@ -100,7 +106,7 @@ module TwitterWithAutoPagination
|
|
100
106
|
end
|
101
107
|
end
|
102
108
|
|
103
|
-
def
|
109
|
+
def removed_by(pre_me, cur_me)
|
104
110
|
if uid_or_screen_name?(pre_me) && uid_or_screen_name?(cur_me)
|
105
111
|
followers_parallelly(pre_me).to_a - followers_parallelly(cur_me).to_a
|
106
112
|
elsif pre_me.respond_to?(:followers) && cur_me.respond_to?(:followers)
|
@@ -118,7 +124,7 @@ module TwitterWithAutoPagination
|
|
118
124
|
|
119
125
|
# users which specified user is replying
|
120
126
|
# in_reply_to_user_id and in_reply_to_status_id is not used because of distinguishing mentions from replies
|
121
|
-
def
|
127
|
+
def replied(*args)
|
122
128
|
options = args.extract_options!
|
123
129
|
tweets =
|
124
130
|
if args.empty?
|
@@ -157,7 +163,7 @@ module TwitterWithAutoPagination
|
|
157
163
|
|
158
164
|
# users which specified user is replied
|
159
165
|
# when user is login you had better to call mentions_timeline
|
160
|
-
def
|
166
|
+
def replied_by(*args)
|
161
167
|
options = args.extract_options!
|
162
168
|
|
163
169
|
result =
|
@@ -192,7 +198,7 @@ module TwitterWithAutoPagination
|
|
192
198
|
end.flatten
|
193
199
|
end
|
194
200
|
|
195
|
-
def
|
201
|
+
def users_you_faved(*args)
|
196
202
|
options = args.extract_options!
|
197
203
|
|
198
204
|
favs =
|
@@ -229,7 +235,7 @@ module TwitterWithAutoPagination
|
|
229
235
|
end
|
230
236
|
end
|
231
237
|
|
232
|
-
def
|
238
|
+
def users_fav_you(*args)
|
233
239
|
end
|
234
240
|
|
235
241
|
def close_friends(*args)
|
@@ -7,14 +7,14 @@ module TwitterWithAutoPagination
|
|
7
7
|
|
8
8
|
def __uid
|
9
9
|
ActiveSupport::Deprecation.warn(<<-MESSAGE.strip_heredoc)
|
10
|
-
`TwitterWithAutoPagination::Utils
|
10
|
+
`TwitterWithAutoPagination::Utils##{__method__}` is deprecated.
|
11
11
|
MESSAGE
|
12
12
|
uid
|
13
13
|
end
|
14
14
|
|
15
15
|
def __uid_i
|
16
16
|
ActiveSupport::Deprecation.warn(<<-MESSAGE.strip_heredoc)
|
17
|
-
`TwitterWithAutoPagination::Utils
|
17
|
+
`TwitterWithAutoPagination::Utils##{__method__}` is deprecated.
|
18
18
|
MESSAGE
|
19
19
|
uid
|
20
20
|
end
|
@@ -26,7 +26,7 @@ module TwitterWithAutoPagination
|
|
26
26
|
|
27
27
|
def __screen_name
|
28
28
|
ActiveSupport::Deprecation.warn(<<-MESSAGE.strip_heredoc)
|
29
|
-
`TwitterWithAutoPagination::Utils
|
29
|
+
`TwitterWithAutoPagination::Utils##{__method__}` is deprecated.
|
30
30
|
MESSAGE
|
31
31
|
screen_name
|
32
32
|
end
|