ayadn 1.8.2 → 2.0

Sign up to get free protection for your applications and to get access to all the features.
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/view.rb CHANGED
@@ -4,6 +4,8 @@ module Ayadn
4
4
 
5
5
  def initialize
6
6
  @workers = Workers.new
7
+ @thor = Thor::Shell::Basic.new
8
+ @status = Status.new
7
9
  end
8
10
 
9
11
  def show_cursor
@@ -58,23 +60,23 @@ module Ayadn
58
60
  puts "\n"
59
61
  end
60
62
 
61
- def show_list_followings(list, target)
62
- puts @workers.build_followings_list(list, target)
63
+ def show_list_followings(list, target, options = {})
64
+ puts @workers.build_followings_list(list, target, options)
63
65
  puts "\n"
64
66
  end
65
67
 
66
- def show_list_followers(list, target)
67
- puts @workers.build_followers_list(list, target)
68
+ def show_list_followers(list, target, options = {})
69
+ puts @workers.build_followers_list(list, target, options)
68
70
  puts "\n"
69
71
  end
70
72
 
71
- def show_list_muted(list)
72
- puts @workers.build_muted_list(list)
73
+ def show_list_muted(list, options = {})
74
+ puts @workers.build_muted_list(list, options)
73
75
  puts "\n"
74
76
  end
75
77
 
76
- def show_list_blocked(list)
77
- puts @workers.build_blocked_list(list)
78
+ def show_list_blocked(list, options = {})
79
+ puts @workers.build_blocked_list(list, options)
78
80
  puts "\n"
79
81
  end
80
82
 
@@ -89,13 +91,16 @@ module Ayadn
89
91
 
90
92
  def show_settings
91
93
  table = Terminal::Table.new do |t|
92
- t.style = { :width => Settings.options[:formats][:table][:width], border_x: ' ', border_i: ' ', border_y: ' ' }
94
+ if Settings.options[:formats][:table][:borders] == true
95
+ t.style = { :width => Settings.options[:formats][:table][:width], border_x: '—', border_i: '+', border_y: '|' }
96
+ else
97
+ t.style = { :width => Settings.options[:formats][:table][:width], border_x: ' ', border_i: ' ', border_y: ' ' }
98
+ end
93
99
  t.title = "Current Ayadn settings".color(:cyan)
94
100
  t.headings = [ "Category".color(:red), "Parameter".color(:red), "Value(s)".color(:red) ]
95
101
  @iter = 0
96
102
  opts = Settings.options.dup
97
103
  opts.each do |k,v|
98
- v.delete_if {|ke,_| ke == :deleted || ke == :annotations} # don't show immutable values
99
104
  v.each do |x,y|
100
105
  t << :separator if @iter >= 1 && Settings.options[:timeline][:compact] == false
101
106
  unless y.is_a?(Hash)
@@ -111,20 +116,29 @@ module Ayadn
111
116
  end
112
117
  clear_screen()
113
118
  puts table
119
+ puts "\n"
114
120
  end
115
121
 
116
122
  def show_userinfos(content, token, show_ranks = false)
123
+ if Settings.options[:timeline][:compact] == true
124
+ padding = "\n"
125
+ view = "\n"
126
+ else
127
+ padding = "\n\n"
128
+ view = ""
129
+ end
130
+
117
131
  if content['name']
118
- view = "Name\t\t\t".color(:cyan) + content['name'].color(Settings.options[:colors][:name])
132
+ view << "Name\t\t\t".color(:cyan) + content['name'].color(Settings.options[:colors][:name])
119
133
  else
120
- view = "Name\t\t\t".color(:cyan) + "(no name)".color(:red)
134
+ view << "Name\t\t\t".color(:cyan) + "(no name)".color(:red)
121
135
  end
122
136
 
123
- view << "\n\nUsername\t\t".color(:cyan) + "@#{content['username']}".color(Settings.options[:colors][:id])
137
+ view << "#{padding}Username\t\t".color(:cyan) + "@#{content['username']}".color(Settings.options[:colors][:username])
124
138
 
125
- view << "\n\nID\t\t\t".color(:cyan) + content['id'].color(Settings.options[:colors][:username])
139
+ view << "#{padding}ID\t\t\t".color(:cyan) + content['id'].color(Settings.options[:colors][:id])
126
140
 
127
- view << "\n\nURL\t\t\t".color(:cyan) + content['canonical_url'].color(Settings.options[:colors][:link])
141
+ view << "#{padding}URL\t\t\t".color(:cyan) + content['canonical_url'].color(Settings.options[:colors][:link])
128
142
 
129
143
  unless content['verified_domain'].nil?
130
144
  if content['verified_domain'] =~ (/http/ || /https/)
@@ -136,11 +150,11 @@ module Ayadn
136
150
  end
137
151
 
138
152
 
139
- view << "\n\nAccount creation\t".color(:cyan) + @workers.parsed_time(content['created_at']).color(:green)
140
- view << "\n\nTimeZone\t\t".color(:cyan) + content['timezone'].color(:green)
141
- view << "\nLocale\t\t\t".color(:cyan) + content['locale'].color(:green)
153
+ view << "#{padding}Account creation\t".color(:cyan) + @workers.parsed_time(content['created_at']).color(Settings.options[:colors][:excerpt])
154
+ view << "#{padding}TimeZone\t\t".color(:cyan) + content['timezone'].color(Settings.options[:colors][:excerpt])
155
+ view << "\nLocale\t\t\t".color(:cyan) + content['locale'].color(Settings.options[:colors][:excerpt])
142
156
 
143
- view << "\n\nPosts\t\t\t".color(:cyan) + content['counts']['posts'].to_s.color(:green)
157
+ view << "#{padding}Posts\t\t\t".color(:cyan) + content['counts']['posts'].to_s.color(Settings.options[:colors][:excerpt])
144
158
 
145
159
 
146
160
  unless show_ranks == false
@@ -148,25 +162,25 @@ module Ayadn
148
162
  # do call them all at once instead if many
149
163
  ranks = NiceRank.new.get_posts_day([content['id'].to_i])
150
164
  unless ranks.empty?
151
- view << "\n\nPosts/day\t\t".color(:cyan) + ranks[0][:posts_day].to_s.color(:green)
165
+ view << "#{padding}Posts/day\t\t".color(:cyan) + ranks[0][:posts_day].to_s.color(Settings.options[:colors][:excerpt])
152
166
  end
153
167
  end
154
168
 
155
- view << "\n\nFollowing\t\t".color(:cyan) + content['counts']['following'].to_s.color(:green)
156
- view << "\nFollowers\t\t".color(:cyan) + content['counts']['followers'].to_s.color(:green)
169
+ view << "#{padding}Following\t\t".color(:cyan) + content['counts']['following'].to_s.color(Settings.options[:colors][:excerpt])
170
+ view << "\nFollowers\t\t".color(:cyan) + content['counts']['followers'].to_s.color(Settings.options[:colors][:excerpt])
157
171
 
158
172
  if content['username'] == Settings.config[:identity][:username] && !token.nil?
159
- view << "\n\nStorage used\t\t".color(:cyan) + "#{token['storage']['used'].to_filesize}".color(:red)
160
- view << "\nStorage available\t".color(:cyan) + "#{token['storage']['available'].to_filesize}".color(:green)
173
+ view << "#{padding}Storage used\t\t".color(:cyan) + "#{token['storage']['used'].to_filesize}".color(Settings.options[:colors][:excerpt])
174
+ view << "\nStorage available\t".color(:cyan) + "#{token['storage']['available'].to_filesize}".color(Settings.options[:colors][:excerpt])
161
175
  end
162
176
 
163
177
  #view << "\nStars\t\t\t".color(:cyan) + content['counts']['stars'].to_s.color(:yellow)
164
178
 
165
179
  unless content['username'] == Settings.config[:identity][:username]
166
180
  if content['you_follow']
167
- view << "\n\nYou follow ".color(:cyan) + "@#{content['username']}".color(Settings.options[:colors][:username])
181
+ view << "#{padding}You follow ".color(:cyan) + "@#{content['username']}".color(Settings.options[:colors][:username])
168
182
  else
169
- view << "\n\nYou don't follow ".color(:cyan) + "@#{content['username']}".color(Settings.options[:colors][:username])
183
+ view << "#{padding}You don't follow ".color(:cyan) + "@#{content['username']}".color(Settings.options[:colors][:username])
170
184
  end
171
185
  if content['follows_you']
172
186
  view << "\n" + "@#{content['username']}".color(Settings.options[:colors][:username]) + " follows you".color(:cyan)
@@ -182,7 +196,7 @@ module Ayadn
182
196
  end
183
197
 
184
198
  unless content['annotations'].empty?
185
- view << "\n"
199
+ view << "\n" unless Settings.options[:timeline][:compact] == true
186
200
  end
187
201
  content['annotations'].each do |anno|
188
202
  case anno['type']
@@ -196,12 +210,17 @@ module Ayadn
196
210
  end
197
211
 
198
212
 
199
- #view << "\n\nAvatar URL\t\t".color(:cyan) + content['avatar_image']['url']
213
+ #view << "#{padding}Avatar URL\t\t".color(:cyan) + content['avatar_image']['url']
200
214
 
201
215
  if content['description']
202
- view << "\n\n#{content['description']['text']}\n".color(:magenta) + "\n\n"
216
+ mentions = content['description']['entities']['mentions'].map {|m| "@#{m['name']}"}
217
+ hashtags = content['description']['entities']['hashtags'].map {|m| m['name']}
218
+ view << "#{padding}#{@workers.colorize_text(content['description']['text'], mentions, hashtags)}\n"
219
+ view << "\n" unless Settings.options[:timeline][:compact] == true
203
220
  end
204
221
 
222
+ view << "\n" if Settings.options[:timeline][:compact] == true
223
+
205
224
  puts view
206
225
 
207
226
  end
@@ -210,18 +229,39 @@ module Ayadn
210
229
  view = ""
211
230
  bucket = @workers.build_channels(resp['data'], options)
212
231
  bucket.reverse.each do |ch|
213
- view << "\n"
214
- ch_alias = false
215
- Databases.aliases.each do |k,v|
216
- if v == "#{ch.id}"
217
- ch_alias = k
218
- break
232
+ if options[:broadcasts]
233
+ next if ch.type != "net.app.core.broadcast"
234
+ end
235
+ if options[:"no-broadcasts"]
236
+ next if ch.type == "net.app.core.broadcast"
237
+ end
238
+ if options[:messages]
239
+ next if ch.type != "net.app.core.pm"
240
+ end
241
+ if options[:"no-messages"]
242
+ next if ch.type == "net.app.core.pm"
243
+ end
244
+ if options[:patter]
245
+ next if ch.type != "net.patter-app.room"
246
+ end
247
+ if options[:"no-patter"]
248
+ next if ch.type == "net.patter-app.room"
249
+ end
250
+ if options[:other]
251
+ case ch.type
252
+ when "net.app.core.pm", "net.app.core.broadcast", "net.patter-app.room"
253
+ next
219
254
  end
220
255
  end
256
+ if options[:"no-other"]
257
+ next if ch.type != "net.app.core.pm" || ch.type != "net.app.core.broadcast" || ch.type != "net.patter-app.room"
258
+ end
259
+ view << "\n"
221
260
  view << "ID: ".color(:cyan)
222
261
  view << "#{ch.id}".color(Settings.options[:colors][:id])
223
262
  view << "\n"
224
- if ch_alias
263
+ ch_alias = Databases.get_alias_from_id(ch.id)
264
+ unless ch_alias.nil?
225
265
  view << "Alias: ".color(:cyan)
226
266
  view << "#{ch_alias}".color(Settings.options[:colors][:username])
227
267
  view << "\n"
@@ -241,7 +281,7 @@ module Ayadn
241
281
  view << "\n"
242
282
  end
243
283
  view << "Type: ".color(:cyan)
244
- view << "#{ch.type}".color(Settings.options[:colors][:id])
284
+ view << "#{ch.type}".color(Settings.options[:colors][:index])
245
285
  view << "\n"
246
286
  if ch.type == "net.patter-app.room"
247
287
  ann = ch.annotations.select {|a| a['type'] == "net.patter-app.settings"}
@@ -284,8 +324,11 @@ module Ayadn
284
324
  end
285
325
  view << "\n\n"
286
326
  end
287
- view << "\nYour account is currently linked to #{bucket.length} channels.\n\n".color(:green) unless options[:channels] || options[:id]
288
327
  puts view
328
+ unless options[:channels] || options[:id]
329
+ @status.info("info", "your account is currently linked to #{bucket.length} channels", "cyan")
330
+ puts "\n"
331
+ end
289
332
  end
290
333
 
291
334
  def render(stream, options = {}, niceranks = {})
@@ -310,7 +353,8 @@ module Ayadn
310
353
  end
311
354
 
312
355
  def page msg
313
- clear_screen
356
+ # clear_screen
357
+ puts "\n"
314
358
  puts msg
315
359
  puts "\n"
316
360
  end
@@ -320,12 +364,12 @@ module Ayadn
320
364
  end
321
365
 
322
366
  def show_links(links)
323
- links.each {|l| puts "#{l}\n".color(Settings.options[:colors][:link])}
367
+ links.each {|l| puts "#{l}".color(Settings.options[:colors][:link])}
324
368
  end
325
369
 
326
370
  def all_hashtag_links(stream, hashtag)
327
371
  clear_screen()
328
- puts "Links from posts containing hashtag '##{hashtag}': \n".color(:cyan)
372
+ @status.info("info", "links from posts containing hashtag '##{hashtag}':", "cyan")
329
373
  links = @workers.links_from_posts(stream)
330
374
  links.uniq!
331
375
  show_links(links)
@@ -334,7 +378,7 @@ module Ayadn
334
378
 
335
379
  def all_search_links(stream, words)
336
380
  clear_screen()
337
- puts "Links from posts containing word(s) '#{words}': \n".color(:cyan)
381
+ @status.info("info", "links from posts containing word(s) '#{words}':", "cyan")
338
382
  links = @workers.links_from_posts(stream)
339
383
  links.uniq!
340
384
  show_links(links)
@@ -343,7 +387,7 @@ module Ayadn
343
387
 
344
388
  def all_stars_links(stream)
345
389
  clear_screen()
346
- puts "Links from your starred posts: \n".color(:cyan)
390
+ @status.info("info", "links from your starred posts:", "cyan")
347
391
  links = @workers.links_from_posts(stream)
348
392
  links.uniq!
349
393
  show_links(links)
@@ -351,18 +395,17 @@ module Ayadn
351
395
  end
352
396
 
353
397
  def infos(stream, token)
354
- clear_screen()
355
398
  show_userinfos(stream, token, true)
356
399
  end
357
400
 
358
401
  def downloading(options = {})
359
402
  unless options[:raw]
360
403
  clear_screen()
361
- print Status.downloading
404
+ @status.downloading
362
405
  end
363
406
  end
364
407
 
365
- def list(what, list, target)
408
+ def list(what, list, target, options = {})
366
409
  clear_screen()
367
410
  case what
368
411
  when :whoreposted
@@ -370,13 +413,13 @@ module Ayadn
370
413
  when :whostarred
371
414
  show_list_starred(list, target)
372
415
  when :followings
373
- show_list_followings(list, target)
416
+ show_list_followings(list, target, options)
374
417
  when :followers
375
- show_list_followers(list, target)
418
+ show_list_followers(list, target, options)
376
419
  when :muted
377
- show_list_muted(list)
420
+ show_list_muted(list, options)
378
421
  when :blocked
379
- show_list_blocked(list)
422
+ show_list_blocked(list, options)
380
423
  end
381
424
  end
382
425
 
@@ -388,7 +431,11 @@ module Ayadn
388
431
 
389
432
  def get_broadcast_alias_from_id(event_id)
390
433
  al = Databases.get_alias_from_id(event_id)
391
- al.nil? ? event_id : al
434
+ if al.nil? || al.empty?
435
+ return event_id
436
+ else
437
+ return al
438
+ end
392
439
  end
393
440
 
394
441
  def filter_nicerank posts, options
@@ -396,13 +443,13 @@ module Ayadn
396
443
  if Settings.options[:nicerank][:filter] == true
397
444
  filtered = {}
398
445
  posts.each do |id,content|
399
- if Settings.options[:nicerank][:filter_unranked] == true
446
+ if Settings.options[:nicerank][:unranked] == true
400
447
  next if content[:nicerank] == false
401
448
  end
402
449
  unless content[:nicerank] == false
403
450
  next if content[:nicerank] < Settings.options[:nicerank][:threshold]
404
- next if content[:is_human] == false
405
- next if content[:real_person] == false
451
+ next if content[:is_human] == 0
452
+ next if content[:real_person] == 0
406
453
  end
407
454
  filtered[id] = content
408
455
  end
@@ -510,7 +557,11 @@ module Ayadn
510
557
  inter << "welcomed ".color(:green)
511
558
  inter << "you!".color(:yellow)
512
559
  end
513
- inter << "\n\n"
560
+ if Settings.options[:timeline][:compact] == true
561
+ inter << "\n"
562
+ else
563
+ inter << "\n\n"
564
+ end
514
565
  end
515
566
  inter
516
567
  end
@@ -589,19 +640,27 @@ module Ayadn
589
640
  def build_header(content)
590
641
  header = ""
591
642
  header << content[:handle].color(Settings.options[:colors][:username])
592
- if Settings.options[:timeline][:show_real_name]
643
+ if Settings.options[:timeline][:name]
593
644
  header << " "
594
645
  header << content[:name].color(Settings.options[:colors][:name])
595
646
  end
596
- if Settings.options[:timeline][:show_date]
647
+ if Settings.options[:timeline][:date]
597
648
  header << " "
598
- header << content[:date].color(Settings.options[:colors][:date])
649
+ if Settings.global[:scrolling] == false
650
+ header << content[:date].color(Settings.options[:colors][:date])
651
+ else
652
+ if Settings.options[:scroll][:date] == false
653
+ header << content[:date_short].color(Settings.options[:colors][:date])
654
+ else
655
+ header << content[:date].color(Settings.options[:colors][:date])
656
+ end
657
+ end
599
658
  end
600
- if Settings.options[:timeline][:show_source]
659
+ if Settings.options[:timeline][:source]
601
660
  header << " "
602
661
  header << "[#{content[:source_name]}]".color(Settings.options[:colors][:source])
603
662
  end
604
- if Settings.options[:timeline][:show_symbols]
663
+ if Settings.options[:timeline][:symbols]
605
664
  header << " <".color(Settings.options[:colors][:symbols]) if content[:is_reply]
606
665
  header << " #{content[:num_stars]}*".color(Settings.options[:colors][:symbols]) if content[:is_starred]
607
666
  header << " #{content[:num_reposts]}x".color(Settings.options[:colors][:symbols]) if content[:num_reposts] > 0