<commit_before>##
# Lita module.
#
module Lita
  ##
  # Lita adapters module.
  #
  module Adapters
    ##
    # Gitter adapter for the Lita chat bot.
    #
    class Gitter < Adapter
      config :token,   type: String, required: true
      config :room_id, type: String, required: true
    end

    Lita.register_adapter(:gitter, Gitter)
  end
end<commit_msg>Implement main loop in Lita::Adapters::Gitter#run<commit_after>require 'em-http'
require 'json'

##
# Lita module.
#
module Lita
  ##
  # Lita adapters module.
  #
  module Adapters
    ##
    # Gitter adapter for the Lita chat bot.
    #
    class Gitter < Adapter
      config :token,   type: String, required: true
      config :room_id, type: String, required: true

      # The main loop. Listens for incoming messages,
      # creates {Lita::Message} objects from them,
      # and dispatches them to the robot.
      #
      def run # rubocop:disable Metrics/MethodLength
        stream_url =
          "https://stream.gitter.im/v1/rooms/#{config.room_id}/chatMessages"

        http = EventMachine::HttpRequest.new(
          stream_url,
          keepalive: true,
          connect_timeout: 0,
          inactivity_timeout: 0,
        )

        EventMachine.run do
          request = http.get(
            head: {
              'Accept' => 'application/json',
              'Authorization' => "Bearer #{config.token}",
            }
          )

          request.stream do |chunk|
            unless chunk.strip.empty?
              text = JSON.parse(chunk)['text']
            end
          end
        end
      end
    end

    Lita.register_adapter(:gitter, Gitter)
  end
end
{'fraction_non_alphanumeric': 0.0986682808716707, 'fraction_numerical': 0.0018159806295399517, 'mean_word_length': 1.9676840215439857, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5871322', 'n_tokens_mistral': 511, 'n_tokens_neox': 497, 'n_words': 134}