ayadn 3.0 → 4.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 (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
@@ -1,6 +1,7 @@
1
1
  # encoding: utf-8
2
2
  module Ayadn
3
3
  class Blacklist < Thor
4
+
4
5
  desc "add TYPE TARGET", "Adds a mention, hashtag, client, username or keyword to your blacklist"
5
6
  map "create" => :add
6
7
  long_desc Descriptions.blacklist_add
@@ -33,12 +34,6 @@ module Ayadn
33
34
  BlacklistWorkers.new.list(options)
34
35
  end
35
36
 
36
- # desc "import DATABASE", "Imports a blacklist database from another Ayadn account"
37
- # long_desc Descriptions.blacklist_import
38
- # def import(database)
39
- # BlacklistWorkers.new.import(database)
40
- # end
41
-
42
37
  desc "clear", "Clear your blacklist database"
43
38
  def clear
44
39
  BlacklistWorkers.new.clear
@@ -56,18 +51,7 @@ module Ayadn
56
51
  Databases.open_databases
57
52
  @workers = Workers.new
58
53
  end
59
- # def import(database)
60
- # begin
61
- # new_db = File.realpath(database)
62
- # if File.exist?(new_db)
63
- # Databases.import_blacklist(new_db)
64
- # Logs.rec.info "Imported '#{new_db}' values in blacklist database."
65
- # else
66
- # puts "\nFile '#{new_db}' doesn't exist.\n\n".color(:red)
67
- # Logs.rec.warn "File '#{new_db}' doesn't exist."
68
- # end
69
- # end
70
- # end
54
+
71
55
  def clear
72
56
  begin
73
57
  Status.new.ask_clear_blacklist
@@ -81,6 +65,7 @@ module Ayadn
81
65
  end
82
66
  end
83
67
  end
68
+
84
69
  def add(args)
85
70
  begin
86
71
  type = args.shift
@@ -110,6 +95,7 @@ module Ayadn
110
95
  end
111
96
  end
112
97
  end
98
+
113
99
  def remove(args)
114
100
  begin
115
101
  type = args.shift
@@ -137,9 +123,10 @@ module Ayadn
137
123
  end
138
124
  end
139
125
  end
126
+
140
127
  def list(options)
141
128
  begin
142
- Settings.options[:timeline][:compact] = true if options[:compact] == true
129
+ Settings.options.timeline.compact = true if options[:compact]
143
130
  show_list(options)
144
131
  end
145
132
  end
@@ -0,0 +1,75 @@
1
+ # encoding: utf-8
2
+ module Ayadn
3
+
4
+ class ChannelReadersObject
5
+
6
+ attr_reader :input, :you, :any_user, :public, :immutable
7
+
8
+ def initialize hash
9
+ @input = hash
10
+ @you = @input["you"]
11
+ @any_user = @input["any_user"]
12
+ @public = @input["public"]
13
+ @immutable = @input["immutable"]
14
+ end
15
+ end
16
+
17
+ class ChannelEditorsObject
18
+
19
+ attr_reader :input, :you, :any_user, :public, :immutable, :user_ids
20
+
21
+ def initialize hash
22
+ @input = hash
23
+ @you = @input["you"]
24
+ @any_user = @input["any_user"]
25
+ @public = @input["public"]
26
+ @immutable = @input["immutable"]
27
+ @user_ids = @input["user_ids"]
28
+ end
29
+ end
30
+
31
+ class ChannelCountsObject
32
+
33
+ attr_reader :input, :messages, :subscribers
34
+
35
+ def initialize hash
36
+ @input = hash
37
+ @messages = @input["messages"]
38
+ @subscribers = @input["subscribers"]
39
+ end
40
+
41
+ end
42
+
43
+ class ChannelObject
44
+
45
+ attr_reader :input, :pagination_id, :is_inactive, :readers, :you_muted, :you_can_edit, :has_unread, :editors, :annotations, :recent_message_id, :writers, :you_subscribed, :owner, :type, :id, :counts, :recent_message
46
+
47
+ def initialize hash
48
+ @input = hash
49
+ @pagination_id = @input["pagination_id"]
50
+ @is_inactive = @input["is_inactive"]
51
+ @readers = ChannelReadersObject.new(@input["readers"])
52
+ @you_muted = @input["you_muted"]
53
+ @you_can_edit = @input["you_can_edit"]
54
+ @has_unread = @input["has_unread"]
55
+ @editors = ChannelEditorsObject.new(@input["editors"])
56
+ @annotations = @input["annotations"].map { |ann| PostAnnotationObject.new(ann) }
57
+ @recent_message_id = @input["recent_message_id"]
58
+ @writers = ChannelEditorsObject.new(@input["writers"])
59
+ @you_subscribed = @input["you_subscribed"]
60
+ @owner = @input["owner"].nil? ? nil : UserObject.new(@input["owner"])
61
+ @type = @input["type"]
62
+ @id = @input["id"]
63
+ @counts = ChannelCountsObject.new(@input["counts"])
64
+ @recent_message = @input["recent_message"].nil? ? nil : PostObject.new(@input["recent_message"])
65
+ end
66
+
67
+ end
68
+ end
69
+
70
+
71
+
72
+
73
+
74
+
75
+
data/lib/ayadn/check.rb CHANGED
@@ -3,24 +3,24 @@ module Ayadn
3
3
 
4
4
  class Check
5
5
 
6
- def initialize
7
- @status = Status.new
6
+ def initialize status = Status.new
7
+ @status = status
8
8
  end
9
9
 
10
- def same_username(stream)
11
- stream['data']['username'] == Settings.config[:identity][:username]
10
+ def same_username(user_object)
11
+ user_object.username == Settings.config.identity.username
12
12
  end
13
13
 
14
14
  def auto_save_muted(list)
15
- FileOps.save_muted_list(list) if Settings.options[:backup][:lists]
15
+ FileOps.save_muted_list(list) if Settings.options.backup.lists
16
16
  end
17
17
 
18
18
  def auto_save_followers(list)
19
- FileOps.save_followers_list(list) if Settings.options[:backup][:lists]
19
+ FileOps.save_followers_list(list) if Settings.options.backup.lists
20
20
  end
21
21
 
22
22
  def auto_save_followings(list)
23
- FileOps.save_followings_list(list) if Settings.options[:backup][:lists]
23
+ FileOps.save_followings_list(list) if Settings.options.backup.lists
24
24
  end
25
25
 
26
26
  def no_username username
@@ -31,7 +31,7 @@ module Ayadn
31
31
  end
32
32
 
33
33
  def no_data stream, target
34
- if stream['data'].empty?
34
+ if stream.posts.empty?
35
35
  Errors.warn "In action/#{target}: no data"
36
36
  @status.empty_list
37
37
  exit
@@ -39,7 +39,7 @@ module Ayadn
39
39
  end
40
40
 
41
41
  def no_new_posts stream, options, title
42
- if options[:new] == true
42
+ if options[:new]
43
43
  unless Databases.has_new?(stream, title)
44
44
  @status.no_new_posts
45
45
  exit
@@ -48,7 +48,15 @@ module Ayadn
48
48
  end
49
49
 
50
50
  def no_post stream, post_id
51
- if stream['meta']['code'] == 404
51
+ if stream.meta.code == 404
52
+ @status.post_404(post_id)
53
+ Errors.info("Impossible to find #{post_id}")
54
+ exit
55
+ end
56
+ end
57
+
58
+ def no_details stream, post_id
59
+ if stream["meta"]["code"] == 404
52
60
  @status.post_404(post_id)
53
61
  Errors.info("Impossible to find #{post_id}")
54
62
  exit
@@ -72,7 +80,7 @@ module Ayadn
72
80
  end
73
81
 
74
82
  def no_user stream, username
75
- if stream['meta']['code'] == 404
83
+ if stream.meta.code == 404
76
84
  @status.user_404(username)
77
85
  Errors.info("User #{username} doesn't exist")
78
86
  exit
data/lib/ayadn/cnx.rb CHANGED
@@ -9,7 +9,7 @@ module Ayadn
9
9
  rescue RestClient::RequestTimeout => e
10
10
  thor = Thor::Shell::Color.new
11
11
  thor.say_status :error, "connection timeout", :red
12
- if working == true
12
+ if working
13
13
  working = false
14
14
  thor.say_status :info, "trying again", :yellow
15
15
  retry
@@ -17,7 +17,7 @@ module Ayadn
17
17
  Errors.global_error({error: e, caller: caller, data: [url]})
18
18
  rescue SocketError, SystemCallError, OpenSSL::SSL::SSLError => e
19
19
  thor = Thor::Shell::Color.new
20
- if working == true
20
+ if working
21
21
  working = false
22
22
  thor.say_status :error, "'#{url}' didn't respond", :red
23
23
  thor.say_status :info, "trying again in 5 secs", :yellow
@@ -45,7 +45,7 @@ module Ayadn
45
45
  check_nr response, url
46
46
  end
47
47
  rescue SocketError, SystemCallError, OpenSSL::SSL::SSLError, RestClient::RequestTimeout => e
48
- if working == true
48
+ if working
49
49
  working = false
50
50
  sleep 0.5
51
51
  retry
@@ -84,8 +84,7 @@ module Ayadn
84
84
  check response
85
85
  end
86
86
  rescue RestClient::RequestTimeout => e
87
- thor = Thor::Shell::Color.new
88
- thor.say_status :error, "connection timeout", :red
87
+ Thor::Shell::Color.new.say_status :error, "connection timeout", :red
89
88
  if try_cnx < 4
90
89
  try_cnx = retry_adn 5, try_cnx
91
90
  retry
@@ -102,9 +101,8 @@ module Ayadn
102
101
  Thor::Shell::Color.new.say_status :error, "connection or authorization problem", :red
103
102
  Errors.global_error({error: e, caller: caller, data: [url]})
104
103
  rescue Interrupt
105
- thor = Thor::Shell::Color.new
106
104
  puts "\n"
107
- thor.say_status :canceled, "connection canceled", :red
105
+ Thor::Shell::Color.new.say_status :canceled, "connection canceled", :red
108
106
  puts "\n"
109
107
  exit
110
108
  rescue => e
@@ -155,9 +153,8 @@ module Ayadn
155
153
  Thor::Shell::Color.new.say_status :error, "connection problem", :red
156
154
  Errors.global_error({error: e, caller: caller, data: [url]})
157
155
  rescue Interrupt
158
- thor = Thor::Shell::Color.new
159
156
  puts "\n"
160
- thor.say_status :canceled, "connection canceled", :red
157
+ Thor::Shell::Color.new.say_status :canceled, "connection canceled", :red
161
158
  puts "\n"
162
159
  exit
163
160
  rescue => e
@@ -175,9 +172,8 @@ module Ayadn
175
172
  Thor::Shell::Color.new.say_status :error, "connection problem", :red
176
173
  Errors.global_error({error: e, caller: caller, data: [url, payload]})
177
174
  rescue Interrupt
178
- thor = Thor::Shell::Color.new
179
175
  puts "\n"
180
- thor.say_status :canceled, "connection canceled", :red
176
+ Thor::Shell::Color.new.say_status :canceled, "connection canceled", :red
181
177
  puts "\n"
182
178
  exit
183
179
  rescue => e
@@ -195,9 +191,8 @@ module Ayadn
195
191
  Thor::Shell::Color.new.say_status :error, "connection problem", :red
196
192
  Errors.global_error({error: e, caller: caller, data: [url, payload]})
197
193
  rescue Interrupt
198
- thor = Thor::Shell::Color.new
199
194
  puts "\n"
200
- thor.say_status :canceled, "connection canceled", :red
195
+ Thor::Shell::Color.new.say_status :canceled, "connection canceled", :red
201
196
  puts "\n"
202
197
  exit
203
198
  rescue => e
@@ -215,9 +210,8 @@ module Ayadn
215
210
  Thor::Shell::Color.new.say_status :error, "connection problem", :red
216
211
  Errors.global_error({error: e, caller: caller, data: [url, payload]})
217
212
  rescue Interrupt
218
- thor = Thor::Shell::Color.new
219
213
  puts "\n"
220
- thor.say_status :canceled, "connection canceled", :red
214
+ Thor::Shell::Color.new.say_status :canceled, "connection canceled", :red
221
215
  puts "\n"
222
216
  exit
223
217
  rescue => e
@@ -4,7 +4,7 @@ module Ayadn
4
4
  class Databases
5
5
 
6
6
  def self.open_databases
7
- @sqlfile = "#{Settings.config[:paths][:db]}/ayadn.sqlite"
7
+ @sqlfile = "#{Settings.config.paths.db}/ayadn.sqlite"
8
8
  @sql = Amalgalite::Database.new(@sqlfile)
9
9
  @accounts = Amalgalite::Database.new(Dir.home + "/ayadn/accounts.sqlite")
10
10
  end
@@ -178,20 +178,6 @@ module Ayadn
178
178
  end
179
179
  end
180
180
 
181
- # def self.import_blacklist(blacklist)
182
- # new_list = self.init blacklist
183
- # new_list.each {|name,type| @blacklist[name] = type}
184
- # new_list.close
185
- # end
186
- # def self.convert_blacklist
187
- # dummy = {}
188
- # @blacklist.each {|v,k| dummy[v.downcase] = k}
189
- # @blacklist.clear
190
- # dummy.each {|v,k| @blacklist[v] = k}
191
- # end
192
-
193
-
194
-
195
181
  def self.active_account(acc)
196
182
  crashes = 0
197
183
  begin
@@ -628,12 +614,14 @@ module Ayadn
628
614
  @sql.execute("DELETE FROM TLIndex")
629
615
  @sql.transaction do |db_in_transaction|
630
616
  posts.each do |k, v|
631
- insert_data = {}
632
- insert_data[":post_id"] = v[:id]
633
- insert_data[":count"] = v[:count]
634
- insert_data[":content"] = v.to_json.to_s
635
- db_in_transaction.prepare("INSERT INTO TLIndex(count, post_id, content) VALUES(:count, :post_id, :content);") do |insert|
636
- insert.execute(insert_data)
617
+ if !v.blank?
618
+ insert_data = {}
619
+ insert_data[":post_id"] = v[:id]
620
+ insert_data[":count"] = v[:count]
621
+ insert_data[":content"] = v.to_json.to_s
622
+ db_in_transaction.prepare("INSERT INTO TLIndex(count, post_id, content) VALUES(:count, :post_id, :content);") do |insert|
623
+ insert.execute(insert_data)
624
+ end
637
625
  end
638
626
  end
639
627
  end
@@ -871,7 +859,7 @@ module Ayadn
871
859
  crashes = 0
872
860
  begin
873
861
  res = @sql.execute("SELECT post_id FROM Pagination WHERE name=(?)", [title]).flatten[0]
874
- stream['meta']['max_id'].to_i > res.to_i
862
+ stream.meta.max_id.to_i > res.to_i
875
863
  rescue Amalgalite::SQLite3::Error => e
876
864
  if crashes < 2
877
865
  crashes += 1
@@ -881,7 +869,7 @@ module Ayadn
881
869
  puts "ERROR in Databases"
882
870
  puts caller
883
871
  puts e
884
- puts ['has_new?', stream, title].inspect
872
+ puts ['has_new?', stream.inspect, title].inspect
885
873
  exit
886
874
  end
887
875
  end
@@ -890,13 +878,13 @@ module Ayadn
890
878
  def self.save_max_id(stream, name = 'unknown')
891
879
  crashes = 0
892
880
  begin
893
- if stream['meta']['marker'].nil?
881
+ if stream.meta.marker.nil?
894
882
  key = name
895
883
  else
896
- key = stream['meta']['marker']['name']
884
+ key = stream.meta.marker.name
897
885
  end
898
886
  @sql.execute("DELETE FROM Pagination WHERE name=(?)", [key])
899
- @sql.execute("INSERT INTO Pagination(name, post_id) VALUES(?, ?);", [key, stream['meta']['max_id'].to_i])
887
+ @sql.execute("INSERT INTO Pagination(name, post_id) VALUES(?, ?);", [key, stream.meta.max_id.to_i])
900
888
  rescue Amalgalite::SQLite3::Error => e
901
889
  if crashes < 2
902
890
  crashes += 1
@@ -906,7 +894,7 @@ module Ayadn
906
894
  puts "ERROR in Databases"
907
895
  puts caller
908
896
  puts e
909
- puts ['save_max_id', stream, name].inspect
897
+ puts ['save_max_id', stream.inspect, name].inspect
910
898
  exit
911
899
  end
912
900
  end
data/lib/ayadn/debug.rb CHANGED
@@ -3,13 +3,13 @@ module Ayadn
3
3
  class Debug
4
4
 
5
5
  def self.skipped dic
6
- if Settings.options[:timeline][:debug] == true
6
+ if Settings.options.timeline.debug
7
7
  Logs.rec.debug "SKIPPED: #{dic.keys.first.to_s.capitalize} => #{dic.values.first}"
8
8
  end
9
9
  end
10
10
 
11
11
  def self.http response, url
12
- if Settings.options[:timeline][:debug] == true
12
+ if Settings.options.timeline.debug
13
13
  deb = "\n"
14
14
  deb << "+ HTTP\n"
15
15
  deb << "* t#{Time.now.to_i}\n"
@@ -24,7 +24,7 @@ module Ayadn
24
24
 
25
25
  def self.err error, stack
26
26
  # Logs.rec.debug "+DEBUG STACK: #{stack}"
27
- if Settings.options[:timeline][:debug] == true
27
+ if Settings.options.timeline.debug
28
28
  puts "\nDEBUG:\n"
29
29
  puts error.inspect
30
30
  raise error
@@ -35,20 +35,20 @@ module Ayadn
35
35
  end
36
36
 
37
37
  def self.stream(stream, options, target)
38
- if Settings.options[:timeline][:debug] == true
38
+ if Settings.options.timeline.debug
39
39
  deb = "\n"
40
40
  deb << "+ STREAM\n"
41
41
  deb << "* t#{Time.now.to_i}\n"
42
42
  deb << "Options:\t#{options.inspect}\n"
43
43
  deb << "Target:\t\t#{target.inspect}\n"
44
- deb << "Posts:\t\t#{stream['data'].length}\n"
45
- deb << "Meta:\t\t#{stream['meta']}\n"
44
+ deb << "Posts:\t\t#{stream.posts.length}\n"
45
+ deb << "Meta:\t\t#{stream.meta.input.inspect}\n"
46
46
  deb << "\n"
47
- puts deb.color(Settings.options[:colors][:debug])
48
- Logs.rec.debug "STREAM/META: #{stream['meta']}"
47
+ puts deb.color(Settings.options.colors.debug)
48
+ Logs.rec.debug "STREAM/META: #{stream.meta.input.inspect}"
49
49
  Logs.rec.debug "STREAM/OPTIONS: #{options.inspect}"
50
50
  Logs.rec.debug "STREAM/TARGET: #{target.inspect}"
51
- Logs.rec.debug "STREAM/POSTS: #{stream['data'].length}"
51
+ Logs.rec.debug "STREAM/POSTS: #{stream.posts.length}"
52
52
  end
53
53
  end
54
54