Commit abea17e36f369bbd216fd7a042bef5ff6d96cfaa

Authored by Francisco Marcelo de Araújo Lima Júnior
1 parent 7b8dee32

migrate community hub plugin to rails 3

plugins/community_hub/lib/community_hub_plugin/hub.rb
... ... @@ -3,6 +3,8 @@ require File.dirname(__FILE__) + '/../../facebook_stream/lib_facebook_stream'
3 3  
4 4 class CommunityHubPlugin::Hub < Folder
5 5  
  6 + attr_accessible :last_changed_by_id, :integer
  7 +
6 8 settings_items :twitter_enabled, :type => :boolean, :default => false
7 9 settings_items :twitter_hashtags, :type => :string, :default => ""
8 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 32 end
33 33  
34 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 37 logpath = File.join(logdir, "#{ENV['RAILS_ENV']}_#{Time.now.strftime('%F')}.log")
38 38 @logger = Logger.new(logpath)
39 39 end
... ...
plugins/community_hub/test/unit/community_hub_plugin/listener_test.rb
... ... @@ -10,7 +10,7 @@ class ListenerTest &lt; ActiveSupport::TestCase
10 10 end
11 11  
12 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 15 if File.exists?(logdir)
16 16 Dir.foreach(logdir) { |f|
... ...
plugins/community_hub/twitter/stream.rb
... ... @@ -30,15 +30,13 @@ def listen_twitter_stream(hub, author_id)
30 30 sleep (10 + 2 ** tries)
31 31 end
32 32 end
33   -
  33 +
34 34 tries = 0
35 35 while true
36 36 begin
37 37 tries += 1
38 38 client.filter(:track => hub.twitter_hashtags) do |object|
39 39 if object.is_a?(Twitter::Tweet)
40   -# puts '@' + object.user.screen_name + ' said: ' + object.text
41   -# puts object.user.profile_image_url
42 40 comment = Comment.new
43 41 comment.title = 'hub-message-twitter'
44 42 comment.source = hub
... ... @@ -48,16 +46,16 @@ def listen_twitter_stream(hub, author_id)
48 46 comment.name = UTF8Filter(object.user.screen_name)
49 47 comment.email = 'admin@localhost.local'
50 48  
51   - tries = 0
  49 + tries = 0
52 50 begin
53 51 comment.save!
54 52 rescue => e
55   - puts "Erro gravando comentário twitter #{e.inspect}"
  53 + puts "Error writing twitter comment #{e.inspect}"
56 54 end
57 55 end
58 56 end
59 57 rescue => e
60   - puts "Erro lendo stream #{e.inspect}"
  58 + puts "Error reading twitter stream #{e.inspect}"
61 59 sleep (10 + 2 ** tries)
62 60 break
63 61 end
... ...