<commit_before>require 'active_support'
require 'action_controller'
require 'action_dispatch/http/request'
require 'uri'

ActionController::Request::HTTP_METHODS << "patch"
ActionController::Request::HTTP_METHOD_LOOKUP["PATCH"] = :patch
ActionController::Request::HTTP_METHOD_LOOKUP["patch"] = :patch

module OAuth::RequestProxy
  class ActionControllerRequest < OAuth::RequestProxy::Base
    proxies(defined?(ActionDispatch::AbstractRequest) ? ActionDispatch::AbstractRequest : ActionDispatch::Request)

    def method
      request.method.to_s.upcase
    end

    def uri
      request.url
    end

    def parameters
      if options[:clobber_request]
        options[:parameters] || {}
      else
        params = request_params.merge(query_params).merge(header_params)
        params.stringify_keys! if params.respond_to?(:stringify_keys!)
        params.merge(options[:parameters] || {})
      end
    end

    # Override from OAuth::RequestProxy::Base to avoid roundtrip
    # conversion to Hash or Array and thus preserve the original
    # parameter names
    def parameters_for_signature
      params = []
      params << options[:parameters].to_query if options[:parameters]

      unless options[:clobber_request]
        params << header_params.to_query
        params << request.query_string unless query_string_blank?

        if request.post? && request.content_type.to_s.downcase.start_with?("application/x-www-form-urlencoded")
          params << request.raw_post
        end
      end

      params.
        join('&').split('&').
        reject(&:blank?).
        map { |p| p.split('=').map{|esc| CGI.unescape(esc)} }.
        reject { |kv| kv[0] == 'oauth_signature'}
    end

  protected

    def query_params
      request.query_parameters
    end

    def request_params
      request.request_parameters
    end

  end
end
<commit_msg>fix support for patch in newer rails versions, update #67<commit_after>require 'active_support'
require "active_support/version"
require 'action_controller'
require 'uri'

if
  Gem::Version.new(ActiveSupport::VERSION::STRING) < Gem::Version.new("3")
then # rails 2.x
  require 'action_controller/request'
  unless ActionController::Request::HTTP_METHODS.include?("patch")
    ActionController::Request::HTTP_METHODS << "patch"
    ActionController::Request::HTTP_METHOD_LOOKUP["PATCH"] = :patch
    ActionController::Request::HTTP_METHOD_LOOKUP["patch"] = :patch
  end

elsif
  Gem::Version.new(ActiveSupport::VERSION::STRING) < Gem::Version.new("4")
then # rails 3.x
  require 'action_dispatch/http/request'
  unless ActionDispatch::Request::HTTP_METHODS.include?("patch")
    ActionDispatch::Request::HTTP_METHODS << "patch"
    ActionDispatch::Request::HTTP_METHOD_LOOKUP["PATCH"] = :patch
    ActionDispatch::Request::HTTP_METHOD_LOOKUP["patch"] = :patch
  end

else # rails 4.x - already has patch
  require 'action_dispatch/http/request'
end

module OAuth::RequestProxy
  class ActionControllerRequest < OAuth::RequestProxy::Base
    proxies(defined?(ActionDispatch::AbstractRequest) ? ActionDispatch::AbstractRequest : ActionDispatch::Request)

    def method
      request.method.to_s.upcase
    end

    def uri
      request.url
    end

    def parameters
      if options[:clobber_request]
        options[:parameters] || {}
      else
        params = request_params.merge(query_params).merge(header_params)
        params.stringify_keys! if params.respond_to?(:stringify_keys!)
        params.merge(options[:parameters] || {})
      end
    end

    # Override from OAuth::RequestProxy::Base to avoid roundtrip
    # conversion to Hash or Array and thus preserve the original
    # parameter names
    def parameters_for_signature
      params = []
      params << options[:parameters].to_query if options[:parameters]

      unless options[:clobber_request]
        params << header_params.to_query
        params << request.query_string unless query_string_blank?

        if request.post? && request.content_type.to_s.downcase.start_with?("application/x-www-form-urlencoded")
          params << request.raw_post
        end
      end

      params.
        join('&').split('&').
        reject(&:blank?).
        map { |p| p.split('=').map{|esc| CGI.unescape(esc)} }.
        reject { |kv| kv[0] == 'oauth_signature'}
    end

  protected

    def query_params
      request.query_parameters
    end

    def request_params
      request.request_parameters
    end

  end
end

{'fraction_non_alphanumeric': 0.11205928587469122, 'fraction_numerical': 0.0020211093644733886, 'mean_word_length': 3.6012396694214877, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '1365907', 'n_tokens_mistral': 1299, 'n_tokens_neox': 1270, 'n_words': 260}