def handle_data(chunk)
      if chunk.nil?
        logger.info("Unable to process nil data")
        return nil
      end
      logger.debug("raw data #{chunk}")
      chunk = chunk.split("\n") # more than one event can be retrieved separated by '\n'
      if chunk.is_a?(Array)
        events = []
        temp_events = []
        chunk.each { |value|
          begin
            json = ActiveSupport::JSON.decode(value.force_encoding("UTF-8"))
          rescue Exception => ex
            json = nil
            logger.error("Unable to decode JSON")
          end
          if json
            unless json.is_a?(Array) # Twitter - RSS message
              unless json.nil?
                logger.debug("#{self.class} Got a stream message")
                temp_events << @formatter.format_message(json)
                temp_events.nil? or events << temp_events.flatten
              else
                logger.debug("#{self.class} Invalid data received")
                events = nil
              end
            else # Voice - SMS message
              logger.debug("#{self.class} Got a voice/sms message")
              logger.debug(json)
              temp_events = @formatter.format_voice_sms(json)
              temp_events.nil? or events << temp_events.flatten
            end
          end
        }
        events.flatten
      else
        logger.info("#{self.class} Invalid data received #{chunk}")
        nil
      end
    end
def handle_data(chunk)
      if chunk.nil?
        logger.info("Unable to process nil data")
        return nil
      end
      logger.debug("raw data #{chunk}")
      chunk = chunk.split("\n") # more than one event can be retrieved separated by '\n'
      if chunk.is_a?(Array)
        events = []
        temp_events = []
        chunk.each { |value|
          begin
            json = ActiveSupport::JSON.decode(value.force_encoding("UTF-8"))
          rescue Exception => ex
            json = nil
            logger.error("Unable to decode JSON")
          end
          if json
            unless json.is_a?(Array) # Twitter - RSS message
              unless json.nil?
                logger.debug("#{self.class} Got a stream message")
                temp_events << @formatter.format_message(json)
                temp_events.nil? or events << temp_events.flatten
              else
                logger.debug("#{self.class} Invalid data received")
                events = nil
              end
            else # Voice - SMS message
              logger.debug("#{self.class} Got a voice/sms message")
              logger.debug(json)
              temp_events = @formatter.format_voice_sms(json)
              temp_events.nil? or events << temp_events.flatten
            end
          end
        }
        events.flatten
      else
        logger.info("#{self.class} Invalid data received #{chunk}")
        nil
      end
    end
Process the data retrieved, formatting the raw data into one or more Connfu::Message instances

 ==== Parameters
 * +chunk+ data got from the HTTP stream

 ==== Return
 * Array of Connfu::Message instances
 * nil if invalid data