<commit_before># vim:foldmethod=indent:foldlevel=3
module GH
  class Request
    class GET
      attr_reader :accept, :access_token, :client_id, :client_secret, :url

      def initialize(url, client_id:, client_secret:, accept: :json, access_token: nil)
        @accept        = accept
        @access_token  = access_token
        @client_id     = client_id
        @client_secret = client_secret
        @url           = url
      end

      def execute
        RestClient::Request.execute(
          method: :get, url: url, headers: headers,
          ssl_version: GH::Request.ssl_version
        )
      end

      def headers
        {
          params: params,
          accept: accept,
          'Authorization' => "token #{access_token}"
        }
      end

      def params
        {
          client_id:     client_id,
          client_secret: client_secret
        }
      end

    end

    class POST
      attr_reader :accept, :access_token, :payload, :url

      def initialize(url, payload:, accept: :json, access_token: nil, headers: {})
        @accept        = accept
        @access_token  = access_token
        @payload       = payload
        @url           = url
        @headers       = headers
      end

      def execute
        RestClient::Request.execute(
          method: :post,
          url: url,
          ssl_version: GH::Request.ssl_version,
          payload: payload,
          headers: headers
        )
      end

      def headers
        headers = @headers.merge(accept: :json, content_type: :json)
        headers.merge('Authorization' => "token #{access_token}") if access_token
        headers
      end

    end

    class << self
      def ssl_version
        'TLSv1'.freeze # TODO make this configurable
      end

      def get(*args)
        GET.new(*args).execute
      end

      def post(*args)
        POST.new(*args).execute
      end
    end

  end
end
<commit_msg>Fix mergeing of auth token into headers<commit_after># vim:foldmethod=indent:foldlevel=3
module GH
  class Request
    class GET
      attr_reader :accept, :access_token, :client_id, :client_secret, :url

      def initialize(url, client_id:, client_secret:, accept: :json, access_token: nil)
        @accept        = accept
        @access_token  = access_token
        @client_id     = client_id
        @client_secret = client_secret
        @url           = url
      end

      def execute
        RestClient::Request.execute(
          method: :get, url: url, headers: headers,
          ssl_version: GH::Request.ssl_version
        )
      end

      def headers
        {
          params: params,
          accept: accept,
          'Authorization' => "token #{access_token}"
        }
      end

      def params
        {
          client_id:     client_id,
          client_secret: client_secret
        }
      end

    end

    class POST
      attr_reader :accept, :access_token, :payload, :url

      def initialize(url, payload:, accept: :json, access_token: nil, headers: {})
        @accept        = accept
        @access_token  = access_token
        @payload       = payload
        @url           = url
        @headers       = headers
      end

      def execute
        RestClient::Request.execute(
          method: :post,
          url: url,
          ssl_version: GH::Request.ssl_version,
          payload: payload,
          headers: headers
        )
      end

      def headers
        headers = @headers.merge(accept: :json, content_type: :json)
        headers.merge!('Authorization' => "token #{access_token}") if access_token
        headers
      end

    end

    class << self
      def ssl_version
        'TLSv1'.freeze # TODO make this configurable
      end

      def get(*args)
        GET.new(*args).execute
      end

      def post(*args)
        POST.new(*args).execute
      end
    end

  end
end

{'fraction_non_alphanumeric': 0.08597986057319908, 'fraction_numerical': 0.0010327911179963851, 'mean_word_length': 1.6996515679442508, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '6840988', 'n_tokens_mistral': 1113, 'n_tokens_neox': 1078, 'n_words': 284}