ayadn 3.0 → 4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +1 -4
  3. data/CHANGELOG.md +12 -4
  4. data/README.md +2 -5
  5. data/ayadn.gemspec +0 -2
  6. data/doc/01-index.md +0 -3
  7. data/doc/02-install.md +0 -4
  8. data/doc/06-post.md +0 -16
  9. data/doc/{18-contact.md → 16-contact.md} +0 -0
  10. data/doc/{19-examples.md → 17-examples.md} +0 -0
  11. data/doc/18-develop.md +165 -0
  12. data/lib/ayadn/action.rb +206 -396
  13. data/lib/ayadn/alias.rb +1 -1
  14. data/lib/ayadn/annotations.rb +15 -27
  15. data/lib/ayadn/api.rb +39 -28
  16. data/lib/ayadn/app.rb +19 -29
  17. data/lib/ayadn/authorize.rb +22 -13
  18. data/lib/ayadn/blacklist.rb +6 -19
  19. data/lib/ayadn/channel_object.rb +75 -0
  20. data/lib/ayadn/check.rb +19 -11
  21. data/lib/ayadn/cnx.rb +9 -15
  22. data/lib/ayadn/databases.rb +15 -27
  23. data/lib/ayadn/debug.rb +9 -9
  24. data/lib/ayadn/descriptions.rb +1 -99
  25. data/lib/ayadn/diagnostics.rb +16 -15
  26. data/lib/ayadn/endpoints.rb +18 -22
  27. data/lib/ayadn/errors.rb +1 -1
  28. data/lib/ayadn/fileops.rb +12 -12
  29. data/lib/ayadn/filtered_post_object.rb +11 -0
  30. data/lib/ayadn/ids.rb +0 -3
  31. data/lib/ayadn/logs.rb +4 -4
  32. data/lib/ayadn/mark.rb +34 -30
  33. data/lib/ayadn/nicerank.rb +7 -7
  34. data/lib/ayadn/nowplaying.rb +8 -22
  35. data/lib/ayadn/pinboard.rb +8 -12
  36. data/lib/ayadn/post.rb +18 -18
  37. data/lib/ayadn/post_object.rb +118 -0
  38. data/lib/ayadn/preferences_object.rb +290 -0
  39. data/lib/ayadn/profile.rb +2 -2
  40. data/lib/ayadn/scroll.rb +58 -67
  41. data/lib/ayadn/search.rb +22 -15
  42. data/lib/ayadn/set.rb +93 -83
  43. data/lib/ayadn/settings.rb +25 -33
  44. data/lib/ayadn/status.rb +24 -26
  45. data/lib/ayadn/stream.rb +68 -66
  46. data/lib/ayadn/stream_object.rb +56 -0
  47. data/lib/ayadn/switch.rb +2 -2
  48. data/lib/ayadn/user_object.rb +116 -0
  49. data/lib/ayadn/version.rb +1 -1
  50. data/lib/ayadn/view.rb +255 -278
  51. data/lib/ayadn/workers.rb +172 -174
  52. data/spec/integration/action_spec.rb +55 -34
  53. data/spec/mock/ayadn.sqlite +0 -0
  54. data/spec/unit/annotations_spec.rb +54 -41
  55. data/spec/unit/api_spec.rb +78 -7
  56. data/spec/unit/blacklistworkers_spec.rb +92 -20
  57. data/spec/unit/databases_spec.rb +117 -36
  58. data/spec/unit/endpoints_spec.rb +82 -10
  59. data/spec/unit/nicerank_spec.rb +56 -27
  60. data/spec/unit/post_spec.rb +94 -21
  61. data/spec/unit/set_spec.rb +141 -210
  62. data/spec/unit/view_spec.rb +105 -32
  63. data/spec/unit/workers_spec.rb +143 -52
  64. metadata +12 -37
  65. data/doc/16-movie.md +0 -39
  66. data/doc/17-tvshow.md +0 -46
  67. data/lib/ayadn/nowwatching.rb +0 -118
  68. data/lib/ayadn/tvshow.rb +0 -162
data/lib/ayadn/search.rb CHANGED
@@ -7,37 +7,43 @@ module Ayadn
7
7
  @api = api
8
8
  @view = view
9
9
  @workers = workers
10
- @check = Check.new
11
10
  end
12
11
 
13
12
  def hashtag(hashtag, options)
14
- Settings.global[:force] = true if options[:force]
13
+ Settings.options.timeline.compact = true if options[:compact]
14
+ Settings.global.force = true if options[:force]
15
15
  @view.downloading(options)
16
16
  stream = @api.get_hashtag(hashtag)
17
- @check.no_data(stream, 'hashtag')
17
+ stream_object = StreamObject.new(stream)
18
+ Check.new.no_data(stream_object, 'hashtag')
18
19
  if options[:extract]
19
- @view.all_hashtag_links(stream, hashtag)
20
+ @view.all_hashtag_links(stream_object, hashtag)
20
21
  else
21
- @view.render(stream, options)
22
- if Settings.options[:timeline][:compact] == true && !options[:raw]
22
+ @view.render(stream_object, options)
23
+ if Settings.options.timeline.compact && !options[:raw]
23
24
  puts "\n"
24
25
  end
25
26
  end
26
27
  end
27
28
 
28
29
  def find(words, options)
29
- Settings.global[:force] = true if options[:force]
30
+ Settings.options.timeline.compact = true if options[:compact]
31
+ Settings.global.force = true if options[:force]
30
32
  @view.downloading(options)
31
33
  stream = get_stream(words, options)
32
- @check.no_data(stream, 'search')
33
34
  if options[:users]
34
- get_users(stream, options)
35
+ stream_object = stream["data"].map { |user| UserObject.new(user) }
36
+ elsif !options[:channels]
37
+ stream_object = StreamObject.new(stream)
38
+ end
39
+ if options[:users]
40
+ get_users(stream_object, options)
35
41
  elsif options[:channels]
36
42
  get_channels(stream, options)
37
43
  else
38
- get_generic(stream, words, options)
44
+ get_generic(stream_object, words, options)
39
45
  end
40
- if Settings.options[:timeline][:compact] == true && !options[:raw]
46
+ if Settings.options.timeline.compact && !options[:raw]
41
47
  puts "\n"
42
48
  end
43
49
  end
@@ -70,16 +76,17 @@ module Ayadn
70
76
  end
71
77
 
72
78
  def get_channels stream, options
73
- @view.show_channels(stream, options)
79
+ stream_object = stream["data"].map { |ch| ChannelObject.new(ch) }
80
+ @view.show_channels(stream_object, options)
74
81
  end
75
82
 
76
83
  def get_users stream, options
77
- sorted = stream['data'].sort_by {|obj| obj['counts']['followers']}
84
+ sorted = stream.sort_by {|obj| obj.counts.followers}
78
85
  sorted.each do |obj|
79
- puts @view.big_separator unless Settings.options[:timeline][:compact] == true
86
+ puts @view.big_separator unless Settings.options.timeline.compact
80
87
  @view.show_userinfos(obj, nil, false)
81
88
  end
82
- puts "\n" if Settings.options[:timeline][:compact] == true
89
+ puts "\n" if Settings.options.timeline.compact
83
90
  end
84
91
 
85
92
  end
data/lib/ayadn/set.rb CHANGED
@@ -14,32 +14,6 @@ module Ayadn
14
14
  scroll_config.save
15
15
  end
16
16
 
17
- desc "movie ITEM VALUE", "Set values for movie (nowwatching)"
18
- map "nowwatching" => :movie
19
- def movie(*args)
20
- movie_config = SetMovie.new
21
- unless args.length != 2
22
- movie_config.send(args[0], args[1])
23
- else
24
- Status.new.error_missing_parameters
25
- exit
26
- end
27
- movie_config.save
28
- end
29
-
30
- desc "tvshow ITEM VALUE", "Set values for tvshow (nowwatching)"
31
- map "tv" => :tvshow
32
- def tvshow(*args)
33
- tvshow_config = SetTVShow.new
34
- unless args.length != 2
35
- tvshow_config.send(args[0], args[1])
36
- else
37
- Status.new.error_missing_parameters
38
- exit
39
- end
40
- tvshow_config.save
41
- end
42
-
43
17
  desc "marker ITEM TRUE/FALSE", "Set values for stream markers"
44
18
  map "markers" => :marker
45
19
  def marker(*args)
@@ -135,7 +109,7 @@ module Ayadn
135
109
  desc "edit", "Edit settings in $EDITOR"
136
110
  def edit
137
111
  Settings.load_config()
138
- sets = Settings.config[:paths][:config] + "/config.yml"
112
+ sets = Settings.config.paths.config + "/config.yml"
139
113
  if sets.blank?
140
114
  Status.new.not_authorized
141
115
  exit
@@ -378,12 +352,12 @@ module Ayadn
378
352
  value = args[0].to_i
379
353
  @input = 'table width'
380
354
  @output = Validators.width_range(value)
381
- Settings.options[:formats][:table][:width] = @output
355
+ Settings.options.formats.table.width = @output
382
356
  elsif type == 'borders' || type == 'border'
383
357
  value = args[0]
384
358
  @input = 'table borders'
385
359
  @output = Validators.boolean(value)
386
- Settings.options[:formats][:table][:borders] = @output
360
+ Settings.options.formats.table.borders = @output
387
361
  else
388
362
  @status.error_missing_parameters
389
363
  exit
@@ -400,7 +374,7 @@ module Ayadn
400
374
  if type == 'reverse' || type == 'reversed'
401
375
  @input = 'list reverse'
402
376
  @output = Validators.boolean(value)
403
- Settings.options[:formats][:list][:reverse] = @output
377
+ Settings.options.formats.list.reverse = @output
404
378
  else
405
379
  @status.error_missing_parameters
406
380
  exit
@@ -427,49 +401,19 @@ module Ayadn
427
401
  def timer(t)
428
402
  @input = 'timer'
429
403
  @output = validate(t)
430
- Settings.options[:scroll][:timer] = @output
404
+ Settings.options.scroll.timer = @output
431
405
  end
432
406
 
433
407
  def date(value)
434
408
  @input = 'date'
435
409
  @output = Validators.boolean(value)
436
- Settings.options[:scroll][:date] = @output
410
+ Settings.options.scroll.date = @output
437
411
  end
438
412
 
439
413
  def spinner(value)
440
414
  @input = 'spinner'
441
415
  @output = Validators.boolean(value)
442
- Settings.options[:scroll][:spinner] = @output
443
- end
444
-
445
- end
446
-
447
- class SetMovie < SetBase
448
-
449
- def initialize
450
- super
451
- @category = 'movie'
452
- end
453
-
454
- def hashtag(tag)
455
- @input = 'hashtag'
456
- @output = tag
457
- Settings.options[:movie][:hashtag] = @output
458
- end
459
-
460
- end
461
-
462
- class SetTVShow < SetBase
463
-
464
- def initialize
465
- super
466
- @category = 'tvshow'
467
- end
468
-
469
- def hashtag(tag)
470
- @input = 'hashtag'
471
- @output = tag
472
- Settings.options[:tvshow][:hashtag] = @output
416
+ Settings.options.scroll.spinner = @output
473
417
  end
474
418
 
475
419
  end
@@ -484,7 +428,7 @@ module Ayadn
484
428
  def filter value
485
429
  @input = 'filter'
486
430
  @output = Validators.boolean(value)
487
- Settings.options[:nicerank][:filter] = @output
431
+ Settings.options.nicerank.filter = @output
488
432
  end
489
433
 
490
434
  def active value
@@ -494,13 +438,13 @@ module Ayadn
494
438
  def unranked value
495
439
  @input = 'unranked'
496
440
  @output = Validators.boolean(value)
497
- Settings.options[:nicerank][:unranked] = @output
441
+ Settings.options.nicerank.unranked = @output
498
442
  end
499
443
 
500
444
  def threshold value
501
445
  @input = 'threshold'
502
446
  @output = Validators.threshold(value)
503
- Settings.options[:nicerank][:threshold] = @output
447
+ Settings.options.nicerank.threshold = @output
504
448
  end
505
449
 
506
450
  end
@@ -520,8 +464,12 @@ module Ayadn
520
464
  @input = meth.to_s
521
465
  @output = validate(options)
522
466
  case @input
523
- when 'posts', 'messages', 'lists'
524
- Settings.options[:backup][meth.to_sym] = @output
467
+ when 'posts'
468
+ Settings.options.backup.posts = @output
469
+ when 'messages'
470
+ Settings.options.backup.messages = @output
471
+ when 'lists'
472
+ Settings.options.backup.lists = @output
525
473
  else
526
474
  super
527
475
  end
@@ -545,7 +493,7 @@ module Ayadn
545
493
  @output = validate(options)
546
494
  case @input
547
495
  when 'messages'
548
- Settings.options[:marker][meth.to_sym] = @output
496
+ Settings.options.marker.messages = @output
549
497
  else
550
498
  super
551
499
  end
@@ -569,7 +517,7 @@ module Ayadn
569
517
  @output = validate(options)
570
518
  case @input
571
519
  when 'links'
572
- Settings.options[:channels][meth.to_sym] = @output
520
+ Settings.options.channels.links = @output
573
521
  else
574
522
  super
575
523
  end
@@ -593,7 +541,7 @@ module Ayadn
593
541
  @output = validate(options)
594
542
  case @input
595
543
  when 'active', 'activated'
596
- Settings.options[:blacklist][meth.to_sym] = @output
544
+ Settings.options.blacklist.active = @output
597
545
  else
598
546
  super
599
547
  end
@@ -616,8 +564,38 @@ module Ayadn
616
564
  @input = meth.to_s.capitalize
617
565
  @output = validate(options.to_i)
618
566
  case meth.to_s
619
- when 'default', 'unified', 'checkins', 'conversations', 'global', 'photos', 'trending', 'mentions', 'convo', 'posts', 'messages', 'search', 'whoreposted', 'whostarred', 'whatstarred', 'files'
620
- Settings.options[:counts][meth.to_sym] = @output
567
+ when 'default'
568
+ Settings.options.counts.default = @output
569
+ when 'unified'
570
+ Settings.options.counts.unified = @output
571
+ when 'checkins'
572
+ Settings.options.counts.checkins = @output
573
+ when 'conversations'
574
+ Settings.options.counts.conversations = @output
575
+ when 'global'
576
+ Settings.options.counts.global = @output
577
+ when 'photos'
578
+ Settings.options.counts.photos = @output
579
+ when 'trending'
580
+ Settings.options.counts.trending = @output
581
+ when 'mentions'
582
+ Settings.options.counts.mentions = @output
583
+ when 'convo'
584
+ Settings.options.counts.convo = @output
585
+ when 'posts'
586
+ Settings.options.counts.posts = @output
587
+ when 'messages'
588
+ Settings.options.counts.messages = @output
589
+ when 'search'
590
+ Settings.options.counts.search = @output
591
+ when 'whoreposted'
592
+ Settings.options.counts.whoreposted = @output
593
+ when 'whostarred'
594
+ Settings.options.counts.whostarred = @output
595
+ when 'whatstarred'
596
+ Settings.options.counts.whatstarred = @output
597
+ when 'files'
598
+ Settings.options.counts.files = @output
621
599
  else
622
600
  super
623
601
  end
@@ -640,10 +618,20 @@ module Ayadn
640
618
  @input = meth.to_s
641
619
  @output = validate(options)
642
620
  case @input
643
- when 'directed', 'source', 'symbols', 'name', 'date', 'debug', 'compact'
644
- Settings.options[:timeline][meth.to_sym] = @output
645
- else
646
- super
621
+ when 'directed'
622
+ Settings.options.timeline.directed = @output
623
+ when 'source'
624
+ Settings.options.timeline.source = @output
625
+ when 'symbols'
626
+ Settings.options.timeline.symbols = @output
627
+ when 'name'
628
+ Settings.options.timeline.name = @output
629
+ when 'date'
630
+ Settings.options.timeline.date = @output
631
+ when 'debug'
632
+ Settings.options.timeline.debug = @output
633
+ when 'compact'
634
+ Settings.options.timeline.compact = @output
647
635
  end
648
636
  end
649
637
 
@@ -664,12 +652,34 @@ module Ayadn
664
652
  @input = meth.to_s.capitalize
665
653
  @output = validate(options)
666
654
  case meth.to_s
667
- when 'id', 'index', 'username', 'name', 'date', 'link', 'dots', 'hashtags', 'mentions', 'source', 'symbols', 'unread', 'debug', 'excerpt'
668
- Settings.options[:colors][meth.to_sym] = @output
669
- when 'hashtag', 'mention', 'symbol'
670
- Settings.options[:colors]["#{meth}s".to_sym] = @output
671
- when 'client'
672
- Settings.options[:colors][:source] = @output
655
+ when 'id'
656
+ Settings.options.colors.id = @output
657
+ when 'index'
658
+ Settings.options.colors.index = @output
659
+ when 'username'
660
+ Settings.options.colors.username = @output
661
+ when 'name'
662
+ Settings.options.colors.name = @output
663
+ when 'date'
664
+ Settings.options.colors.date = @output
665
+ when 'link'
666
+ Settings.options.colors.link = @output
667
+ when 'dots'
668
+ Settings.options.colors.dots = @output
669
+ when 'mentions', 'mention'
670
+ Settings.options.colors.mentions = @output
671
+ when 'symbols', 'symbol'
672
+ Settings.options.colors.symbols = @output
673
+ when 'unread'
674
+ Settings.options.colors.unread = @output
675
+ when 'debug'
676
+ Settings.options.colors.debug = @output
677
+ when 'excerpt'
678
+ Settings.options.colors.excerpt = @output
679
+ when 'hashtag', 'tag', 'hashtags'
680
+ Settings.options.colors.hashtag = @output
681
+ when 'client', 'source'
682
+ Settings.options.colors.source = @output
673
683
  else
674
684
  super
675
685
  end
@@ -2,11 +2,9 @@
2
2
  module Ayadn
3
3
  class Settings
4
4
 
5
- # Warning
6
- # comment next line
7
5
  require_relative "ids"
8
- # uncomment and insert your own client id
9
- # CLIENT_ID = ""
6
+
7
+ require 'ostruct'
10
8
 
11
9
  class << self
12
10
  attr_accessor :options, :config, :global
@@ -26,7 +24,7 @@ module Ayadn
26
24
  else
27
25
  "https://api.app.net"
28
26
  end
29
- @config = {
27
+ config_hash = {
30
28
  paths: {
31
29
  home: home,
32
30
  log: "#{home}/log",
@@ -47,8 +45,11 @@ module Ayadn
47
45
  baseURL: baseURL
48
46
  }
49
47
  }
50
- @options = self.defaults
51
- @global = {scrolling: false, force: false}
48
+ @config = JSON.parse(config_hash.to_json, object_class: OpenStruct)
49
+ global_hash = {scrolling: false, force: false}
50
+ @global = JSON.parse(global_hash.to_json, object_class: OpenStruct)
51
+
52
+ @options = Preferences.new(self.defaults)
52
53
  end
53
54
 
54
55
  def self.check_for_accounts
@@ -84,41 +85,38 @@ module Ayadn
84
85
  end
85
86
 
86
87
  def self.init_config
87
- @config[:version] = VERSION
88
- @config[:platform] = RbConfig::CONFIG['host_os']
89
- @config[:ruby] = RUBY_VERSION
90
- @config[:locale] = ENV["LANG"]
88
+ @config.version = VERSION
89
+ @config.platform = RbConfig::CONFIG['host_os']
90
+ @config.ruby = RUBY_VERSION
91
+ @config.locale = ENV["LANG"]
91
92
  self.config_file
92
93
  self.create_api_file
93
94
  self.create_version_file
94
95
  end
95
96
 
96
97
  def self.save_config
97
- File.write(@config[:paths][:config] + "/config.yml", @options.to_yaml)
98
+ File.write(@config.paths.config + "/config.yml", @options.to_h.to_yaml)
98
99
  end
99
100
 
100
101
  def self.has_token_file?
101
- File.exist?(@config[:paths][:auth] + "/token")
102
+ File.exist?(@config.paths.auth + "/token")
102
103
  end
103
104
 
104
105
  def self.read_token_file
105
- File.read(@config[:paths][:auth] + "/token")
106
+ File.read(@config.paths.auth + "/token")
106
107
  end
107
108
 
108
109
  def self.config_file
109
- config_file = @config[:paths][:config] + "/config.yml"
110
+ config_file = @config.paths.config + "/config.yml"
110
111
  if File.exist?(config_file)
111
112
  begin
112
- # conf = YAML.load(File.read(config_file))
113
- # @options = conf
114
- @options = YAML.load(File.read(config_file))
115
- # self.write_config_file(config_file, @options)
113
+ @options = Preferences.new(YAML.load(File.read(config_file)))
116
114
  rescue => e
117
115
  Errors.global_error({error: e, caller: caller, data: []})
118
116
  end
119
117
  else
120
118
  begin
121
- self.write_config_file(config_file, @options)
119
+ self.write_config_file(config_file, @options.to_h)
122
120
  rescue => e
123
121
  Errors.global_error({error: e, caller: caller, data: []})
124
122
  end
@@ -126,7 +124,7 @@ module Ayadn
126
124
  end
127
125
 
128
126
  def self.create_api_file
129
- api_file = @config[:paths][:config] + "/api.json"
127
+ api_file = @config.paths.config + "/api.json"
130
128
  if File.exist?(api_file)
131
129
  # should be 48h in secs (172800)
132
130
  # but since ADN's API won't change any time soon...
@@ -140,12 +138,12 @@ module Ayadn
140
138
  end
141
139
 
142
140
  def self.create_version_file
143
- File.write(@config[:paths][:config] + "/version.yml", {version: @config[:version]}.to_yaml)
141
+ File.write(@config.paths.config + "/version.yml", {version: @config.version}.to_yaml)
144
142
  end
145
143
 
146
144
  def self.restore_defaults
147
145
  self.load_config
148
- File.write(@config[:paths][:config] + "/config.yml", @options.to_yaml)
146
+ File.write(@config.paths.config + "/config.yml", @options.to_h.to_yaml)
149
147
  end
150
148
 
151
149
  private
@@ -159,16 +157,16 @@ module Ayadn
159
157
 
160
158
  def self.read_api(api_file)
161
159
  content = JSON.parse(File.read(api_file))
162
- @config[:post_max_length] = content['post']['text_max_length']
163
- @config[:message_max_length] = content['message']['text_max_length']
160
+ @config.post_max_length = content['post']['text_max_length']
161
+ @config.message_max_length = content['message']['text_max_length']
164
162
  end
165
163
 
166
164
  def self.has_version_file?
167
- File.exist?(@config[:paths][:config] + "/version.yml")
165
+ File.exist?(@config.paths.config + "/version.yml")
168
166
  end
169
167
 
170
168
  def self.read_version_file
171
- YAML.load(File.read(@config[:paths][:config] + "/version.yml"))
169
+ YAML.load(File.read(@config.paths.config + "/version.yml"))
172
170
  end
173
171
 
174
172
  def self.write_config_file(config_file, options)
@@ -251,12 +249,6 @@ module Ayadn
251
249
  unranked: false
252
250
  },
253
251
  nowplaying: {},
254
- movie: {
255
- hashtag: 'nowwatching'
256
- },
257
- tvshow: {
258
- hashtag: 'nowwatching'
259
- },
260
252
  blacklist: {
261
253
  active: true
262
254
  }