pry-send_tweet.rb 0.6.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,184 +0,0 @@
1
- class Pry::SendTweet::TwitterAction < Pry::SendTweet::BaseCommand
2
- match 'twitter-action'
3
- description 'Like, unlike, follow, unfollow and more'
4
- banner <<-B
5
- twitter-action OPTIONS
6
-
7
- Like, unlike, follow, unfollow and more.
8
- B
9
-
10
- def options(o)
11
- #
12
- # Like / unlike tweets
13
- #
14
- o.on 'like-tweet=', 'Like a tweet'
15
- o.on 'unlike-tweet=', 'Unlike a tweet'
16
- #
17
- # Follow / unfollow a user
18
- #
19
- o.on 'follow=', 'Follow a user'
20
- o.on 'unfollow=', 'Unfollow a user'
21
- #
22
- # Delete tweets and reweets
23
- #
24
- o.on 'delete-retweet=', 'Delete a retweet'
25
- o.on 'delete-tweet=', 'Delete a tweet'
26
- #
27
- # Retweet a tweet
28
- #
29
- o.on 'retweet=', 'Retweet a tweet'
30
- #
31
- # Profile management
32
- #
33
- o.on 'set-profile-bio', 'Set your profiles bio'
34
- o.on 'set-profile-url=', 'Set the URL associated with your profile'
35
- o.on 'set-profile-banner-image=', 'Set your profiles banner image'
36
- o.on 'set-profile-name=', 'Set the name associated with your profile'
37
- o.on 'set-profile-image=', 'Set your profile image'
38
- end
39
-
40
- def process
41
- super
42
- case
43
- when opts.present?('like-tweet') then like_tweet
44
- when opts.present?('unlike-tweet') then unlike_tweet
45
- when opts.present?('follow') then follow_user
46
- when opts.present?('unfollow') then unfollow_user
47
- when opts.present?('delete-tweet') then delete_tweet
48
- when opts.present?('delete-retweet') then delete_retweet
49
- when opts.present?('retweet') then retweet_tweet
50
- when opts.present?('set-profile-banner-image') then set_profile_banner_image
51
- when opts.present?('set-profile-bio') then set_profile_bio
52
- when opts.present?('set-profile-name') then set_profile_name
53
- when opts.present?('set-profile-image') then set_profile_image
54
- when opts.present?('set-profile-url') then set_profile_url(opts['set-profile-url'])
55
- end
56
- end
57
-
58
- private
59
-
60
- def set_profile_url(url)
61
- if client.update_profile url: url
62
- page "Profile URL updated"
63
- else
64
- raise Pry::CommandError, "Something went wrong"
65
- end
66
- end
67
-
68
- def set_profile_image
69
- path = opts['set-profile-image']
70
- if client.update_profile_image path
71
- page "Profile image updated"
72
- else
73
- raise Pry::CommandError, "Something went wrong"
74
- end
75
- end
76
-
77
- def set_profile_banner_image
78
- path = opts['set-profile-banner-image']
79
- if client.update_profile_banner Base64.strict_encode64(File.binread(path))
80
- page "Profile banner updated"
81
- else
82
- raise Pry::CommandError, "Something went wrong"
83
- end
84
- end
85
-
86
- def set_profile_name
87
- client.update_profile name: opts['set-profile-name']
88
- page "Profile name updated"
89
- end
90
-
91
- def set_profile_bio
92
- Tempfile.open('pry-send_tweet-set-bio') do |file|
93
- Pry::Editor.new(_pry_).invoke_editor(file.path, 0)
94
- file.rewind
95
- client.update_profile description: file.read
96
- page "Profile bio updated"
97
- end
98
- end
99
-
100
- def retweet_tweet
101
- tweet_url = opts['retweet']
102
- if !client.retweet(tweet_url).empty?
103
- page "Tweet retweeted"
104
- else
105
- raise Pry::CommandError, "Something went wrong"
106
- end
107
- end
108
-
109
- def like_tweet
110
- tweets = client.favorite(opts['like-tweet'])
111
- if tweets.any?
112
- render_tweets tweets, title: bold("Liked tweets"), timeout: false
113
- else
114
- page "Tweet was not liked. Maybe you liked that tweet already?"
115
- end
116
- end
117
-
118
- def unlike_tweet
119
- tweets = client.unfavorite(opts['unlike-tweet'])
120
- if tweets.any?
121
- render_tweets tweets, title: bold("Unliked tweets"), timeout: false
122
- else
123
- page "Tweet was not unliked. Maybe you haven't liked that tweet?"
124
- end
125
- end
126
-
127
- def delete_retweet
128
- tweets = client.unretweet(opts['delete-retweet'])
129
- if tweets.any?
130
- render_tweets tweets, title: bold("Deleted retweets"), timeout: false
131
- else
132
- page "Retweet was not deleted. Maybe you deleted it already?"
133
- end
134
- end
135
-
136
- def delete_tweet
137
- tweets = client.destroy_status(opts['delete-tweet'])
138
- if tweets.any?
139
- render_tweets tweets, title: bold("Deleted tweets"), timeout: false
140
- else
141
- page "Tweet was not deleted. Maybe you deleted it already?"
142
- end
143
- end
144
-
145
- def follow_user
146
- usernames = find_usernames_in(opts['follow'])
147
- follows = client.follow(usernames)
148
- if follows.empty?
149
- page "Didn't follow #{list_usernames(usernames)}, " \
150
- "you could be following them already."
151
- else
152
- page numbered_list(bold("Users you started following"), follows) {|user, index|
153
- display_followed_or_unfollowed(user, index)
154
- }
155
- end
156
- end
157
-
158
- def unfollow_user
159
- usernames = find_usernames_in(opts['unfollow'])
160
- unfollows = client.unfollow(usernames)
161
- if unfollows.empty?
162
- page "Didn't unfollow #{list_usernames(usernames)} " \
163
- "you might not be following them already."
164
- else
165
- page numbered_list(bold("Users you stopped following"), unfollows) {|user, index|
166
- display_followed_or_unfollowed(user, index)
167
- }
168
- end
169
- end
170
-
171
- def display_followed_or_unfollowed(user, index)
172
- sn = "@#{user.screen_name}"
173
- "#{sn} #{bold(bright_blue('|'))} #{user.url}"
174
- end
175
-
176
- def list_usernames(ary)
177
- find_usernames_in(*ary).map do |username|
178
- bold("@#{username}")
179
- end.join(', ')
180
- end
181
-
182
- Pry.commands.add_command(self)
183
- Pry.commands.alias_command "on-twitter", "twitter-action"
184
- end