Commit abea17e36f369bbd216fd7a042bef5ff6d96cfaa
1 parent
7b8dee32
Exists in
theme-brasil-digital-from-staging
and in
9 other branches
migrate community hub plugin to rails 3
Showing
4 changed files
with
9 additions
and
9 deletions
Show diff stats
plugins/community_hub/lib/community_hub_plugin/hub.rb
@@ -3,6 +3,8 @@ require File.dirname(__FILE__) + '/../../facebook_stream/lib_facebook_stream' | @@ -3,6 +3,8 @@ require File.dirname(__FILE__) + '/../../facebook_stream/lib_facebook_stream' | ||
3 | 3 | ||
4 | class CommunityHubPlugin::Hub < Folder | 4 | class CommunityHubPlugin::Hub < Folder |
5 | 5 | ||
6 | + attr_accessible :last_changed_by_id, :integer | ||
7 | + | ||
6 | settings_items :twitter_enabled, :type => :boolean, :default => false | 8 | settings_items :twitter_enabled, :type => :boolean, :default => false |
7 | settings_items :twitter_hashtags, :type => :string, :default => "" | 9 | settings_items :twitter_hashtags, :type => :string, :default => "" |
8 | settings_items :twitter_consumer_key, :type => :string, :default => "" | 10 | settings_items :twitter_consumer_key, :type => :string, :default => "" |
plugins/community_hub/lib/community_hub_plugin/listener.rb
@@ -32,8 +32,8 @@ class CommunityHubPlugin::Listener | @@ -32,8 +32,8 @@ class CommunityHubPlugin::Listener | ||
32 | end | 32 | end |
33 | 33 | ||
34 | def initialize_logger | 34 | def initialize_logger |
35 | - logdir = File.join(RAILS_ROOT, 'log', CommunityHubPlugin::Listener.name.underscore) | ||
36 | - File.makedirs(logdir) if !File.exist?(logdir) | 35 | + logdir = File.join(Rails.root, 'log', CommunityHubPlugin::Listener.name.underscore) |
36 | + FileUtils.makedirs(logdir) if !File.exist?(logdir) | ||
37 | logpath = File.join(logdir, "#{ENV['RAILS_ENV']}_#{Time.now.strftime('%F')}.log") | 37 | logpath = File.join(logdir, "#{ENV['RAILS_ENV']}_#{Time.now.strftime('%F')}.log") |
38 | @logger = Logger.new(logpath) | 38 | @logger = Logger.new(logpath) |
39 | end | 39 | end |
plugins/community_hub/test/unit/community_hub_plugin/listener_test.rb
@@ -10,7 +10,7 @@ class ListenerTest < ActiveSupport::TestCase | @@ -10,7 +10,7 @@ class ListenerTest < ActiveSupport::TestCase | ||
10 | end | 10 | end |
11 | 11 | ||
12 | should 'log message' do | 12 | should 'log message' do |
13 | - logdir = File.join(RAILS_ROOT, 'log', CommunityHubPlugin::Listener.name.underscore) | 13 | + logdir = File.join(Rails.root, 'log', CommunityHubPlugin::Listener.name.underscore) |
14 | 14 | ||
15 | if File.exists?(logdir) | 15 | if File.exists?(logdir) |
16 | Dir.foreach(logdir) { |f| | 16 | Dir.foreach(logdir) { |f| |
plugins/community_hub/twitter/stream.rb
@@ -30,15 +30,13 @@ def listen_twitter_stream(hub, author_id) | @@ -30,15 +30,13 @@ def listen_twitter_stream(hub, author_id) | ||
30 | sleep (10 + 2 ** tries) | 30 | sleep (10 + 2 ** tries) |
31 | end | 31 | end |
32 | end | 32 | end |
33 | - | 33 | + |
34 | tries = 0 | 34 | tries = 0 |
35 | while true | 35 | while true |
36 | begin | 36 | begin |
37 | tries += 1 | 37 | tries += 1 |
38 | client.filter(:track => hub.twitter_hashtags) do |object| | 38 | client.filter(:track => hub.twitter_hashtags) do |object| |
39 | if object.is_a?(Twitter::Tweet) | 39 | if object.is_a?(Twitter::Tweet) |
40 | -# puts '@' + object.user.screen_name + ' said: ' + object.text | ||
41 | -# puts object.user.profile_image_url | ||
42 | comment = Comment.new | 40 | comment = Comment.new |
43 | comment.title = 'hub-message-twitter' | 41 | comment.title = 'hub-message-twitter' |
44 | comment.source = hub | 42 | comment.source = hub |
@@ -48,16 +46,16 @@ def listen_twitter_stream(hub, author_id) | @@ -48,16 +46,16 @@ def listen_twitter_stream(hub, author_id) | ||
48 | comment.name = UTF8Filter(object.user.screen_name) | 46 | comment.name = UTF8Filter(object.user.screen_name) |
49 | comment.email = 'admin@localhost.local' | 47 | comment.email = 'admin@localhost.local' |
50 | 48 | ||
51 | - tries = 0 | 49 | + tries = 0 |
52 | begin | 50 | begin |
53 | comment.save! | 51 | comment.save! |
54 | rescue => e | 52 | rescue => e |
55 | - puts "Erro gravando comentário twitter #{e.inspect}" | 53 | + puts "Error writing twitter comment #{e.inspect}" |
56 | end | 54 | end |
57 | end | 55 | end |
58 | end | 56 | end |
59 | rescue => e | 57 | rescue => e |
60 | - puts "Erro lendo stream #{e.inspect}" | 58 | + puts "Error reading twitter stream #{e.inspect}" |
61 | sleep (10 + 2 ** tries) | 59 | sleep (10 + 2 ** tries) |
62 | break | 60 | break |
63 | end | 61 | end |