lib/ayadn/search.rb in ayadn-3.0 vs lib/ayadn/search.rb in ayadn-4.0

- old
+ new

@@ -5,41 +5,47 @@ def initialize api, view, workers @api = api @view = view @workers = workers - @check = Check.new end def hashtag(hashtag, options) - Settings.global[:force] = true if options[:force] + Settings.options.timeline.compact = true if options[:compact] + Settings.global.force = true if options[:force] @view.downloading(options) stream = @api.get_hashtag(hashtag) - @check.no_data(stream, 'hashtag') + stream_object = StreamObject.new(stream) + Check.new.no_data(stream_object, 'hashtag') if options[:extract] - @view.all_hashtag_links(stream, hashtag) + @view.all_hashtag_links(stream_object, hashtag) else - @view.render(stream, options) - if Settings.options[:timeline][:compact] == true && !options[:raw] + @view.render(stream_object, options) + if Settings.options.timeline.compact && !options[:raw] puts "\n" end end end def find(words, options) - Settings.global[:force] = true if options[:force] + Settings.options.timeline.compact = true if options[:compact] + Settings.global.force = true if options[:force] @view.downloading(options) stream = get_stream(words, options) - @check.no_data(stream, 'search') if options[:users] - get_users(stream, options) + stream_object = stream["data"].map { |user| UserObject.new(user) } + elsif !options[:channels] + stream_object = StreamObject.new(stream) + end + if options[:users] + get_users(stream_object, options) elsif options[:channels] get_channels(stream, options) else - get_generic(stream, words, options) + get_generic(stream_object, words, options) end - if Settings.options[:timeline][:compact] == true && !options[:raw] + if Settings.options.timeline.compact && !options[:raw] puts "\n" end end private @@ -68,19 +74,20 @@ @view.render(stream, options) end end def get_channels stream, options - @view.show_channels(stream, options) + stream_object = stream["data"].map { |ch| ChannelObject.new(ch) } + @view.show_channels(stream_object, options) end def get_users stream, options - sorted = stream['data'].sort_by {|obj| obj['counts']['followers']} + sorted = stream.sort_by {|obj| obj.counts.followers} sorted.each do |obj| - puts @view.big_separator unless Settings.options[:timeline][:compact] == true + puts @view.big_separator unless Settings.options.timeline.compact @view.show_userinfos(obj, nil, false) end - puts "\n" if Settings.options[:timeline][:compact] == true + puts "\n" if Settings.options.timeline.compact end end end