Commit 8976ba89db8e8d7e801ec0fc9b60048e48cb653a
1 parent
11fe390b
Exists in
theme-brasil-digital-from-staging
and in
9 other branches
Fixed tweeter stream for broken token
Showing
1 changed file
with
29 additions
and
16 deletions
Show diff stats
plugins/community_hub/tweeter_stream/lib/twurl/request_controller.rb
@@ -14,26 +14,39 @@ module Twurl | @@ -14,26 +14,39 @@ module Twurl | ||
14 | 14 | ||
15 | def perform_request | 15 | def perform_request |
16 | client.perform_request_from_options(options) { |response| | 16 | client.perform_request_from_options(options) { |response| |
17 | + chunk_begining = "" | ||
18 | + puts "Connecting to tweeter stream : " + response.inspect | ||
17 | response.read_body { |chunk| | 19 | response.read_body { |chunk| |
18 | - #print "chunk: #{chunk}\n" | 20 | + chunk = chunk_begining + chunk |
21 | + chunk_complete = false | ||
19 | unless chunk.blank? | 22 | unless chunk.blank? |
20 | - begin | 23 | + begin |
21 | parsed = JSON.parse(chunk) | 24 | parsed = JSON.parse(chunk) |
22 | - ic = Iconv.new('UTF-8//IGNORE', 'UTF-8') | ||
23 | - #Attention please, don't remove + ' ')[0..-2] it is used for UTF8 validation | ||
24 | - comment_text = ic.iconv(parsed["text"] + ' ')[0..-2] | ||
25 | - print "#{comment_text}\n" | ||
26 | - comment = Comment.new | ||
27 | - comment.title = 'hub-message-twitter' | ||
28 | - comment.source = options.page | ||
29 | - comment.body = comment_text | ||
30 | - comment.author_id = options.author_id | ||
31 | - #Attention please, don't remove + ' ')[0..-2] it is used for UTF8 validation | ||
32 | - comment.name = ic.iconv(parsed["user"]["name"] + ' ')[0..-2] | ||
33 | - comment.email = 'admin@localhost.local' | ||
34 | - comment.save! | 25 | + chunk_complete = true |
26 | + chunk_begining = "" | ||
27 | + rescue JSON::ParserError => e | ||
28 | + chunk_begining = chunk | ||
29 | + chunk_complete = false | ||
30 | +# puts "@@@@@@@@ Erro fazendo parse do chunk #{e.inspect} @@@@@@@@\n\n" | ||
31 | + end | ||
32 | + begin | ||
33 | + if chunk_complete | ||
34 | + ic = Iconv.new('UTF-8//IGNORE', 'UTF-8') | ||
35 | + #Attention please, don't remove + ' ')[0..-2] it is used for UTF8 validation | ||
36 | + comment_text = ic.iconv(parsed["text"] + ' ')[0..-2] | ||
37 | + comment = Comment.new | ||
38 | + comment.title = 'hub-message-twitter' | ||
39 | + comment.source = options.page | ||
40 | + comment.body = comment_text | ||
41 | + comment.author_id = options.author_id | ||
42 | + #Attention please, don't remove + ' ')[0..-2] it is used for UTF8 validation | ||
43 | + comment.name = ic.iconv(parsed["user"]["name"] + ' ')[0..-2] | ||
44 | + comment.email = 'admin@localhost.local' | ||
45 | + comment.save! | ||
46 | + puts "@#{comment.name} " +_('said') + ": #{comment_text}" | ||
47 | + end | ||
35 | rescue => e | 48 | rescue => e |
36 | - print "Erro gravando comentário twitter #{e}\n" | 49 | + puts "Erro gravando comentário twitter #{e.inspect}" |
37 | end | 50 | end |
38 | end | 51 | end |
39 | } | 52 | } |