<commit_before># -*- coding: utf-8 -*-
require 'yodatra/base'
require 'yodatra/logger'
require 'yodatra/api_formatter'
require 'yodatra/throttling'
require 'rack/parser'
require 'rack/ssl'
require 'newrelic_rpm' if ENV['RACK_ENV'] == 'production'

# ############## #
# Squareteam API #
# ############## #
class Api < Yodatra::Base
  VERSION = '0.3.2'
  config = Squareteam::Application::CONFIG
  use Yodatra::Logger
  use Yodatra::Throttle, redis_conf: config.redis
  use Rack::Parser, :parsers => { 'application/json' => proc { |data| JSON.parse data } }
  use Rack::SSL

  # Omniauth
  use Rack::Session::Redis, redis_server: config.redis, :expire_after => 30
  use ::OmniAuth::Builder do
    provider :github, config.oauth[:github]['key'], config.oauth[:github]['secret']
    provider :behance, config.oauth[:behance]['key'], config.oauth[:behance]['secret'], { scope: 'collection_read|wip_read|project_read' }
  end

  # ST api formatter
  use Yodatra::ApiFormatter do |status, headers, response|
    if headers['Content-Type'] =~ /application\/json/
      valid = status >= 200 && status < 300
      data = valid ? '?' : ''
      errors = valid ? '' : '?'
      replace = /.\?./
      body = response.empty? ? '' : response.first
      response = [{:data => data, :errors => errors}.to_json.gsub(replace, body)]
    end
    [status, headers, response]
  end

  # Omniauth callback
  use OmniauthController<commit_msg>chore(ssl): remove rack-ssl in test<commit_after># -*- coding: utf-8 -*-
require 'yodatra/base'
require 'yodatra/logger'
require 'yodatra/api_formatter'
require 'yodatra/throttling'
require 'rack/parser'
require 'rack/ssl'
require 'newrelic_rpm' if ENV['RACK_ENV'] == 'production'

# ############## #
# Squareteam API #
# ############## #
class Api < Yodatra::Base
  VERSION = '0.3.2'
  config = Squareteam::Application::CONFIG
  use Yodatra::Logger
  use Yodatra::Throttle, redis_conf: config.redis
  use Rack::Parser, :parsers => { 'application/json' => proc { |data| JSON.parse data } }
  set :ssl, lambda { !test? }
  use Rack::SSL if ssl

  # Omniauth
  use Rack::Session::Redis, redis_server: config.redis, :expire_after => 30
  use ::OmniAuth::Builder do
    provider :github, config.oauth[:github]['key'], config.oauth[:github]['secret']
    provider :behance, config.oauth[:behance]['key'], config.oauth[:behance]['secret'], { scope: 'collection_read|wip_read|project_read' }
  end

  # ST api formatter
  use Yodatra::ApiFormatter do |status, headers, response|
    if headers['Content-Type'] =~ /application\/json/
      valid = status >= 200 && status < 300
      data = valid ? '?' : ''
      errors = valid ? '' : '?'
      replace = /.\?./
      body = response.empty? ? '' : response.first
      response = [{:data => data, :errors => errors}.to_json.gsub(replace, body)]
    end
    [status, headers, response]
  end

  # Omniauth callback
  use OmniauthController
{'fraction_non_alphanumeric': 0.17774715811229763, 'fraction_numerical': 0.00826730967964175, 'mean_word_length': 4.041666666666667, 'pattern_counts': {'":': 0, '<': 7, '<?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': '5332102', 'n_tokens_mistral': 1008, 'n_tokens_neox': 973, 'n_words': 221}