ayadn 1.6.0 → 1.7.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/ayadn/set.rb CHANGED
@@ -62,7 +62,7 @@ module Ayadn
62
62
  begin
63
63
  param = timeline_config.validate(args[1])
64
64
  timeline_config.send(args[0], param)
65
- rescue NoMethodError
65
+ rescue NoMethodError, ArgumentError
66
66
  puts Status.error_missing_parameters
67
67
  exit
68
68
  rescue => e
@@ -84,7 +84,7 @@ module Ayadn
84
84
  begin
85
85
  param = counts_config.validate(args[1])
86
86
  counts_config.send(args[0], param)
87
- rescue NoMethodError
87
+ rescue NoMethodError, ArgumentError
88
88
  puts Status.error_missing_parameters
89
89
  exit
90
90
  rescue => e
@@ -108,7 +108,7 @@ module Ayadn
108
108
  begin
109
109
  color_config.validate(args[1])
110
110
  color_config.send(args[0], args[1])
111
- rescue NoMethodError
111
+ rescue NoMethodError, ArgumentError
112
112
  puts Status.error_missing_parameters
113
113
  exit
114
114
  rescue => e
@@ -129,7 +129,7 @@ module Ayadn
129
129
  begin
130
130
  param = backup_config.validate(args[1])
131
131
  backup_config.send(args[0], param)
132
- rescue NoMethodError
132
+ rescue NoMethodError, ArgumentError
133
133
  puts Status.error_missing_parameters
134
134
  exit
135
135
  rescue => e
@@ -148,7 +148,53 @@ module Ayadn
148
148
  Settings.restore_defaults
149
149
  puts Status.done
150
150
  end
151
+ end
151
152
 
153
+ class Validators
154
+ def self.boolean(value)
155
+ case value.downcase
156
+ when "true", "1", "yes"
157
+ true
158
+ when "false", "0", "no"
159
+ false
160
+ else
161
+ abort(Status.error_missing_parameters)
162
+ end
163
+ end
164
+ def self.index_range(min, max, value)
165
+ x = value.to_i
166
+ if x >= min && x <= max
167
+ x
168
+ else
169
+ abort(Status.must_be_integer)
170
+ end
171
+ end
172
+ def self.cache_range value
173
+ if value >= 1 && value <= 168
174
+ value.round
175
+ else
176
+ abort(Status.cache_range)
177
+ end
178
+ end
179
+ def self.threshold value
180
+ value = value.to_f
181
+ if value > 0 and value < 5
182
+ value
183
+ else
184
+ abort(Status.threshold)
185
+ end
186
+ end
187
+ def self.timer(t)
188
+ t = t.to_i
189
+ t >= 1 ? t : 3
190
+ end
191
+ def self.color(color)
192
+ colors_list = %w{red green magenta cyan yellow blue white black}
193
+ unless colors_list.include?(color)
194
+ puts Status.error_missing_parameters
195
+ abort(Status.valid_colors(colors_list))
196
+ end
197
+ end
152
198
  end
153
199
 
154
200
  class SetScroll
@@ -222,7 +268,7 @@ module Ayadn
222
268
  Logs.create_logger
223
269
  end
224
270
  def log(args)
225
- x = "New value for '#{args[0]}' in 'NiceRank' => #{"%1.1f" % args[1].to_f}"
271
+ x = "New value for '#{args[0]}' in 'NiceRank' => #{args[1]}"
226
272
  puts "\n#{x}\n".color(:cyan)
227
273
  Logs.rec.info x
228
274
  end
@@ -261,60 +307,12 @@ module Ayadn
261
307
  def validate(value)
262
308
  Validators.boolean(value)
263
309
  end
264
- def auto_save_sent_posts(value)
265
- Settings.options[:backup][:auto_save_sent_posts] = value
266
- end
267
- def auto_save_sent_messages(value)
268
- Settings.options[:backup][:auto_save_sent_messages] = value
269
- end
270
- def auto_save_lists(value)
271
- Settings.options[:backup][:auto_save_lists] = value
272
- end
273
- end
274
-
275
- class Validators
276
- def self.boolean(value)
277
- case value.downcase
278
- when "true", "1", "yes"
279
- true
280
- when "false", "0", "no"
281
- false
282
- else
283
- abort(Status.error_missing_parameters)
284
- end
285
- end
286
- def self.index_range(min, max, value)
287
- x = value.to_i
288
- if x >= min && x <= max
289
- x
310
+ def method_missing(meth, options)
311
+ case meth.to_s
312
+ when 'auto_save_sent_posts', 'auto_save_sent_messages', 'auto_save_lists'
313
+ Settings.options[:backup][meth.to_sym] = options
290
314
  else
291
- abort(Status.must_be_integer)
292
- end
293
- end
294
- def self.cache_range value
295
- if value >= 1 && value <= 168
296
- value.round
297
- else
298
- abort(Status.cache_range)
299
- end
300
- end
301
- def self.threshold value
302
- value = value.to_f
303
- if value > 0 and value < 5
304
- value
305
- else
306
- abort(Status.threshold)
307
- end
308
- end
309
- def self.timer(t)
310
- t = t.to_i
311
- t >= 1 ? t : 3
312
- end
313
- def self.color(color)
314
- colors_list = %w{red green magenta cyan yellow blue white black}
315
- unless colors_list.include?(color)
316
- puts Status.error_missing_parameters
317
- abort(Status.valid_colors(colors_list))
315
+ super
318
316
  end
319
317
  end
320
318
  end
@@ -337,53 +335,13 @@ module Ayadn
337
335
  def validate(value)
338
336
  Validators.index_range(1, 200, value)
339
337
  end
340
- def default(value)
341
- Settings.options[:counts][:default] = value
342
- end
343
- def unified(value)
344
- Settings.options[:counts][:unified] = value
345
- end
346
- def global(value)
347
- Settings.options[:counts][:global] = value
348
- end
349
- def checkins(value)
350
- Settings.options[:counts][:checkins] = value
351
- end
352
- def conversations(value)
353
- Settings.options[:counts][:conversations] = value
354
- end
355
- def photos(value)
356
- Settings.options[:counts][:photos] = value
357
- end
358
- def trending(value)
359
- Settings.options[:counts][:trending] = value
360
- end
361
- def mentions(value)
362
- Settings.options[:counts][:mentions] = value
363
- end
364
- def convo(value)
365
- Settings.options[:counts][:convo] = value
366
- end
367
- def posts(value)
368
- Settings.options[:counts][:posts] = value
369
- end
370
- def messages(value)
371
- Settings.options[:counts][:messages] = value
372
- end
373
- def search(value)
374
- Settings.options[:counts][:search] = value
375
- end
376
- def whoreposted(value)
377
- Settings.options[:counts][:whoreposted] = value
378
- end
379
- def whostarred(value)
380
- Settings.options[:counts][:whostarred] = value
381
- end
382
- def whatstarred(value)
383
- Settings.options[:counts][:whatstarred] = value
384
- end
385
- def files(value)
386
- Settings.options[:counts][:files] = value
338
+ def method_missing(meth, options)
339
+ case meth.to_s
340
+ when 'default', 'unified', 'checkins', 'conversations', 'global', 'photos', 'trending', 'mentions', 'convo', 'posts', 'messages', 'search', 'whoreposted', 'whostarred', 'whatstarred', 'files'
341
+ Settings.options[:counts][meth.to_sym] = options.to_i
342
+ else
343
+ super
344
+ end
387
345
  end
388
346
  end
389
347
 
@@ -405,37 +363,15 @@ module Ayadn
405
363
  def save
406
364
  Settings.save_config
407
365
  end
408
- def directed(value)
409
- Settings.options[:timeline][:directed] = value
410
- end
411
- def deleted(value)
412
- #Settings.options[:timeline][:deleted] = value
413
- abort(Status.not_mutable)
414
- end
415
- def html(value)
416
- Settings.options[:timeline][:html] = value
417
- end
418
- def annotations(value)
419
- #Settings.options[:timeline][:annotations] = value
420
- abort(Status.not_mutable)
421
- end
422
- def show_source(value)
423
- Settings.options[:timeline][:show_source] = value
424
- end
425
- def show_symbols(value)
426
- Settings.options[:timeline][:show_symbols] = value
427
- end
428
- def show_real_name(value)
429
- Settings.options[:timeline][:show_real_name] = value
430
- end
431
- def show_date(value)
432
- Settings.options[:timeline][:show_date] = value
433
- end
434
- def show_spinner value
435
- Settings.options[:timeline][:show_spinner] = value
436
- end
437
- def show_debug value
438
- Settings.options[:timeline][:show_debug] = value
366
+ def method_missing(meth, options)
367
+ case meth.to_s
368
+ when 'directed', 'html', 'show_source', 'show_symbols', 'show_real_name', 'show_date', 'show_spinner', 'show_debug'
369
+ Settings.options[:timeline][meth.to_sym] = options
370
+ when 'deleted', 'annotations'
371
+ abort(Status.not_mutable)
372
+ else
373
+ super
374
+ end
439
375
  end
440
376
  end
441
377
 
@@ -461,68 +397,17 @@ module Ayadn
461
397
  Settings.save_config
462
398
  end
463
399
 
464
- def id(color)
465
- Settings.options[:colors][:id] = color.to_sym
466
- end
467
-
468
- def index(color)
469
- Settings.options[:colors][:index] = color.to_sym
470
- end
471
-
472
- def username(color)
473
- Settings.options[:colors][:username] = color.to_sym
474
- end
475
-
476
- def name(color)
477
- Settings.options[:colors][:name] = color.to_sym
478
- end
479
-
480
- def date(color)
481
- Settings.options[:colors][:date] = color.to_sym
482
- end
483
-
484
- def link(color)
485
- Settings.options[:colors][:link] = color.to_sym
486
- end
487
-
488
- def dots(color)
489
- Settings.options[:colors][:dots] = color.to_sym
490
- end
491
-
492
- def hashtags(color)
493
- Settings.options[:colors][:hashtags] = color.to_sym
494
- end
495
-
496
- def hashtag color
497
- hashtags color
498
- end
499
-
500
- def mentions(color)
501
- Settings.options[:colors][:mentions] = color.to_sym
502
- end
503
-
504
- def mention color
505
- mentions color
506
- end
507
-
508
- def source(color)
509
- Settings.options[:colors][:source] = color.to_sym
510
- end
511
-
512
- def client color
513
- source color
514
- end
515
-
516
- def symbols(color)
517
- Settings.options[:colors][:symbols] = color.to_sym
518
- end
519
-
520
- def symbol(color)
521
- symbols color
522
- end
523
-
524
- def debug(color)
525
- Settings.options[:colors][:debug] = color.to_sym
400
+ def method_missing(meth, options)
401
+ case meth.to_s
402
+ when 'id', 'index', 'username', 'name', 'date', 'link', 'dots', 'hashtags', 'mentions', 'source', 'symbols', 'debug'
403
+ Settings.options[:colors][meth.to_sym] = options.to_sym
404
+ when 'hashtag', 'mention', 'symbol'
405
+ Settings.options[:colors]["#{meth}s".to_sym] = options.to_sym
406
+ when 'client'
407
+ Settings.options[:colors][:source] = options.to_sym
408
+ else
409
+ super
410
+ end
526
411
  end
527
412
  end
528
413
  end
data/lib/ayadn/status.rb CHANGED
@@ -309,5 +309,8 @@ module Ayadn
309
309
  def self.no_show_infos
310
310
  "\nSorry, can't find informations about this show.\n".color(:blue)
311
311
  end
312
+ def self.no_force target
313
+ "\n'#{target}' can't be displayed (could be muted, blocked, in the Blacklist, etc). Use option '--force' ('-f') to try and display this content anyway.\n\n".color(:blue)
314
+ end
312
315
  end
313
316
  end
data/lib/ayadn/stream.rb CHANGED
@@ -9,64 +9,46 @@ module Ayadn
9
9
  @workers = workers
10
10
  end
11
11
 
12
- def unified options
13
- @view.downloading(options)
14
- stream = @api.get_unified(options)
15
- Check.no_new_posts(stream, options, 'unified')
16
- Databases.save_max_id(stream)
17
- @view.render(stream, options)
18
- Scroll.new(@api, @view).unified(options) if options[:scroll]
19
- end
20
-
21
- def checkins options
22
- @view.downloading(options)
23
- stream = @api.get_checkins(options)
24
- Check.no_new_posts(stream, options, 'explore:checkins')
25
- Databases.save_max_id(stream)
26
- @view.render(stream, options)
27
- Scroll.new(@api, @view).checkins(options) if options[:scroll]
28
- end
29
-
30
12
  def global settings
13
+ Settings.options[:force] = true if settings[:force]
31
14
  options = settings.dup
32
15
  options[:filter] = nicerank_true()
33
16
  @view.downloading(options)
34
17
  stream = @api.get_global(options)
35
- niceranks = NiceRank.new.get_ranks(stream)
18
+ Settings.options[:force] == true ? niceranks = {} : niceranks = NiceRank.new.get_ranks(stream)
36
19
  Check.no_new_posts(stream, options, 'global')
37
- Databases.save_max_id(stream)
20
+ Databases.save_max_id(stream, 'global') unless stream['meta']['max_id'].nil?
38
21
  @view.render(stream, options, niceranks)
39
22
  Scroll.new(@api, @view).global(options) if options[:scroll]
40
23
  end
41
24
 
42
- def trending options
43
- @view.downloading(options)
44
- stream = @api.get_trending(options)
45
- Check.no_new_posts(stream, options, 'explore:trending')
46
- Databases.save_max_id(stream)
47
- @view.render(stream, options)
48
- Scroll.new(@api, @view).trending(options) if options[:scroll]
49
- end
50
25
 
51
- def photos options
52
- @view.downloading(options)
53
- stream = @api.get_photos(options)
54
- Check.no_new_posts(stream, options, 'explore:photos')
55
- Databases.save_max_id(stream)
56
- @view.render(stream, options)
57
- Scroll.new(@api, @view).photos(options) if options[:scroll]
26
+ def method_missing(meth, options)
27
+ case meth
28
+ when :checkins, :trending, :photos
29
+ stream(meth, options, "explore:#{meth}")
30
+ when :conversations
31
+ stream(meth, options, "explore:replies")
32
+ when :unified
33
+ stream(meth, options, meth.to_s)
34
+ else
35
+ super
36
+ end
58
37
  end
59
38
 
60
- def conversations options
39
+ def stream meth, options, target
40
+ Settings.options[:force] = true if options[:force]
61
41
  @view.downloading(options)
62
- stream = @api.get_conversations(options)
63
- Check.no_new_posts(stream, options, 'explore:replies')
42
+ stream = @api.send("get_#{meth}".to_sym, options)
43
+ Check.no_new_posts(stream, options, target)
64
44
  Databases.save_max_id(stream)
65
45
  @view.render(stream, options)
66
- Scroll.new(@api, @view).replies(options) if options[:scroll]
46
+ Scroll.new(@api, @view).send(meth, options) if options[:scroll]
67
47
  end
68
48
 
49
+
69
50
  def mentions username, options
51
+ Settings.options[:force] = true if options[:force]
70
52
  Check.no_username(username)
71
53
  username = @workers.add_arobase(username)
72
54
  @view.downloading(options)
@@ -81,13 +63,17 @@ module Ayadn
81
63
  end
82
64
 
83
65
  def posts username, options
66
+ Settings.options[:force] = true if options[:force]
84
67
  Check.no_username(username)
85
68
  username = @workers.add_arobase(username)
86
69
  @view.downloading(options)
87
70
  stream = @api.get_posts(username, options)
88
71
  Check.no_user(stream, username)
89
- Databases.save_max_id(stream)
72
+ Databases.save_max_id(stream) unless stream['meta']['marker'].nil?
90
73
  Check.no_data(stream, 'mentions')
74
+ if Databases.blacklist["-#{username.downcase}"] || stream['data'][0]['user']['you_muted'] || stream['data'][0]['user']['you_blocked']
75
+ abort(Status.no_force("#{username.downcase}")) unless options[:raw] || Settings.options[:force]
76
+ end
91
77
  @view.render(stream, options)
92
78
  Scroll.new(@api, @view).posts(username, options) if options[:scroll]
93
79
  end
@@ -178,6 +164,7 @@ module Ayadn
178
164
  end
179
165
 
180
166
  def convo(post_id, options)
167
+ Settings.options[:force] = true if options[:force]
181
168
  Check.bad_post_id(post_id)
182
169
  @view.downloading(options)
183
170
  details = @api.get_details(post_id, options)
data/lib/ayadn/tvshow.rb CHANGED
@@ -72,6 +72,7 @@ module Ayadn
72
72
  end
73
73
 
74
74
  def post options = {}
75
+ options = options.dup
75
76
  reg = /[~:-;,?!\'&`^=+<>*%()\/"“”’°£$€.…]/
76
77
  filename = "#{@name.downcase.strip.gsub(reg, '_').split(' ').join('_')}.jpg"
77
78
  if options['banner']
@@ -81,14 +82,15 @@ module Ayadn
81
82
  end
82
83
  @view.clear_screen
83
84
  puts "\nPosting and uploading the show poster...\n".color(:green)
84
- file = ["#{Settings.config[:paths][:downloads]}/#{filename}"]
85
+ options[:embed] = ["#{Settings.config[:paths][:downloads]}/#{filename}"]
86
+ options[:tvshow] = true
85
87
  dic = {
86
- 'text' => @text,
87
- 'data' => FileOps.upload_files(file),
88
- 'title' => @name,
89
- 'source' => 'TVDb'
88
+ options: options,
89
+ text: @text,
90
+ title: @name,
91
+ source: 'TVDb'
90
92
  }
91
- resp = Post.new.send_tvshow(dic)
93
+ resp = Post.new.post(dic)
92
94
  FileOps.save_post(resp) if Settings.options[:backup][:auto_save_sent_posts]
93
95
  @view.clear_screen
94
96
  puts Status.yourpost
data/lib/ayadn/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  module Ayadn
3
- VERSION = "1.6.0"
3
+ VERSION = "1.7.0"
4
4
  end
data/lib/ayadn/view.rb CHANGED
@@ -6,6 +6,14 @@ module Ayadn
6
6
  @workers = Workers.new
7
7
  end
8
8
 
9
+ def show_cursor
10
+ puts "\e[?25h"
11
+ end
12
+
13
+ def hide_cursor
14
+ puts "\e[?25l"
15
+ end
16
+
9
17
  def show_posts_with_index(data, options, niceranks = {})
10
18
  posts, view = build_stream_with_index(data, options, niceranks)
11
19
  puts view unless view == ""
data/lib/ayadn/workers.rb CHANGED
@@ -118,39 +118,49 @@ module Ayadn
118
118
  table
119
119
  end
120
120
 
121
+ # builds a hash of hashes, each hash is a normalized post with post id as a key
121
122
  def build_posts(data, niceranks = {})
122
- # builds a hash of hashes, each hash is a normalized post with post id as a key
123
+ # skip objects in blacklist unless force
123
124
  posts = {}
124
125
  data.each.with_index(1) do |post, index|
125
- if Databases.blacklist[post['source']['name'].downcase]
126
- Debug.skipped({source: post['source']['name']})
127
- next
126
+ unless Settings.options[:force]
127
+ if Databases.blacklist[post['source']['name'].downcase]
128
+ Debug.skipped({source: post['source']['name']})
129
+ next
130
+ end
128
131
  end
129
- if Databases.blacklist["-@#{post['user']['username'].downcase}"]
130
- Debug.skipped({user: post['user']['username']})
131
- next
132
+ unless Settings.options[:force]
133
+ if Databases.blacklist["-@#{post['user']['username'].downcase}"]
134
+ Debug.skipped({user: post['user']['username']})
135
+ next
136
+ end
132
137
  end
133
138
  hashtags = extract_hashtags(post)
134
139
  @skip = false
135
- hashtags.each do |h|
136
- if Databases.blacklist[h.downcase]
137
- @skip = true
138
- Debug.skipped({hashtag: h})
139
- break
140
+ unless Settings.options[:force]
141
+ hashtags.each do |h|
142
+ if Databases.blacklist[h.downcase]
143
+ @skip = true
144
+ Debug.skipped({hashtag: h})
145
+ break
146
+ end
140
147
  end
141
148
  end
142
149
  next if @skip
143
150
  mentions= []
144
151
  post['entities']['mentions'].each { |m| mentions << m['name'] }
145
- mentions.each do |m|
146
- if Databases.blacklist["@#{m.downcase}"]
147
- @skip = true
148
- Debug.skipped({mention: m})
149
- break
152
+ unless Settings.options[:force]
153
+ mentions.each do |m|
154
+ if Databases.blacklist["@#{m.downcase}"]
155
+ @skip = true
156
+ Debug.skipped({mention: m})
157
+ break
158
+ end
150
159
  end
151
160
  end
152
161
  next if @skip
153
162
 
163
+ # create custom objects from ADN response
154
164
  if niceranks[post['user']['id'].to_i]
155
165
  rank = niceranks[post['user']['id'].to_i][:rank]
156
166
  is_human = niceranks[post['user']['id'].to_i][:is_human]
@@ -242,8 +252,7 @@ module Ayadn
242
252
  end
243
253
 
244
254
  def extract_links(post)
245
- links = []
246
- post['entities']['links'].each { |l| links << l['url'] }
255
+ links = post['entities']['links'].map { |l| l['url'] }
247
256
  unless post['annotations'].nil? || post['annotations'].empty?
248
257
  post['annotations'].each do |ann|
249
258
  if ann['type'] == "net.app.core.oembed"
@@ -251,14 +260,11 @@ module Ayadn
251
260
  end
252
261
  end
253
262
  end
254
- links.uniq!
255
- links
263
+ links.uniq
256
264
  end
257
265
 
258
266
  def extract_hashtags(post)
259
- tags = []
260
- post['entities']['hashtags'].each { |h| tags << h['name'] }
261
- tags
267
+ post['entities']['hashtags'].map { |h| h['name'] }
262
268
  end
263
269
 
264
270
  def build_channels(data, options = {})
@@ -369,7 +375,16 @@ module Ayadn
369
375
  username.join
370
376
  end
371
377
 
372
- def add_arobases_to_usernames args #TODO: replace
378
+ def remove_arobase_if_present args
379
+ args.map! do |username|
380
+ temp = username.chars
381
+ temp.shift if temp.first == "@"
382
+ temp.join
383
+ end
384
+ args
385
+ end
386
+
387
+ def add_arobases_to_usernames args #TODO: replace all these arobase legacy methods by a unique one
373
388
  args.map do |username|
374
389
  if username == 'me'
375
390
  who_am_i
@@ -387,15 +402,6 @@ module Ayadn
387
402
  db[active][:handle]
388
403
  end
389
404
 
390
- def remove_arobase_if_present args
391
- args.map! do |username|
392
- temp = username.chars
393
- temp.shift if temp.first == "@"
394
- temp.join
395
- end
396
- args
397
- end
398
-
399
405
  def extract_users(resp)
400
406
  users_hash = {}
401
407
  resp['data'].each do |item|
@@ -473,8 +479,7 @@ module Ayadn
473
479
  stream['data'].each do |post|
474
480
  extract_links(post).each {|l| links << l}
475
481
  end
476
- links.uniq!
477
- links
482
+ links.uniq
478
483
  end
479
484
 
480
485
  def all_but_me usernames