ayadn 1.8.2 → 2.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.
Files changed (81) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +4 -0
  3. data/CHANGELOG.md +73 -52
  4. data/README.md +17 -3
  5. data/ayadn.gemspec +3 -4
  6. data/doc/01-index.md +6 -5
  7. data/doc/02-install.md +23 -1
  8. data/doc/03-first-steps.md +22 -28
  9. data/doc/04-options.md +1 -1
  10. data/doc/05-streams.md +29 -9
  11. data/doc/06-post.md +13 -5
  12. data/doc/07-actions.md +63 -1
  13. data/doc/08-listings.md +112 -4
  14. data/doc/09-accounts.md +17 -3
  15. data/doc/10-nicerank.md +5 -5
  16. data/doc/11-blacklist.md +8 -14
  17. data/doc/12-alias.md +1 -13
  18. data/doc/14-set.md +8 -110
  19. data/doc/15-nowplaying.md +16 -4
  20. data/doc/18-contact.md +14 -13
  21. data/doc/19-examples.md +2 -0
  22. data/lib/ayadn/action.rb +322 -183
  23. data/lib/ayadn/alias.rb +17 -45
  24. data/lib/ayadn/annotations.rb +1 -1
  25. data/lib/ayadn/api.rb +7 -8
  26. data/lib/ayadn/app.rb +99 -12
  27. data/lib/ayadn/authorize.rb +92 -57
  28. data/lib/ayadn/blacklist.rb +52 -62
  29. data/lib/ayadn/check.rb +81 -74
  30. data/lib/ayadn/cnx.rb +77 -26
  31. data/lib/ayadn/databases.rb +890 -105
  32. data/lib/ayadn/debug.rb +30 -89
  33. data/lib/ayadn/descriptions.rb +876 -329
  34. data/lib/ayadn/endpoints.rb +2 -2
  35. data/lib/ayadn/errors.rb +9 -9
  36. data/lib/ayadn/extend.rb +8 -1
  37. data/lib/ayadn/fileops.rb +10 -8
  38. data/lib/ayadn/mark.rb +79 -56
  39. data/lib/ayadn/migration.rb +427 -0
  40. data/lib/ayadn/nicerank.rb +74 -72
  41. data/lib/ayadn/nowplaying.rb +123 -60
  42. data/lib/ayadn/nowwatching.rb +26 -10
  43. data/lib/ayadn/pinboard.rb +12 -7
  44. data/lib/ayadn/post.rb +40 -37
  45. data/lib/ayadn/profile.rb +5 -2
  46. data/lib/ayadn/scroll.rb +20 -5
  47. data/lib/ayadn/search.rb +30 -22
  48. data/lib/ayadn/set.rb +146 -50
  49. data/lib/ayadn/settings.rb +66 -67
  50. data/lib/ayadn/status.rb +459 -234
  51. data/lib/ayadn/stream.rb +80 -46
  52. data/lib/ayadn/switch.rb +51 -47
  53. data/lib/ayadn/tvshow.rb +47 -15
  54. data/lib/ayadn/version.rb +1 -1
  55. data/lib/ayadn/view.rb +119 -60
  56. data/lib/ayadn/workers.rb +144 -92
  57. data/lib/ayadn.rb +7 -8
  58. data/spec/mock/ayadn/accounts.sqlite +0 -0
  59. data/spec/mock/ayadn.sqlite +0 -0
  60. data/spec/unit/annotations_spec.rb +12 -13
  61. data/spec/unit/api_spec.rb +3 -4
  62. data/spec/unit/blacklistworkers_spec.rb +18 -23
  63. data/spec/unit/databases_spec.rb +51 -36
  64. data/spec/unit/endpoints_spec.rb +5 -2
  65. data/spec/unit/extend_spec.rb +24 -0
  66. data/spec/unit/nicerank_spec.rb +13 -13
  67. data/spec/unit/post_spec.rb +47 -36
  68. data/spec/unit/set_spec.rb +67 -96
  69. data/spec/unit/view_spec.rb +12 -6
  70. data/spec/unit/workers_spec.rb +38 -12
  71. data/tags +1285 -0
  72. metadata +29 -39
  73. data/spec/mock/aliases.db +0 -0
  74. data/spec/mock/blacklist.db +0 -0
  75. data/spec/mock/bookmarks.db +0 -0
  76. data/spec/mock/channels.db +0 -0
  77. data/spec/mock/index.db +0 -0
  78. data/spec/mock/nicerank.db +0 -0
  79. data/spec/mock/pagination.db +0 -0
  80. data/spec/mock/users.db +0 -0
  81. data/spec/unit/status_spec.rb +0 -9
data/lib/ayadn/action.rb CHANGED
@@ -4,27 +4,29 @@ module Ayadn
4
4
 
5
5
  ##
6
6
  # This class is the main initializer + dispatcher
7
+ # It responds to the CLI commands dispatcher, app.rb
7
8
 
8
9
  def initialize
9
10
  @api = API.new
10
11
  @view = View.new
11
12
  @workers = Workers.new
12
- @stream = Stream.new(@api, @view, @workers)
13
- @search = Search.new(@api, @view, @workers)
14
- @shell = Thor::Shell::Color.new
13
+ @thor = Thor::Shell::Color.new
14
+ @status = Status.new
15
+ @check = Check.new
15
16
  Settings.load_config
16
17
  Settings.get_token
17
18
  Settings.init_config
18
19
  Logs.create_logger
19
20
  Databases.open_databases
20
- at_exit { Databases.close_all }
21
21
  end
22
22
 
23
23
  def method_missing(meth, options)
24
24
  case meth.to_s
25
25
  when 'unified', 'checkins', 'global', 'trending', 'photos', 'conversations', 'interactions'
26
26
  begin
27
- @stream.send(meth.to_sym, options)
27
+ Settings.options[:timeline][:compact] = true if options[:compact] == true
28
+ stream = Stream.new(@api, @view, @workers)
29
+ stream.send(meth.to_sym, options)
28
30
  rescue => e
29
31
  Errors.global_error({error: e, caller: caller, data: [meth, options]})
30
32
  end
@@ -35,7 +37,9 @@ module Ayadn
35
37
 
36
38
  def mentions(username, options)
37
39
  begin
38
- @stream.mentions(username, options)
40
+ Settings.options[:timeline][:compact] = true if options[:compact] == true
41
+ stream = Stream.new(@api, @view, @workers)
42
+ stream.mentions(username, options)
39
43
  rescue => e
40
44
  Errors.global_error({error: e, caller: caller, data: [username, options]})
41
45
  end
@@ -43,7 +47,9 @@ module Ayadn
43
47
 
44
48
  def posts(username, options)
45
49
  begin
46
- @stream.posts(username, options)
50
+ Settings.options[:timeline][:compact] = true if options[:compact] == true
51
+ stream = Stream.new(@api, @view, @workers)
52
+ stream.posts(username, options)
47
53
  rescue => e
48
54
  Errors.global_error({error: e, caller: caller, data: [username, options]})
49
55
  end
@@ -51,7 +57,9 @@ module Ayadn
51
57
 
52
58
  def whatstarred(username, options)
53
59
  begin
54
- @stream.whatstarred(username, options)
60
+ Settings.options[:timeline][:compact] = true if options[:compact] == true
61
+ stream = Stream.new(@api, @view, @workers)
62
+ stream.whatstarred(username, options)
55
63
  rescue => e
56
64
  Errors.global_error({error: e, caller: caller, data: [username, options]})
57
65
  end
@@ -59,7 +67,9 @@ module Ayadn
59
67
 
60
68
  def whoreposted(post_id, options)
61
69
  begin
62
- @stream.whoreposted(post_id, options)
70
+ Settings.options[:timeline][:compact] = true if options[:compact] == true
71
+ stream = Stream.new(@api, @view, @workers)
72
+ stream.whoreposted(post_id, options)
63
73
  rescue => e
64
74
  Errors.global_error({error: e, caller: caller, data: [post_id, options]})
65
75
  end
@@ -67,7 +77,9 @@ module Ayadn
67
77
 
68
78
  def whostarred(post_id, options)
69
79
  begin
70
- @stream.whostarred(post_id, options)
80
+ Settings.options[:timeline][:compact] = true if options[:compact] == true
81
+ stream = Stream.new(@api, @view, @workers)
82
+ stream.whostarred(post_id, options)
71
83
  rescue => e
72
84
  Errors.global_error({error: e, caller: caller, data: [post_id, options]})
73
85
  end
@@ -75,52 +87,71 @@ module Ayadn
75
87
 
76
88
  def convo(post_id, options)
77
89
  begin
78
- @stream.convo(post_id, options)
90
+ Settings.options[:timeline][:compact] = true if options[:compact] == true
91
+ stream = Stream.new(@api, @view, @workers)
92
+ stream.convo(post_id, options)
79
93
  rescue => e
80
94
  Errors.global_error({error: e, caller: caller, data: [post_id, options]})
81
95
  end
82
96
  end
83
97
 
84
- def delete(post_ids)
98
+ def delete(post_ids, options = {})
85
99
  begin
86
100
  ids = post_ids.select { |post_id| post_id.is_integer? }
87
- abort(Status.error_missing_post_id) if ids.empty?
101
+ if ids.empty?
102
+ @status.error_missing_post_id
103
+ exit
104
+ end
105
+ if options[:force]
106
+ Settings.global[:force] = true
107
+ else
108
+ ids.map! { |post_id| @workers.get_real_post_id(post_id) }
109
+ end
110
+ puts "\n"
88
111
  ids.each do |post_id|
89
- print Status.deleting_post(post_id)
112
+ @status.deleting_post(post_id)
90
113
  resp = @api.delete_post(post_id)
91
- Check.has_been_deleted(post_id, resp)
114
+ @check.has_been_deleted(post_id, resp)
92
115
  end
93
116
  rescue => e
94
- Errors.global_error({error: e, caller: caller, data: [post_id]})
117
+ Errors.global_error({error: e, caller: caller, data: [post_ids]})
95
118
  end
96
119
  end
97
120
 
98
121
  def delete_m(args)
99
122
  begin
100
- abort(Status.error_missing_message_id) unless args.length >= 2
123
+ unless args.length >= 2
124
+ @status.error_missing_message_id
125
+ exit
126
+ end
101
127
  channel = args[0]
102
128
  args.shift
103
129
  ids = args.select {|message_id| message_id.is_integer?}
104
- abort(Status.error_missing_message_id) if ids.empty?
130
+ if ids.empty?
131
+ @status.error_missing_message_id
132
+ exit
133
+ end
105
134
  channel_id = @workers.get_channel_id_from_alias(channel)
135
+ puts "\n"
106
136
  ids.each do |message_id|
107
- print Status.deleting_message(message_id)
137
+ @status.deleting_message(message_id)
108
138
  resp = @api.delete_message(channel_id, message_id)
109
- Check.message_has_been_deleted(message_id, resp)
139
+ @check.message_has_been_deleted(message_id, resp)
110
140
  end
111
141
  rescue => e
112
- Errors.global_error({error: e, caller: caller, data: [message_id]})
142
+ Errors.global_error({error: e, caller: caller, data: [args]})
113
143
  end
114
144
  end
115
145
 
116
146
  def unfollow(usernames)
117
147
  begin
118
- Check.no_username(usernames)
148
+ @check.no_username(usernames)
119
149
  users = @workers.all_but_me(usernames)
120
- puts Status.unfollowing(users.join(','))
150
+ puts "\n"
151
+ @status.unfollowing(users.join(','))
121
152
  users.each do |user|
122
153
  resp = @api.unfollow(user)
123
- Check.has_been_unfollowed(user, resp)
154
+ @check.has_been_unfollowed(user, resp)
124
155
  end
125
156
  rescue => e
126
157
  Errors.global_error({error: e, caller: caller, data: [usernames]})
@@ -129,12 +160,13 @@ module Ayadn
129
160
 
130
161
  def follow(usernames)
131
162
  begin
132
- Check.no_username(usernames)
163
+ @check.no_username(usernames)
133
164
  users = @workers.all_but_me(usernames)
134
- puts Status.following(users.join(','))
165
+ puts "\n"
166
+ @status.following(users.join(','))
135
167
  users.each do |user|
136
168
  resp = @api.follow(user)
137
- Check.has_been_followed(user, resp)
169
+ @check.has_been_followed(user, resp)
138
170
  end
139
171
  rescue => e
140
172
  Errors.global_error({error: e, caller: caller, data: [usernames]})
@@ -143,12 +175,13 @@ module Ayadn
143
175
 
144
176
  def unmute(usernames)
145
177
  begin
146
- Check.no_username(usernames)
178
+ @check.no_username(usernames)
147
179
  users = @workers.all_but_me(usernames)
148
- puts Status.unmuting(users.join(','))
180
+ puts "\n"
181
+ @status.unmuting(users.join(','))
149
182
  users.each do |user|
150
183
  resp = @api.unmute(user)
151
- Check.has_been_unmuted(user, resp)
184
+ @check.has_been_unmuted(user, resp)
152
185
  end
153
186
  rescue => e
154
187
  Errors.global_error({error: e, caller: caller, data: [usernames]})
@@ -157,12 +190,13 @@ module Ayadn
157
190
 
158
191
  def mute(usernames)
159
192
  begin
160
- Check.no_username(usernames)
193
+ @check.no_username(usernames)
161
194
  users = @workers.all_but_me(usernames)
162
- puts Status.muting(users.join(','))
195
+ puts "\n"
196
+ @status.muting(users.join(','))
163
197
  users.each do |user|
164
198
  resp = @api.mute(user)
165
- Check.has_been_muted(user, resp)
199
+ @check.has_been_muted(user, resp)
166
200
  end
167
201
  rescue => e
168
202
  Errors.global_error({error: e, caller: caller, data: [usernames]})
@@ -171,12 +205,13 @@ module Ayadn
171
205
 
172
206
  def unblock(usernames)
173
207
  begin
174
- Check.no_username(usernames)
208
+ @check.no_username(usernames)
175
209
  users = @workers.all_but_me(usernames)
176
- puts Status.unblocking(users.join(','))
210
+ puts "\n"
211
+ @status.unblocking(users.join(','))
177
212
  users.each do |user|
178
213
  resp = @api.unblock(user)
179
- Check.has_been_unblocked(user, resp)
214
+ @check.has_been_unblocked(user, resp)
180
215
  end
181
216
  rescue => e
182
217
  Errors.global_error({error: e, caller: caller, data: [usernames]})
@@ -185,78 +220,129 @@ module Ayadn
185
220
 
186
221
  def block(usernames)
187
222
  begin
188
- Check.no_username(usernames)
223
+ @check.no_username(usernames)
189
224
  users = @workers.all_but_me(usernames)
190
- puts Status.blocking(users.join(','))
225
+ puts "\n"
226
+ @status.blocking(users.join(','))
191
227
  users.each do |user|
192
228
  resp = @api.block(user)
193
- Check.has_been_blocked(user, resp)
229
+ @check.has_been_blocked(user, resp)
194
230
  end
195
231
  rescue => e
196
232
  Errors.global_error({error: e, caller: caller, data: [usernames]})
197
233
  end
198
234
  end
199
235
 
200
- def repost(post_id)
236
+ def repost(post_ids, options = {})
201
237
  begin
202
- Check.bad_post_id(post_id)
203
- puts Status.reposting(post_id)
204
- resp = @api.get_details(post_id)
205
- Check.already_reposted(resp)
206
- id = @workers.get_original_id(post_id, resp)
207
- Check.has_been_reposted(id, @api.repost(id))
238
+ ids = post_ids.select { |post_id| post_id.is_integer? }
239
+ if ids.empty?
240
+ @status.error_missing_post_id
241
+ exit
242
+ end
243
+ if options[:force]
244
+ Settings.global[:force] = true
245
+ else
246
+ ids.map! { |post_id| @workers.get_real_post_id(post_id) }
247
+ end
248
+ puts "\n"
249
+ ids.each do |post_id|
250
+ @status.reposting(post_id)
251
+ resp = @api.get_details(post_id)
252
+ @check.already_reposted(resp)
253
+ id = @workers.get_original_id(post_id, resp)
254
+ @check.has_been_reposted(id, @api.repost(id))
255
+ end
208
256
  rescue => e
209
- Errors.global_error({error: e, caller: caller, data: [post_id, id]})
257
+ Errors.global_error({error: e, caller: caller, data: [post_ids, id]})
210
258
  end
211
259
  end
212
260
 
213
- def unrepost(post_id)
261
+ def unrepost(post_ids, options = {})
214
262
  begin
215
- Check.bad_post_id(post_id)
216
- puts Status.unreposting(post_id)
217
- if @api.get_details(post_id)['data']['you_reposted']
218
- Check.has_been_unreposted(post_id, @api.unrepost(post_id))
263
+ ids = post_ids.select { |post_id| post_id.is_integer? }
264
+ if ids.empty?
265
+ @status.error_missing_post_id
266
+ exit
267
+ end
268
+ if options[:force]
269
+ Settings.global[:force] = true
219
270
  else
220
- puts Status.not_your_repost
271
+ ids.map! { |post_id| @workers.get_real_post_id(post_id) }
272
+ end
273
+ puts "\n"
274
+ ids.each do |post_id|
275
+ @status.unreposting(post_id)
276
+ if @api.get_details(post_id)['data']['you_reposted']
277
+ @check.has_been_unreposted(post_id, @api.unrepost(post_id))
278
+ else
279
+ @status.not_your_repost
280
+ end
221
281
  end
222
282
  rescue => e
223
- Errors.global_error({error: e, caller: caller, data: [post_id]})
283
+ Errors.global_error({error: e, caller: caller, data: [post_ids]})
224
284
  end
225
285
  end
226
286
 
227
- def unstar(post_id)
287
+ def unstar(post_ids, options = {})
228
288
  begin
229
- Check.bad_post_id(post_id)
230
- puts Status.unstarring(post_id)
231
- resp = @api.get_details(post_id)
232
- id = @workers.get_original_id(post_id, resp)
233
- resp = @api.get_details(id)
234
- if resp['data']['you_starred']
235
- Check.has_been_unstarred(id, @api.unstar(id))
289
+ ids = post_ids.select { |post_id| post_id.is_integer? }
290
+ if ids.empty?
291
+ @status.error_missing_post_id
292
+ exit
293
+ end
294
+ if options[:force]
295
+ Settings.global[:force] = true
236
296
  else
237
- puts Status.not_your_starred
297
+ ids.map! { |post_id| @workers.get_real_post_id(post_id) }
298
+ end
299
+ puts "\n"
300
+ ids.each do |post_id|
301
+ @status.unstarring(post_id)
302
+ resp = @api.get_details(post_id)
303
+ id = @workers.get_original_id(post_id, resp)
304
+ resp = @api.get_details(id)
305
+ if resp['data']['you_starred']
306
+ @check.has_been_unstarred(id, @api.unstar(id))
307
+ else
308
+ @status.not_your_starred
309
+ end
238
310
  end
239
311
  rescue => e
240
- Errors.global_error({error: e, caller: caller, data: [post_id]})
312
+ Errors.global_error({error: e, caller: caller, data: [post_ids]})
241
313
  end
242
314
  end
243
315
 
244
- def star(post_id)
316
+ def star(post_ids, options = {})
245
317
  begin
246
- Check.bad_post_id(post_id)
247
- puts Status.starring(post_id)
248
- resp = @api.get_details(post_id)
249
- Check.already_starred(resp)
250
- id = @workers.get_original_id(post_id, resp)
251
- Check.has_been_starred(id, @api.star(id))
318
+ ids = post_ids.select { |post_id| post_id.is_integer? }
319
+ if ids.empty?
320
+ @status.error_missing_post_id
321
+ exit
322
+ end
323
+ if options[:force]
324
+ Settings.global[:force] = true
325
+ else
326
+ ids.map! { |post_id| @workers.get_real_post_id(post_id) }
327
+ end
328
+ puts "\n"
329
+ ids.each do |post_id|
330
+ @status.starring(post_id)
331
+ resp = @api.get_details(post_id)
332
+ @check.already_starred(resp)
333
+ id = @workers.get_original_id(post_id, resp)
334
+ @check.has_been_starred(id, @api.star(id))
335
+ end
252
336
  rescue => e
253
- Errors.global_error({error: e, caller: caller, data: [post_id]})
337
+ Errors.global_error({error: e, caller: caller, data: [post_ids]})
254
338
  end
255
339
  end
256
340
 
257
341
  def hashtag(hashtag, options)
258
342
  begin
259
- @search.hashtag(hashtag, options)
343
+ Settings.options[:timeline][:compact] = true if options[:compact] == true
344
+ search = Search.new(@api, @view, @workers)
345
+ search.hashtag(hashtag, options)
260
346
  rescue => e
261
347
  Errors.global_error({error: e, caller: caller, data: [hashtag, options]})
262
348
  end
@@ -264,7 +350,9 @@ module Ayadn
264
350
 
265
351
  def search(words, options)
266
352
  begin
267
- @search.find(words, options)
353
+ Settings.options[:timeline][:compact] = true if options[:compact] == true
354
+ search = Search.new(@api, @view, @workers)
355
+ search.find(words, options)
268
356
  rescue => e
269
357
  Errors.global_error({error: e, caller: caller, data: [words, options]})
270
358
  end
@@ -272,7 +360,9 @@ module Ayadn
272
360
 
273
361
  def followings(username, options)
274
362
  begin
275
- @stream.followings(username, options)
363
+ Settings.options[:timeline][:compact] = true if options[:compact] == true
364
+ stream = Stream.new(@api, @view, @workers)
365
+ stream.followings(username, options)
276
366
  rescue => e
277
367
  Errors.global_error({error: e, caller: caller, data: [username, options]})
278
368
  end
@@ -280,7 +370,9 @@ module Ayadn
280
370
 
281
371
  def followers(username, options)
282
372
  begin
283
- @stream.followers(username, options)
373
+ Settings.options[:timeline][:compact] = true if options[:compact] == true
374
+ stream = Stream.new(@api, @view, @workers)
375
+ stream.followers(username, options)
284
376
  rescue => e
285
377
  Errors.global_error({error: e, caller: caller, data: [username, options]})
286
378
  end
@@ -288,7 +380,9 @@ module Ayadn
288
380
 
289
381
  def muted(options)
290
382
  begin
291
- @stream.muted(options)
383
+ Settings.options[:timeline][:compact] = true if options[:compact] == true
384
+ stream = Stream.new(@api, @view, @workers)
385
+ stream.muted(options)
292
386
  rescue => e
293
387
  Errors.global_error({error: e, caller: caller, data: [options]})
294
388
  end
@@ -296,7 +390,9 @@ module Ayadn
296
390
 
297
391
  def blocked(options)
298
392
  begin
299
- @stream.blocked(options)
393
+ Settings.options[:timeline][:compact] = true if options[:compact] == true
394
+ stream = Stream.new(@api, @view, @workers)
395
+ stream.blocked(options)
300
396
  rescue => e
301
397
  Errors.global_error({error: e, caller: caller, data: [options]})
302
398
  end
@@ -308,6 +404,7 @@ module Ayadn
308
404
  jj JSON.parse(Settings.config.to_json)
309
405
  jj JSON.parse(Settings.options.to_json)
310
406
  else
407
+ Settings.options[:timeline][:compact] = true if options[:compact] == true
311
408
  @view.show_settings
312
409
  end
313
410
  rescue => e
@@ -320,10 +417,10 @@ module Ayadn
320
417
  profile = Profile.new(options)
321
418
  profile.get_text_from_user
322
419
  profile.prepare_payload
323
- puts "\n\nUpdating profile...\n".color(:green)
420
+ @status.updating_profile
324
421
  profile.update
325
- puts Status.done
326
- userinfo('me')
422
+ @status.done
423
+ userinfo(['me'], options)
327
424
  rescue => e
328
425
  Errors.global_error({error: e, caller: caller, data: [options]})
329
426
  end
@@ -331,18 +428,20 @@ module Ayadn
331
428
 
332
429
  def userinfo(username, options = {})
333
430
  begin
334
- username = [username] unless username.is_a?(Array)
335
- Check.no_username(username)
336
- username = @workers.add_arobase(username)
337
- if options[:raw]
338
- @view.show_raw(@api.get_user(username), options)
339
- else
340
- @view.downloading
341
- stream = @api.get_user(username)
342
- Check.no_user(stream, username)
343
- Check.same_username(stream) ? token = @api.get_token_info['data'] : token = nil
344
- @view.clear_screen
345
- @view.infos(stream['data'], token)
431
+ Settings.options[:timeline][:compact] = true if options[:compact] == true
432
+ @check.no_username(username)
433
+ usernames = @workers.add_arobases_to_usernames(username)
434
+ usernames.each.with_index do |username, index|
435
+ if options[:raw]
436
+ @view.show_raw(@api.get_user(username), options)
437
+ else
438
+ @view.downloading if index == 0
439
+ stream = @api.get_user(username)
440
+ @check.no_user(stream, username)
441
+ @check.same_username(stream) ? token = @api.get_token_info['data'] : token = nil
442
+ @view.clear_screen if index == 0
443
+ @view.infos(stream['data'], token)
444
+ end
346
445
  end
347
446
  rescue => e
348
447
  Errors.global_error({error: e, caller: caller, data: [username, options]})
@@ -351,8 +450,13 @@ module Ayadn
351
450
 
352
451
  def postinfo(post_id, options)
353
452
  begin
354
- Settings.options[:force] = true if options[:force]
355
- Check.bad_post_id(post_id)
453
+ @check.bad_post_id(post_id)
454
+ Settings.options[:timeline][:compact] = true if options[:compact] == true
455
+ if options[:force]
456
+ Settings.global[:force] = true
457
+ else
458
+ post_id = @workers.get_real_post_id(post_id)
459
+ end
356
460
  details = lambda { @api.get_details(post_id, options) }
357
461
  if options[:raw]
358
462
  @view.show_raw(details.call, options)
@@ -360,28 +464,27 @@ module Ayadn
360
464
  end
361
465
  @view.clear_screen
362
466
  response = details.call
363
- Check.no_post(response, post_id)
467
+ @check.no_post(response, post_id)
364
468
  resp = response['data']
365
469
  response = @api.get_user("@#{resp['user']['username']}")
366
- Check.no_user(response, response['data']['username'])
470
+ @check.no_user(response, response['data']['username'])
367
471
  stream = response['data']
368
- puts "POST:\n".inverse
472
+ @status.post_info
369
473
  @view.show_simple_post([resp], options)
370
- if resp['repost_of']
371
- puts "REPOST OF:\n".inverse
372
- Errors.repost(post_id, resp['repost_of']['id'])
373
- @view.show_simple_post([resp['repost_of']], options)
374
- end
375
- if Settings.options[:timeline][:compact] == true
376
- puts "\nAUTHOR:\n".inverse
377
- else
378
- puts "AUTHOR:\n".inverse
379
- end
474
+ puts "\n" if Settings.options[:timeline][:compact] == true
475
+ @thor.say_status "info", "author", "cyan"
476
+ puts "\n" unless Settings.options[:timeline][:compact] == true
380
477
  if response['data']['username'] == Settings.config[:identity][:username]
381
478
  @view.show_userinfos(stream, @api.get_token_info['data'], true)
382
479
  else
383
480
  @view.show_userinfos(stream, nil, true)
384
481
  end
482
+ if resp['repost_of']
483
+ @status.repost_info
484
+ Errors.repost(post_id, resp['repost_of']['id'])
485
+ @view.show_simple_post([resp['repost_of']], options)
486
+ puts "\n" if Settings.options[:timeline][:compact] == true
487
+ end
385
488
  rescue => e
386
489
  Errors.global_error({error: e, caller: caller, data: [post_id, options]})
387
490
  end
@@ -408,7 +511,7 @@ module Ayadn
408
511
  begin
409
512
  file = @api.get_file(file_id)['data']
410
513
  FileOps.download_url(file['name'], file['url'])
411
- puts Status.downloaded(file['name'])
514
+ @status.downloaded(file['name'])
412
515
  rescue => e
413
516
  Errors.global_error({error: e, caller: caller, data: [file_id, file['url']]})
414
517
  end
@@ -438,7 +541,9 @@ module Ayadn
438
541
 
439
542
  def messages(channel_id, options)
440
543
  begin
441
- @stream.messages(channel_id, options)
544
+ Settings.options[:timeline][:compact] = true if options[:compact] == true
545
+ stream = Stream.new(@api, @view, @workers)
546
+ stream.messages(channel_id, options)
442
547
  rescue => e
443
548
  Errors.global_error({error: e, caller: caller, data: [channel_id, options]})
444
549
  end
@@ -446,11 +551,12 @@ module Ayadn
446
551
 
447
552
  def messages_unread(options)
448
553
  begin
554
+ Settings.options[:timeline][:compact] = true if options[:compact] == true
449
555
  if options[:silent]
450
- Settings.options[:marker][:update_messages] = false
556
+ Settings.options[:marker][:messages] = false
451
557
  end
452
558
  puts "\n"
453
- @shell.say_status :searching, "channels with unread PMs"
559
+ @thor.say_status :searching, "channels with unread PMs"
454
560
  response = @api.get_channels
455
561
  unread_channels = []
456
562
  response['data'].map do |ch|
@@ -458,11 +564,14 @@ module Ayadn
458
564
  unread_channels << ch['id']
459
565
  end
460
566
  end
461
- abort(Status.no_new_messages) if unread_channels.empty?
567
+ if unread_channels.empty?
568
+ @status.no_new_messages
569
+ exit
570
+ end
462
571
  unread_messages = {}
463
572
  unread_channels.each do |id|
464
- @shell.say_status :downloading, "messages from channel #{id}"
465
- since = Databases.pagination["channel:#{id}"]
573
+ @thor.say_status :downloading, "messages from channel #{id}"
574
+ since = Databases.find_last_id_from("channel:#{id}")
466
575
  unless since.nil?
467
576
  api_options = {count: 20, since_id: since}
468
577
  else
@@ -477,26 +586,22 @@ module Ayadn
477
586
  end
478
587
  unread_messages[id] = [messages, last_message_id]
479
588
  end
480
- if Settings.options[:marker][:update_messages] == true
589
+ if Settings.options[:marker][:messages] == true
481
590
  unread_messages.each do |k,v|
482
591
  name = "channel:#{k}"
483
- Databases.pagination[name] = v[1]
592
+ Databases.pagination_insert(name, v[1])
484
593
  resp = @api.update_marker(name, v[1])
485
594
  res = JSON.parse(resp)
486
595
  if res['meta']['code'] != 200
487
- @shell.say_status :error, "couldn't update channel #{k} as read", :red
596
+ @thor.say_status :error, "couldn't update channel #{k} as read", :red
488
597
  else
489
- @shell.say_status :updated, "channel #{k} as read", :green
598
+ @thor.say_status :updated, "channel #{k} as read", :green
490
599
  end
491
600
  end
492
601
  end
493
602
  @view.clear_screen
494
603
  unread_messages.each do |k,v|
495
- if v[0].length == 1
496
- puts "\nUnread message from channel #{k}:\n".color(Settings.options[:colors][:unread]).inverse
497
- else
498
- puts "\nUnread messages from channel #{k}:\n".color(Settings.options[:colors][:unread]).inverse
499
- end
604
+ @status.unread_from_channel(k)
500
605
  @view.show_posts(v[0])
501
606
  end
502
607
  puts "\n" if Settings.options[:timeline][:compact]
@@ -505,11 +610,23 @@ module Ayadn
505
610
  end
506
611
  end
507
612
 
508
- def pin(post_id, usertags)
509
- require 'pinboard'
510
- require 'base64'
613
+ def pin(post_id, usertags, options = {})
614
+ begin
615
+ require 'pinboard'
616
+ require 'base64'
617
+ rescue LoadError => e
618
+ puts "\nAYADN: Error while loading Gems\n\n"
619
+ puts "RUBY: #{e}\n\n"
620
+ exit
621
+ end
511
622
  begin
512
- Check.bad_post_id(post_id)
623
+ @check.bad_post_id(post_id)
624
+ Settings.options[:timeline][:compact] = true if options[:compact] == true
625
+ if options[:force]
626
+ Settings.global[:force] = true
627
+ else
628
+ post_id = @workers.get_real_post_id(post_id)
629
+ end
513
630
  @view.downloading
514
631
  resp = @api.get_details(post_id)['data']
515
632
  @view.clear_screen
@@ -520,16 +637,16 @@ module Ayadn
520
637
  post_text = "From: #{handle} -- Text: #{text} -- Links: #{links.join(" ")}"
521
638
  pinner = Ayadn::PinBoard.new
522
639
  unless pinner.has_credentials_file?
523
- puts Status.no_pin_creds
640
+ @status.no_pin_creds
524
641
  pinner.ask_credentials
525
- puts Status.pin_creds_saved
642
+ @status.pin_creds_saved
526
643
  end
527
644
  credentials = pinner.load_credentials
528
645
  maker = Struct.new(:username, :password, :url, :tags, :text, :description)
529
646
  bookmark = maker.new(credentials[0], credentials[1], resp['canonical_url'], usertags.join(","), post_text, links[0])
530
- puts Status.saving_pin
647
+ @status.saving_pin
531
648
  pinner.pin(bookmark)
532
- puts Status.done
649
+ @status.done
533
650
  rescue => e
534
651
  Errors.global_error({error: e, caller: caller, data: [post_id, usertags]})
535
652
  end
@@ -538,7 +655,7 @@ module Ayadn
538
655
  def auto(options)
539
656
  begin
540
657
  @view.clear_screen
541
- puts Status.auto
658
+ @status.auto
542
659
  Post.new.auto_readline
543
660
  rescue => e
544
661
  Errors.global_error({error: e, caller: caller, data: [options]})
@@ -547,14 +664,17 @@ module Ayadn
547
664
 
548
665
  def post(args, options)
549
666
  begin
667
+ Settings.options[:timeline][:compact] = true if options[:compact] == true
550
668
  writer = Post.new
551
- @view.clear_screen
552
- puts Status.posting
553
669
  if options[:poster] # Returns the same options hash + poster embed
554
670
  settings = options.dup
555
671
  options = NowWatching.new.get_poster(settings[:poster], settings)
556
672
  end
557
- resp = writer.post({options: options, text: args.join(" ")})
673
+ text = args.join(" ")
674
+ writer.post_size_error(text) if writer.post_size_ok?(text) == false
675
+ @view.clear_screen
676
+ @status.posting
677
+ resp = writer.post({options: options, text: text})
558
678
  save_and_view(resp)
559
679
  rescue => e
560
680
  Errors.global_error({error: e, caller: caller, data: [args, options]})
@@ -563,14 +683,15 @@ module Ayadn
563
683
 
564
684
  def write(options)
565
685
  begin
686
+ Settings.options[:timeline][:compact] = true if options[:compact] == true
566
687
  writer = Post.new
567
- puts Status.writing
568
- puts Status.post
688
+ @status.writing
689
+ @status.post
569
690
  lines_array = writer.compose
570
- writer.check_post_length(lines_array)
571
691
  text = lines_array.join("\n")
692
+ writer.post_size_error(text) if writer.post_size_ok?(text) == false
572
693
  @view.clear_screen
573
- puts Status.posting
694
+ @status.posting
574
695
  if options[:poster]
575
696
  settings = options.dup
576
697
  options = NowWatching.new.get_poster(settings[:poster], settings)
@@ -584,29 +705,30 @@ module Ayadn
584
705
 
585
706
  def pmess(username, options = {})
586
707
  begin
708
+ Settings.options[:timeline][:compact] = true if options[:compact] == true
587
709
  if options[:silent]
588
- Settings.options[:marker][:update_messages] = false
710
+ Settings.options[:marker][:messages] = false
589
711
  end
590
- Check.no_username(username)
712
+ @check.no_username(username)
591
713
  username = [@workers.add_arobase(username)]
592
714
  writer = Post.new
593
- puts Status.message_from(username)
594
- puts Status.message
715
+ @status.message_from(username)
716
+ @status.message
595
717
  lines_array = writer.compose
596
- writer.check_message_length(lines_array)
597
718
  text = lines_array.join("\n")
719
+ writer.message_size_error(text) if writer.message_size_ok?(text) == false
598
720
  @view.clear_screen
599
- puts Status.posting
721
+ @status.posting
600
722
  if options[:poster]
601
723
  settings = options.dup
602
724
  options = NowWatching.new.get_poster(settings[:poster], settings)
603
725
  end
604
726
  resp = writer.pm({options: options, text: text, username: username})
605
- if Settings.options[:marker][:update_messages] == true
727
+ if Settings.options[:marker][:messages] == true
606
728
  if resp['meta']['code'] == 200
607
729
  data = resp['data']
608
730
  name = "channel:#{data['channel_id']}"
609
- Databases.pagination[name] = data['id']
731
+ Databases.pagination_insert(name, data['id'])
610
732
  marked = @api.update_marker(name, data['id'])
611
733
  updated = JSON.parse(marked)
612
734
  if updated['meta']['code'] != 200
@@ -614,9 +736,9 @@ module Ayadn
614
736
  end
615
737
  end
616
738
  end
617
- FileOps.save_message(resp) if Settings.options[:backup][:auto_save_sent_messages]
739
+ FileOps.save_message(resp) if Settings.options[:backup][:messages]
618
740
  @view.clear_screen
619
- puts Status.yourmessage(username[0])
741
+ @status.yourmessage(username[0])
620
742
  @view.show_posted(resp)
621
743
  rescue => e
622
744
  Errors.global_error({error: e, caller: caller, data: [username, options]})
@@ -625,34 +747,40 @@ module Ayadn
625
747
 
626
748
  def reply(post_id, options = {})
627
749
  begin
628
- post_id = @workers.get_real_post_id(post_id)
629
- puts Status.replying_to(post_id)
750
+ Settings.options[:timeline][:compact] = true if options[:compact] == true
751
+ @check.bad_post_id(post_id)
752
+ if options[:force]
753
+ Settings.global[:force] = true
754
+ else
755
+ post_id = @workers.get_real_post_id(post_id)
756
+ end
757
+ @status.replying_to(post_id)
630
758
  replied_to = @api.get_details(post_id)
631
- Check.no_post(replied_to, post_id)
759
+ @check.no_post(replied_to, post_id)
632
760
  unless options[:noredirect]
633
761
  post_id = @workers.get_original_id(post_id, replied_to)
634
762
  end
635
763
  if replied_to['data']['repost_of']
636
764
  if post_id == replied_to['data']['repost_of']['id']
637
765
  replied_to = @api.get_details(post_id)
638
- Check.no_post(replied_to, post_id)
766
+ @check.no_post(replied_to, post_id)
639
767
  end
640
768
  end
641
769
  # ----
642
770
  writer = Post.new
643
- puts Status.writing
644
- puts Status.reply
771
+ @status.writing
772
+ @status.reply
645
773
  lines_array = writer.compose
646
- writer.check_post_length(lines_array)
647
- @view.clear_screen
648
774
  text = lines_array.join("\n")
775
+ # text length is tested in Post class for the reply command
776
+ @view.clear_screen
649
777
  replied_to = @workers.build_posts([replied_to['data']])
650
778
  if options[:poster]
651
779
  settings = options.dup
652
780
  options = NowWatching.new.get_poster(settings[:poster], settings)
653
781
  end
654
782
  resp = writer.reply({options: options, text: text, id: post_id, reply_to: replied_to})
655
- FileOps.save_post(resp) if Settings.options[:backup][:auto_save_sent_posts]
783
+ FileOps.save_post(resp) if Settings.options[:backup][:posts]
656
784
  # ----
657
785
  options = options.dup
658
786
  unless resp['data']['reply_to'].nil?
@@ -660,6 +788,7 @@ module Ayadn
660
788
  end
661
789
  options[:post_id] = resp['data']['id'].to_i
662
790
  @view.render(@api.get_convo(post_id), options)
791
+ puts "\n" if Settings.options[:timeline][:compact] == true && !options[:raw]
663
792
  rescue => e
664
793
  Errors.global_error({error: e, caller: caller, data: [post_id, options]})
665
794
  end
@@ -667,27 +796,29 @@ module Ayadn
667
796
 
668
797
  def send_to_channel(channel_id, options = {})
669
798
  begin
799
+ Settings.options[:timeline][:compact] = true if options[:compact] == true
670
800
  if options[:silent]
671
- Settings.options[:marker][:update_messages] = false
801
+ Settings.options[:marker][:messages] = false
672
802
  end
673
803
  channel_id = @workers.get_channel_id_from_alias(channel_id)
674
804
  writer = Post.new
675
- puts Status.writing
676
- puts Status.message
805
+ @status.writing
806
+ @status.message
677
807
  lines_array = writer.compose
678
- writer.check_message_length(lines_array)
808
+ text = lines_array.join("\n")
809
+ writer.message_size_error(text) if writer.message_size_ok?(text) == false
679
810
  @view.clear_screen
680
- puts Status.posting
811
+ @status.posting
681
812
  if options[:poster]
682
813
  settings = options.dup
683
814
  options = NowWatching.new.get_poster(settings[:poster], settings)
684
815
  end
685
- resp = writer.message({options: options, id: channel_id, text: lines_array.join("\n")})
686
- if Settings.options[:marker][:update_messages] == true
816
+ resp = writer.message({options: options, id: channel_id, text: text})
817
+ if Settings.options[:marker][:messages] == true
687
818
  if resp['meta']['code'] == 200
688
819
  data = resp['data']
689
820
  name = "channel:#{data['channel_id']}"
690
- Databases.pagination[name] = data['id']
821
+ Databases.pagination_insert(name, data['id'])
691
822
  marked = @api.update_marker(name, data['id'])
692
823
  updated = JSON.parse(marked)
693
824
  if updated['meta']['code'] != 200
@@ -695,9 +826,9 @@ module Ayadn
695
826
  end
696
827
  end
697
828
  end
698
- FileOps.save_message(resp) if Settings.options[:backup][:auto_save_sent_messages]
829
+ FileOps.save_message(resp) if Settings.options[:backup][:messages]
699
830
  @view.clear_screen
700
- puts Status.yourpost
831
+ @status.yourpost
701
832
  @view.show_posted(resp)
702
833
  rescue => e
703
834
  Errors.global_error({error: e, caller: caller, data: [channel_id, options]})
@@ -705,26 +836,35 @@ module Ayadn
705
836
  end
706
837
 
707
838
  def nowplaying(options = {})
708
- np = NowPlaying.new(@api, @view, @workers)
839
+ Settings.options[:timeline][:compact] = true if options[:compact] == true
840
+ np = NowPlaying.new(@api, @view, @workers, options)
709
841
  options[:lastfm] ? np.lastfm(options) : np.itunes(options)
710
842
  end
711
843
 
712
844
  def nowwatching(args, options = {})
713
845
  begin
714
- abort(Status.error_missing_title) if args.empty?
846
+ Settings.options[:timeline][:compact] = true if options[:compact] == true
847
+ if args.empty?
848
+ @status.error_missing_title
849
+ exit
850
+ end
715
851
  nw = NowWatching.new(@view)
716
852
  nw.post(args, options)
717
853
  rescue ArgumentError => e
718
- puts Status.no_movie
854
+ @status.no_movie
719
855
  rescue => e
720
- puts Status.wtf
856
+ @status.wtf
721
857
  Errors.global_error({error: e, caller: caller, data: [args, options]})
722
858
  end
723
859
  end
724
860
 
725
861
  def tvshow(args, options = {})
726
862
  begin
727
- abort(Status.error_missing_title) if args.empty?
863
+ Settings.options[:timeline][:compact] = true if options[:compact] == true
864
+ if args.empty?
865
+ @status.error_missing_title
866
+ exit
867
+ end
728
868
  client = TvShow.new
729
869
  show_obj = if options[:alt]
730
870
  client.find_alt(args.join(' '))
@@ -734,14 +874,16 @@ module Ayadn
734
874
  candidate = client.create_details(show_obj)
735
875
  candidate.ok ? candidate.post(options) : candidate.cancel
736
876
  rescue => e
737
- puts Status.wtf
877
+ @status.wtf
738
878
  Errors.global_error({error: e, caller: caller, data: [args, options]})
739
879
  end
740
880
  end
741
881
 
742
882
  def random_posts(options)
743
883
  begin
744
- @stream.random_posts(options)
884
+ Settings.options[:timeline][:compact] = true if options[:compact] == true
885
+ stream = Stream.new(@api, @view, @workers)
886
+ stream.random_posts(options)
745
887
  rescue => e
746
888
  Errors.global_error({error: e, caller: caller, data: [@max_id, @random_post_id, @resp, options]})
747
889
  end
@@ -749,11 +891,7 @@ module Ayadn
749
891
 
750
892
  def version
751
893
  begin
752
- puts "\nAYADN\n".color(:red)
753
- puts "Version:\t".color(:cyan) + "#{VERSION}\n".color(:green)
754
- puts "Changelog:\t".color(:cyan) + "https://github.com/ericdke/na/blob/master/CHANGELOG.md\n".color(Settings.options[:colors][:link])
755
- puts "Docs:\t\t".color(:cyan) + "https://github.com/ericdke/na/tree/master/doc".color(Settings.options[:colors][:link])
756
- puts "\n"
894
+ @status.version
757
895
  rescue => e
758
896
  Errors.global_error({error: e, caller: caller, data: []})
759
897
  end
@@ -762,9 +900,10 @@ module Ayadn
762
900
  private
763
901
 
764
902
  def save_and_view(resp)
765
- FileOps.save_post(resp) if Settings.options[:backup][:auto_save_sent_posts]
903
+ FileOps.save_post(resp) if Settings.options[:backup][:posts]
766
904
  @view.clear_screen
767
- puts Status.yourpost
905
+ @status.yourpost
906
+ puts "\n\n"
768
907
  @view.show_posted(resp)
769
908
  end
770
909