<commit_before>#!/usr/bin/env ruby

gem 'rest-client', '~> 1.6.7'
require "rest_client"

# Interface is compatible with RestClient exception
class UnexpectedResponseError < StandardError
  attr_reader :response

  def initialize(response)
    @response = response
  end

  def http_code
    response.code.to_i
  end

  def http_body
    response.body
  end  
end

class Client
  # Establishes initial connection to text_tunneld server
  def initialize(port, file_path)
    @file_path = file_path

    open(file_path, "rb") do |f|
      response = RestClient.post "http://localhost:#{port}/files", :file => f
      raise UnexpectedResponseError.new(response) unless response.code == 201
      @location = response.headers[:location]
      @etag = response.headers[:etag]
    end    
  end

  # Returns true if a change was made
  def poll
    RestClient.get(@location, :if_none_match => @etag) do |response, request, result|
      return false if response.code == 304
      if response.code == 200
        @etag = response.headers[:etag]
        File.write(@file_path, response.body)
        return true
      end

      raise UnexpectedResponseError.new(response)
    end
  end

  def cleanup
    # This call can fail, especially if text_tunnel is terminating because of
    # a previous error. So swallow any errors.
    RestClient.delete(@location) rescue nil
  end
end
<commit_msg>Minor tweak<commit_after>#!/usr/bin/env ruby

gem 'rest-client', '~> 1.6.7'
require "rest_client"

# Interface is compatible with RestClient exception
class UnexpectedResponseError < StandardError
  attr_reader :response

  def initialize(response)
    @response = response
  end

  def http_code
    response.code.to_i
  end

  def http_body
    response.body
  end  
end

class Client
  # Establishes initial connection to text_tunneld server
  def initialize(port, file_path)
    @file_path = file_path

    open(file_path, "rb") do |f|
      response = RestClient.post "http://localhost:#{port}/files", :file => f
      raise UnexpectedResponseError.new(response) unless response.code == 201
      @location = response.headers[:location]
      @etag = response.headers[:etag]
    end    
  end

  # Returns a truthy value if a change was made
  def poll
    response = RestClient.get(@location, :if_none_match => @etag)
    raise UnexpectedResponseError.new(response) unless response.code == 200

    @etag = response.headers[:etag]
    File.write(@file_path, response.body)
  rescue RestClient::NotModified
    false
  end

  def cleanup
    # This call can fail, especially if text_tunnel is terminating because of
    # a previous error. So swallow any errors.
    RestClient.delete(@location) rescue nil
  end
end

{'fraction_non_alphanumeric': 0.08795269770879527, 'fraction_numerical': 0.007760532150776054, 'mean_word_length': 3.3381410256410255, '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': '2234240', 'n_tokens_mistral': 841, 'n_tokens_neox': 800, 'n_words': 244}