Commit fe641774aa6bea3340c7b20221c4e2cdb307c668
Exists in
master
Merge branch 'AI3074-community_dashboard' of gitlab.com:participa/noosfero into …
…AI3074-community_dashboard
Showing
2 changed files
with
33 additions
and
37 deletions
Show diff stats
facebook_stream/lib_facebook_stream.rb
@@ -8,45 +8,41 @@ require 'json' | @@ -8,45 +8,41 @@ require 'json' | ||
8 | # BACKUP TOKEN 'CAAEhsewl0ZAcBAHhipXszZCURSwWLmgvceDbs9mB5baJdLriFxYMEzywmF2fvZBuThuA2Mm7QF8wPd3E6R5pVqVEnC2VhcBb4VrfAnkZC73ZC5g1NRUnKZCB2e6CaRiUBDatR2nf505PeKp7Aj5XxvTdfSqdZCsXxQFYZApPNSUUgkUWm6HwL4rp21MRJXb612sZD' | 8 | # BACKUP TOKEN 'CAAEhsewl0ZAcBAHhipXszZCURSwWLmgvceDbs9mB5baJdLriFxYMEzywmF2fvZBuThuA2Mm7QF8wPd3E6R5pVqVEnC2VhcBb4VrfAnkZC73ZC5g1NRUnKZCB2e6CaRiUBDatR2nf505PeKp7Aj5XxvTdfSqdZCsXxQFYZApPNSUUgkUWm6HwL4rp21MRJXb612sZD' |
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 | ||
12 | - pooling_time = 5 | ||
13 | - end | 11 | + pooling_time ||= 5 |
12 | + Koala.http_service.http_options = { :proxy => proxy_url } unless proxy_url.blank? | ||
13 | + | ||
14 | @graph = Koala::Facebook::API.new(token) | 14 | @graph = Koala::Facebook::API.new(token) |
15 | initialComments = [] | 15 | initialComments = [] |
16 | - extractedComments = [] | ||
17 | firstTime = true | 16 | firstTime = true |
18 | while true | 17 | while true |
19 | - feed = @graph.get_connections(page_id, "posts") | ||
20 | - array = [] | ||
21 | - extractedComments = [] | ||
22 | - feed.each {|f| | ||
23 | - if f['comments'] != nil && f['comments']['data'] != nil | ||
24 | - array.push(f['comments']['data']) | ||
25 | - end | ||
26 | - } | ||
27 | - array.each{ |comments| | ||
28 | - comments.each{|comment| | ||
29 | - extractedComments.push("#{comment['from']['name']} " + _("said") + ": #{comment['message']}") | ||
30 | - } | ||
31 | - } | ||
32 | - extractedComments = extractedComments.uniq | ||
33 | - if firstTime | ||
34 | - initialComments=extractedComments.clone | ||
35 | - 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']) | ||
36 | end | 24 | end |
37 | - newComments = extractedComments - initialComments | ||
38 | - newComments = newComments.uniq | ||
39 | - initialComments += newComments | ||
40 | - initialComments = initialComments.uniq | ||
41 | - 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! | ||
49 | - } | ||
50 | - sleep(pooling_time) | 25 | + } |
26 | + extractedComments = array.flatten.uniq | ||
27 | + if firstTime | ||
28 | + initialComments = extractedComments.clone | ||
29 | + firstTime = false | ||
51 | end | 30 | end |
52 | -end | ||
53 | \ No newline at end of file | 31 | \ No newline at end of file |
32 | + newComments = extractedComments - initialComments | ||
33 | + newComments = newComments.uniq | ||
34 | + initialComments += newComments | ||
35 | + initialComments = initialComments.uniq | ||
36 | + newComments.each{|comment| | ||
37 | + puts "#{comment['from']['name']} " + _("said") + ": #{comment['message']}" | ||
38 | + noosferoComment = Comment.new | ||
39 | + noosferoComment.title = 'hub-message-facebook' | ||
40 | + noosferoComment.source = hub | ||
41 | + noosferoComment.body = comment['message'] | ||
42 | + noosferoComment.author_id = author_id | ||
43 | + noosferoComment.name = comment['from']['name'] | ||
44 | + noosferoComment.email = 'admin@localhost.local' | ||
45 | + noosferoComment.save! | ||
46 | + } | ||
47 | + sleep(pooling_time) | ||
48 | + end | ||
49 | +end |
lib/community_hub_plugin/hub.rb
@@ -3,7 +3,7 @@ require File.dirname(__FILE__) + '/../../facebook_stream/lib_facebook_stream' | @@ -3,7 +3,7 @@ require File.dirname(__FILE__) + '/../../facebook_stream/lib_facebook_stream' | ||
3 | 3 | ||
4 | class CommunityHubPlugin::Hub < Folder | 4 | class CommunityHubPlugin::Hub < Folder |
5 | 5 | ||
6 | - settings_items :proxy_url, :type => :string, :default => 'http://161.148.1.167:3128' # Remember to use add the port, if needed! | 6 | + settings_items :proxy_url, :type => :string, :default => 'http://161.148.1.167:3128' # Remember to use add the port, in case needed. |
7 | settings_items :twitter_enabled, :type => :boolean, :default => false | 7 | settings_items :twitter_enabled, :type => :boolean, :default => false |
8 | settings_items :hashtags_twitter, :type => :string, :default => "participa.br,participabr,arenanetmundial,netmundial" | 8 | settings_items :hashtags_twitter, :type => :string, :default => "participa.br,participabr,arenanetmundial,netmundial" |
9 | settings_items :facebook_enabled, :type => :boolean, :default => false | 9 | settings_items :facebook_enabled, :type => :boolean, :default => false |