From 79ba9413f7ef72ef76c089ed882780462c3fece0 Mon Sep 17 00:00:00 2001 From: Victor Costa Date: Tue, 15 Apr 2014 17:13:00 -0300 Subject: [PATCH] community-gub: added proxy config to facebook --- plugins/community_hub/facebook_stream/lib_facebook_stream.rb | 65 +++++++++++++++++++++++++++++++---------------------------------- 1 file changed, 31 insertions(+), 34 deletions(-) diff --git a/plugins/community_hub/facebook_stream/lib_facebook_stream.rb b/plugins/community_hub/facebook_stream/lib_facebook_stream.rb index a06f407..a7e394f 100644 --- a/plugins/community_hub/facebook_stream/lib_facebook_stream.rb +++ b/plugins/community_hub/facebook_stream/lib_facebook_stream.rb @@ -8,44 +8,41 @@ require 'json' # BACKUP TOKEN 'CAAEhsewl0ZAcBAHhipXszZCURSwWLmgvceDbs9mB5baJdLriFxYMEzywmF2fvZBuThuA2Mm7QF8wPd3E6R5pVqVEnC2VhcBb4VrfAnkZC73ZC5g1NRUnKZCB2e6CaRiUBDatR2nf505PeKp7Aj5XxvTdfSqdZCsXxQFYZApPNSUUgkUWm6HwL4rp21MRJXb612sZD' def facebook_comments(hub, author_id, page_id, pooling_time, token, proxy_url) - if pooling_time == nil - pooling_time = 5 - end - #Koala.http_service.http_options = { - # :proxy => 'http://161.148.1.167:3128' - #} + pooling_time ||= 5 + Koala.http_service.http_options = { :proxy => proxy_url } unless proxy_url.blank? + @graph = Koala::Facebook::API.new(token) initialComments = [] firstTime = true while true - feed = @graph.get_connections(page_id, "posts") - array = [] - extractedComments = [] - feed.each {|f| - if f['comments'] != nil && f['comments']['data'] != nil - array.push(f['comments']['data']) - end - } - extractedComments = array.flatten.uniq - if firstTime - initialComments=extractedComments.clone - firstTime = false + feed = @graph.get_connections(page_id, "posts") + array = [] + extractedComments = [] + feed.each {|f| + if f['comments'] != nil && f['comments']['data'] != nil + array.push(f['comments']['data']) end - newComments = extractedComments - initialComments - newComments = newComments.uniq - initialComments += newComments - initialComments = initialComments.uniq - newComments.each{|comment| - puts "#{comment['from']['name']} " + _("said") + ": #{comment['message']}" - noosferoComment = Comment.new - noosferoComment.title = 'hub-message-facebook' - noosferoComment.source = hub - noosferoComment.body = comment['message'] - noosferoComment.author_id = author_id - noosferoComment.name = comment['from']['name'] - noosferoComment.email = 'admin@localhost.local' - noosferoComment.save! - } - sleep(pooling_time) + } + extractedComments = array.flatten.uniq + if firstTime + initialComments = extractedComments.clone + firstTime = false end + newComments = extractedComments - initialComments + newComments = newComments.uniq + initialComments += newComments + initialComments = initialComments.uniq + newComments.each{|comment| + puts "#{comment['from']['name']} " + _("said") + ": #{comment['message']}" + noosferoComment = Comment.new + noosferoComment.title = 'hub-message-facebook' + noosferoComment.source = hub + noosferoComment.body = comment['message'] + noosferoComment.author_id = author_id + noosferoComment.name = comment['from']['name'] + noosferoComment.email = 'admin@localhost.local' + noosferoComment.save! + } + sleep(pooling_time) + end end -- libgit2 0.21.2