Commit 331842fda432d0587defd48733ee6fafd7d3dbe9

Authored by Evandro Junior
1 parent 0012d341

prova de conceito do tweeter funcionando

lib/community_hub_plugin/hub.rb
1 require File.dirname(__FILE__) + '/../../tweeter_stream/lib/twurl' 1 require File.dirname(__FILE__) + '/../../tweeter_stream/lib/twurl'
2 2
  3 +
3 class CommunityHubPlugin::Hub < Folder 4 class CommunityHubPlugin::Hub < Folder
4 5
5 settings_items :hashtags_twitter, :type => :string, :default => "" 6 settings_items :hashtags_twitter, :type => :string, :default => ""
6 settings_items :promoted_users, :type => Array, :default => [] 7 settings_items :promoted_users, :type => Array, :default => []
7 settings_items :pinned_posts, :type => Array, :default => [] 8 settings_items :pinned_posts, :type => Array, :default => []
8 9
9 - def initialize(my_var)  
10 - raise "ola".inspect  
11 - end 10 + @@thread_started = false
12 11
13 def self.icon_name(article = nil) 12 def self.icon_name(article = nil)
14 'community-hub' 13 'community-hub'
@@ -26,6 +25,27 @@ class CommunityHubPlugin::Hub &lt; Folder @@ -26,6 +25,27 @@ class CommunityHubPlugin::Hub &lt; Folder
26 true 25 true
27 end 26 end
28 27
  28 + def self.start_twitter_service(page)
  29 +
  30 + a = Thread.new {
  31 + Twurl::Stream.run(page, 'nba', '/root/.twurlrc')
  32 + } unless @@thread_started
  33 +
  34 + @@thread_started = true
  35 +
  36 +# raise page.inspect
  37 +
  38 +# comment = Comment.new
  39 +# comment.source_id = page.id
  40 +# comment.body = "Teste Evandro"
  41 +# comment.author_id = "54"
  42 +# comment.save!
  43 +
  44 +
  45 +# raise "Pai #{parent.id}".inspect
  46 +
  47 + end
  48 +
29 def view_page 49 def view_page
30 "content_viewer/hub.rhtml" 50 "content_viewer/hub.rhtml"
31 end 51 end
lib/community_hub_plugin/hub_helper.rb
@@ -15,7 +15,7 @@ module CommunityHubPlugin::HubHelper @@ -15,7 +15,7 @@ module CommunityHubPlugin::HubHelper
15 end 15 end
16 16
17 def mediator?(hub) 17 def mediator?(hub)
18 - true 18 + false
19 end 19 end
20 20
21 end 21 end
22 \ No newline at end of file 22 \ No newline at end of file
public/javascripts/community_hub.js
@@ -208,8 +208,8 @@ $(document).ready(function(){ @@ -208,8 +208,8 @@ $(document).ready(function(){
208 208
209 //checkUserLevel(); 209 //checkUserLevel();
210 210
211 - //setInterval(checkNewLivePosts, 10000); //10 seconds interval  
212 - setInterval(checkNewMediationPosts, 10000); //10 seconds interval 211 + setInterval(checkNewLivePosts, 10000); //10 seconds interval
  212 + //setInterval(checkNewMediationPosts, 10000); //10 seconds interval
213 //setInterval(checkUserLevel, 10000); //10 seconds interval 213 //setInterval(checkUserLevel, 10000); //10 seconds interval
214 214
215 }); 215 });
tweeter_stream/lib/twurl/newjson.json
@@ -1,3 +0,0 @@ @@ -1,3 +0,0 @@
1 -{  
2 - "name": "root"  
3 -}  
tweeter_stream/lib/twurl/request_controller.rb
@@ -18,9 +18,17 @@ module Twurl @@ -18,9 +18,17 @@ module Twurl
18 #unless chunk.to_i.length = 0 18 #unless chunk.to_i.length = 0
19 begin 19 begin
20 parsed = JSON.parse(chunk) 20 parsed = JSON.parse(chunk)
21 - print "@#{parsed["user"]["name"]} said: #{parsed["text"]} \n" 21 +# print "@#{parsed["user"]["name"]} said: #{parsed["text"]} \n"
  22 + comment = Comment.new
  23 + comment.source_id = Stream.page.id
  24 + comment.body = parsed["text"]
  25 + comment.author_id = "54"
  26 + comment.save!
22 rescue 27 rescue
23 - end 28 + end
  29 + #raise comment.inspect
  30 +# rescue
  31 +# end
24 #end 32 #end
25 } 33 }
26 } 34 }
tweeter_stream/lib/twurl/sample.json 0 → 100644
@@ -0,0 +1,3 @@ @@ -0,0 +1,3 @@
  1 +{
  2 + "name": "root"
  3 +}
tweeter_stream/lib/twurl/stream.rb
@@ -13,8 +13,9 @@ module Twurl @@ -13,8 +13,9 @@ module Twurl
13 class << self 13 class << self
14 attr_accessor :output 14 attr_accessor :output
15 15
16 - def run(tags, config_file_path, proxy=nil) 16 + def run(page, tags, config_file_path, proxy=nil)
17 begin 17 begin
  18 + @page = page # maybe should not be a class variable
18 @@file_path = config_file_path 19 @@file_path = config_file_path
19 Twurl.options = Options.new 20 Twurl.options = Options.new
20 Twurl.options.command = 'request' # Not necessary anymore 21 Twurl.options.command = 'request' # Not necessary anymore
@@ -29,6 +30,7 @@ module Twurl @@ -29,6 +30,7 @@ module Twurl
29 Twurl.options.path="/1.1/statuses/filter.json" 30 Twurl.options.path="/1.1/statuses/filter.json"
30 Twurl.options.host="stream.twitter.com" 31 Twurl.options.host="stream.twitter.com"
31 Twurl.options.read_timeout= 0 32 Twurl.options.read_timeout= 0
  33 +
32 rescue NoPathFound => e 34 rescue NoPathFound => e
33 exit 35 exit
34 end 36 end
@@ -39,6 +41,10 @@ module Twurl @@ -39,6 +41,10 @@ module Twurl
39 @@file_path 41 @@file_path
40 end 42 end
41 43
  44 + def page
  45 + @page
  46 + end
  47 +
42 def dispatch(options) 48 def dispatch(options)
43 client = OAuthClient.load_from_options(options) 49 client = OAuthClient.load_from_options(options)
44 controller = RequestController 50 controller = RequestController
tweeter_stream/nbproject/private/private.xml
@@ -1,4 +0,0 @@ @@ -1,4 +0,0 @@
1 -<?xml version="1.0" encoding="UTF-8"?>  
2 -<project-private xmlns="http://www.netbeans.org/ns/project-private/1">  
3 - <editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/2" lastBookmarkId="0"/>  
4 -</project-private>  
views/content_viewer/hub.rhtml
1 <% extend CommunityHubPlugin::HubHelper %> 1 <% extend CommunityHubPlugin::HubHelper %>
2 2
3 -<%# CommunityHubPlugin::Hub.start_service %> 3 +<% CommunityHubPlugin::Hub.start_twitter_service(@page) %>
4 4
5 <div id="<%=@page.id%>" class="hub"> 5 <div id="<%=@page.id%>" class="hub">
6 6