diff --git a/plugins/community_hub/tweeter_stream/lib/twurl/request_controller.rb b/plugins/community_hub/tweeter_stream/lib/twurl/request_controller.rb index b40cb76..99ea38c 100755 --- a/plugins/community_hub/tweeter_stream/lib/twurl/request_controller.rb +++ b/plugins/community_hub/tweeter_stream/lib/twurl/request_controller.rb @@ -14,26 +14,39 @@ module Twurl def perform_request client.perform_request_from_options(options) { |response| + chunk_begining = "" + puts "Connecting to tweeter stream : " + response.inspect response.read_body { |chunk| - #print "chunk: #{chunk}\n" + chunk = chunk_begining + chunk + chunk_complete = false unless chunk.blank? - begin + begin parsed = JSON.parse(chunk) - ic = Iconv.new('UTF-8//IGNORE', 'UTF-8') - #Attention please, don't remove + ' ')[0..-2] it is used for UTF8 validation - comment_text = ic.iconv(parsed["text"] + ' ')[0..-2] - print "#{comment_text}\n" - comment = Comment.new - comment.title = 'hub-message-twitter' - comment.source = options.page - comment.body = comment_text - comment.author_id = options.author_id - #Attention please, don't remove + ' ')[0..-2] it is used for UTF8 validation - comment.name = ic.iconv(parsed["user"]["name"] + ' ')[0..-2] - comment.email = 'admin@localhost.local' - comment.save! + chunk_complete = true + chunk_begining = "" + rescue JSON::ParserError => e + chunk_begining = chunk + chunk_complete = false +# puts "@@@@@@@@ Erro fazendo parse do chunk #{e.inspect} @@@@@@@@\n\n" + end + begin + if chunk_complete + ic = Iconv.new('UTF-8//IGNORE', 'UTF-8') + #Attention please, don't remove + ' ')[0..-2] it is used for UTF8 validation + comment_text = ic.iconv(parsed["text"] + ' ')[0..-2] + comment = Comment.new + comment.title = 'hub-message-twitter' + comment.source = options.page + comment.body = comment_text + comment.author_id = options.author_id + #Attention please, don't remove + ' ')[0..-2] it is used for UTF8 validation + comment.name = ic.iconv(parsed["user"]["name"] + ' ')[0..-2] + comment.email = 'admin@localhost.local' + comment.save! + puts "@#{comment.name} " +_('said') + ": #{comment_text}" + end rescue => e - print "Erro gravando comentário twitter #{e}\n" + puts "Erro gravando comentário twitter #{e.inspect}" end end } -- libgit2 0.21.2