<commit_before>require 'sinatra'
require 'endpoint_base'

Dir['./lib/**/*.rb'].each &method(:require)

class VTEXEndpoint < EndpointBase::Sinatra::Base
  set :logging, true

  Honeybadger.configure do |config|
    config.api_key = ENV['HONEYBADGER_KEY']
    config.environment_name = ENV['RACK_ENV']
  end

  post %r{(add_order|update_order)$} do
    begin
      client                      = VTEX::Client.new(@config['vtex_site_id'], @config['vtex_app_key'], @config['vtex_app_token'])
      response                    = client.send_order(@payload[:order])
      code                        = 200
      set_summary "The order #{@payload[:order][:id]} was sent to VTEX Storefront."
    rescue VTEXEndpointError => e
      code = 500
      set_summary "Validation error has ocurred: #{e.message}"
    rescue => e
      code = 500
      error_notification(e)
    end

    process_result code
  end

  post '/get_orders' do
    begin
      client = VTEX::Client.new(@config['vtex_site_id'], @config['vtex_app_key'], @config['vtex_app_token'])
      orders = client.get_orders(@config['vtex_poll_order_timestamp'])

      orders.each do |order|
        add_object "order", order
      end

      code = 200
      set_summary "#{orders.size} orders were retrieved from VTEX Storefront." if orders.any?
    rescue VTEXEndpointError => e
      code = 500
      set_summary "Validation error has ocurred: #{e.message}"
    rescue => e
      code = 500
      error_notification(e)
    end

    process_result code
  end

  post '/get_products' do
  end

  post '/get_inventory' do
  end

  post '/get_customers' do
  end

  post %r{(add_customer|update_customer)$} do
  end


  def error_notification(error)
    log_exception(error)
    set_summary "A VTEX Endpoint error has ocurred: #{error.message}"
  end

end<commit_msg>IN-607 Adds endpoints calls to sinatra file<commit_after>require 'sinatra'
require 'endpoint_base'

Dir['./lib/**/*.rb'].each &method(:require)

class VTEXEndpoint < EndpointBase::Sinatra::Base
  set :logging, true

  Honeybadger.configure do |config|
    config.api_key = ENV['HONEYBADGER_KEY']
    config.environment_name = ENV['RACK_ENV']
  end

  post %r{(add_shipment|update_shipment)$} do
    begin
      client                      = VTEX::Client.new(@config['vtex_site_id'], @config['vtex_app_key'], @config['vtex_app_token'])
      response                    = client.send_shipment(@payload[:order])
      code                        = 200
      set_summary "The order #{@payload[:order][:id]} was sent to VTEX Storefront."
    rescue VTEXEndpointError => e
      code = 500
      set_summary "Validation error has ocurred: #{e.message}"
    rescue => e
      code = 500
      error_notification(e)
    end

    process_result code
  end

  post '/get_orders' do
    begin
      client = VTEX::Client.new(@config['vtex_site_id'], @config['vtex_app_key'], @config['vtex_app_token'])
      orders = client.get_orders(@config['vtex_poll_order_timestamp'])

      orders.each do |order|
        add_object "order", order
      end

      code = 200
      set_summary "#{orders.size} orders were retrieved from VTEX Storefront." if orders.any?
    rescue VTEXEndpointError => e
      code = 500
      set_summary "Validation error has ocurred: #{e.message}"
    rescue => e
      code = 500
      error_notification(e)
    end

    process_result code
  end

  post %r{(add_shipment|update_shipment)$} do
  end

  post '/set_inventory' do
  end

  def error_notification(error)
    log_exception(error)
    set_summary "A VTEX Endpoint error has ocurred: #{error.message}"
  end

end
{'fraction_non_alphanumeric': 0.11289875173370319, 'fraction_numerical': 0.010818307905686546, 'mean_word_length': 2.9323882224645583, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, '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': '4846121', 'n_tokens_mistral': 1193, 'n_tokens_neox': 1126, 'n_words': 275}