<commit_before>require 'sinatra'
require 'yaml'
require 'json'
require 'webhooker/version'

module Webhooker
  class App < Sinatra::Base

    # Sinatra configuration
    configure { set :show_exceptions, false }

    not_found do
      'Route not found. Do you know what you want to do?'
    end

    error 400 do
      'Payload type unknown'
    end

    error do |err|
        "There was an application error: #{err}"
    end

    ### Sinatra routes
    # we don't have anything to show
    get '/' do
        "I'm running. Nice, isn't it?"
    end

    post '/payload/:payloadtype' do
      begin
        require "webhooker/payloadtype/#{params[:payloadtype]}"
      rescue LoadError
        halt 400
      end
      parser = ParsePayload.new(request.body.read)
      parser.parse
    end
  end
end<commit_msg>use load instead of require to load the payload type dynamically<commit_after>require 'sinatra'
require 'yaml'
require 'json'
require 'webhooker/version'

module Webhooker
  class App < Sinatra::Base

    # Sinatra configuration
    configure { set :show_exceptions, false }

    not_found do
      'Route not found. Do you know what you want to do?'
    end

    error 400 do
      'Payload type unknown'
    end

    error do |err|
        "There was an application error: #{err}"
    end

    ### Sinatra routes
    # we don't have anything to show
    get '/' do
        "I'm running. Nice, isn't it?"
    end

    post '/payload/:payloadtype' do
      begin
        load "webhooker/payloadtype/#{params[:payloadtype]}.rb"
      rescue LoadError
        halt 400
      end
      parser = ParsePayload.new(request.body.read)
      parser.parse
    end
  end
end
{'fraction_non_alphanumeric': 0.08527131782945736, 'fraction_numerical': 0.007155635062611807, 'mean_word_length': 2.3694779116465865, 'pattern_counts': {'":': 0, '<': 5, '<?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': '73335', 'n_tokens_mistral': 518, 'n_tokens_neox': 490, 'n_words': 175}