Commit 686526ec3effc31a5bde513ff2b3b4d7dd497aae
1 parent
b207b610
Exists in
theme-brasil-digital-from-staging
and in
9 other branches
community-hub: fix facebook stream
Showing
1 changed file
with
16 additions
and
17 deletions
Show diff stats
plugins/community_hub/facebook_stream/lib_facebook_stream.rb
@@ -9,11 +9,13 @@ require 'json' | @@ -9,11 +9,13 @@ require 'json' | ||
9 | 9 | ||
10 | def facebook_comments(hub, author_id, page_id, pooling_time, token, proxy_url) | 10 | def facebook_comments(hub, author_id, page_id, pooling_time, token, proxy_url) |
11 | if pooling_time == nil | 11 | if pooling_time == nil |
12 | - pooling_time = 5 | ||
13 | - end | 12 | + pooling_time = 5 |
13 | + end | ||
14 | + #Koala.http_service.http_options = { | ||
15 | + # :proxy => 'http://161.148.1.167:3128' | ||
16 | + #} | ||
14 | @graph = Koala::Facebook::API.new(token) | 17 | @graph = Koala::Facebook::API.new(token) |
15 | initialComments = [] | 18 | initialComments = [] |
16 | - extractedComments = [] | ||
17 | firstTime = true | 19 | firstTime = true |
18 | while true | 20 | while true |
19 | feed = @graph.get_connections(page_id, "posts") | 21 | feed = @graph.get_connections(page_id, "posts") |
@@ -24,12 +26,7 @@ def facebook_comments(hub, author_id, page_id, pooling_time, token, proxy_url) | @@ -24,12 +26,7 @@ def facebook_comments(hub, author_id, page_id, pooling_time, token, proxy_url) | ||
24 | array.push(f['comments']['data']) | 26 | array.push(f['comments']['data']) |
25 | end | 27 | end |
26 | } | 28 | } |
27 | - array.each{ |comments| | ||
28 | - comments.each{|comment| | ||
29 | - extractedComments.push("#{comment['from']['name']} " + _("said") + ": #{comment['message']}") | ||
30 | - } | ||
31 | - } | ||
32 | - extractedComments = extractedComments.uniq | 29 | + extractedComments = array.flatten.uniq |
33 | if firstTime | 30 | if firstTime |
34 | initialComments=extractedComments.clone | 31 | initialComments=extractedComments.clone |
35 | firstTime = false | 32 | firstTime = false |
@@ -39,14 +36,16 @@ def facebook_comments(hub, author_id, page_id, pooling_time, token, proxy_url) | @@ -39,14 +36,16 @@ def facebook_comments(hub, author_id, page_id, pooling_time, token, proxy_url) | ||
39 | initialComments += newComments | 36 | initialComments += newComments |
40 | initialComments = initialComments.uniq | 37 | initialComments = initialComments.uniq |
41 | newComments.each{|comment| | 38 | newComments.each{|comment| |
42 | - puts comment | ||
43 | - noosferoComment = Comment.new | ||
44 | - noosferoComment.title = 'hub-message-facebook' | ||
45 | - noosferoComment.source_id = hub.id | ||
46 | - noosferoComment.body = comment | ||
47 | - noosferoComment.author_id = author_id | ||
48 | - noosferoComment.save! | 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! | ||
49 | } | 48 | } |
50 | sleep(pooling_time) | 49 | sleep(pooling_time) |
51 | end | 50 | end |
52 | -end | ||
53 | \ No newline at end of file | 51 | \ No newline at end of file |
52 | +end |