<commit_before>module StraightEngine
  module BlockchainAdapter

    # An almost abstract class, providing guidance for the interfaces of
    # all blockchain adapters as well as supplying some useful methods.
    
    # Raised when blockchain data cannot be retrived for any reason.
    # We're not really intereste in the precise reason, although it is
    # stored in the message.
    class RequestError < Exception; end

    class Base

      require 'json'
      require 'uri'
      require 'open-uri'
      require 'yaml'

      class << self

        # Returns transaction info for the tid
        def fetch_transaction(tid)
        end

        # Returns all transactions for the address
        def fetch_transactions_for(address)
        end

        # This method is a wrapper for creating an HTTP request
        # to various services that ancestors of this class may use
        # to retrieve blockchain data. Why do we need a wrapper?
        # Because it respects timeouts.
        def http_request(url)
          uri = URI.parse(url)
          begin
            http = uri.read
          rescue OpenURI::HTTPError => e
            raise RequestError, YAML::dump(e)
          end
        end

      private

        # Converts transaction info received from the source into the
        # unified format expected by users of BlockchainAdapter instances.
        def straighten_transaction(transaction)
        end

      end

    end

  end
end
<commit_msg>Add read timeout to BlockchainAdapter::Base.http_request<commit_after>module StraightEngine
  module BlockchainAdapter

    # An almost abstract class, providing guidance for the interfaces of
    # all blockchain adapters as well as supplying some useful methods.
    
    # Raised when blockchain data cannot be retrived for any reason.
    # We're not really intereste in the precise reason, although it is
    # stored in the message.
    class RequestError < Exception; end

    class Base

      require 'json'
      require 'uri'
      require 'open-uri'
      require 'yaml'

      class << self

        # Returns transaction info for the tid
        def fetch_transaction(tid)
        end

        # Returns all transactions for the address
        def fetch_transactions_for(address)
        end

        # This method is a wrapper for creating an HTTP request
        # to various services that ancestors of this class may use
        # to retrieve blockchain data. Why do we need a wrapper?
        # Because it respects timeouts.
        def http_request(url)
          uri = URI.parse(url)
          begin
            http = uri.read(read_timeout: 4)
          rescue OpenURI::HTTPError => e
            raise RequestError, YAML::dump(e)
          end
        end

      private

        # Converts transaction info received from the source into the
        # unified format expected by users of BlockchainAdapter instances.
        def straighten_transaction(transaction)
        end

      end

    end

  end
end

{'fraction_non_alphanumeric': 0.04330446369087275, 'fraction_numerical': 0.00033311125916055963, 'mean_word_length': 2.164383561643836, 'pattern_counts': {'":': 0, '<': 9, '<?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': '3099461', 'n_tokens_mistral': 751, 'n_tokens_neox': 704, 'n_words': 321}