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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ae88328b20378917474eec4a9b41346938f04b0a4ebcb3708bf9d937ea1c5691
4
- data.tar.gz: 5223319e205eef81dfad63169be032aac646c9eafd8efca518ebe38f58929c51
3
+ metadata.gz: 8feaa382edf88c8b48066b7cbfc2c2d08b0fcb34a3d6f976e639041af51d4820
4
+ data.tar.gz: ac72cdd37aee73e2aeefc7dea74b596ba62e40c23238734be1fad90f06a1d063
5
5
  SHA512:
6
- metadata.gz: 45fdfbbf1334c97f04e554226ecb8263a65e62f9521efe89cd77a440096db235f0ee4e3327e68583077f74534df874d9f4124e58b5b9dabf71f44311b8e39e0f
7
- data.tar.gz: 983ff67471fe84c19dd5d88ed378628bcd3f30c4b0279098ff7f2490db5f09cdec72c8128cb8c37e1df93786f1609f2fbe48c490099cde60b964d97ff4402fa5
6
+ metadata.gz: 9e6ab0d98689c9e3f101f1e9f5afa0389afdaaf5041ec3eacc939452bd058ed7834d7c4b60ed1887a0eb7c54bbeb1cad7337393946b27abc92e938889841306e
7
+ data.tar.gz: 5f019e2cdbf53d8598c09abebaf0f930075f3f9f8df0b5e38b9834901f313caae0a88969f958cea077c80eebccba193020a3b3e53c21992f78eb74982baa453d
@@ -1,5 +1,48 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## master
4
+
5
+ * Add `send-tweet -n`, `send-tweet --no-newline`, for removing newlines from a
6
+ tweet before sending it.
7
+
8
+ * Add `twitter-action --mute-user=`
9
+
10
+ * Add `twitter-action --suggested-users=`, `twitter-action --suggested-topics`
11
+ and `twitter-action --suggested-lang`.
12
+
13
+ * Add configuration option, `Pry.config.twitter.line_width`, for choosing the
14
+ a lines width before word wrapping occurs. Default line width is 200.
15
+
16
+ * Add pre-post tweet validation that catches empty tweets, and tweets who use
17
+ too many characters.
18
+
19
+ * Add `send-tweet --delay=xx` for delaying the creation of a tweet by a number
20
+ of seconds.
21
+
22
+ * Add `send-tweet --self-destruct=xx` for automatically deleting a tweet after
23
+ a number of seconds.
24
+
25
+ * Add `twitter-search`.
26
+
27
+ * Add `read-tweets --tweeter=`, a longer version of `read-tweets -t`.
28
+
29
+ * Add `read-tweets --replies <user>`.
30
+
31
+ * Add short hand variants for all `read-tweets` options.
32
+
33
+ * Combine the `read-tweets` options `--my-likes` and `--liked-by` into
34
+ one option, `--likes`.
35
+
36
+ * Rename `read-tweets --that-mention-me` to `read-tweets --mentions`.
37
+
38
+ * Don't hit the Twitter API if a composed tweet is entirely whitespace.
39
+
40
+ * `send-tweet --file` accepts a comma separated list for attaching multiple
41
+ images to a tweet.
42
+
43
+ * Like, unlike, and delete actions accept a comma separated list for performing
44
+ an action on multiple tweets.
45
+
3
46
  ## v0.6.0
4
47
 
5
48
  * Fix a bug where the auto refresh feature could not be disabled.
data/Dockerfile CHANGED
@@ -1,4 +1,4 @@
1
- FROM ruby:2.5.3-stretch
1
+ FROM ruby:2.6.0-stretch
2
2
 
3
3
  # Create working directory
4
4
  RUN mkdir -p /app/
@@ -7,13 +7,15 @@ WORKDIR /app/
7
7
  # Bundler
8
8
  ADD Gemfile pry-send_tweet.gemspec /app/
9
9
  ADD lib /app/lib
10
- RUN gem install bundler --no-rdoc --no-ri
10
+ RUN gem install bundler
11
+ # FIXME: During 'bundle install', i got: Could not find gem 'buftok (~> 0.2.0)'
12
+ # Installing twitter as a gem first fixes that.
13
+ RUN gem install twitter
11
14
  RUN bundle install
12
15
 
13
16
  # Install packages
14
17
  RUN apt-get update
15
- RUN apt-get install -y --no-install-recommends cowsay locales emacs24-nox less
16
- RUN ln -s /usr/games/cowsay /usr/bin/cowsay
18
+ RUN apt-get install -y --no-install-recommends locales emacs24-nox less
17
19
 
18
20
  # Configure locale
19
21
  RUN sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen
data/Gemfile CHANGED
@@ -1,5 +1,7 @@
1
1
  source 'https://rubygems.org'
2
2
  gemspec
3
+ gem 'pry-auto_benching.rb'
4
+ gem 'pry-doc'
3
5
  group :test do
4
6
  gem 'rspec'
5
- end
7
+ end
data/README.md CHANGED
@@ -1,16 +1,34 @@
1
1
  # pry-send_tweet.rb
2
2
 
3
- ## Introduction
4
-
5
- Extends the Pry REPL with the capabilities of a Twitter client.
6
-
7
- ## API Access
3
+ * [Introduction](#introduction)
4
+ * [API Access](#api-access)
5
+ * [Configuration - required](#configuration)
6
+ * [Usage](#usage)
7
+ * [Sending Tweets](#sending-tweets)
8
+ * [Reading Tweets](#reading-tweets)
9
+ * [Deleting Tweets](#deleting-tweets)
10
+ * [Liking Tweets](#liking-tweets)
11
+ * [Searching Twitter](#searching-twitter)
12
+ * [Retweets](#retweets)
13
+ * [Profile Actions](#profile-actions)
14
+ * [Twitter Suggestions](#twitter-suggestions)
15
+ * [Muting other users](#muting-other-users)
16
+ * [Tip: Command Aliases](#tip)
17
+ * [Multi-tasking: tmux / screen](#multi-tasking)
18
+ * [Install](#install)
19
+ * [License](#license)
20
+
21
+ ## <a id='Introduction'>Introduction</a>
22
+
23
+ A Twitter client for the Pry REPL.
24
+
25
+ ## <a id='api-access'>API Access</a>
8
26
 
9
27
  Using the Twitter API requires a developer account.
10
28
  Follow the instructions at [https://developer.twitter.com](https://developer.twitter.com)
11
29
  if you haven't already setup access to the Twitter API.
12
30
 
13
- ## Configuration (required)
31
+ ## <a id='configuration'>Configuration (required)</a>
14
32
 
15
33
  The placeholder keys and tokens in the below example can be replaced
16
34
  by those from your developer account.
@@ -27,14 +45,16 @@ Pry.configure do |config|
27
45
  # Optional configuration
28
46
  # The User-Agent to use when making requests to the Twitter API.
29
47
  # Default is: 'pry-send_tweet.rb vX.Y.Z'
30
- user_agent: 'Custom User-Agent'
48
+ user_agent: 'Custom User-Agent',
49
+ # The width of a line before word wrapping occurs, the default is 100.
50
+ line_width: 120
31
51
  })
32
52
  end
33
53
  ```
34
54
 
35
- ## Usage
55
+ ## <a id='usage'>Usage</a>
36
56
 
37
- There are three commands added to Pry by this plugin, those commands are:
57
+ There are four commands added to Pry by this plugin, those commands are:
38
58
 
39
59
  * `send-tweet`
40
60
  For sending tweets.
@@ -45,7 +65,10 @@ There are three commands added to Pry by this plugin, those commands are:
45
65
  * `twitter-action` (aliased as: `on-twitter`)
46
66
  For performing misc actions on Twitter, such as following, unfollowing, etc.
47
67
 
48
- ### Sending tweets
68
+ * `twitter-search`
69
+ For searching Twitter.
70
+
71
+ ### <a id='sending-tweets'>Sending tweets</a>
49
72
 
50
73
 
51
74
  * Send a tweet:
@@ -60,29 +83,34 @@ There are three commands added to Pry by this plugin, those commands are:
60
83
 
61
84
  [1] pry(main)> send-tweet --file #{File.join ENV['HOME'], 'photos', 'image.jpg'}
62
85
 
86
+
63
87
  * Reply to a tweet:
64
88
 
65
89
  [1] pry(main)> send-tweet --reply-to https://twitter.com/username/status/1
66
90
 
67
- * There is built-in support for the `cowsay` program, which is a program that
68
- draws humorous ascii art. The following example will send a tweet using the
69
- Linux 'tux' mascot.
70
- <br>
71
- **Tip:** `--cowsay-char` is optional and can be left blank. A cow will be used
72
- as the default. For a full list of available `cowsay` characters that can be
73
- used with the `--cowsay-char` option, run `cowsay -l` from a shell.
91
+ * Send a tweet that will self-destruct after 70 seconds.
92
+ It's worth adding that if the Pry process exits this operation will be cancelled:
93
+
94
+ [1] pry(main)> send-tweet --self-destruct=70
74
95
 
75
- **Extra Tip:** The `Dockerfile` in this repository installs `cowsay`.
96
+ * Send a tweet that will be published 70 seconds in the future.
97
+ It's worth adding that if the Pry process exits, this operation will be cancelled:
76
98
 
77
- [1] pry(main)> send-tweet --cowsay-text 'Hello, world' --cowsay-char tux
99
+ [1] pry(main)> send-tweet --delay=70
78
100
 
79
- ### Reading tweets
101
+ * Delay sending a tweet until 12AM, today. `--self-destruct` also supports this
102
+ syntax:
103
+
104
+ [1] pry(main)> send-tweet --delay=00:00
105
+
106
+ ### <a id='reading-tweets'>Reading tweets</a>
80
107
 
81
108
  By default the tweets displayed by the `read-tweets` command are automatically
82
- refreshed every 4 minutes.
109
+ refreshed every 5 minutes.
83
110
 
84
111
  That can be changed to a custom interval by setting `Pry.config.twitter.refresh_interval`
85
- to a number of seconds, or to `false` if you want to disable this feature.
112
+ to a number of seconds, or to `false` if you want to disable this
113
+ feature.
86
114
 
87
115
  * Read recent tweets from your timeline:
88
116
 
@@ -94,84 +122,143 @@ to a number of seconds, or to `false` if you want to disable this feature.
94
122
 
95
123
  * Read recent tweets that `@mention` you:
96
124
 
97
- [1] pry(main)> read-tweets --that-mention-me
125
+ [1] pry(main)> read-tweets --mentions
98
126
 
99
127
  * Read recent tweets that you've liked:
100
128
 
101
- [1] pry(main) read-tweets --my-likes
129
+ [1] pry(main) read-tweets --likes
102
130
 
103
131
  * Read recent tweets liked by another user:
104
132
 
105
- [1] pry(main)> read-tweets --liked-by ladygaga
133
+ [1] pry(main)> read-tweets --likes ladygaga
134
+
135
+ * Read recent tweets sent as replies by a given user, the example uses `@github`:
136
+
137
+ [1] pry(main)> read-tweets --replies github
138
+
139
+ * Read 100 recent tweets instead of the default 200 recent tweets.
140
+ **Tip:** `--count` can be combined with all of the options described above.
141
+
142
+ [1] pry(main)> read-tweets --count 100
106
143
 
107
144
  * By default retweets are not displayed.
108
145
  To display retweets, pass the `--with-retweets` option.
109
146
 
110
147
  [1] pry(main)> read-tweets --with-retweets
111
148
 
112
- * Read 100 recent tweets instead of the default 35 recent tweets.
113
- **Tip:** `--count` can be combined with all of the options described above.
149
+ ### <a id='deleting-tweets'>Deleting tweets</a>
114
150
 
115
- [1] pry(main)> read-tweets --count 100
151
+ * Delete one or more tweets with a comma separated list:
116
152
 
117
- ### Deleting tweets
153
+ [1] pry(main)> on-twitter --delete-tweet https://twitter.com/username/status/1
118
154
 
119
- * Delete a tweet:
155
+ * Delete one or more retweets with a comma separated list:
120
156
 
121
- [1] pry(main)> twitter-action --delete-tweet https://twitter.com/username/status/1
157
+ [1] pry(main)> on-twitter --delete-retweet https://twitter.com/username/status/1
122
158
 
123
- * Delete a retweet:
159
+ ### <a id='liking-tweets'>Liking tweets</a>
124
160
 
125
- [1] pry(main)> twitter-action --delete-retweet https://twitter.com/username/status/1
161
+ * Like one or more tweets with a comma separated list:
126
162
 
127
- ### Liking tweets
163
+ [1] pry(main)> on-twitter --like https://twitter.com/user/status/1
128
164
 
129
- * Like a tweet:
165
+ * Unlike one or more tweets with a comma separated list:
130
166
 
131
- [1] pry(main)> twitter-action --like https://twitter.com/user/status/1
167
+ [1] pry(main)> on-twitter --unlike https://twitter.com/user/status/1
132
168
 
133
- * Unlike a tweet:
169
+ ### <a id='searching-twitter'>Searching Twitter</a>
134
170
 
135
- [1] pry(main)> twitter-action --unlike https://twitter.com/user/status/1
171
+ The `twitter-search` command can be used to search Twitter.
136
172
 
137
- ### Retweets
173
+ * Search Twitter using a given hashtag:
138
174
 
139
- * Retweet a tweet:
175
+ [1] pry(main)> twitter-search #ruby
140
176
 
141
- [1] pry(main)> twitter-action --retweet https://twitter.com/user/status/1
177
+ ### <a id='retweets'>Retweets</a>
142
178
 
143
- ### Update your Twitter profile
179
+ * Retweet one or more tweets with a comma separated list:
180
+
181
+ [1] pry(main)> on-twitter --retweet https://twitter.com/user/status/1
182
+
183
+ ### <a id='profile-actions'>Profile actions</a>
144
184
 
145
185
  * Update your profiles image:
146
186
 
147
- [1] pry(main)> twitter-action --set-profile-image /path/to/image.jpg
187
+ [1] pry(main)> on-twitter --set-profile-image /path/to/image.jpg
148
188
 
149
189
  * Update your profiles banner image:
150
190
 
151
- [1] pry(main)> twitter-action --set-profile-banner-image /path/to/image.jpg
191
+ [1] pry(main)> on-twitter --set-profile-banner-image /path/to/image.jpg
152
192
 
153
193
  * Update your profiles bio:
154
194
 
155
195
  # Your editor opens (`_pry_.editor`), write your bio then hit save & close.
156
196
  # Your bio will be updated after closing your editor.
157
- [1] pry(main)> twitter-action --set-profile-bio
197
+ [1] pry(main)> on-twitter --set-profile-bio
198
+
199
+ ### <a id='twitter-suggestions'>Twitter Suggestions</a>
200
+
201
+ * View a list of suggested topics, optionally restricted to Spanish:
158
202
 
159
- ## Install
203
+ [1] pry(main)> on-twitter --suggested-lang=es --suggested-topics
204
+
205
+ * View a list of suggested users from a given topic, optionally restricted to
206
+ Spanish:
207
+
208
+ [1] pry(main)> on-twitter --suggested-lang=es --suggested-users=<topic>
209
+
210
+
211
+ ### <a id='muting-other-users'>Muting other users</a>
212
+
213
+ * Mute one or more users with a comma separated list:
214
+
215
+ [1] pry(main)> on-twitter --mute-user=user1,user2,user3
216
+
217
+ * Unmute one or more users with a comma separated list:
218
+
219
+ [1] pry(main)> on-twitter --unmute-user=user1,user2,user3
220
+
221
+ ### <a id='tip'>Tip: Command Aliases</a>
222
+
223
+ When there are Twitter accounts you read often, it can turn out to be faster
224
+ to create command aliases for reading those accounts. An example follows, a
225
+ hyphen is included in the aliased commands to avoid collisions with Ruby code.
226
+
227
+ ```ruby
228
+ # .pryrc
229
+ Pry.commands.alias_command "prez-trump", "read-tweets -t realdonaldtrump"
230
+ Pry.commands.alias_command "prez-obama", "read-tweets -t barackobama"
231
+ ```
232
+
233
+ ## <a id='multi-tasking'>Multi-tasking: tmux / screen</a>
234
+
235
+ To get the most out of `pry-send_tweet.rb` I use tmux to manage a pane for reading
236
+ tweets and another for writing tweets. I've found this to be the best way since
237
+ a single shell does not allow for multi tasking but tmux and screen do.
238
+
239
+ I use
240
+ [tmuxinator](https://github.com/tmuxinator/tmuxinator)
241
+ to manage my tmux sessions.
242
+ The tmuxinator configuration I use is available as a
243
+ [sample](./samples/tmuxinator.yml)
244
+ to use yourself or to act
245
+ as inspiration for your own configuration.
246
+
247
+ ## <a id='install'>Install</a>
160
248
 
161
249
  Install the gem:
162
250
 
163
251
  $ gem install pry-send_tweet.rb
164
252
 
165
- There's also the option to clone this repository and then use the provided
166
- `Dockerfile` to run pry-send_tweet.rb inside a Docker container.
167
- The container is configured to use `emacs` when sending tweets and when using
168
- other commands that open an editor.
253
+ There's also the option to clone this repository and then use the provided
254
+ `Dockerfile` to run pry-send_tweet.rb inside a Docker container.
255
+ The container is configured to use `emacs` when sending tweets and when using
256
+ other commands that open an editor.
169
257
 
170
258
  $ git clone https://github.com/r-obert/pry-send_tweet.rb
171
259
  $ cd pry-send_tweet.rb
172
260
  $ ./dockerize.sh
173
261
 
174
-
175
- ## License
262
+ ## <a id='license'>License</a>
176
263
 
177
264
  This project uses the MIT license, see [LICENSE.txt](./LICENSE.txt) for details.
@@ -1,12 +1,32 @@
1
- require 'pry' if not defined?(Pry::ClassCommand)
2
- require 'twitter'
3
- require 'cgi'
4
- require 'shellwords'
5
- require 'timeout'
6
- module Pry::SendTweet
7
- require_relative 'pry/send_tweet/mixins/tweet_renderer'
8
- require_relative 'pry/send_tweet/base_command'
9
- require_relative 'pry/send_tweet/send_tweet_command'
10
- require_relative 'pry/send_tweet/read_tweets_command'
11
- require_relative 'pry/send_tweet/twitter_action_command'
1
+ class Pry
2
+ module SendTweet
3
+ #
4
+ # @return [Integer]
5
+ # The size of a line before word wrapping occurs.
6
+ #
7
+ # @api private
8
+ #
9
+ DEFAULT_LINE_WIDTH = 100
10
+
11
+ #
12
+ # @return [Integer]
13
+ # The number of tweets to request when reading tweets from Twitters API.
14
+ #
15
+ # @api private
16
+ #
17
+ DEFAULT_READ_SIZE = 200
18
+
19
+ require 'pry' if not defined?(Pry::ClassCommand)
20
+ require 'twitter'
21
+ require 'cgi'
22
+ require 'shellwords'
23
+ require 'timeout'
24
+ require 'time-lord'
25
+ require_relative 'pry/send_tweet/renderers/tweet_renderer'
26
+ require_relative 'pry/send_tweet/commands/base_command'
27
+ require_relative 'pry/send_tweet/commands/send_tweet'
28
+ require_relative 'pry/send_tweet/commands/read_tweets'
29
+ require_relative 'pry/send_tweet/commands/twitter_search'
30
+ require_relative 'pry/send_tweet/commands/twitter_action'
31
+ end
12
32
  end
@@ -17,7 +17,7 @@ class Pry::SendTweet::BaseCommand < Pry::ClassCommand
17
17
  private
18
18
 
19
19
  def page(txt)
20
- _pry_.pager.page txt
20
+ _pry_.pager.page txt.to_s
21
21
  end
22
22
 
23
23
  def find_usernames_in(*ary)
@@ -34,7 +34,7 @@ class Pry::SendTweet::BaseCommand < Pry::ClassCommand
34
34
 
35
35
  # With thanks to ActionView for this method
36
36
  def word_wrap(text, options = {})
37
- line_width = options.fetch(:line_width, 80)
37
+ line_width = _pry_.config.twitter.line_width || Pry::SendTweet::DEFAULT_LINE_WIDTH
38
38
  text.split("\n").collect! do |line|
39
39
  line.length > line_width ? line.gsub(/(.{1,#{line_width}})(\s+|$)/, "\\1\n").strip : line
40
40
  end * "\n"
@@ -46,14 +46,23 @@ class Pry::SendTweet::BaseCommand < Pry::ClassCommand
46
46
  title + ary.map.with_index { |item, index| yield(item, index+1) }.join("\n")
47
47
  end
48
48
 
49
- def client
50
- @client ||= Twitter::REST::Client.new { |config|
49
+ def twitter_error(e)
50
+ msg = Exception === e ? e.message : e
51
+ "#{bold(bright_red('Twitter Error:'))} #{msg}"
52
+ end
53
+
54
+ def time_format
55
+ "%-d %b %Y, %-I:%M:%S %p"
56
+ end
57
+
58
+ def twitter
59
+ @twitter ||= Twitter::REST::Client.new { |config|
51
60
  config.consumer_key = _pry_.config.twitter.consumer_key
52
61
  config.consumer_secret = _pry_.config.twitter.consumer_secret
53
62
  config.access_token = _pry_.config.twitter.access_token
54
63
  config.access_token_secret = _pry_.config.twitter.access_token_secret
55
- }.tap {|client|
56
- client.user_agent = _pry_.config.twitter.user_agent ||
64
+ }.tap {|twitter|
65
+ twitter.user_agent = _pry_.config.twitter.user_agent ||
57
66
  "pry-send_tweet.rb v#{Pry::SendTweet::VERSION}"
58
67
  }
59
68
  end