<commit_before>require 'json'

module AdminApi

  def self.registered(app)

    app.post '/setup' do
      content_type :json
      request.body.rewind
      payload = request.body.read.strip
      config = payload.empty? ? {} : JSON.parse(payload, symbolize_names: true)
      app.settings.game.setup(config)
      [200, JSON.pretty_generate(app.settings.game.status)]
    end

    app.post '/teams/:name' do
      content_type :json
      request.body.rewind
      payload = request.body.read.strip
      if app.settings.game.add_team(payload[:name])
        [200, JSON.pretty_generate(app.settings.game.status)]
      else
        [400, JSON.pretty_generate({
          errors: 'Too late, the game has already begun'
        })]
      end
    end

    app.post '/play' do
      content_type :json
      app.settings.game.play
      [200, JSON.pretty_generate(app.settings.game.status)]
    end

    app.get '/status' do
      content_type :json
      [200, JSON.pretty_generate(app.settings.game.status)]
    end

    app.post '/pause' do
      content_type :json
      app.settings.game.pause
      [200, JSON.pretty_generate(app.settings.game.status)]
    end

  end

end

<commit_msg>Parse incoming teams as JSON<commit_after>require 'json'

module AdminApi

  def self.registered(app)

    app.post '/setup' do
      content_type :json
      request.body.rewind
      payload = request.body.read.strip
      config = payload.empty? ? {} : JSON.parse(payload, symbolize_names: true)
      app.settings.game.setup(config)
      [200, JSON.pretty_generate(app.settings.game.status)]
    end

    app.post '/teams' do
      content_type :json
      request.body.rewind
      payload = JSON.parse(request.body.read.strip, symbolize_names: true)
      if app.settings.game.add_team(payload[:name])
        [200, JSON.pretty_generate(app.settings.game.status)]
      else
        [400, JSON.pretty_generate({
          errors: 'Too late, the game has already begun'
        })]
      end
    end

    app.post '/play' do
      content_type :json
      app.settings.game.play
      [200, JSON.pretty_generate(app.settings.game.status)]
    end

    app.get '/status' do
      content_type :json
      [200, JSON.pretty_generate(app.settings.game.status)]
    end

    app.post '/pause' do
      content_type :json
      app.settings.game.pause
      [200, JSON.pretty_generate(app.settings.game.status)]
    end

  end

end


{'fraction_non_alphanumeric': 0.11262376237623763, 'fraction_numerical': 0.01485148514851485, 'mean_word_length': 2.44950213371266, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '5244569', 'n_tokens_mistral': 809, 'n_tokens_neox': 756, 'n_words': 158}