Commit 79ba9413f7ef72ef76c089ed882780462c3fece0
1 parent
686526ec
Exists in
theme-brasil-digital-from-staging
and in
9 other branches
community-gub: added proxy config to facebook
Showing
1 changed file
with
31 additions
and
34 deletions
Show diff stats
plugins/community_hub/facebook_stream/lib_facebook_stream.rb
... | ... | @@ -8,44 +8,41 @@ require 'json' |
8 | 8 | # BACKUP TOKEN 'CAAEhsewl0ZAcBAHhipXszZCURSwWLmgvceDbs9mB5baJdLriFxYMEzywmF2fvZBuThuA2Mm7QF8wPd3E6R5pVqVEnC2VhcBb4VrfAnkZC73ZC5g1NRUnKZCB2e6CaRiUBDatR2nf505PeKp7Aj5XxvTdfSqdZCsXxQFYZApPNSUUgkUWm6HwL4rp21MRJXb612sZD' |
9 | 9 | |
10 | 10 | def facebook_comments(hub, author_id, page_id, pooling_time, token, proxy_url) |
11 | - if pooling_time == nil | |
12 | - pooling_time = 5 | |
13 | - end | |
14 | - #Koala.http_service.http_options = { | |
15 | - # :proxy => 'http://161.148.1.167:3128' | |
16 | - #} | |
11 | + pooling_time ||= 5 | |
12 | + Koala.http_service.http_options = { :proxy => proxy_url } unless proxy_url.blank? | |
13 | + | |
17 | 14 | @graph = Koala::Facebook::API.new(token) |
18 | 15 | initialComments = [] |
19 | 16 | firstTime = true |
20 | 17 | while true |
21 | - feed = @graph.get_connections(page_id, "posts") | |
22 | - array = [] | |
23 | - extractedComments = [] | |
24 | - feed.each {|f| | |
25 | - if f['comments'] != nil && f['comments']['data'] != nil | |
26 | - array.push(f['comments']['data']) | |
27 | - end | |
28 | - } | |
29 | - extractedComments = array.flatten.uniq | |
30 | - if firstTime | |
31 | - initialComments=extractedComments.clone | |
32 | - firstTime = false | |
18 | + feed = @graph.get_connections(page_id, "posts") | |
19 | + array = [] | |
20 | + extractedComments = [] | |
21 | + feed.each {|f| | |
22 | + if f['comments'] != nil && f['comments']['data'] != nil | |
23 | + array.push(f['comments']['data']) | |
33 | 24 | end |
34 | - newComments = extractedComments - initialComments | |
35 | - newComments = newComments.uniq | |
36 | - initialComments += newComments | |
37 | - initialComments = initialComments.uniq | |
38 | - newComments.each{|comment| | |
39 | - puts "#{comment['from']['name']} " + _("said") + ": #{comment['message']}" | |
40 | - noosferoComment = Comment.new | |
41 | - noosferoComment.title = 'hub-message-facebook' | |
42 | - noosferoComment.source = hub | |
43 | - noosferoComment.body = comment['message'] | |
44 | - noosferoComment.author_id = author_id | |
45 | - noosferoComment.name = comment['from']['name'] | |
46 | - noosferoComment.email = 'admin@localhost.local' | |
47 | - noosferoComment.save! | |
48 | - } | |
49 | - sleep(pooling_time) | |
25 | + } | |
26 | + extractedComments = array.flatten.uniq | |
27 | + if firstTime | |
28 | + initialComments = extractedComments.clone | |
29 | + firstTime = false | |
50 | 30 | end |
31 | + newComments = extractedComments - initialComments | |
32 | + newComments = newComments.uniq | |
33 | + initialComments += newComments | |
34 | + initialComments = initialComments.uniq | |
35 | + newComments.each{|comment| | |
36 | + puts "#{comment['from']['name']} " + _("said") + ": #{comment['message']}" | |
37 | + noosferoComment = Comment.new | |
38 | + noosferoComment.title = 'hub-message-facebook' | |
39 | + noosferoComment.source = hub | |
40 | + noosferoComment.body = comment['message'] | |
41 | + noosferoComment.author_id = author_id | |
42 | + noosferoComment.name = comment['from']['name'] | |
43 | + noosferoComment.email = 'admin@localhost.local' | |
44 | + noosferoComment.save! | |
45 | + } | |
46 | + sleep(pooling_time) | |
47 | + end | |
51 | 48 | end | ... | ... |