Skip to content

Commit

Permalink
don't fail on miltiple chunks
Browse files Browse the repository at this point in the history
  • Loading branch information
Braiden Vasco committed Jun 20, 2015
1 parent c26e820 commit 3040682
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions lib/lita/adapters/gitter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,25 @@ def run # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
}
)

buffer = ''

request.stream do |chunk|
unless chunk.strip.empty?
response = JSON.parse(chunk)
body = buffer + chunk

unless body.strip.empty?
begin
response = JSON.parse(body)
body = ''

text = response['text']
from_id = response['fromUser']['id']
room_id = config.room_id

text = response['text']
from_id = response['fromUser']['id']
room_id = config.room_id
get_message(text, from_id, room_id)

get_message(text, from_id, room_id)
rescue JSON::ParserError
buffer = body
end
end
end
end
Expand Down

0 comments on commit 3040682

Please sign in to comment.