<commit_before>require 'faraday'
require 'time'
require 'uri'
require 'openssl'
require 'base64'

module Tumblr
  module Request
    class TumblrOAuth < Faraday::Middleware
      def call(env)
        if env[:method].to_s == "get"
            params = Faraday::Utils.parse_query(env[:url].query) || {}
            url = "#{env[:url].scheme}://#{env[:url].host}#{env[:url].path}"
        else
            params = env[:body] || {}
            url = env[:url]
        end
        signature_params = params
        params.each do |key, value|
          signature_params = {} if value.respond_to?(:content_type)
        end
        env[:request_headers]["Authorization"] = self.oauth_gen(env[:method], url, signature_params) 
        env[:request_headers]["Content-type"] = "application/x-www-form-urlencoded"                                                                              
        env[:request_headers]["Host"] = "api.tumblr.com"
        

        @app.call(env)
      end

      def initialize(app, options={})
        @app, @options = app, options
      end

      def oauth_gen(method, url, params)
         params[:oauth_consumer_key] = @options[:consumer_key]
         params[:oauth_nonce] = Time.now.to_i
         params[:oauth_signature_method] = 'HMAC-SHA1'
         params[:oauth_timestamp] = Time.now.to_i
         params[:oauth_token] = @options[:token]
         params[:oauth_version] = "1.0"
         params[:oauth_signature] = self.oauth_sig(method, url, params)
         
         header = []<commit_msg>Change how the nonce is generated<commit_after>require 'faraday'
require 'time'
require 'uri'
require 'openssl'
require 'base64'

module Tumblr
  module Request
    class TumblrOAuth < Faraday::Middleware
      def call(env)
        if env[:method].to_s == "get"
            params = Faraday::Utils.parse_query(env[:url].query) || {}
            url = "#{env[:url].scheme}://#{env[:url].host}#{env[:url].path}"
        else
            params = env[:body] || {}
            url = env[:url]
        end
        signature_params = params
        params.each do |key, value|
          signature_params = {} if value.respond_to?(:content_type)
        end
        env[:request_headers]["Authorization"] = self.oauth_gen(env[:method], url, signature_params) 
        env[:request_headers]["Content-type"] = "application/x-www-form-urlencoded"                                                                              
        env[:request_headers]["Host"] = "api.tumblr.com"
        

        @app.call(env)
      end

      def initialize(app, options={})
        @app, @options = app, options
      end

      def oauth_gen(method, url, params)
         params[:oauth_consumer_key] = @options[:consumer_key]
         params[:oauth_nonce] = Base64.encode64(OpenSSL::Random.random_bytes(32)).gsub(/\W/, '')
         params[:oauth_signature_method] = 'HMAC-SHA1'
         params[:oauth_timestamp] = Time.now.to_i
         params[:oauth_token] = @options[:token]
         params[:oauth_version] = "1.0"
         params[:oauth_signature] = self.oauth_sig(method, url, params)
         
         header = []
{'fraction_non_alphanumeric': 0.13765570105397637, 'fraction_numerical': 0.005110188438198659, 'mean_word_length': 2.1732522796352582, 'pattern_counts': {'":': 0, '<': 5, '<?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': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3715259', 'n_tokens_mistral': 959, 'n_tokens_neox': 927, 'n_words': 167}