lib/ayadn/scroll.rb in ayadn-1.1.3 vs lib/ayadn/scroll.rb in ayadn-1.2.0
- old
+ new
@@ -5,27 +5,36 @@
def initialize(api, view)
@api = api
@view = view
end
- def method_missing(meth, options)
+ def method_missing(meth, options, niceranks = {})
case meth.to_s
when 'trending', 'photos', 'checkins', 'replies', 'global', 'unified'
- scroll_it(meth.to_s, options)
+ scroll_it(meth.to_s, options, niceranks)
else
super
end
end
- def scroll_it(target, options)
+ def scroll_it(target, options, niceranks)
options = check_raw(options)
orig_target = target
loop do
begin
stream = get(target, options)
+ if options[:filter] == true
+ unless stream['data'].empty?
+ niceranks = @api.get_niceranks stream
+ else
+ niceranks = {}
+ end
+ else
+ niceranks = {}
+ end
target = "explore:#{target}" if explore?(target)
- show_if_new(stream, options, target)
+ show_if_new(stream, options, target, niceranks)
target = orig_target if target =~ /explore/
options = save_then_return(stream, options)
pause
rescue Interrupt
canceled
@@ -123,36 +132,48 @@
def pause
sleep Settings.options[:scroll][:timer]
end
- def show_if_new(stream, options, target)
- show(stream, options) if Databases.has_new?(stream, target)
+ def show_if_new(stream, options, target, niceranks = {})
+ show(stream, options, niceranks) if Databases.has_new?(stream, target)
end
def save_then_return(stream, options)
unless stream['meta']['max_id'].nil?
Databases.save_max_id(stream)
- return options_hash(stream)
+ return options_hash(stream, options)
end
options
end
def check_raw(options)
if options[:raw]
- {count: 200, since_id: nil, raw: true, scroll: true}
+ if options[:filter] == true
+ {count: 200, since_id: nil, raw: true, scroll: true, filter: true}
+ else
+ {count: 200, since_id: nil, raw: true, scroll: true}
+ end
else
- {count: 200, since_id: nil, scroll: true}
+ if options[:filter] == true
+ {count: 200, since_id: nil, scroll: true, filter: true}
+ else
+ {count: 200, since_id: nil, scroll: true}
+ end
end
end
- def options_hash(stream)
- {:count => 50, :since_id => stream['meta']['max_id'], scroll: true}
+ def options_hash(stream, options)
+ if options[:filter] == true
+ {:count => 50, :since_id => stream['meta']['max_id'], scroll: true, filter: true}
+ else
+ {:count => 50, :since_id => stream['meta']['max_id'], scroll: true}
+ end
end
- def show(stream, options)
+ def show(stream, options, niceranks)
unless options[:raw]
- @view.show_posts(stream['data'], options)
+ @view.show_posts(stream['data'], options, niceranks)
else
jj stream
end
end