<commit_before>module Hobostove
  class Campfire
    attr_reader :room_id

    def initialize
      load_current_room

      @users = {}
    end

    def recent_messages
      messages = connection.get("/room/#{room_id}/recent.json?limit=10").body
      messages = JSON.parse(messages)["messages"]
      messages.map do |message|
        message = Hobostove::Models::Message.new(
          message["id"],
          Time.parse(message["created_at"]),
          message["type"],
          user(message["user_id"]),
          message["body"]
        )
        message = handle_upload(message) if message.type == "UploadMessage"
        message
      end
    end

    def send_message(message)
      connection.post("/room/#{room_id}/speak.json") do |req|
        req.body = {
          :message => {
            :type => "TextMessage",
            :body => message,
          }
        }.to_json
      end
    end

    def current_users
      room = connection.get("/room/#{room_id}.json").body
      room = JSON.parse(room)["room"]<commit_msg>Send Content-Type of json when speaking a message<commit_after>module Hobostove
  class Campfire
    attr_reader :room_id

    def initialize
      load_current_room

      @users = {}
    end

    def recent_messages
      messages = connection.get("/room/#{room_id}/recent.json?limit=10").body
      messages = JSON.parse(messages)["messages"]
      messages.map do |message|
        message = Hobostove::Models::Message.new(
          message["id"],
          Time.parse(message["created_at"]),
          message["type"],
          user(message["user_id"]),
          message["body"]
        )
        message = handle_upload(message) if message.type == "UploadMessage"
        message
      end
    end

    def send_message(message)
      connection.post("/room/#{room_id}/speak.json") do |req|
        req.headers["Content-Type"] = "application/json"
        req.body = {
          :message => {
            :type => "TextMessage",
            :body => message,
          }
        }.to_json
      end
    end

    def current_users
      room = connection.get("/room/#{room_id}.json").body
      room = JSON.parse(room)["room"]
{'fraction_non_alphanumeric': 0.1310344827586207, 'fraction_numerical': 0.0018390804597701149, 'mean_word_length': 2.130935251798561, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, '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': '1649987', 'n_tokens_mistral': 636, 'n_tokens_neox': 619, 'n_words': 118}