Commit f26acc1da17ef83c53ec31e5f493dbbc6bd48990

Authored by Evandro Junior
1 parent d90f9c3e

prova de conceito do tweeter funcionando

plugins/community_hub/lib/community_hub_plugin/hub.rb
1 1 require File.dirname(__FILE__) + '/../../tweeter_stream/lib/twurl'
2 2  
  3 +
3 4 class CommunityHubPlugin::Hub < Folder
4 5  
5 6 settings_items :hashtags_twitter, :type => :string, :default => ""
6 7 settings_items :promoted_users, :type => Array, :default => []
7 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 12 def self.icon_name(article = nil)
14 13 'community-hub'
... ... @@ -26,6 +25,27 @@ class CommunityHubPlugin::Hub &lt; Folder
26 25 true
27 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 49 def view_page
30 50 "content_viewer/hub.rhtml"
31 51 end
... ...
plugins/community_hub/lib/community_hub_plugin/hub_helper.rb
... ... @@ -15,7 +15,7 @@ module CommunityHubPlugin::HubHelper
15 15 end
16 16  
17 17 def mediator?(hub)
18   - true
  18 + false
19 19 end
20 20  
21 21 end
22 22 \ No newline at end of file
... ...
plugins/community_hub/public/javascripts/community_hub.js
... ... @@ -208,8 +208,8 @@ $(document).ready(function(){
208 208  
209 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 213 //setInterval(checkUserLevel, 10000); //10 seconds interval
214 214  
215 215 });
... ...
plugins/community_hub/tweeter_stream/lib/twurl/newjson.json
... ... @@ -1,3 +0,0 @@
1   -{
2   - "name": "root"
3   -}
plugins/community_hub/tweeter_stream/lib/twurl/request_controller.rb
... ... @@ -18,9 +18,17 @@ module Twurl
18 18 #unless chunk.to_i.length = 0
19 19 begin
20 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 27 rescue
23   - end
  28 + end
  29 + #raise comment.inspect
  30 +# rescue
  31 +# end
24 32 #end
25 33 }
26 34 }
... ...
plugins/community_hub/tweeter_stream/lib/twurl/sample.json 0 → 100644
... ... @@ -0,0 +1,3 @@
  1 +{
  2 + "name": "root"
  3 +}
... ...
plugins/community_hub/tweeter_stream/lib/twurl/stream.rb
... ... @@ -13,8 +13,9 @@ module Twurl
13 13 class << self
14 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 17 begin
  18 + @page = page # maybe should not be a class variable
18 19 @@file_path = config_file_path
19 20 Twurl.options = Options.new
20 21 Twurl.options.command = 'request' # Not necessary anymore
... ... @@ -29,6 +30,7 @@ module Twurl
29 30 Twurl.options.path="/1.1/statuses/filter.json"
30 31 Twurl.options.host="stream.twitter.com"
31 32 Twurl.options.read_timeout= 0
  33 +
32 34 rescue NoPathFound => e
33 35 exit
34 36 end
... ... @@ -39,6 +41,10 @@ module Twurl
39 41 @@file_path
40 42 end
41 43  
  44 + def page
  45 + @page
  46 + end
  47 +
42 48 def dispatch(options)
43 49 client = OAuthClient.load_from_options(options)
44 50 controller = RequestController
... ...
plugins/community_hub/tweeter_stream/nbproject/private/private.xml
... ... @@ -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>
plugins/community_hub/views/content_viewer/hub.rhtml
1 1 <% extend CommunityHubPlugin::HubHelper %>
2 2  
3   -<%# CommunityHubPlugin::Hub.start_service %>
  3 +<% CommunityHubPlugin::Hub.start_twitter_service(@page) %>
4 4  
5 5 <div id="<%=@page.id%>" class="hub">
6 6  
... ...