ayadn 1.5.1 → 1.6.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: c27895d681609f9415e70476330ed879ab1e9593
4
- data.tar.gz: bbf4d6af209533db1571875e09a879a275f27547
3
+ metadata.gz: d1dbd05e3a853fb34403880501ca7fd4191ae74c
4
+ data.tar.gz: 5e2cd526b19ff009e127028a33fba5a21d8ea941
5
5
  SHA512:
6
- metadata.gz: 5148331842c2bae97ebc53a6294f9395a970640c9900729ba4b6f68cd7cbb28683dcbec22477556cf924645e2418d3f407461ce16890c44318e24a4cafadeb95
7
- data.tar.gz: 829b10f92d7e55c02fdf8c125b212c635ed75a7b8846df2fdb1b0cc1cf570e75020ea0e77259aab8cbefda8e483b149b00577c212c6bcf956e424607c4edf3a2
6
+ metadata.gz: 7c5b81ff93034553556e78699c67c17ebf552b6c07d311686ff48c762476d1083cfb1fd209488db58f4e13f3962524376988566b08ec9df95b11f0d12c6e3a4c
7
+ data.tar.gz: 6037b01600859172ec938f5c384a87660d5cbc8dd0e1b6dfbd456405597f50dd6dfdcb961a4059b25fffe9cdfc0af5d71b0023de3344834a0f8f49152b08772b
data/CHANGELOG.md CHANGED
@@ -1,3 +1,14 @@
1
+ # 1.6.0 - 'Beetlejuice'
2
+
3
+ - New command: 'movie'. Create a post from a movie title (with link + movie poster). Customisable hashtag (default: '#nowwatching').
4
+ - New command: 'tvshow'. Create a post from a TV show title (with link + show poster). Customisable hashtag (default: '#nowwatching'). Option to display a banner instead of a poster.
5
+ - New: see the target of your PM when writing a message.
6
+ - New: delete several posts at once.
7
+ - New: delete several PMs at once.
8
+ - Fixed: uploading jpg if there were spaces in the filename.
9
+ - Fixed: bookmark convos.
10
+ - General code cleaning and refactoring.
11
+
1
12
  # 1.5.1 - 'Holograms'
2
13
 
3
14
  - Improved accuracy of iTunes Store requests for NowPlaying
data/MANUAL.md CHANGED
@@ -1,3 +1,3 @@
1
1
  # MANUAL
2
2
 
3
- [Read the docs at ayadn-app.net/doc](http://ayadn-app.net/doc/)
3
+ [Read the docs](https://github.com/ericdke/na/tree/master/doc)
data/README.md CHANGED
@@ -23,7 +23,9 @@ The purpose of Ayadn is to let you use all the features of App.net from the cons
23
23
  - extract links from conversations, streams, posts, etc
24
24
  - list and download your files
25
25
  - view (and write to) all your channels including Broadcasts, Patter, Ohai, etc
26
- - #nowplaying from iTunes or Last.fm, with album art and store link
26
+ - 'nowplaying' from iTunes or Last.fm, with album art and store link
27
+ - 'movie' creates a post from a movie title with poster, etc
28
+ - 'tvshow' creates a post from a TV show title with poster, etc
27
29
  - view/send private messages
28
30
  - view geolocation data in streams
29
31
  - create/manage silent black lists of users, mentions or hashtags
data/ayadn.gemspec CHANGED
@@ -29,6 +29,8 @@ Gem::Specification.new do |spec|
29
29
  spec.add_dependency "daybreak", "~> 0.3"
30
30
  spec.add_dependency "pinboard", "~> 0.1"
31
31
  spec.add_dependency "unicode_utils", "~> 1.4"
32
+ spec.add_dependency "spotlite", "~> 0.8"
33
+ spec.add_dependency "tvdb_party", "~> 0.7"
32
34
 
33
35
  spec.add_development_dependency "bundler", "~> 1.5"
34
36
  spec.add_development_dependency "rake", "~> 10.1"
data/doc/16-movie.md ADDED
@@ -0,0 +1,46 @@
1
+ # MOVIE (nowwatching)
2
+
3
+ Create a post from (part of) a movie title. Includes movie poster, IMDb url and hashtag.
4
+
5
+ Usage:
6
+
7
+ `ayadn movie ghost in the shell`
8
+
9
+ `ayadn movie existenz`
10
+
11
+ `ayadn -NW beetlejuice`
12
+
13
+ (shortcut is 'NW' because of 'nowwatching')
14
+
15
+ ## ALT
16
+
17
+ If the movie is not the one you're looking for, you can specify the 'alt' option to force find an alternative.
18
+
19
+ This is useful for remakes:
20
+
21
+ `ayadn -NW solaris`
22
+
23
+ (gives the 2002 version)
24
+
25
+ `ayadn -NW solaris --alt`
26
+
27
+ (gives the 1972 version)
28
+
29
+ ## ALIASES
30
+
31
+ `ayadn nowwatching godfather II`
32
+
33
+ `ayadn imdb -a conan`
34
+
35
+ ## HASHTAG
36
+
37
+ You can modify the hashtag with 'set':
38
+
39
+ `ayadn set movie hashtag movietime`
40
+
41
+ `ayadn set movie hashtag adnmovieclub`
42
+
43
+ (default is 'nowwatching')
44
+
45
+
46
+
data/doc/17-tvshow.md ADDED
@@ -0,0 +1,44 @@
1
+ # TVSHOW (nowwatching)
2
+
3
+ Create a post from (part of) a TV show title. Includes show poster, IMDb url and hashtag.
4
+
5
+ Usage:
6
+
7
+ `ayadn tvshow game of thrones`
8
+
9
+ `ayadn tvshow magnum`
10
+
11
+ `ayadn -TV 24`
12
+
13
+ ## ALT
14
+
15
+ If the show is not the one you're looking for, you can specify the 'alt' option to force find an alternative.
16
+
17
+ `ayadn -TV whose line`
18
+
19
+ (gives the US version)
20
+
21
+ `ayadn -TV whose line --alt`
22
+
23
+ (gives the UK version)
24
+
25
+ ## HASHTAG
26
+
27
+ You can modify the hashtag with 'set':
28
+
29
+ `ayadn set tvshow hashtag showtime`
30
+
31
+ `ayadn set tvshow hashtag tvshow`
32
+
33
+ (default is 'nowwatching')
34
+
35
+ ## BANNER
36
+
37
+ You can display a banner instead of a poster, with the `--banner` (`-b`) option:
38
+
39
+ ```
40
+ ayadn -TV magnum --banner
41
+ ayadn -TV -b magnum
42
+ ```
43
+
44
+
File without changes
File without changes
File without changes
data/lib/ayadn/action.rb CHANGED
@@ -2,9 +2,15 @@
2
2
  module Ayadn
3
3
  class Action
4
4
 
5
+ ##
6
+ # This class is the main initializer + dispatcher
7
+
5
8
  def initialize
6
9
  @api = API.new
7
10
  @view = View.new
11
+ @workers = Workers.new
12
+ @stream = Stream.new(@api, @view, @workers)
13
+ @search = Search.new(@api, @view, @workers)
8
14
  Settings.load_config
9
15
  Settings.get_token
10
16
  Settings.init_config
@@ -15,12 +21,7 @@ module Ayadn
15
21
 
16
22
  def unified(options)
17
23
  begin
18
- doing(options)
19
- stream = @api.get_unified(options)
20
- stop_if_no_new_posts(stream, options, 'unified')
21
- Databases.save_max_id(stream)
22
- render_view(stream, options)
23
- Scroll.new(@api, @view).unified(options) if options[:scroll]
24
+ @stream.unified(options)
24
25
  rescue => e
25
26
  Errors.global_error({error: e, caller: caller, data: [options]})
26
27
  end
@@ -28,12 +29,7 @@ module Ayadn
28
29
 
29
30
  def checkins(options)
30
31
  begin
31
- doing(options)
32
- stream = @api.get_checkins(options)
33
- stop_if_no_new_posts(stream, options, 'explore:checkins')
34
- Databases.save_max_id(stream)
35
- render_view(stream, options)
36
- Scroll.new(@api, @view).checkins(options) if options[:scroll]
32
+ @stream.checkins(options)
37
33
  rescue => e
38
34
  Errors.global_error({error: e, caller: caller, data: [options]})
39
35
  end
@@ -41,28 +37,15 @@ module Ayadn
41
37
 
42
38
  def global(settings)
43
39
  begin
44
- options = settings.dup
45
- options[:filter] = nicerank_true()
46
- doing(options)
47
- stream = @api.get_global(options)
48
- niceranks = NiceRank.new.get_ranks(stream)
49
- stop_if_no_new_posts(stream, options, 'global')
50
- Databases.save_max_id(stream)
51
- render_view(stream, options, niceranks)
52
- Scroll.new(@api, @view).global(options) if options[:scroll]
40
+ @stream.global(settings)
53
41
  rescue => e
54
- Errors.global_error({error: e, caller: caller, data: [options]})
42
+ Errors.global_error({error: e, caller: caller, data: [settings]})
55
43
  end
56
44
  end
57
45
 
58
46
  def trending(options)
59
47
  begin
60
- doing(options)
61
- stream = @api.get_trending(options)
62
- stop_if_no_new_posts(stream, options, 'explore:trending')
63
- Databases.save_max_id(stream)
64
- render_view(stream, options)
65
- Scroll.new(@api, @view).trending(options) if options[:scroll]
48
+ @stream.trending(options)
66
49
  rescue => e
67
50
  Errors.global_error({error: e, caller: caller, data: [options]})
68
51
  end
@@ -70,12 +53,7 @@ module Ayadn
70
53
 
71
54
  def photos(options)
72
55
  begin
73
- doing(options)
74
- stream = @api.get_photos(options)
75
- stop_if_no_new_posts(stream, options, 'explore:photos')
76
- Databases.save_max_id(stream)
77
- render_view(stream, options)
78
- Scroll.new(@api, @view).photos(options) if options[:scroll]
56
+ @stream.photos(options)
79
57
  rescue => e
80
58
  Errors.global_error({error: e, caller: caller, data: [options]})
81
59
  end
@@ -83,12 +61,7 @@ module Ayadn
83
61
 
84
62
  def conversations(options)
85
63
  begin
86
- doing(options)
87
- stream = @api.get_conversations(options)
88
- stop_if_no_new_posts(stream, options, 'explore:replies')
89
- Databases.save_max_id(stream)
90
- render_view(stream, options)
91
- Scroll.new(@api, @view).replies(options) if options[:scroll]
64
+ @stream.conversations(options)
92
65
  rescue => e
93
66
  Errors.global_error({error: e, caller: caller, data: [options]})
94
67
  end
@@ -96,17 +69,7 @@ module Ayadn
96
69
 
97
70
  def mentions(username, options)
98
71
  begin
99
- stop_if_no_username(username)
100
- username = add_arobase(username)
101
- doing(options)
102
- stream = @api.get_mentions(username, options)
103
- stop_if_no_user(stream, username)
104
- Databases.save_max_id(stream)
105
- options = options.dup
106
- options[:in_mentions] = true
107
- stop_if_no_data(stream, 'mentions')
108
- render_view(stream, options)
109
- Scroll.new(@api, @view).mentions(username, options) if options[:scroll]
72
+ @stream.mentions(username, options)
110
73
  rescue => e
111
74
  Errors.global_error({error: e, caller: caller, data: [username, options]})
112
75
  end
@@ -114,15 +77,7 @@ module Ayadn
114
77
 
115
78
  def posts(username, options)
116
79
  begin
117
- stop_if_no_username(username)
118
- username = add_arobase(username)
119
- doing(options)
120
- stream = @api.get_posts(username, options)
121
- stop_if_no_user(stream, username)
122
- Databases.save_max_id(stream)
123
- stop_if_no_data(stream, 'mentions')
124
- render_view(stream, options)
125
- Scroll.new(@api, @view).posts(username, options) if options[:scroll]
80
+ @stream.posts(username, options)
126
81
  rescue => e
127
82
  Errors.global_error({error: e, caller: caller, data: [username, options]})
128
83
  end
@@ -130,11 +85,7 @@ module Ayadn
130
85
 
131
86
  def interactions(options)
132
87
  begin
133
- doing(options)
134
- stream = @api.get_interactions
135
- if_raw_show(stream, options)
136
- @view.clear_screen
137
- @view.show_interactions(stream['data'])
88
+ @stream.interactions(options)
138
89
  rescue => e
139
90
  Errors.global_error({error: e, caller: caller, data: [options]})
140
91
  end
@@ -142,13 +93,7 @@ module Ayadn
142
93
 
143
94
  def whatstarred(username, options)
144
95
  begin
145
- stop_if_no_username(username)
146
- username = add_arobase(username)
147
- doing(options)
148
- stream = @api.get_whatstarred(username, options)
149
- stop_if_no_user(stream, username)
150
- stop_if_no_data(stream, 'whatstarred')
151
- options[:extract] ? view_all_stars_links(stream) : render_view(stream, options)
96
+ @stream.whatstarred(username, options)
152
97
  rescue => e
153
98
  Errors.global_error({error: e, caller: caller, data: [username, options]})
154
99
  end
@@ -156,18 +101,7 @@ module Ayadn
156
101
 
157
102
  def whoreposted(post_id, options)
158
103
  begin
159
- stop_if_bad_post_id(post_id)
160
- doing(options)
161
- details = @api.get_details(post_id, options)
162
- stop_if_404(details, post_id)
163
- id = get_original_id(post_id, details)
164
- list = @api.get_whoreposted(id)
165
- if_raw_show(list, options)
166
- unless list['data'].empty?
167
- get_list(:whoreposted, list['data'], post_id)
168
- else
169
- puts Status.nobody_reposted
170
- end
104
+ @stream.whoreposted(post_id, options)
171
105
  rescue => e
172
106
  Errors.global_error({error: e, caller: caller, data: [post_id, options]})
173
107
  end
@@ -175,55 +109,30 @@ module Ayadn
175
109
 
176
110
  def whostarred(post_id, options)
177
111
  begin
178
- stop_if_bad_post_id(post_id)
179
- doing(options)
180
- details = @api.get_details(post_id, options)
181
- stop_if_404(details, post_id)
182
- id = get_original_id(post_id, details)
183
- list = @api.get_whostarred(id)
184
- if_raw_show(list, options)
185
- unless list['data'].empty?
186
- get_list(:whostarred, list['data'], id)
187
- else
188
- puts Status.nobody_starred
189
- end
112
+ @stream.whostarred(post_id, options)
190
113
  rescue => e
191
- Errors.global_error({error: e, caller: caller, data: [post_id, id, options]})
114
+ Errors.global_error({error: e, caller: caller, data: [post_id, options]})
192
115
  end
193
116
  end
194
117
 
195
118
  def convo(post_id, options)
196
119
  begin
197
- stop_if_bad_post_id(post_id)
198
- doing(options)
199
- details = @api.get_details(post_id, options)
200
- stop_if_404(details, post_id)
201
- id = get_original_id(post_id, details)
202
- stream = get_convo id, options
203
- Databases.pagination["replies:#{id}"] = stream['meta']['max_id']
204
- options = options.dup
205
- unless details['data']['reply_to'].nil?
206
- options[:reply_to] = details['data']['reply_to'].to_i
207
- end
208
- options[:post_id] = post_id.to_i
209
- render_view(stream, options)
210
- Scroll.new(@api, @view).convo(id, options) if options[:scroll]
120
+ @stream.convo(post_id, options)
211
121
  rescue => e
212
- Errors.global_error({error: e, caller: caller, data: [post_id, id, options]})
122
+ Errors.global_error({error: e, caller: caller, data: [post_id, options]})
213
123
  end
214
124
  end
215
125
 
216
- def get_convo id, options
217
- stream = @api.get_convo(id, options)
218
- stop_if_no_post(stream, id)
219
- stream
220
- end
221
-
222
- def delete(post_id)
126
+ def delete(post_ids)
223
127
  begin
224
- stop_if_bad_post_id(post_id)
225
- print Status.deleting_post(post_id)
226
- check_has_been_deleted(post_id, @api.delete_post(post_id))
128
+ ids = post_ids.select { |post_id| post_id.is_integer? }
129
+ abort(Status.error_missing_post_id) if ids.empty?
130
+ ids.each do |post_id|
131
+ print Status.deleting_post(post_id)
132
+ resp = @api.delete_post(post_id)
133
+ Check.has_been_deleted(post_id, resp)
134
+ sleep 1 unless ids.length == 1
135
+ end
227
136
  rescue => e
228
137
  Errors.global_error({error: e, caller: caller, data: [post_id]})
229
138
  end
@@ -231,13 +140,18 @@ module Ayadn
231
140
 
232
141
  def delete_m(args)
233
142
  begin
234
- missing_message_id unless args.length == 2
235
- message_id = args[1]
236
- missing_message_id unless message_id.is_integer?
237
- channel_id = get_channel_id_from_alias(args[0])
238
- print Status.deleting_message(message_id)
239
- resp = @api.delete_message(channel_id, message_id)
240
- check_message_has_been_deleted(message_id, resp)
143
+ abort(Status.error_missing_message_id) unless args.length >= 2
144
+ channel = args[0]
145
+ args.shift
146
+ ids = args.select {|message_id| message_id.is_integer?}
147
+ abort(Status.error_missing_message_id) if ids.empty?
148
+ channel_id = @workers.get_channel_id_from_alias(channel)
149
+ ids.each do |message_id|
150
+ print Status.deleting_message(message_id)
151
+ resp = @api.delete_message(channel_id, message_id)
152
+ Check.message_has_been_deleted(message_id, resp)
153
+ sleep 1 unless ids.length == 1
154
+ end
241
155
  rescue => e
242
156
  Errors.global_error({error: e, caller: caller, data: [message_id]})
243
157
  end
@@ -245,12 +159,12 @@ module Ayadn
245
159
 
246
160
  def unfollow(usernames)
247
161
  begin
248
- stop_if_no_username(usernames)
249
- users = all_but_me(usernames)
162
+ Check.no_username(usernames)
163
+ users = @workers.all_but_me(usernames)
250
164
  puts Status.unfollowing(users.join(','))
251
165
  users.each do |user|
252
166
  resp = @api.unfollow(user)
253
- check_has_been_unfollowed(user, resp)
167
+ Check.has_been_unfollowed(user, resp)
254
168
  sleep 1 unless users.length == 1
255
169
  end
256
170
  rescue => e
@@ -260,12 +174,12 @@ module Ayadn
260
174
 
261
175
  def follow(usernames)
262
176
  begin
263
- stop_if_no_username(usernames)
264
- users = all_but_me(usernames)
177
+ Check.no_username(usernames)
178
+ users = @workers.all_but_me(usernames)
265
179
  puts Status.following(users.join(','))
266
180
  users.each do |user|
267
181
  resp = @api.follow(user)
268
- check_has_been_followed(user, resp)
182
+ Check.has_been_followed(user, resp)
269
183
  sleep 1 unless users.length == 1
270
184
  end
271
185
  rescue => e
@@ -275,12 +189,12 @@ module Ayadn
275
189
 
276
190
  def unmute(usernames)
277
191
  begin
278
- stop_if_no_username(usernames)
279
- users = all_but_me(usernames)
192
+ Check.no_username(usernames)
193
+ users = @workers.all_but_me(usernames)
280
194
  puts Status.unmuting(users.join(','))
281
195
  users.each do |user|
282
196
  resp = @api.unmute(user)
283
- check_has_been_unmuted(user, resp)
197
+ Check.has_been_unmuted(user, resp)
284
198
  sleep 1 unless users.length == 1
285
199
  end
286
200
  rescue => e
@@ -290,12 +204,12 @@ module Ayadn
290
204
 
291
205
  def mute(usernames)
292
206
  begin
293
- stop_if_no_username(usernames)
294
- users = all_but_me(usernames)
207
+ Check.no_username(usernames)
208
+ users = @workers.all_but_me(usernames)
295
209
  puts Status.muting(users.join(','))
296
210
  users.each do |user|
297
211
  resp = @api.mute(user)
298
- check_has_been_muted(user, resp)
212
+ Check.has_been_muted(user, resp)
299
213
  sleep 1 unless users.length == 1
300
214
  end
301
215
  rescue => e
@@ -305,12 +219,12 @@ module Ayadn
305
219
 
306
220
  def unblock(usernames)
307
221
  begin
308
- stop_if_no_username(usernames)
309
- users = all_but_me(usernames)
222
+ Check.no_username(usernames)
223
+ users = @workers.all_but_me(usernames)
310
224
  puts Status.unblocking(users.join(','))
311
225
  users.each do |user|
312
226
  resp = @api.unblock(user)
313
- check_has_been_unblocked(user, resp)
227
+ Check.has_been_unblocked(user, resp)
314
228
  sleep 1 unless users.length == 1
315
229
  end
316
230
  rescue => e
@@ -320,12 +234,12 @@ module Ayadn
320
234
 
321
235
  def block(usernames)
322
236
  begin
323
- stop_if_no_username(usernames)
324
- users = all_but_me(usernames)
237
+ Check.no_username(usernames)
238
+ users = @workers.all_but_me(usernames)
325
239
  puts Status.blocking(users.join(','))
326
240
  users.each do |user|
327
241
  resp = @api.block(user)
328
- check_has_been_blocked(user, resp)
242
+ Check.has_been_blocked(user, resp)
329
243
  sleep 1 unless users.length == 1
330
244
  end
331
245
  rescue => e
@@ -335,12 +249,12 @@ module Ayadn
335
249
 
336
250
  def repost(post_id)
337
251
  begin
338
- stop_if_bad_post_id(post_id)
252
+ Check.bad_post_id(post_id)
339
253
  puts Status.reposting(post_id)
340
254
  resp = @api.get_details(post_id)
341
- check_if_already_reposted(resp)
342
- id = get_original_id(post_id, resp)
343
- check_has_been_reposted(id, @api.repost(id))
255
+ Check.already_reposted(resp)
256
+ id = @workers.get_original_id(post_id, resp)
257
+ Check.has_been_reposted(id, @api.repost(id))
344
258
  rescue => e
345
259
  Errors.global_error({error: e, caller: caller, data: [post_id, id]})
346
260
  end
@@ -348,10 +262,10 @@ module Ayadn
348
262
 
349
263
  def unrepost(post_id)
350
264
  begin
351
- stop_if_bad_post_id(post_id)
265
+ Check.bad_post_id(post_id)
352
266
  puts Status.unreposting(post_id)
353
267
  if @api.get_details(post_id)['data']['you_reposted']
354
- check_has_been_unreposted(post_id, @api.unrepost(post_id))
268
+ Check.has_been_unreposted(post_id, @api.unrepost(post_id))
355
269
  else
356
270
  puts Status.not_your_repost
357
271
  end
@@ -362,13 +276,13 @@ module Ayadn
362
276
 
363
277
  def unstar(post_id)
364
278
  begin
365
- stop_if_bad_post_id(post_id)
279
+ Check.bad_post_id(post_id)
366
280
  puts Status.unstarring(post_id)
367
281
  resp = @api.get_details(post_id)
368
- id = get_original_id(post_id, resp)
282
+ id = @workers.get_original_id(post_id, resp)
369
283
  resp = @api.get_details(id)
370
284
  if resp['data']['you_starred']
371
- check_has_been_unstarred(id, @api.unstar(id))
285
+ Check.has_been_unstarred(id, @api.unstar(id))
372
286
  else
373
287
  puts Status.not_your_starred
374
288
  end
@@ -379,12 +293,12 @@ module Ayadn
379
293
 
380
294
  def star(post_id)
381
295
  begin
382
- stop_if_bad_post_id(post_id)
296
+ Check.bad_post_id(post_id)
383
297
  puts Status.starring(post_id)
384
298
  resp = @api.get_details(post_id)
385
- check_if_already_starred(resp)
386
- id = get_original_id(post_id, resp)
387
- check_has_been_starred(id, @api.star(id))
299
+ Check.already_starred(resp)
300
+ id = @workers.get_original_id(post_id, resp)
301
+ Check.has_been_starred(id, @api.star(id))
388
302
  rescue => e
389
303
  Errors.global_error({error: e, caller: caller, data: [post_id]})
390
304
  end
@@ -392,14 +306,7 @@ module Ayadn
392
306
 
393
307
  def hashtag(hashtag, options)
394
308
  begin
395
- doing(options)
396
- stream = @api.get_hashtag(hashtag)
397
- stop_if_no_data(stream, 'hashtag')
398
- if options[:extract]
399
- view_all_hashtag_links(stream, hashtag)
400
- else
401
- render_view(stream, options)
402
- end
309
+ @search.hashtag(hashtag, options)
403
310
  rescue => e
404
311
  Errors.global_error({error: e, caller: caller, data: [hashtag, options]})
405
312
  end
@@ -407,40 +314,7 @@ module Ayadn
407
314
 
408
315
  def search(words, options)
409
316
  begin
410
- doing(options)
411
- stream = if options[:users]
412
- @api.search_users words, options
413
- elsif options[:annotations]
414
- @api.search_annotations words, options
415
- elsif options[:channels]
416
- splitted = splitter_all words
417
- @api.search_channels splitted.join(','), options
418
- elsif options[:messages]
419
- words = words.split(',')
420
- channel_id = get_channel_id_from_alias(words[0])
421
- words.shift
422
- splitted = splitter_all words.join(' ')
423
- @api.search_messages channel_id, splitted.join(','), options
424
- else
425
- splitted = splitter_all words
426
- @api.get_search splitted.join(','), options
427
- end
428
- stop_if_no_data(stream, 'search')
429
- if options[:users]
430
- stream['data'].sort_by! {|obj| obj['counts']['followers']}
431
- stream['data'].each do |obj|
432
- puts @view.big_separator
433
- @view.show_userinfos(obj, nil, false)
434
- end
435
- elsif options[:channels]
436
- @view.show_channels stream, options
437
- else
438
- if options[:extract]
439
- view_all_search_links(stream, words)
440
- else
441
- render_view(stream, options)
442
- end
443
- end
317
+ @search.find(words, options)
444
318
  rescue => e
445
319
  Errors.global_error({error: e, caller: caller, data: [words, options]})
446
320
  end
@@ -448,15 +322,7 @@ module Ayadn
448
322
 
449
323
  def followings(username, options)
450
324
  begin
451
- stop_if_no_username(username)
452
- username = add_arobase(username)
453
- doing(options)
454
- if_raw_list(username, :followings, options)
455
- list = @api.get_followings(username)
456
- auto_save_followings(list)
457
- no_data('followings') if list.empty?
458
- get_list(:followings, list, username)
459
- Databases.add_to_users_db_from_list(list)
325
+ @stream.followings(username, options)
460
326
  rescue => e
461
327
  Errors.global_error({error: e, caller: caller, data: [username, options]})
462
328
  end
@@ -464,15 +330,7 @@ module Ayadn
464
330
 
465
331
  def followers(username, options)
466
332
  begin
467
- stop_if_no_username(username)
468
- username = add_arobase(username)
469
- doing(options)
470
- if_raw_list(username, :followers, options)
471
- list = @api.get_followers(username)
472
- auto_save_followers(list)
473
- no_data('followers') if list.empty?
474
- get_list(:followers, list, username)
475
- Databases.add_to_users_db_from_list(list)
333
+ @stream.followers(username, options)
476
334
  rescue => e
477
335
  Errors.global_error({error: e, caller: caller, data: [username, options]})
478
336
  end
@@ -480,13 +338,7 @@ module Ayadn
480
338
 
481
339
  def muted(options)
482
340
  begin
483
- doing(options)
484
- if_raw_list(nil, :muted, options)
485
- list = @api.get_muted
486
- auto_save_muted(list)
487
- no_data('muted') if list.empty?
488
- get_list(:muted, list, nil)
489
- Databases.add_to_users_db_from_list(list)
341
+ @stream.muted(options)
490
342
  rescue => e
491
343
  Errors.global_error({error: e, caller: caller, data: [options]})
492
344
  end
@@ -494,12 +346,7 @@ module Ayadn
494
346
 
495
347
  def blocked(options)
496
348
  begin
497
- doing(options)
498
- if_raw_list(nil, :blocked, options)
499
- list = @api.get_blocked
500
- no_data('blocked') if list.empty?
501
- get_list(:blocked, list, nil)
502
- Databases.add_to_users_db_from_list(list)
349
+ @stream.blocked(options)
503
350
  rescue => e
504
351
  Errors.global_error({error: e, caller: caller, data: [options]})
505
352
  end
@@ -515,18 +362,18 @@ module Ayadn
515
362
 
516
363
  def userinfo(username, options)
517
364
  begin
518
- stop_if_no_username(username)
519
- username = add_arobase(username)
520
- doing(options)
365
+ Check.no_username(username)
366
+ username = @workers.add_arobase(username)
367
+ @view.downloading(options)
521
368
  if options[:raw]
522
369
  resp = @api.get_user(username)
523
370
  @view.show_raw(resp, options)
524
371
  exit
525
372
  end
526
373
  stream = @api.get_user(username)
527
- stop_if_no_user(stream, username)
528
- same_username?(stream) ? token = @api.get_token_info['data'] : token = nil
529
- get_infos(stream['data'], token)
374
+ Check.no_user(stream, username)
375
+ Check.same_username(stream) ? token = @api.get_token_info['data'] : token = nil
376
+ @view.infos(stream['data'], token)
530
377
  rescue => e
531
378
  Errors.global_error({error: e, caller: caller, data: [username, options]})
532
379
  end
@@ -534,8 +381,8 @@ module Ayadn
534
381
 
535
382
  def postinfo(post_id, options)
536
383
  begin
537
- stop_if_bad_post_id(post_id)
538
- doing(options)
384
+ Check.bad_post_id(post_id)
385
+ @view.downloading(options)
539
386
  if options[:raw]
540
387
  details = @api.get_details(post_id, options)
541
388
  @view.show_raw(details, options)
@@ -543,10 +390,10 @@ module Ayadn
543
390
  end
544
391
  @view.clear_screen
545
392
  response = @api.get_details(post_id, options)
546
- stop_if_no_post(response, post_id)
393
+ Check.no_post(response, post_id)
547
394
  resp = response['data']
548
395
  response = @api.get_user("@#{resp['user']['username']}")
549
- stop_if_no_user(response, response['data']['username'])
396
+ Check.no_user(response, response['data']['username'])
550
397
  stream = response['data']
551
398
  puts "POST:\n".inverse
552
399
  @view.show_simple_post([resp], options)
@@ -568,14 +415,14 @@ module Ayadn
568
415
 
569
416
  def files(options)
570
417
  begin
571
- doing(options)
418
+ @view.downloading(options)
572
419
  if options[:raw]
573
420
  @view.show_raw(@api.get_files_list(options), options)
574
421
  exit
575
422
  end
576
423
  list = @api.get_files_list(options)
577
424
  @view.clear_screen
578
- list.empty? ? no_data('files') : @view.show_files_list(list)
425
+ list.empty? ? Errors.no_data('files') : @view.show_files_list(list)
579
426
  rescue => e
580
427
  Errors.global_error({error: e, caller: caller, data: [options]})
581
428
  end
@@ -593,7 +440,7 @@ module Ayadn
593
440
 
594
441
  def channels
595
442
  begin
596
- doing()
443
+ @view.downloading
597
444
  resp = @api.get_channels
598
445
  @view.clear_screen
599
446
  @view.show_channels(resp)
@@ -604,15 +451,7 @@ module Ayadn
604
451
 
605
452
  def messages(channel_id, options)
606
453
  begin
607
- channel_id = get_channel_id_from_alias(channel_id)
608
- doing(options)
609
- resp = @api.get_messages(channel_id, options)
610
- stop_if_no_new_posts(resp, options, "channel:#{channel_id}")
611
- Databases.save_max_id(resp)
612
- if_raw_show(resp, options)
613
- stop_if_no_data(resp, 'messages')
614
- render_view(resp, options)
615
- Scroll.new(@api, @view).messages(channel_id, options) if options[:scroll]
454
+ @stream.messages(channel_id, options)
616
455
  rescue => e
617
456
  Errors.global_error({error: e, caller: caller, data: [channel_id, options]})
618
457
  end
@@ -622,11 +461,11 @@ module Ayadn
622
461
  require 'pinboard'
623
462
  require 'base64'
624
463
  begin
625
- stop_if_bad_post_id(post_id)
626
- doing()
627
- resp = get_data_from_response(@api.get_details(post_id))
464
+ Check.bad_post_id(post_id)
465
+ @view.downloading
466
+ resp = @api.get_details(post_id)['data']
628
467
  @view.clear_screen
629
- links = Workers.new.extract_links(resp)
468
+ links = @workers.extract_links(resp)
630
469
  resp['text'].nil? ? text = "" : text = resp['text']
631
470
  usertags << "ADN"
632
471
  handle = "@" + resp['user']['username']
@@ -710,8 +549,8 @@ module Ayadn
710
549
  def pmess(username, options = {})
711
550
  begin
712
551
  files = FileOps.make_paths(options['embed']) if options['embed']
713
- stop_if_no_username(username)
714
- username = [add_arobase(username)]
552
+ Check.no_username(username)
553
+ username = [@workers.add_arobase(username)]
715
554
  messenger = Post.new
716
555
  puts Status.message_from(username)
717
556
  puts Status.message
@@ -728,7 +567,7 @@ module Ayadn
728
567
  end
729
568
  FileOps.save_message(resp) if Settings.options[:backup][:auto_save_sent_messages]
730
569
  @view.clear_screen
731
- puts Status.yourmessage
570
+ puts Status.yourmessage(username[0])
732
571
  @view.show_posted(resp)
733
572
  rescue => e
734
573
  Errors.global_error({error: e, caller: caller, data: [username, options]})
@@ -737,7 +576,7 @@ module Ayadn
737
576
 
738
577
  def send_to_channel(channel_id)
739
578
  begin
740
- channel_id = get_channel_id_from_alias(channel_id)
579
+ channel_id = @workers.get_channel_id_from_alias(channel_id)
741
580
  messenger = Post.new
742
581
  puts Status.writing
743
582
  puts Status.post
@@ -758,15 +597,15 @@ module Ayadn
758
597
  def reply(post_id, options = {})
759
598
  begin
760
599
  files = FileOps.make_paths(options['embed']) if options['embed']
761
- post_id = get_real_post_id(post_id)
600
+ post_id = @workers.get_real_post_id(post_id)
762
601
  puts Status.replying_to(post_id)
763
602
  replied_to = @api.get_details(post_id)
764
- stop_if_no_post(replied_to, post_id)
765
- post_id = get_original_id(post_id, replied_to)
603
+ Check.no_post(replied_to, post_id)
604
+ post_id = @workers.get_original_id(post_id, replied_to)
766
605
  if replied_to['data']['repost_of']
767
606
  if post_id == replied_to['data']['repost_of']['id']
768
607
  replied_to = @api.get_details(post_id)
769
- stop_if_no_post(replied_to, post_id)
608
+ Check.no_post(replied_to, post_id)
770
609
  end
771
610
  end
772
611
  poster = Post.new
@@ -775,7 +614,7 @@ module Ayadn
775
614
  lines_array = poster.compose
776
615
  poster.check_post_length(lines_array)
777
616
  @view.clear_screen
778
- reply = poster.reply(lines_array.join("\n"), Workers.new.build_posts([replied_to['data']]))
617
+ reply = poster.reply(lines_array.join("\n"), @workers.build_posts([replied_to['data']]))
779
618
  if options['embed']
780
619
  puts Status.uploading(options['embed'])
781
620
  resp = poster.send_reply_embedded(reply, post_id, files)
@@ -793,613 +632,65 @@ module Ayadn
793
632
  end
794
633
  options[:post_id] = resp['data']['id'].to_i
795
634
 
796
- render_view(@api.get_convo(post_id), options)
635
+ @view.render(@api.get_convo(post_id), options)
797
636
  rescue => e
798
637
  Errors.global_error({error: e, caller: caller, data: [post_id, options]})
799
638
  end
800
639
  end
801
640
 
802
641
  def nowplaying(options = {})
803
- options['lastfm'] ? np_lastfm(options) : np_itunes(options)
804
- end
805
-
806
- def random_posts(options)
807
- begin
808
- _, cols = winsize
809
- max_posts = cols / 12
810
- @view.clear_screen
811
- puts "Fetching random posts, please wait...".color(:cyan)
812
- @max_id = @api.get_global({count: 1})['meta']['max_id'].to_i
813
- @view.clear_screen
814
- counter = 1
815
- wait = options[:wait] || 5
816
- loop do
817
- begin
818
- @random_post_id = rand(@max_id)
819
- @resp = @api.get_details(@random_post_id, {})
820
- next if @resp['data']['is_deleted']
821
- @view.show_simple_post([@resp['data']], {})
822
- counter += 1
823
- if counter == max_posts
824
- countdown(wait)
825
- @view.clear_screen
826
- counter = 1
827
- end
828
- rescue Interrupt
829
- abort(Status.canceled)
830
- end
831
- end
832
- rescue => e
833
- Errors.global_error({error: e, caller: caller, data: [@max_id, @random_post_id, @resp, options]})
834
- end
835
- end
836
-
837
- def version
838
- begin
839
- puts "\nAYADN\n".color(:red)
840
- puts "Version:\t".color(:cyan) + "#{VERSION}\n".color(:green)
841
- puts "Changelog:\t".color(:cyan) + "https://github.com/ericdke/na/blob/master/CHANGELOG.md\n".color(Settings.options[:colors][:link])
842
- puts "Docs:\t\t".color(:cyan) + "http://ayadn-app.net/doc/".color(Settings.options[:colors][:link])
843
- puts "\n"
844
- rescue => e
845
- Errors.global_error({error: e, caller: caller, data: []})
846
- end
847
- end
848
-
849
- private
850
-
851
- def if_raw_list username, what, options
852
- if options[:raw]
853
- @view.show_raw(@api.get_raw_list(username, what), options)
854
- exit
855
- end
856
- end
857
-
858
- def if_raw_show what, options
859
- if options[:raw]
860
- @view.show_raw(what, options)
861
- exit
862
- end
642
+ np = NowPlaying.new(@api, @view, @workers)
643
+ options['lastfm'] ? np.lastfm(options) : np.itunes(options)
863
644
  end
864
645
 
865
- def all_but_me usernames
866
- all_but_me = usernames.select {|user| user != 'me'}
867
- Workers.at(all_but_me)
868
- end
869
-
870
- def np_lastfm options
871
- require 'rss'
646
+ def nowwatching(args, options = {})
872
647
  begin
873
- user = Settings.options[:nowplaying][:lastfm] || create_lastfm_user()
874
- puts Status.fetching_from('Last.fm')
875
- artist, track = get_lastfm_track_infos(user)
876
- puts Status.itunes_store
877
- store = lastfm_istore_request(artist, track) unless options['no_url']
878
- text_to_post = "#nowplaying\n \nTitle: ‘#{track}’\nArtist: #{artist}"
879
- post_nowplaying(text_to_post, store, options)
648
+ abort(Status.error_missing_title) if args.empty?
649
+ nw = NowWatching.new(@view)
650
+ nw.post(args, options)
651
+ rescue ArgumentError => e
652
+ puts Status.no_movie
880
653
  rescue => e
881
654
  puts Status.wtf
882
- Errors.global_error({error: e, caller: caller, data: [store, options]})
883
- end
884
- end
885
-
886
- def get_lastfm_track_infos user
887
- begin
888
- url = "http://ws.audioscrobbler.com/2.0/user/#{user}/recenttracks.rss"
889
- feed = RSS::Parser.parse(CNX.download(url))
890
- lfm = feed.items[0].title.split(' – ')
891
- return lfm[0], lfm[1]
892
- rescue Interrupt
893
- abort(Status.canceled)
894
- end
895
- end
896
-
897
- def np_itunes options
898
- begin
899
- abort(Status.error_only_osx) unless Settings.config[:platform] =~ /darwin/
900
- puts Status.fetching_from('iTunes')
901
- itunes = get_itunes_track_infos()
902
- itunes.each {|el| abort(Status.empty_fields) if el.length == 0}
903
- puts Status.itunes_store
904
- store = itunes_istore_request(itunes) unless options['no_url']
905
- text_to_post = "#nowplaying\n \nTitle: ‘#{itunes.track}’\nArtist: #{itunes.artist}\nfrom ‘#{itunes.album}’"
906
- post_nowplaying(text_to_post, store, options)
907
- rescue => e
908
- puts Status.wtf
909
- Errors.global_error({error: e, caller: caller, data: [itunes, store, options]})
655
+ Errors.global_error({error: e, caller: caller, data: [args, options]})
910
656
  end
911
657
  end
912
658
 
913
- def post_nowplaying text_to_post, store, options
659
+ def tvshow(args, options = {})
914
660
  begin
915
- @view.clear_screen
916
- puts Status.writing
917
- show_nowplaying("\n#{text_to_post}", options, store)
918
- unless options['no_url'] || store.nil?
919
- text_to_post += "\n \n[iTunes Store](#{store['link']})"
920
- end
921
- abort(Status.canceled) unless STDIN.getch == ("y" || "Y")
922
- puts "\n#{Status.yourpost}"
923
- unless store.nil? || options['no_url']
924
- visible, track, artwork, artwork_thumb, link, artist = true, store['track'], store['artwork'], store['artwork_thumb'], store['link'], store['artist']
925
- else
926
- visible, track, artwork, artwork_thumb, link, artist = false
927
- end
928
- if options['lastfm']
929
- source = 'Last.fm'
661
+ abort(Status.error_missing_title) if args.empty?
662
+ client = TvShow.new
663
+ if options['alt']
664
+ show_obj = client.find_alt(args.join(' '))
930
665
  else
931
- source = 'iTunes'
666
+ show_obj = client.find(args.join(' '))
932
667
  end
933
- dic = {
934
- 'text' => text_to_post,
935
- 'title' => track,
936
- 'artist' => artist,
937
- 'artwork' => artwork,
938
- 'artwork_thumb' => artwork_thumb,
939
- 'width' => 1200,
940
- 'height' => 1200,
941
- 'width_thumb' => 200,
942
- 'height_thumb' => 200,
943
- 'link' => link,
944
- 'source' => source,
945
- 'visible' => visible
946
- }
947
- @view.show_posted(Post.new.send_nowplaying(dic))
668
+ candidate = client.create_details(show_obj)
669
+ candidate.ok ? candidate.post(options) : candidate.cancel
948
670
  rescue => e
949
671
  puts Status.wtf
950
- Errors.global_error({error: e, caller: caller, data: [dic, store, options]})
672
+ Errors.global_error({error: e, caller: caller, data: [args, options]})
951
673
  end
952
674
  end
953
675
 
954
- def ask_lastfm_user
955
- puts "\nPlease enter your Last.fm username:\n".color(:cyan)
676
+ def random_posts(options)
956
677
  begin
957
- STDIN.gets.chomp!
958
- rescue Interrupt
959
- abort(Status.canceled)
960
- end
961
- end
962
-
963
- def create_lastfm_user
964
- Settings.options[:nowplaying][:lastfm] = ask_lastfm_user()
965
- Settings.save_config
966
- return Settings.options[:nowplaying][:lastfm]
967
- end
968
-
969
- def itunes_istore_request itunes
970
- infos = itunes_reg([itunes.artist, itunes.track, itunes.album])
971
- itunes_url = "https://itunes.apple.com/search?term=#{infos[0]}&term=#{infos[1]}&term=#{infos[2]}&media=music&entity=musicTrack"
972
- get_itunes_store(itunes_url, itunes.artist, itunes.track)
973
- end
974
-
975
- def lastfm_istore_request artist, track
976
- infos = itunes_reg([artist, track])
977
- itunes_url = "https://itunes.apple.com/search?term=#{infos[0]}&term=#{infos[1]}&media=music&entity=musicTrack"
978
- get_itunes_store(itunes_url, artist, track)
979
- end
980
-
981
- def get_itunes_store url, artist, track
982
- results = JSON.load(CNX.download(URI.escape(url)))['results']
983
- unless results.empty? || results.nil?
984
-
985
- resp = results.select {|obj| obj['artistName'] == artist && obj['trackName'] == track}
986
- candidate = resp[0] || results[0]
987
-
988
- return {
989
- 'code' => 200,
990
- 'artist' => candidate['artistName'],
991
- 'track' => candidate['trackName'],
992
- 'preview' => candidate['previewUrl'],
993
- 'link' => candidate['collectionViewUrl'],
994
- 'artwork' => candidate['artworkUrl100'].gsub('100x100', '1200x1200'),
995
- 'artwork_thumb' => candidate['artworkUrl100'].gsub('100x100', '600x600'),
996
- 'request' => url,
997
- 'results' => results
998
- }
999
- else
1000
- return {
1001
- 'code' => 404,
1002
- 'request' => url
1003
- }
1004
- end
1005
- end
1006
-
1007
- def itunes_reg arr_of_itunes
1008
- regex_exotics = /[~:-;,?!\'&`^=+<>*%()\/"“”’°£$€.…]/
1009
- arr_of_itunes.map do |itune|
1010
- itune.gsub(regex_exotics, ' ').split(' ').join('+')
1011
- end
1012
- end
1013
-
1014
- def get_itunes_track_infos
1015
- track = `osascript -e 'tell application "iTunes"' -e 'set trackName to name of current track' -e 'return trackName' -e 'end tell'`
1016
- if track.empty?
1017
- puts Status.no_itunes
1018
- Errors.warn "Nowplaying canceled: unable to get info from iTunes."
1019
- exit
1020
- end
1021
- album = `osascript -e 'tell application "iTunes"' -e 'set trackAlbum to album of current track' -e 'return trackAlbum' -e 'end tell'`
1022
- artist = `osascript -e 'tell application "iTunes"' -e 'set trackArtist to artist of current track' -e 'return trackArtist' -e 'end tell'`
1023
- maker = Struct.new(:artist, :album, :track)
1024
- maker.new(artist.chomp!, album.chomp!, track.chomp!)
1025
- end
1026
-
1027
- def show_nowplaying(text, options, store)
1028
- puts "\nYour post:\n".color(:cyan)
1029
- if options['no_url'] || store['code'] != 200
1030
- puts text + "\n\n\n"
1031
- else
1032
- puts text + "\n\n\nThe iTunes Store thinks this track is: ".color(:green) + "'#{store['track']}'".color(:magenta) + " by ".color(:green) + "'#{store['artist']}'".color(:magenta) + ".\n\nAyadn will use these elements to insert album artwork and a link to the track.\n\n".color(:green)
1033
- end
1034
- puts "Is it ok? (y/N) ".color(:yellow)
1035
- end
1036
-
1037
- def nicerank_true
1038
- return true if Settings.options[:nicerank][:filter] == true
1039
- end
1040
-
1041
- def stop_if_bad_post_id post_id
1042
- missing_post_id() unless post_id.is_integer?
1043
- end
1044
-
1045
- def stop_if_no_data stream, target
1046
- if stream['data'].empty?
1047
- Errors.warn "In action/#{target}: no data"
1048
- abort(Status.empty_list)
1049
- end
1050
- end
1051
-
1052
- def stop_if_404 stream, post_id
1053
- if stream['meta']['code'] == 404
1054
- abort(Status.post_404(post_id))
1055
- end
1056
- end
1057
-
1058
- def add_arobase username
1059
- Workers.add_arobase_if_missing(username)
1060
- end
1061
-
1062
- def stop_if_no_new_posts stream, options, title
1063
- if options[:new]
1064
- unless Databases.has_new?(stream, title)
1065
- no_new_posts()
1066
- end
1067
- end
1068
- end
1069
-
1070
- def splitter_all words
1071
- [words].collect {|w| w.split(' ')}
1072
- end
1073
-
1074
- def get_original_id(post_id, resp)
1075
- if resp['data']['repost_of']
1076
- puts Status.redirecting
1077
- id = resp['data']['repost_of']['id']
1078
- Errors.repost(post_id, id)
1079
- return id
1080
- else
1081
- return post_id
1082
- end
1083
- end
1084
-
1085
- def check_if_already_starred(resp)
1086
- if resp['data']['you_starred']
1087
- puts "\nYou already starred this post.\n".color(:red)
1088
- exit
1089
- end
1090
- end
1091
-
1092
- def check_if_already_reposted(resp)
1093
- if resp['data']['you_reposted']
1094
- puts "\nYou already reposted this post.\n".color(:red)
1095
- exit
1096
- end
1097
- end
1098
-
1099
- def check_has_been_starred(post_id, resp)
1100
- if resp['meta']['code'] == 200
1101
- puts Status.starred(post_id)
1102
- Logs.rec.info "Starred #{post_id}."
1103
- else
1104
- whine(Status.not_starred(post_id), resp)
1105
- end
1106
- end
1107
-
1108
- def check_has_been_reposted(post_id, resp)
1109
- if resp['meta']['code'] == 200
1110
- puts Status.reposted(post_id)
1111
- Logs.rec.info "Reposted #{post_id}."
1112
- else
1113
- whine(Status.not_reposted(post_id), resp)
1114
- end
1115
- end
1116
-
1117
- def check_has_been_blocked(username, resp)
1118
- if resp['meta']['code'] == 200
1119
- puts Status.blocked(username)
1120
- Logs.rec.info "Blocked #{username}."
1121
- else
1122
- whine(Status.not_blocked(username), resp)
1123
- end
1124
- end
1125
-
1126
- def check_has_been_muted(username, resp)
1127
- if resp['meta']['code'] == 200
1128
- puts Status.muted(username)
1129
- Logs.rec.info "Muted #{username}."
1130
- else
1131
- whine(Status.not_muted(username), resp)
1132
- end
1133
- end
1134
-
1135
- def check_has_been_followed(username, resp)
1136
- if resp['meta']['code'] == 200
1137
- puts Status.followed(username)
1138
- Logs.rec.info "Followed #{username}."
1139
- else
1140
- whine(Status.not_followed(username), resp)
1141
- end
1142
- end
1143
-
1144
- def check_has_been_deleted(post_id, resp)
1145
- if resp['meta']['code'] == 200
1146
- puts Status.deleted(post_id)
1147
- Logs.rec.info "Deleted post #{post_id}."
1148
- else
1149
- whine(Status.not_deleted(post_id), resp)
1150
- end
1151
- end
1152
-
1153
- def check_message_has_been_deleted(message_id, resp)
1154
- if resp['meta']['code'] == 200
1155
- puts Status.deleted_m(message_id)
1156
- Logs.rec.info "Deleted message #{message_id}."
1157
- else
1158
- whine(Status.not_deleted(message_id), resp)
1159
- end
1160
- end
1161
-
1162
- def check_has_been_unblocked(username, resp)
1163
- if resp['meta']['code'] == 200
1164
- puts Status.unblocked(username)
1165
- Logs.rec.info "Unblocked #{username}."
1166
- else
1167
- whine(Status.not_unblocked(username), resp)
1168
- end
1169
- end
1170
-
1171
- def check_has_been_unstarred(post_id, resp)
1172
- if resp['meta']['code'] == 200
1173
- puts Status.unstarred(post_id)
1174
- Logs.rec.info "Unstarred #{post_id}."
1175
- else
1176
- whine(Status.not_unstarred(post_id), resp)
1177
- end
1178
- end
1179
-
1180
- def check_has_been_unreposted(post_id, resp)
1181
- if resp['meta']['code'] == 200
1182
- puts Status.unreposted(post_id)
1183
- Logs.rec.info "Unreposted #{post_id}."
1184
- else
1185
- whine(Status.not_unreposted(post_id), resp)
1186
- end
1187
- end
1188
-
1189
- def check_has_been_unmuted(username, resp)
1190
- if resp['meta']['code'] == 200
1191
- puts Status.unmuted(username)
1192
- Logs.rec.info "Unmuted #{username}."
1193
- else
1194
- whine(Status.not_unmuted(username), resp)
1195
- end
1196
- end
1197
-
1198
- def check_has_been_unfollowed(username, resp)
1199
- if resp['meta']['code'] == 200
1200
- puts Status.unfollowed(username)
1201
- Logs.rec.info "Unfollowed #{username}."
1202
- else
1203
- whine(Status.not_unfollowed(username), resp)
1204
- end
1205
- end
1206
-
1207
- def whine(status, resp)
1208
- puts status
1209
- Errors.error("#{status} => #{resp['meta']}")
1210
- end
1211
-
1212
- def no_data(where)
1213
- Errors.warn "In action/#{where}: no data"
1214
- abort(Status.empty_list)
1215
- end
1216
-
1217
- def stop_if_no_user stream, username
1218
- if stream['meta']['code'] == 404
1219
- puts Status.user_404(username)
1220
- Errors.info("User #{username} doesn't exist")
1221
- exit
1222
- end
1223
- end
1224
-
1225
- def stop_if_no_post stream, post_id
1226
- if stream['meta']['code'] == 404
1227
- puts Status.post_404(post_id)
1228
- Errors.info("Impossible to find #{post_id}")
1229
- exit
1230
- end
1231
- end
1232
-
1233
- def length_of_index
1234
- Databases.get_index_length
1235
- end
1236
-
1237
- def get_post_from_index id
1238
- Databases.get_post_from_index id
1239
- end
1240
-
1241
- def get_real_post_id post_id
1242
- id = post_id.to_i
1243
- if id > 0 && id <= length_of_index
1244
- resp = get_post_from_index(id)
1245
- post_id = resp[:id]
1246
- end
1247
- post_id
1248
- end
1249
-
1250
- def render_view(stream, options = {}, niceranks = {})
1251
- unless options[:raw]
1252
- get_view(stream['data'], options, niceranks)
1253
- else
1254
- @view.show_raw(stream)
1255
- end
1256
- end
1257
-
1258
- def doing(options = {})
1259
- unless options[:raw]
1260
- @view.clear_screen
1261
- print Status.downloading
1262
- end
1263
- end
1264
-
1265
- def get_data_from_response(response)
1266
- response['data']
1267
- end
1268
-
1269
- def get_view(stream, options = {}, niceranks = {})
1270
- @view.clear_screen
1271
- if options[:index]
1272
- @view.show_posts_with_index(stream, options, niceranks)
1273
- else
1274
- @view.show_posts(stream, options, niceranks)
1275
- end
1276
- end
1277
-
1278
- def get_simple_view(stream)
1279
- @view.clear_screen
1280
- @view.show_simple_stream(stream)
1281
- end
1282
-
1283
- def get_infos(stream, token)
1284
- @view.clear_screen
1285
- @view.show_userinfos(stream, token, true)
1286
- end
1287
-
1288
- def get_list(what, list, target)
1289
- @view.clear_screen
1290
- case what
1291
- when :whoreposted
1292
- @view.show_list_reposted(list, target)
1293
- when :whostarred
1294
- @view.show_list_starred(list, target)
1295
- when :followings
1296
- @view.show_list_followings(list, target)
1297
- when :followers
1298
- @view.show_list_followers(list, target)
1299
- when :muted
1300
- @view.show_list_muted(list)
1301
- when :blocked
1302
- @view.show_list_blocked(list)
1303
- end
1304
- end
1305
-
1306
- def get_channel_id_from_alias(channel_id)
1307
- unless channel_id.is_integer?
1308
- orig = channel_id
1309
- channel_id = Databases.get_channel_id(orig)
1310
- if channel_id.nil?
1311
- Errors.warn("Alias '#{orig}' doesn't exist.")
1312
- puts Status.no_alias
1313
- exit
1314
- end
1315
- end
1316
- channel_id
1317
- end
1318
-
1319
- def winsize
1320
- IO.console.winsize
1321
- end
1322
-
1323
- def no_new_posts
1324
- @view.clear_screen
1325
- puts Status.no_new_posts
1326
- exit
1327
- end
1328
-
1329
- def stop_if_no_username username
1330
- if username.empty?
1331
- puts Status.error_missing_username
1332
- exit
1333
- end
1334
- end
1335
-
1336
- def missing_post_id
1337
- puts Status.error_missing_post_id
1338
- exit
1339
- end
1340
-
1341
- def missing_message_id
1342
- puts Status.error_missing_message_id
1343
- exit
1344
- end
1345
-
1346
- def auto_save_followings(list)
1347
- FileOps.save_followings_list(list) if Settings.options[:backup][:auto_save_lists]
1348
- end
1349
- def auto_save_followers(list)
1350
- FileOps.save_followers_list(list) if Settings.options[:backup][:auto_save_lists]
1351
- end
1352
- def auto_save_muted(list)
1353
- FileOps.save_muted_list(list) if Settings.options[:backup][:auto_save_lists]
1354
- end
1355
-
1356
- def same_username?(stream)
1357
- stream['data']['username'] == Settings.config[:identity][:username]
1358
- end
1359
-
1360
- def countdown(wait)
1361
- wait.downto(1) do |i|
1362
- print "\r#{sprintf("%02d", i)} sec... QUIT WITH [CTRL+C]".color(:cyan)
1363
- sleep 1
678
+ @stream.random_posts(options)
679
+ rescue => e
680
+ Errors.global_error({error: e, caller: caller, data: [@max_id, @random_post_id, @resp, options]})
1364
681
  end
1365
682
  end
1366
683
 
1367
- def links_from_posts(stream)
1368
- links = []
1369
- worker = Workers.new
1370
- stream['data'].each do |post|
1371
- from = worker.extract_links(post)
1372
- from.each {|l| links << l}
684
+ def version
685
+ begin
686
+ puts "\nAYADN\n".color(:red)
687
+ puts "Version:\t".color(:cyan) + "#{VERSION}\n".color(:green)
688
+ puts "Changelog:\t".color(:cyan) + "https://github.com/ericdke/na/blob/master/CHANGELOG.md\n".color(Settings.options[:colors][:link])
689
+ puts "Docs:\t\t".color(:cyan) + "https://github.com/ericdke/na/tree/master/doc".color(Settings.options[:colors][:link])
690
+ puts "\n"
691
+ rescue => e
692
+ Errors.global_error({error: e, caller: caller, data: []})
1373
693
  end
1374
- links.uniq!
1375
- links
1376
- end
1377
-
1378
- def show_links(links)
1379
- links.each {|l| puts "#{l}\n".color(Settings.options[:colors][:link])}
1380
- end
1381
-
1382
- def view_all_hashtag_links(stream, hashtag)
1383
- @view.clear_screen
1384
- puts "Links from posts containing hashtag '##{hashtag}': \n".color(:cyan)
1385
- show_links(links_from_posts(stream))
1386
- end
1387
-
1388
- def view_all_search_links(stream, words)
1389
- @view.clear_screen
1390
- puts "Links from posts containing word(s) '#{words}': \n".color(:cyan)
1391
- show_links(links_from_posts(stream))
1392
- end
1393
-
1394
- def view_all_stars_links(stream)
1395
- @view.clear_screen
1396
- puts "Links from your starred posts: \n".color(:cyan)
1397
- show_links(links_from_posts(stream))
1398
- end
1399
-
1400
- def self.quit msg
1401
- puts msg
1402
- exit
1403
694
  end
1404
695
 
1405
696
  end