t 0.2.1 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,97 +0,0 @@
1
- require 't/core_ext/enumerable'
2
- require 't/rcfile'
3
- require 'thor'
4
- require 'twitter'
5
-
6
- module T
7
- class CLI
8
- class Follow
9
- class All < Thor
10
- DEFAULT_HOST = 'api.twitter.com'
11
- DEFAULT_PROTOCOL = 'https'
12
-
13
- check_unknown_options!
14
-
15
- def initialize(*)
16
- super
17
- @rcfile = RCFile.instance
18
- end
19
-
20
- desc "followers", "Follow all followers."
21
- def followers
22
- follower_ids = []
23
- cursor = -1
24
- until cursor == 0
25
- followers = client.follower_ids(:cursor => cursor)
26
- follower_ids += followers.ids
27
- cursor = followers.next_cursor
28
- end
29
- friend_ids = []
30
- cursor = -1
31
- until cursor == 0
32
- friends = client.friend_ids(:cursor => cursor)
33
- friend_ids += friends.ids
34
- cursor = friends.next_cursor
35
- end
36
- follow_ids = (follower_ids - friend_ids)
37
- number = follow_ids.length
38
- return say "@#{@rcfile.default_profile[0]} is already following all followers." if number.zero?
39
- return unless yes? "Are you sure you want to follow #{number} #{number == 1 ? 'user' : 'users'}?"
40
- screen_names = follow_ids.threaded_map do |follow_id|
41
- client.follow(follow_id, :include_entities => false)
42
- end
43
- say "@#{@rcfile.default_profile[0]} is now following #{number} more #{number == 1 ? 'user' : 'users'}."
44
- say
45
- say "Run `#{$0} unfollow all followers` to stop."
46
- end
47
-
48
- desc "listed LIST_NAME", "Follow all members of a list."
49
- def listed(list_name)
50
- list_member_collection = []
51
- cursor = -1
52
- until cursor == 0
53
- list_members = client.list_members(list_name, :cursor => cursor, :skip_status => true, :include_entities => false)
54
- list_member_collection += list_members.users
55
- cursor = list_members.next_cursor
56
- end
57
- number = list_member_collection.length
58
- return say "@#{@rcfile.default_profile[0]} is already following all list members." if number.zero?
59
- return unless yes? "Are you sure you want to follow #{number} #{number == 1 ? 'user' : 'users'}?"
60
- list_member_collection.threaded_map do |list_member|
61
- client.follow(list_member.id, :include_entities => false)
62
- end
63
- say "@#{@rcfile.default_profile[0]} is now following #{number} more #{number == 1 ? 'user' : 'users'}."
64
- say
65
- say "Run `#{$0} unfollow all listed #{list_name}` to stop."
66
- end
67
-
68
- private
69
-
70
- def base_url
71
- "#{protocol}://#{host}"
72
- end
73
-
74
- def client
75
- return @client if @client
76
- @rcfile.path = parent_options['profile'] if parent_options['profile']
77
- @client = Twitter::Client.new(
78
- :endpoint => base_url,
79
- :consumer_key => @rcfile.default_consumer_key,
80
- :consumer_secret => @rcfile.default_consumer_secret,
81
- :oauth_token => @rcfile.default_token,
82
- :oauth_token_secret => @rcfile.default_secret
83
- )
84
- end
85
-
86
- def host
87
- parent_options['host'] || DEFAULT_HOST
88
- end
89
-
90
- def protocol
91
- parent_options['no_ssl'] ? 'http' : DEFAULT_PROTOCOL
92
- end
93
-
94
- end
95
- end
96
- end
97
- end
@@ -1,169 +0,0 @@
1
- require 'active_support/core_ext/array/grouping'
2
- require 't/rcfile'
3
- require 'thor'
4
- require 'twitter'
5
-
6
- module T
7
- class CLI
8
- class List
9
- class Add
10
- class All < Thor
11
- DEFAULT_HOST = 'api.twitter.com'
12
- DEFAULT_PROTOCOL = 'https'
13
- MAX_USERS_PER_LIST = 500
14
-
15
- check_unknown_options!
16
-
17
- def initialize(*)
18
- super
19
- @rcfile = RCFile.instance
20
- end
21
-
22
- desc "friends LIST_NAME", "Add all friends to a list."
23
- def friends(list_name)
24
- list_member_ids = []
25
- cursor = -1
26
- until cursor == 0
27
- list_members = client.list_members(list_name, :cursor => cursor, :skip_status => true, :include_entities => false)
28
- list_member_ids += list_members.users.collect{|user| user.id}
29
- cursor = list_members.next_cursor
30
- end
31
- existing_list_members = list_member_ids.length
32
- if existing_list_members >= MAX_USERS_PER_LIST
33
- return say "The list \"#{list_name}\" are already contains the maximum of #{MAX_USERS_PER_LIST} members."
34
- end
35
- friend_ids = []
36
- cursor = -1
37
- until cursor == 0
38
- friends = client.friend_ids(:cursor => cursor)
39
- friend_ids += friends.ids
40
- cursor = friends.next_cursor
41
- end
42
- list_member_ids_to_add = (friend_ids - list_member_ids)
43
- number = list_member_ids_to_add.length
44
- if number.zero?
45
- return say "All of @#{@rcfile.default_profile[0]}'s friends are already members of the list \"#{list_name}\"."
46
- elsif existing_list_members + number > MAX_USERS_PER_LIST
47
- return unless yes? "Lists can't have more than #{MAX_USERS_PER_LIST} members. Do you want to add up to #{MAX_USERS_PER_LIST} friends to the list \"#{list_name}\"?"
48
- else
49
- return unless yes? "Are you sure you want to add #{number} #{number == 1 ? 'friend' : 'friends'} to the list \"#{list_name}\"?"
50
- end
51
- max_members_to_add = MAX_USERS_PER_LIST - existing_list_members
52
- list_member_ids_to_add[0...max_members_to_add].in_groups_of(100, false) do |user_id_group|
53
- client.list_add_members(list_name, user_id_group)
54
- end
55
- number_added = [number, max_members_to_add].min
56
- say "@#{@rcfile.default_profile[0]} added #{number_added} #{number_added == 1 ? 'friend' : 'friends'} to the list \"#{list_name}\"."
57
- say
58
- say "Run `#{$0} list remove all friends #{list_name}` to undo."
59
- end
60
-
61
- desc "followers LIST_NAME", "Add all followers to a list."
62
- def followers(list_name)
63
- list_member_ids = []
64
- cursor = -1
65
- until cursor == 0
66
- list_members = client.list_members(list_name, :cursor => cursor, :skip_status => true, :include_entities => false)
67
- list_member_ids += list_members.users.collect{|user| user.id}
68
- cursor = list_members.next_cursor
69
- end
70
- existing_list_members = list_member_ids.length
71
- if existing_list_members >= MAX_USERS_PER_LIST
72
- return say "The list \"#{list_name}\" are already contains the maximum of #{MAX_USERS_PER_LIST} members."
73
- end
74
- follower_ids = []
75
- cursor = -1
76
- until cursor == 0
77
- followers = client.follower_ids(:cursor => cursor)
78
- follower_ids += followers.ids
79
- cursor = followers.next_cursor
80
- end
81
- list_member_ids_to_add = (follower_ids - list_member_ids)
82
- number = list_member_ids_to_add.length
83
- if number.zero?
84
- return say "All of @#{@rcfile.default_profile[0]}'s followers are already members of the list \"#{list_name}\"."
85
- elsif existing_list_members + number > MAX_USERS_PER_LIST
86
- return unless yes? "Lists can't have more than #{MAX_USERS_PER_LIST} members. Do you want to add up to #{MAX_USERS_PER_LIST} followers to the list \"#{list_name}\"?"
87
- else
88
- return unless yes? "Are you sure you want to add #{number} #{number == 1 ? 'follower' : 'followers'} to the list \"#{list_name}\"?"
89
- end
90
- max_members_to_add = MAX_USERS_PER_LIST - existing_list_members
91
- list_member_ids_to_add[0...max_members_to_add].in_groups_of(100, false) do |user_id_group|
92
- client.list_add_members(list_name, user_id_group)
93
- end
94
- number_added = [number, max_members_to_add].min
95
- say "@#{@rcfile.default_profile[0]} added #{number_added} #{number_added == 1 ? 'follower' : 'followers'} to the list \"#{list_name}\"."
96
- say
97
- say "Run `#{$0} list remove all followers #{list_name}` to undo."
98
- end
99
-
100
- desc "listed FROM_LIST_NAME TO_LIST_NAME", "Add all list memebers to a list."
101
- def listed(from_list_name, to_list_name)
102
- to_list_member_ids = []
103
- cursor = -1
104
- until cursor == 0
105
- list_members = client.list_members(to_list_name, :cursor => cursor, :skip_status => true, :include_entities => false)
106
- to_list_member_ids += list_members.users.collect{|user| user.id}
107
- cursor = list_members.next_cursor
108
- end
109
- existing_list_members = to_list_member_ids.length
110
- if existing_list_members >= MAX_USERS_PER_LIST
111
- return say "The list \"#{to_list_name}\" are already contains the maximum of #{MAX_USERS_PER_LIST} members."
112
- end
113
- from_list_member_ids = []
114
- cursor = -1
115
- until cursor == 0
116
- list_members = client.list_members(from_list_name, :cursor => cursor, :skip_status => true, :include_entities => false)
117
- from_list_member_ids += list_members.users.collect{|user| user.id}
118
- cursor = list_members.next_cursor
119
- end
120
- list_member_ids_to_add = (from_list_member_ids - to_list_member_ids)
121
- number = list_member_ids_to_add.length
122
- if number.zero?
123
- return say "All of the members of the list \"#{from_list_name}\" are already members of the list \"#{to_list_name}\"."
124
- elsif existing_list_members + number > MAX_USERS_PER_LIST
125
- return unless yes? "Lists can't have more than #{MAX_USERS_PER_LIST} members. Do you want to add up to #{MAX_USERS_PER_LIST} members to the list \"#{to_list_name}\"?"
126
- else
127
- return unless yes? "Are you sure you want to add #{number} #{number == 1 ? 'member' : 'members'} to the list \"#{to_list_name}\"?"
128
- end
129
- max_members_to_add = MAX_USERS_PER_LIST - existing_list_members
130
- list_member_ids_to_add[0...max_members_to_add].in_groups_of(100, false) do |user_id_group|
131
- client.list_add_members(to_list_name, user_id_group)
132
- end
133
- number_added = [number, max_members_to_add].min
134
- say "@#{@rcfile.default_profile[0]} added #{number_added} #{number_added == 1 ? 'member' : 'members'} to the list \"#{to_list_name}\"."
135
- say
136
- say "Run `#{$0} list remove all listed #{from_list_name} #{to_list_name}` to undo."
137
- end
138
-
139
- private
140
-
141
- def base_url
142
- "#{protocol}://#{host}"
143
- end
144
-
145
- def client
146
- return @client if @client
147
- @rcfile.path = parent_options['profile'] if parent_options['profile']
148
- @client = Twitter::Client.new(
149
- :endpoint => base_url,
150
- :consumer_key => @rcfile.default_consumer_key,
151
- :consumer_secret => @rcfile.default_consumer_secret,
152
- :oauth_token => @rcfile.default_token,
153
- :oauth_token_secret => @rcfile.default_secret
154
- )
155
- end
156
-
157
- def host
158
- parent_options['host'] || DEFAULT_HOST
159
- end
160
-
161
- def protocol
162
- parent_options['no_ssl'] ? 'http' : DEFAULT_PROTOCOL
163
- end
164
-
165
- end
166
- end
167
- end
168
- end
169
- end
@@ -1,163 +0,0 @@
1
- require 't/core_ext/enumerable'
2
- require 't/rcfile'
3
- require 'thor'
4
- require 'twitter'
5
-
6
- module T
7
- class CLI
8
- class List
9
- class Remove
10
- class All < Thor
11
- DEFAULT_HOST = 'api.twitter.com'
12
- DEFAULT_PROTOCOL = 'https'
13
-
14
- check_unknown_options!
15
-
16
- def initialize(*)
17
- super
18
- @rcfile = RCFile.instance
19
- end
20
-
21
- desc "friends LIST_NAME", "Remove all friends from a list."
22
- def friends(list_name)
23
- list_member_ids = []
24
- cursor = -1
25
- until cursor == 0
26
- list_members = client.list_members(list_name, :cursor => cursor, :skip_status => true, :include_entities => false)
27
- list_member_ids += list_members.users.collect{|user| user.id}
28
- cursor = list_members.next_cursor
29
- end
30
- friend_ids = []
31
- cursor = -1
32
- until cursor == 0
33
- friends = client.friend_ids(:cursor => cursor)
34
- friend_ids += friends.ids
35
- cursor = friends.next_cursor
36
- end
37
- list_member_ids_to_remove = (friend_ids - list_member_ids)
38
- number = list_member_ids_to_remove.length
39
- if number.zero?
40
- return say "None of @#{@rcfile.default_profile[0]}'s friends are members of the list \"#{list_name}\"."
41
- else
42
- return unless yes? "Are you sure you want to remove #{number} #{number == 1 ? 'friend' : 'friends'} from the list \"#{list_name}\"?"
43
- end
44
- list_member_ids_to_remove.threaded_map do |list_member_id|
45
- client.list_remove_member(list_name, list_member_id)
46
- end
47
- say "@#{@rcfile.default_profile[0]} removed #{number} #{number == 1 ? 'friend' : 'friends'} from the list \"#{list_name}\"."
48
- say
49
- say "Run `#{$0} list add all friends #{list_name}` to undo."
50
- end
51
-
52
- desc "followers LIST_NAME", "Remove all followers from a list."
53
- def followers(list_name)
54
- list_member_ids = []
55
- cursor = -1
56
- until cursor == 0
57
- list_members = client.list_members(list_name, :cursor => cursor, :skip_status => true, :include_entities => false)
58
- list_member_ids += list_members.users.collect{|user| user.id}
59
- cursor = list_members.next_cursor
60
- end
61
- follower_ids = []
62
- cursor = -1
63
- until cursor == 0
64
- followers = client.follower_ids(:cursor => cursor)
65
- follower_ids += followers.ids
66
- cursor = followers.next_cursor
67
- end
68
- list_member_ids_to_remove = (follower_ids - list_member_ids)
69
- number = list_member_ids_to_remove.length
70
- if number.zero?
71
- return say "None of @#{@rcfile.default_profile[0]}'s followers are members of the list \"#{list_name}\"."
72
- else
73
- return unless yes? "Are you sure you want to remove #{number} #{number == 1 ? 'follower' : 'followers'} from the list \"#{list_name}\"?"
74
- end
75
- list_member_ids_to_remove.threaded_map do |list_member_id|
76
- client.list_remove_member(list_name, list_member_id)
77
- end
78
- say "@#{@rcfile.default_profile[0]} removed #{number} #{number == 1 ? 'follower' : 'followers'} from the list \"#{list_name}\"."
79
- say
80
- say "Run `#{$0} list add all followers #{list_name}` to undo."
81
- end
82
-
83
- desc "listed FROM_LIST_NAME TO_LIST_NAME", "Remove all list members from a list."
84
- def listed(from_list_name, to_list_name)
85
- to_list_member_ids = []
86
- cursor = -1
87
- until cursor == 0
88
- list_members = client.list_members(to_list_name, :cursor => cursor, :skip_status => true, :include_entities => false)
89
- to_list_member_ids += list_members.users.collect{|user| user.id}
90
- cursor = list_members.next_cursor
91
- end
92
- from_list_member_ids = []
93
- cursor = -1
94
- until cursor == 0
95
- list_members = client.list_members(from_list_name, :cursor => cursor, :skip_status => true, :include_entities => false)
96
- from_list_member_ids += list_members.users.collect{|user| user.id}
97
- cursor = list_members.next_cursor
98
- end
99
- list_member_ids_to_remove = (from_list_member_ids - to_list_member_ids)
100
- number = list_member_ids_to_remove.length
101
- if number.zero?
102
- return say "None of the members of the list \"#{from_list_name}\" are members of the list \"#{to_list_name}\"."
103
- else
104
- return unless yes? "Are you sure you want to remove #{number} #{number == 1 ? 'member' : 'members'} from the list \"#{to_list_name}\"?"
105
- end
106
- list_member_ids_to_remove.threaded_map do |list_member_id|
107
- client.list_remove_member(to_list_name, list_member_id)
108
- end
109
- say "@#{@rcfile.default_profile[0]} removed #{number} #{number == 1 ? 'member' : 'members'} from the list \"#{to_list_name}\"."
110
- say
111
- say "Run `#{$0} list add all listed #{from_list_name} #{to_list_name}` to undo."
112
- end
113
-
114
- desc "members LIST_NAME", "Remove all members from a list."
115
- def members(list_name)
116
- list_member_ids = []
117
- cursor = -1
118
- until cursor == 0
119
- list_members = client.list_members(list_name, :cursor => cursor, :skip_status => true, :include_entities => false)
120
- list_member_ids += list_members.users.collect{|user| user.id}
121
- cursor = list_members.next_cursor
122
- end
123
- number = list_member_ids.length
124
- return say "The list \"#{list_name}\" doesn't have any members." if number.zero?
125
- return unless yes? "Are you sure you want to remove #{number} #{number == 1 ? 'member' : 'members'} from the list \"#{list_name}\"?"
126
- list_member_ids.threaded_map do |list_member_id|
127
- client.list_remove_member(list_name, list_member_id)
128
- end
129
- say "@#{@rcfile.default_profile[0]} removed #{number} #{number == 1 ? 'member' : 'members'} from the list \"#{list_name}\"."
130
- end
131
- map %w(users) => :members
132
-
133
- private
134
-
135
- def base_url
136
- "#{protocol}://#{host}"
137
- end
138
-
139
- def client
140
- return @client if @client
141
- @rcfile.path = parent_options['profile'] if parent_options['profile']
142
- @client = Twitter::Client.new(
143
- :endpoint => base_url,
144
- :consumer_key => @rcfile.default_consumer_key,
145
- :consumer_secret => @rcfile.default_consumer_secret,
146
- :oauth_token => @rcfile.default_token,
147
- :oauth_token_secret => @rcfile.default_secret
148
- )
149
- end
150
-
151
- def host
152
- parent_options['host'] || DEFAULT_HOST
153
- end
154
-
155
- def protocol
156
- parent_options['no_ssl'] ? 'http' : DEFAULT_PROTOCOL
157
- end
158
-
159
- end
160
- end
161
- end
162
- end
163
- end
@@ -1,148 +0,0 @@
1
- require 't/core_ext/enumerable'
2
- require 't/rcfile'
3
- require 'thor'
4
- require 'twitter'
5
-
6
- module T
7
- class CLI
8
- class Unfollow
9
- class All < Thor
10
- DEFAULT_HOST = 'api.twitter.com'
11
- DEFAULT_PROTOCOL = 'https'
12
-
13
- check_unknown_options!
14
-
15
- def initialize(*)
16
- super
17
- @rcfile = RCFile.instance
18
- end
19
-
20
- desc "listed LIST_NAME", "Unfollow all members of a list."
21
- def listed(list_name)
22
- list_member_collection = []
23
- cursor = -1
24
- until cursor == 0
25
- list_members = client.list_members(list_name, :cursor => cursor, :include_entities => false, :skip_status => true)
26
- list_member_collection += list_members.users
27
- cursor = list_members.next_cursor
28
- end
29
- number = list_member_collection.length
30
- return say "@#{@rcfile.default_profile[0]} is already not following any list members." if number.zero?
31
- return unless yes? "Are you sure you want to unfollow #{number} #{number == 1 ? 'user' : 'users'}?"
32
- list_member_collection.threaded_map do |list_member|
33
- client.unfollow(list_member.id, :include_entities => false)
34
- end
35
- say "@#{@rcfile.default_profile[0]} is no longer following #{number} #{number == 1 ? 'user' : 'users'}."
36
- say
37
- say "Run `#{$0} follow all listed #{list_name}` to follow again."
38
- end
39
-
40
- desc "followers", "Unfollow all followers."
41
- def followers
42
- follower_ids = []
43
- cursor = -1
44
- until cursor == 0
45
- followers = client.follower_ids(:cursor => cursor)
46
- follower_ids += followers.ids
47
- cursor = followers.next_cursor
48
- end
49
- friend_ids = []
50
- cursor = -1
51
- until cursor == 0
52
- friends = client.friend_ids(:cursor => cursor)
53
- friend_ids += friends.ids
54
- cursor = friends.next_cursor
55
- end
56
- follow_ids = (follower_ids - friend_ids)
57
- number = follow_ids.length
58
- return say "@#{@rcfile.default_profile[0]} is already not following any followers." if number.zero?
59
- return unless yes? "Are you sure you want to unfollow #{number} #{number == 1 ? 'user' : 'users'}?"
60
- screen_names = follow_ids.threaded_map do |follow_id|
61
- client.unfollow(follow_id, :include_entities => false)
62
- end
63
- say "@#{@rcfile.default_profile[0]} is no longer following #{number} #{number == 1 ? 'user' : 'users'}."
64
- say
65
- say "Run `#{$0} follow all followers` to stop."
66
- end
67
-
68
- desc "nonfollowers", "Unfollow all non-followers."
69
- def nonfollowers
70
- friend_ids = []
71
- cursor = -1
72
- until cursor == 0
73
- friends = client.friend_ids(:cursor => cursor)
74
- friend_ids += friends.ids
75
- cursor = friends.next_cursor
76
- end
77
- follower_ids = []
78
- cursor = -1
79
- until cursor == 0
80
- followers = client.follower_ids(:cursor => cursor)
81
- follower_ids += followers.ids
82
- cursor = followers.next_cursor
83
- end
84
- unfollow_ids = (friend_ids - follower_ids)
85
- number = unfollow_ids.length
86
- return say "@#{@rcfile.default_profile[0]} is already not following any non-followers." if number.zero?
87
- return unless yes? "Are you sure you want to unfollow #{number} #{number == 1 ? 'user' : 'users'}?"
88
- screen_names = unfollow_ids.threaded_map do |unfollow_id|
89
- user = client.unfollow(unfollow_id, :include_entities => false)
90
- user.screen_name
91
- end
92
- say "@#{@rcfile.default_profile[0]} is no longer following #{number} #{number == 1 ? 'user' : 'users'}."
93
- say
94
- say "Run `#{$0} follow users #{screen_names.join(' ')}` to follow again."
95
- end
96
-
97
- desc "users", "Unfollow all users."
98
- def users
99
- friend_ids = []
100
- cursor = -1
101
- until cursor == 0
102
- friends = client.friend_ids(:cursor => cursor)
103
- friend_ids += friends.ids
104
- cursor = friends.next_cursor
105
- end
106
- number = friend_ids.length
107
- return say "@#{@rcfile.default_profile[0]} is already not following anyone." if number.zero?
108
- return unless yes? "Are you sure you want to unfollow #{number} #{number == 1 ? 'user' : 'users'}?"
109
- screen_names = friend_ids.threaded_map do |friend_id|
110
- user = client.unfollow(friend_id, :include_entities => false)
111
- user.screen_name
112
- end
113
- say "@#{@rcfile.default_profile[0]} is no longer following #{number} #{number == 1 ? 'user' : 'users'}."
114
- say
115
- say "Run `#{$0} follow users #{screen_names.join(' ')}` to follow again."
116
- end
117
- map %w(friends) => :users
118
-
119
- private
120
-
121
- def base_url
122
- "#{protocol}://#{host}"
123
- end
124
-
125
- def client
126
- return @client if @client
127
- @rcfile.path = parent_options['profile'] if parent_options['profile']
128
- @client = Twitter::Client.new(
129
- :endpoint => base_url,
130
- :consumer_key => @rcfile.default_consumer_key,
131
- :consumer_secret => @rcfile.default_consumer_secret,
132
- :oauth_token => @rcfile.default_token,
133
- :oauth_token_secret => @rcfile.default_secret
134
- )
135
- end
136
-
137
- def host
138
- parent_options['host'] || DEFAULT_HOST
139
- end
140
-
141
- def protocol
142
- parent_options['no_ssl'] ? 'http' : DEFAULT_PROTOCOL
143
- end
144
-
145
- end
146
- end
147
- end
148
- end