From 331842fda432d0587defd48733ee6fafd7d3dbe9 Mon Sep 17 00:00:00 2001 From: Evandro Junior Date: Fri, 11 Apr 2014 22:35:52 +0000 Subject: [PATCH] prova de conceito do tweeter funcionando --- lib/community_hub_plugin/hub.rb | 26 +++++++++++++++++++++++--- lib/community_hub_plugin/hub_helper.rb | 2 +- public/javascripts/community_hub.js | 4 ++-- tweeter_stream/lib/twurl/newjson.json | 3 --- tweeter_stream/lib/twurl/request_controller.rb | 12 ++++++++++-- tweeter_stream/lib/twurl/sample.json | 3 +++ tweeter_stream/lib/twurl/stream.rb | 8 +++++++- tweeter_stream/nbproject/private/private.xml | 4 ---- views/content_viewer/hub.rhtml | 2 +- 9 files changed, 47 insertions(+), 17 deletions(-) delete mode 100644 tweeter_stream/lib/twurl/newjson.json create mode 100644 tweeter_stream/lib/twurl/sample.json delete mode 100644 tweeter_stream/nbproject/private/private.xml diff --git a/lib/community_hub_plugin/hub.rb b/lib/community_hub_plugin/hub.rb index d34eba7..d021e3c 100644 --- a/lib/community_hub_plugin/hub.rb +++ b/lib/community_hub_plugin/hub.rb @@ -1,14 +1,13 @@ require File.dirname(__FILE__) + '/../../tweeter_stream/lib/twurl' + class CommunityHubPlugin::Hub < Folder settings_items :hashtags_twitter, :type => :string, :default => "" settings_items :promoted_users, :type => Array, :default => [] settings_items :pinned_posts, :type => Array, :default => [] - def initialize(my_var) - raise "ola".inspect - end + @@thread_started = false def self.icon_name(article = nil) 'community-hub' @@ -26,6 +25,27 @@ class CommunityHubPlugin::Hub < Folder true end + def self.start_twitter_service(page) + + a = Thread.new { + Twurl::Stream.run(page, 'nba', '/root/.twurlrc') + } unless @@thread_started + + @@thread_started = true + +# raise page.inspect + +# comment = Comment.new +# comment.source_id = page.id +# comment.body = "Teste Evandro" +# comment.author_id = "54" +# comment.save! + + +# raise "Pai #{parent.id}".inspect + + end + def view_page "content_viewer/hub.rhtml" end diff --git a/lib/community_hub_plugin/hub_helper.rb b/lib/community_hub_plugin/hub_helper.rb index 3e7140b..002b696 100644 --- a/lib/community_hub_plugin/hub_helper.rb +++ b/lib/community_hub_plugin/hub_helper.rb @@ -15,7 +15,7 @@ module CommunityHubPlugin::HubHelper end def mediator?(hub) - true + false end end \ No newline at end of file diff --git a/public/javascripts/community_hub.js b/public/javascripts/community_hub.js index dd0bdd4..b4a8706 100644 --- a/public/javascripts/community_hub.js +++ b/public/javascripts/community_hub.js @@ -208,8 +208,8 @@ $(document).ready(function(){ //checkUserLevel(); - //setInterval(checkNewLivePosts, 10000); //10 seconds interval - setInterval(checkNewMediationPosts, 10000); //10 seconds interval + setInterval(checkNewLivePosts, 10000); //10 seconds interval + //setInterval(checkNewMediationPosts, 10000); //10 seconds interval //setInterval(checkUserLevel, 10000); //10 seconds interval }); diff --git a/tweeter_stream/lib/twurl/newjson.json b/tweeter_stream/lib/twurl/newjson.json deleted file mode 100644 index dbd23a1..0000000 --- a/tweeter_stream/lib/twurl/newjson.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "name": "root" -} diff --git a/tweeter_stream/lib/twurl/request_controller.rb b/tweeter_stream/lib/twurl/request_controller.rb index 31837bb..f7ff2d7 100755 --- a/tweeter_stream/lib/twurl/request_controller.rb +++ b/tweeter_stream/lib/twurl/request_controller.rb @@ -18,9 +18,17 @@ module Twurl #unless chunk.to_i.length = 0 begin parsed = JSON.parse(chunk) - print "@#{parsed["user"]["name"]} said: #{parsed["text"]} \n" +# print "@#{parsed["user"]["name"]} said: #{parsed["text"]} \n" + comment = Comment.new + comment.source_id = Stream.page.id + comment.body = parsed["text"] + comment.author_id = "54" + comment.save! rescue - end + end + #raise comment.inspect +# rescue +# end #end } } diff --git a/tweeter_stream/lib/twurl/sample.json b/tweeter_stream/lib/twurl/sample.json new file mode 100644 index 0000000..dbd23a1 --- /dev/null +++ b/tweeter_stream/lib/twurl/sample.json @@ -0,0 +1,3 @@ +{ + "name": "root" +} diff --git a/tweeter_stream/lib/twurl/stream.rb b/tweeter_stream/lib/twurl/stream.rb index 39f4fa6..05595bd 100755 --- a/tweeter_stream/lib/twurl/stream.rb +++ b/tweeter_stream/lib/twurl/stream.rb @@ -13,8 +13,9 @@ module Twurl class << self attr_accessor :output - def run(tags, config_file_path, proxy=nil) + def run(page, tags, config_file_path, proxy=nil) begin + @page = page # maybe should not be a class variable @@file_path = config_file_path Twurl.options = Options.new Twurl.options.command = 'request' # Not necessary anymore @@ -29,6 +30,7 @@ module Twurl Twurl.options.path="/1.1/statuses/filter.json" Twurl.options.host="stream.twitter.com" Twurl.options.read_timeout= 0 + rescue NoPathFound => e exit end @@ -39,6 +41,10 @@ module Twurl @@file_path end + def page + @page + end + def dispatch(options) client = OAuthClient.load_from_options(options) controller = RequestController diff --git a/tweeter_stream/nbproject/private/private.xml b/tweeter_stream/nbproject/private/private.xml deleted file mode 100644 index 4750962..0000000 --- a/tweeter_stream/nbproject/private/private.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - diff --git a/views/content_viewer/hub.rhtml b/views/content_viewer/hub.rhtml index f415c9e..0879a3d 100644 --- a/views/content_viewer/hub.rhtml +++ b/views/content_viewer/hub.rhtml @@ -1,6 +1,6 @@ <% extend CommunityHubPlugin::HubHelper %> -<%# CommunityHubPlugin::Hub.start_service %> +<% CommunityHubPlugin::Hub.start_twitter_service(@page) %>
-- libgit2 0.21.2