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
@@ -5,58 +5,63 @@ module Ayadn
5
5
  AYADN_CLIENT_ID = "hFsCGArAjgJkYBHTHbZnUvzTmL4vaLHL"
6
6
 
7
7
  class << self
8
- attr_accessor :options, :config
9
- attr_reader :user_token, :default_nr
8
+ attr_accessor :options, :config, :global
9
+ attr_reader :user_token
10
10
  end
11
11
 
12
12
  def self.load_config
13
- acc_db = Dir.home + "/ayadn/accounts.db"
14
- self.check_for_accounts(acc_db)
15
- db = Databases.init acc_db
16
- active = db['ACTIVE']
17
- home = db[active][:path]
13
+ active = self.check_for_accounts
14
+ home = active[3]
18
15
  @config = {
19
16
  paths: {
20
17
  home: home,
21
18
  log: "#{home}/log",
22
19
  db: "#{home}/db",
23
- pagination: "#{home}/pagination",
24
20
  config: "#{home}/config",
25
21
  auth: "#{home}/auth",
26
22
  downloads: "#{home}/downloads",
27
- backup: "#{home}/backup",
28
23
  posts: "#{home}/posts",
29
24
  messages: "#{home}/messages",
30
25
  lists: "#{home}/lists"
31
26
  },
32
27
  identity: {
33
- id: db[active][:id],
34
- username: db[active][:username],
35
- handle: db[active][:handle]
28
+ id: active[1],
29
+ username: active[0],
30
+ handle: active[2]
36
31
  }
37
32
  }
38
- @default_nr = {
39
- threshold: 2.1,
40
- cache: 48,
41
- filter: true,
42
- filter_unranked: false
43
- }
44
- db.close
45
33
  @options = self.defaults
34
+ @global = {scrolling: false, force: false}
46
35
  end
47
36
 
48
- def self.check_for_accounts(acc_db)
49
- unless File.exist?(acc_db)
50
- puts Status.not_authorized
51
- exit
37
+ def self.check_for_accounts
38
+ sqlaccounts = Dir.home + "/ayadn/accounts.sqlite"
39
+ status = Status.new
40
+ if File.exist?(sqlaccounts)
41
+ # Ayadn 2.x with already authorized account(s)
42
+ return self.init_sqlite(sqlaccounts)
43
+ else
44
+ if File.exist?(Dir.home + "/ayadn/accounts.db")
45
+ # Ayadn 1.x with already authorized account(s)
46
+ status.has_to_migrate
47
+ exit
48
+ else
49
+ # Ayadn 1.x without any authorized account (gem installed but no ~/ayadn folder)
50
+ status.not_authorized
51
+ exit
52
+ end
52
53
  end
53
54
  end
54
55
 
56
+ def self.init_sqlite(sqlaccounts)
57
+ Databases.active_account(Amalgalite::Database.new(sqlaccounts))
58
+ end
59
+
55
60
  def self.get_token
56
61
  if self.has_token_file?
57
62
  @user_token = self.read_token_file
58
63
  else
59
- puts Status.not_authorized
64
+ Status.new.not_authorized
60
65
  exit
61
66
  end
62
67
  end
@@ -87,27 +92,10 @@ module Ayadn
87
92
  config_file = @config[:paths][:config] + "/config.yml"
88
93
  if File.exist?(config_file)
89
94
  begin
90
- conf = YAML.load(File.read(config_file))
91
-
92
- # force delete obsolete keys (because legacy versions of the config file)
93
- conf[:timeline].delete_if {|k,_| k == :show_nicerank}
94
- conf[:colors].delete_if {|k,_| k == :nicerank}
95
- # force create mandatory keys (idem)
96
- conf[:nicerank] = @default_nr if conf[:nicerank].nil? || conf[:nicerank].size != 4
97
- conf[:timeline][:show_debug] = false if conf[:timeline][:show_debug].nil?
98
- conf[:timeline][:show_spinner] = true if conf[:timeline][:show_spinner].nil?
99
- conf[:colors][:debug] = :red if conf[:colors][:debug].nil?
100
- conf[:colors][:unread] = :cyan if conf[:colors][:unread].nil?
101
- conf[:nowplaying] = {} if conf[:nowplaying].nil?
102
- conf[:movie] = {hashtag: 'nowwatching'} if conf[:movie].nil?
103
- conf[:tvshow] = {hashtag: 'nowwatching'} if conf[:tvshow].nil?
104
- conf[:formats][:list] = {reverse: true} if conf[:formats][:list].nil?
105
- conf[:timeline][:compact] = false if conf[:timeline][:compact].nil?
106
- conf[:timeline][:show_channel_oembed] = true if conf[:timeline][:show_channel_oembed].nil?
107
- conf[:marker] = {update_messages: true} if conf[:marker].nil?
108
-
109
- @options = conf
110
- self.write_config_file(config_file, @options)
95
+ # conf = YAML.load(File.read(config_file))
96
+ # @options = conf
97
+ @options = YAML.load(File.read(config_file))
98
+ # self.write_config_file(config_file, @options)
111
99
  rescue => e
112
100
  Errors.global_error({error: e, caller: caller, data: []})
113
101
  end
@@ -123,7 +111,9 @@ module Ayadn
123
111
  def self.create_api_file
124
112
  api_file = @config[:paths][:config] + "/api.json"
125
113
  if File.exist?(api_file)
126
- if ( File.ctime(api_file) < (Time.now - 172800) ) #48h in secs
114
+ # should be 48h in secs (172800)
115
+ # but since ADN's API won't change any time soon...
116
+ if ( File.ctime(api_file) < (Time.now - 604800) )
127
117
  self.new_api_file(api_file)
128
118
  end
129
119
  else
@@ -171,21 +161,16 @@ module Ayadn
171
161
  def self.defaults
172
162
  {
173
163
  timeline: {
174
- directed: 1,
175
- deleted: 0,
176
- html: 0,
177
- annotations: true,
178
- show_source: true,
179
- show_symbols: true,
180
- show_real_name: true,
181
- show_date: true,
182
- show_spinner: true,
183
- show_debug: false,
184
- show_channel_oembed: true,
164
+ directed: true,
165
+ source: true,
166
+ symbols: true,
167
+ name: true,
168
+ date: true,
169
+ debug: false,
185
170
  compact: false
186
171
  },
187
172
  marker: {
188
- update_messages: true
173
+ messages: true
189
174
  },
190
175
  counts: {
191
176
  default: 50,
@@ -197,8 +182,8 @@ module Ayadn
197
182
  trending: 50,
198
183
  mentions: 50,
199
184
  convo: 50,
200
- posts: 100,
201
- messages: 50,
185
+ posts: 50,
186
+ messages: 20,
202
187
  search: 200,
203
188
  whoreposted: 20,
204
189
  whostarred: 20,
@@ -207,12 +192,16 @@ module Ayadn
207
192
  },
208
193
  formats: {
209
194
  table: {
210
- width: 75
195
+ width: 75,
196
+ borders: true
211
197
  },
212
198
  list: {
213
199
  reverse: true
214
200
  }
215
201
  },
202
+ channels: {
203
+ links: true
204
+ },
216
205
  colors: {
217
206
  id: :blue,
218
207
  index: :red,
@@ -226,23 +215,33 @@ module Ayadn
226
215
  source: :cyan,
227
216
  symbols: :green,
228
217
  unread: :cyan,
229
- debug: :red
218
+ debug: :red,
219
+ excerpt: :green
230
220
  },
231
221
  backup: {
232
- auto_save_sent_posts: false,
233
- auto_save_sent_messages: false,
234
- auto_save_lists: false
222
+ posts: false,
223
+ messages: false,
224
+ lists: false
235
225
  },
236
226
  scroll: {
237
- timer: 3
227
+ spinner: true,
228
+ timer: 3,
229
+ date: false
230
+ },
231
+ nicerank: {
232
+ threshold: 2.1,
233
+ filter: true,
234
+ unranked: false
238
235
  },
239
- nicerank: @default_nr,
240
236
  nowplaying: {},
241
237
  movie: {
242
238
  hashtag: 'nowwatching'
243
239
  },
244
240
  tvshow: {
245
241
  hashtag: 'nowwatching'
242
+ },
243
+ blacklist: {
244
+ active: true
246
245
  }
247
246
  }
248
247
  end