<commit_before># coding: UTF-8

require 'faraday'

module Daddy
  class HttpClient
  
    def initialize(url, options = {})
      @url = url
      @options = options
      @cookie = nil
      Rails.logger.debug "[HttpClient] url: #{@url}"
    end
    
    def get(path, params = {})
      Rails.logger.debug "[HttpClient] path: #{path}"
      Rails.logger.debug "[HttpClient] params: #{params}"

      response = connection.get(path, params) do |request|
        if @options[:auth_user] and @options[:auth_password]
          basic = Base64.encode64(@options[:auth_user] + ':' + @options[:auth_password])
          request.headers['Authorization'] = 'Basic ' + basic
        end
        
        if @cookie
          request.headers['Cookie'] = @cookie
        end
        
        params.each do |key, value|
          request.params[key] = value
        end
      end
      
      @cookie = response.headers['set-cookie']
      
      if block_given?
        yield response
      else
        Rails.logger.debug "[HttpClient] stutus: #{response.status}"
        response.body.force_encoding('UTF-8')
      end
    end
  
    def post(path, params = {})
      response = connection.post(path, params)
    end

    private
  
    def connection
      Faraday.new(:url => @url, :ssl => ssl_options) do |faraday|
        faraday.request :url_encoded
        faraday.adapter Faraday.default_adapter
      end
    end
    <commit_msg>Basic認証<commit_after># coding: UTF-8

require 'faraday'

module Daddy
  class HttpClient
  
    def initialize(url, options = {})
      @url = url
      @options = options
      @cookie = nil
      Rails.logger.debug "[HttpClient] url: #{@url}"
    end
    
    def get(path, params = {})
      Rails.logger.debug "[HttpClient] path: #{path}"
      Rails.logger.debug "[HttpClient] params: #{params}"

      response = connection.get(path, params) do |request|
        if @options[:auth_user] and @options[:auth_password]
          basic = Base64.encode64(@options[:auth_user] + ':' + @options[:auth_password])
          request.headers['Authorization'] = 'Basic ' + basic
        end
        
        if @cookie
          Rails.logger.debug "[HttpClient] cookie: #{@cookie}"
          request.headers['Cookie'] = @cookie
        end
        
        params.each do |key, value|
          request.params[key] = value
        end
      end
      
      @cookie = response.headers['set-cookie']
      
      if block_given?
        yield response
      else
        Rails.logger.debug "[HttpClient] stutus: #{response.status}"
        response.body.force_encoding('UTF-8')
      end
    end
  
    def post(path, params = {})
      response = connection.post(path, params)
    end

    private
  
    def connection
      Faraday.new(:url => @url, :ssl => ssl_options) do |faraday|
        faraday.request :url_encoded
        faraday.adapter Faraday.default_adapter
      end
    end
    
{'fraction_non_alphanumeric': 0.11964346931779225, 'fraction_numerical': 0.00411381556393555, 'mean_word_length': 2.127545551982851, 'pattern_counts': {'":': 0, '<': 3, '<?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': '738295', 'n_tokens_mistral': 881, 'n_tokens_neox': 866, 'n_words': 202}