<commit_before>require 'rubygems'
require 'addressable/uri'
require 'rest-client'
require File.join(File.dirname(__FILE__), "/authentication/mashape_authentication.rb")
require File.join(File.dirname(__FILE__), "/authentication/custom_header_authentication.rb")
require File.join(File.dirname(__FILE__), "/authentication/query_authentication.rb")
require File.join(File.dirname(__FILE__), "/authentication/basic_authentication.rb")
require File.join(File.dirname(__FILE__), "/http_utils.rb")
require File.join(File.dirname(__FILE__), "/mashape_exception.rb")

module Mashape
  class HttpResponse
    attr :code, true
    attr :raw_body, true  
    attr :body, true
    attr :headers, true
  end
  
  class HttpClient
    
    def HttpClient.do_request(method, url, parameters = nil, content_type = nil, response_type = nil, authentication_handlers = nil, &callback)
      if callback
        return Thread.new do
          callback.call(internal_do_request(method, url, parameters, content_type, response_type, authentication_handlers))
        end
      else
        return internal_do_request(method, url, parameters, content_type, response_type, authentication_handlers)
      end
    end
    
    def HttpClient.internal_do_request(method, url, parameters = nil, content_type = nil, response_type = nil, authentication_handlers = nil)
       httpResponse = nil;
       
       headers = {}
       if parameters == nil
         case content_type
          when :form || :binary
            parameters = {}
         end
       end
       
       # figure out what kind of auth we have and where to put it
       authentication_handlers.each do |handler|
         if handler.kind_of? Mashape::HeaderAuthentication
           headers = headers.merge(handler.handleHeader)
         elsif handler.kind_of? Mashape::QueryAuthentication
           parameters = parameters.merge(handler.handleParams)
#         elsif handler.kind_of? Mashape::OAuth10aAuthentication
#           if handler.handleParams[:access_token] == nil || handler.handleParams[:access_secret] == nil
#             raise Mashape::JsonException.new("Before consuming OAuth endpoint, invoke authenticate_oauth('access_token','access_secret') with not null values")
#           end
           # These headers will be processed by the proxy to sign the request
#           headers["X-Mashape-OAuth-ConsumerKey"] = handler.handleParams[:consumer_key]
#           headers["X-Mashape-OAuth-ConsumerSecret"] = handler.handleParams[:consumer_secret]
#           headers["X-Mashape-OAuth-AccessToken"] = handler.handleParams[:access_token]
#           headers["X-Mashape-OAuth-AccessSecret"] = handler.handleParams[:access_secret]
#         elsif handler.kind_of? Mashape::OAuth2Authentication
#           if handler.handleParams[:access_token] == nil
#              raise Mashape::JsonException.new("Before consuming OAuth endpoint, invoke authenticate_oauth('access_token') with a not null value")
#            end
#           parameters = parameters.merge({"access_token" => handler.handleParams[:access_token]})
         end
       end
       
       Mashape::HttpUtils.setRequestHeaders(content_type, response_type, headers)
       
       begin
        case method
          when :get
            uri = Addressable::URI.new<commit_msg>oauth support<commit_after>require 'rubygems'
require 'addressable/uri'
require 'rest-client'
require File.join(File.dirname(__FILE__), "/authentication/mashape_authentication.rb")
require File.join(File.dirname(__FILE__), "/authentication/custom_header_authentication.rb")
require File.join(File.dirname(__FILE__), "/authentication/query_authentication.rb")
require File.join(File.dirname(__FILE__), "/authentication/basic_authentication.rb")
require File.join(File.dirname(__FILE__), "/authentication/oauth_authentication.rb")
require File.join(File.dirname(__FILE__), "/authentication/oauth10a_authentication.rb")
require File.join(File.dirname(__FILE__), "/authentication/oauth2_authentication.rb")
require File.join(File.dirname(__FILE__), "/http_utils.rb")
require File.join(File.dirname(__FILE__), "/mashape_exception.rb")

module Mashape
  class HttpResponse
    attr :code, true
    attr :raw_body, true  
    attr :body, true
    attr :headers, true
  end
  
  class HttpClient
    
    def HttpClient.do_request(method, url, parameters = nil, content_type = nil, response_type = nil, authentication_handlers = nil, &callback)
      if callback
        return Thread.new do
          callback.call(internal_do_request(method, url, parameters, content_type, response_type, authentication_handlers))
        end
      else
        return internal_do_request(method, url, parameters, content_type, response_type, authentication_handlers)
      end
    end
    
    def HttpClient.internal_do_request(method, url, parameters = nil, content_type = nil, response_type = nil, authentication_handlers = nil)
       httpResponse = nil;
       
       headers = {}
       if parameters == nil
         case content_type
          when :form || :binary
            parameters = {}
         end
       end
       
       # figure out what kind of auth we have and where to put it
       authentication_handlers.each do |handler|
         if handler.kind_of? Mashape::HeaderAuthentication
           headers = headers.merge(handler.handleHeader)
         elsif handler.kind_of? Mashape::QueryAuthentication
           parameters = parameters.merge(handler.handleParams)
         elsif handler.kind_of? Mashape::OAuth10aAuthentication
           if handler.handleParams[:access_token] == nil || handler.handleParams[:access_secret] == nil
             raise Mashape::JsonException.new("Before consuming OAuth endpoint, invoke authorize('access_token','access_secret') with not null values")
           end
           # These headers will be processed by the proxy to sign the request
           headers["x-mashape-oauth-consumerkey"] = handler.handleParams[:consumer_key]
           headers["x-mashape-oauth-consumersecret"] = handler.handleParams[:consumer_secret]
           headers["x-mashape-oauth-accesstoken"] = handler.handleParams[:access_token]
           headers["x-mashape-oauth-accesssecret"] = handler.handleParams[:access_secret]
         elsif handler.kind_of? Mashape::OAuth2Authentication
           if handler.handleParams[:access_token] == nil
              raise Mashape::JsonException.new("Before consuming OAuth endpoint, invoke authorize('access_token') with a not null value")
           end
           parameters = parameters.merge({"access_token" => handler.handleParams[:access_token]})
         end
       end
       
       Mashape::HttpUtils.setRequestHeaders(content_type, response_type, headers)
       
       begin
        case method
          when :get
            uri = Addressable::URI.new
{'fraction_non_alphanumeric': 0.09488194749963337, 'fraction_numerical': 0.0013198416190057193, 'mean_word_length': 3.3522654754307593, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '5130021', 'n_tokens_mistral': 1853, 'n_tokens_neox': 1837, 'n_words': 413}