lib/ayadn/scroll.rb in ayadn-1.2.8 vs lib/ayadn/scroll.rb in ayadn-1.2.9
- old
+ new
@@ -4,11 +4,10 @@
def initialize(api, view)
@api = api
@view = view
@chars = %w{ | / - \\ }
- @show_debug = Settings.options[:timeline][:show_debug]
end
def method_missing(meth, options)
case meth.to_s
when 'trending', 'photos', 'checkins', 'replies', 'global', 'unified'
@@ -23,23 +22,12 @@
orig_target = target
@nr = NiceRank.new
loop do
begin
stream = get(target, options)
-
- # if options[:filter] == true
- unless stream['data'].empty?
- niceranks = @nr.get_ranks stream
- else
- niceranks = {}
- end
- # else
- # niceranks = {}
- # end
-
- debug_stream(stream, options, target) if @show_debug == true
-
+ stream['data'].empty? ? niceranks = {} : niceranks = @nr.get_ranks(stream)
+ Debug.stream stream, options, target
target = "explore:#{target}" if explore?(target)
show_if_new(stream, options, target, niceranks)
target = orig_target if target =~ /explore/
options = save_then_return(stream, options)
countdown
@@ -49,18 +37,15 @@
end
end
def mentions(username, options)
options = check_raw(options)
- user = @api.get_user(username)
- id = user['data']['id']
+ id = @api.get_user(username)['data']['id']
loop do
begin
stream = @api.get_mentions(username, options)
-
- debug_stream(stream, options, username) if @show_debug == true
-
+ Debug.stream stream, options, username
show_if_new(stream, options, "mentions:#{id}")
options = save_then_return(stream, options)
countdown
rescue Interrupt
canceled
@@ -68,18 +53,15 @@
end
end
def posts(username, options)
options = check_raw(options)
- user = @api.get_user(username)
- id = user['data']['id']
+ id = @api.get_user(username)['data']['id']
loop do
begin
stream = @api.get_posts(username, options)
-
- debug_stream(stream, options, username) if @show_debug == true
-
+ Debug.stream stream, options, username
show_if_new(stream, options, "posts:#{id}")
options = save_then_return(stream, options)
countdown
rescue Interrupt
canceled
@@ -90,13 +72,11 @@
def convo(post_id, options)
options = check_raw(options)
loop do
begin
stream = @api.get_convo(post_id, options)
-
- debug_stream(stream, options, post_id) if @show_debug == true
-
+ Debug.stream stream, options, post_id
show_if_new(stream, options, "replies:#{post_id}")
options = save_then_return(stream, options)
countdown
rescue Interrupt
canceled
@@ -107,13 +87,11 @@
def messages(channel_id, options)
options = check_raw(options)
loop do
begin
stream = @api.get_messages(channel_id, options)
-
- debug_stream(stream, options, channel_id) if @show_debug == true
-
+ Debug.stream stream, options, channel_id
show_if_new(stream, options, "channel:#{channel_id}")
options = save_then_return(stream, options)
countdown
rescue Interrupt
canceled
@@ -121,24 +99,12 @@
end
end
private
- def debug_stream stream, options, target
- deb = "+++++\nStream meta:\t#{stream['meta']}\n\n"
- deb << "Options:\t#{options.inspect}\n\n"
- deb << "Target:\t\t#{target.inspect}\n\n"
- deb << "Posts:\t\t#{stream['data'].length}\n+++++\n"
- puts deb.color(Settings.options[:colors][:debug])
- end
-
def countdown
- if Settings.options[:timeline][:show_spinner] == true
- waiting
- else
- pause
- end
+ Settings.options[:timeline][:show_spinner] == true ? waiting : pause
end
def clear
print("\r")
print(" ".ljust(5))
@@ -177,14 +143,11 @@
false
end
end
def waiting
- interval = Settings.options[:scroll][:timer] * 10
- interval.times do
- spin
- end
+ (Settings.options[:scroll][:timer] * 10).times { spin }
end
def pause
sleep Settings.options[:scroll][:timer]
end
@@ -224,13 +187,13 @@
{:count => 50, :since_id => stream['meta']['max_id'], scroll: true}
end
end
def show(stream, options, niceranks)
- unless options[:raw]
- @view.show_posts(stream['data'], options, niceranks)
- else
+ if options[:raw]
jj stream
+ else
+ @view.show_posts(stream['data'], options, niceranks)
end
end
def canceled
puts Status.canceled