<commit_before>require 'typhoeus'
require 'stringio'

class RAWS::HTTP::Typhoeus
  def self.connect(uri, &block)
    response = nil
    begin
      response = block.call(Request.new(uri))
    rescue RAWS::HTTP::Redirect => e
      r = e.response
      uri = r.header['location'] || r.doc['Error']['Endpoint']
      retry
    end
    response
  end

  class Request < RAWS::HTTP::Request
    attr_reader :header
    attr_accessor :uri, :method

    def initialize(uri)
      @uri, @header, @method, @before_send = uri, {}, :get , nil
    end

    def before_send(&block)
      @before_send = block
    end

    def send(body=nil, &block)
      RAWS.logger.debug self
      @before_send && @before_send.call(self)
      response = Response.new(
        ::Typhoeus::Request.__send__(
          @method.downcase.to_sym,
          @uri,
          :headers => @header,
          :body => if block_given?
            # TODO エラーにした方が。。。　
            io = StringIO.new
            block.call(io)<commit_msg>Typhoeus の method に symbole を渡すとエラーになるのを直した<commit_after>require 'typhoeus'
require 'stringio'

class RAWS::HTTP::Typhoeus
  def self.connect(uri, &block)
    response = nil
    begin
      response = block.call(Request.new(uri))
    rescue RAWS::HTTP::Redirect => e
      r = e.response
      uri = r.header['location'] || r.doc['Error']['Endpoint']
      retry
    end
    response
  end

  class Request < RAWS::HTTP::Request
    attr_reader :header
    attr_accessor :uri, :method

    def initialize(uri)
      @uri, @header, @method, @before_send = uri, {}, :get , nil
    end

    def before_send(&block)
      @before_send = block
    end

    def send(body=nil, &block)
      RAWS.logger.debug self
      @before_send && @before_send.call(self)
      response = Response.new(
        ::Typhoeus::Request.__send__(
          @method.to_s.downcase.to_sym,
          @uri,
          :headers => @header,
          :body => if block_given?
            # TODO エラーにした方が。。。　
            io = StringIO.new
            block.call(io)
{'fraction_non_alphanumeric': 0.12456917774495323, 'fraction_numerical': 0.0, 'mean_word_length': 2.3476112026359144, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, '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': '4088842', 'n_tokens_mistral': 696, 'n_tokens_neox': 676, 'n_words': 146}