lib/ayadn/api.rb in ayadn-1.2.5 vs lib/ayadn/api.rb in ayadn-1.2.6

- old
+ new

@@ -198,102 +198,9 @@ else resp end end - ###DEBUG - #def get_niceranks stream - def get_niceranks stream, iter - ###DEBUG - @iter = iter - - user_ids, table, niceranks = [], {}, {} - stream['data'].each do |post| - user_ids << post['user']['id'].to_i - table[post['user']['id'].to_i] = post['user']['username'] - end - user_ids.uniq! - - db_ranks = Databases.get_niceranks user_ids - get_these = [] - db_ranks.each do |id,ranks| - if ranks.nil? - get_these << id - elsif (Time.now - ranks[:cached]) > 86400 # 24 hours cache - get_these << id - else - niceranks[id] = { - username: ranks[:username], - rank: ranks[:rank], - is_human: ranks[:is_human], - cached: ranks[:cached] - } - end - end - - if Settings.options[:timeline][:show_debug] == true - puts "=====\nNiceRanks\n".color(Settings.options[:colors][:debug]) - puts "From DB:\t#{niceranks}\n".color(Settings.options[:colors][:debug]) - puts "To get:\t\t#{get_these}\n=====\n".color(Settings.options[:colors][:debug]) - end - - unless get_these.empty? - req = "http://api.search-adn.net/user/nicerank?ids=#{get_these.join(',')}" - resp = JSON.parse(CNX.get req) - - #Error handling - if resp['meta']['code'] != 200 - if Settings.options[:timeline][:show_debug] == true - puts "=====\nNiceRank:\tError #{resp['meta']['code']} (#{resp['meta']['time']})\n=====\n".color(Settings.options[:colors][:debug]) - end - Errors.nr "REQUESTED: #{get_these.join(' ')}" - - ###DEBUG - @iter += 1 - - if niceranks - if Settings.options[:timeline][:show_debug] == true - puts "=====\nNiceRanks:\t#{niceranks}".color(Settings.options[:colors][:debug]) - puts "=====\n".color(Settings.options[:colors][:debug]) - end - - #return niceranks - - ###DEBUG - return niceranks, @iter - else - - # return {} - - ###DEBUG - return {}, @iter - end - end - - ###DEBUG - @iter += 1 - - resp['data'].each do |obj| - niceranks[obj['user_id']] = { - username: table[obj['user_id']], - rank: obj['rank'], - is_human: obj['is_human'], - cached: Time.now - } - end - if Settings.options[:timeline][:show_debug] == true - puts "=====\nNiceRanks:\t#{niceranks}".color(Settings.options[:colors][:debug]) - puts "Resp:\t\t#{resp}".color(Settings.options[:colors][:debug]) - puts "=====\n".color(Settings.options[:colors][:debug]) - end - end - Databases.add_niceranks niceranks - - ###DEBUG - #niceranks - return niceranks, @iter - end - def get_channels options = {:count => 200, :recent_message => 1, :annotations => 1, :before_id => nil} get_parsed_response(Endpoints.new.channels(options)) # big = [] # loop do