<commit_before>require 'sinatra/base'
require 'oj'
require 'webhook/settings'
require 'webhook/metrics'
require 'webhook/status_check'
require 'webhook/shopify'
require 'loginator/middleware/sinatra'
require 'publishers'
require 'multi_json'

MultiJson.use Oj
Oj.default_options = {:mode => :compat}

module Webhook
  class Web < Sinatra::Base
    configure do
      Publishers.configure!
      set :raise_errors, false
      set :show_exceptions, false
      set :root, File.expand_path('../..', __FILE__)
      use Webhook::StatusCheck
      logfile = ENV['LOGFILE'] || 'log/webhook.log'
      log = File.open(logfile, 'a')
      log.sync = true
      use Loginator::Middleware::Sinatra, log
      use Webhook::Shopify
    end

    post '/stripe' do
      webhook = Oj.load(request.body.read)
      routing_key = ['stripe', webhook['type']].compact.join('.')
      Publisher::Stripe.new(webhook).publish(routing_key)
      Webhook::Metrics.instance.increment(routing_key)
      status 200
    end

    post %r{shopify/(?<wanelo_store_id>\w*)/(?<topic>\w*)/(?<action>\w*)} do
      webhook = Oj.load(request.body.read)
      routing_key = ['shopify', params['topic'], params['action']].join('.')
      webhook['wanelo_store_id'] = params['wanelo_store_id']
      Publisher::Shopify.new(webhook).publish(routing_key)
      Webhook::Metrics.instance.increment(routing_key)
      status 200
    end

    post %r{shopify/(?<topic>\w*)/(?<action>\w*)} do
      webhook = Oj.load(request.body.read)
      routing_key = ['shopify', params['topic'], params['action']].join('.')
      Publisher::Shopify.new(webhook).publish(routing_key)
      Webhook::Metrics.instance.increment(routing_key)
      status 200
    end
  end
end<commit_msg>Force UTF-8 encoding on routing key<commit_after>require 'sinatra/base'
require 'oj'
require 'webhook/settings'
require 'webhook/metrics'
require 'webhook/status_check'
require 'webhook/shopify'
require 'loginator/middleware/sinatra'
require 'publishers'
require 'multi_json'

MultiJson.use Oj
Oj.default_options = {:mode => :compat}

module Webhook
  class Web < Sinatra::Base
    configure do
      Publishers.configure!
      set :raise_errors, false
      set :show_exceptions, false
      set :root, File.expand_path('../..', __FILE__)
      use Webhook::StatusCheck
      logfile = ENV['LOGFILE'] || 'log/webhook.log'
      log = File.open(logfile, 'a')
      log.sync = true
      use Loginator::Middleware::Sinatra, log
      use Webhook::Shopify
    end

    post '/stripe' do
      webhook = Oj.load(request.body.read)
      routing_key = ['stripe', webhook['type']].compact.join('.').force_encoding('UTF-8')
      Publisher::Stripe.new(webhook).publish(routing_key)
      Webhook::Metrics.instance.increment(routing_key)
      status 200
    end

    post %r{shopify/(?<wanelo_store_id>\w*)/(?<topic>\w*)/(?<action>\w*)} do
      webhook = Oj.load(request.body.read)
      routing_key = ['shopify', params['topic'], params['action']].join('.').force_encoding('UTF-8')
      webhook['wanelo_store_id'] = params['wanelo_store_id']
      Publisher::Shopify.new(webhook).publish(routing_key)
      Webhook::Metrics.instance.increment(routing_key)
      status 200
    end

    post %r{shopify/(?<topic>\w*)/(?<action>\w*)} do
      webhook = Oj.load(request.body.read)
      routing_key = ['shopify', params['topic'], params['action']].join('.').force_encoding('UTF-8')
      Publisher::Shopify.new(webhook).publish(routing_key)
      Webhook::Metrics.instance.increment(routing_key)
      status 200
    end
  end
end
{'fraction_non_alphanumeric': 0.15438695163104613, 'fraction_numerical': 0.006186726659167604, 'mean_word_length': 3.7112582781456953, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, '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': '2679442', 'n_tokens_mistral': 1221, 'n_tokens_neox': 1195, 'n_words': 208}