<commit_before>module SaasPulse
  BASE_URI = "http://sdr.saaspulse.com/pixel.gif/?sdr_s=".freeze unless self.const_defined?(:BASE_URI)

  class NoClientError < StandardError; end

  class << self
    attr_reader :client

    def track(data)
      raise NoClientError, "You must set the current client first" unless client
      client.track(data)
    end

    def srv_id(srv_id)
      @client = Client.new(srv_id)
    end

    def on?
      !!@on
    end

    def on!
      @on = true
    end
  end

  class Client
    def initialize(srv_id)
      @srv_id = srv_id
    end

    def track(data={})
      url = build_url(data)

      if SaasPulse.on?
        Thread.new {open(url)}
      else
        puts "[SaasPulse] Fake call to #{url}. To make a real call, run SaasPulse.on!"
      end
    end

    def build_url(data)
      [BASE_URI, @srv_id, "&", ArgParser.parse(data).to_params].join
    end
  end
end

<commit_msg>Rescue and log if an error occurs contacting SP<commit_after>module SaasPulse
  BASE_URI = "http://sdr.saaspulse.com/pixel.gif/?sdr_s=".freeze unless self.const_defined?(:BASE_URI)

  class NoClientError < StandardError; end

  class << self
    attr_reader :client

    def track(data)
      raise NoClientError, "You must set the current client first" unless client
      client.track(data)
    end

    def srv_id(srv_id)
      @client = Client.new(srv_id)
    end

    def on?
      !!@on
    end

    def on!
      @on = true
    end
  end

  class Client
    def initialize(srv_id)
      @srv_id = srv_id
    end

    def track(data={})
      url = build_url(data)

      if SaasPulse.on?
        Thread.new do
          begin
            open(url)
          rescue => e
            STDERR.puts "[SaasPulse] ERROR making call to SaaSPulse: #{e.class} ~> #{e.message}"
          end
        end
      else
        puts "[SaasPulse] Fake call to #{url}. To make a real call, run SaasPulse.on!"
      end
    end

    def build_url(data)
      [BASE_URI, @srv_id, "&", ArgParser.parse(data).to_params].join
    end
  end
end


{'fraction_non_alphanumeric': 0.10048780487804879, 'fraction_numerical': 0.0, 'mean_word_length': 2.2097026604068857, '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': '2849551', 'n_tokens_mistral': 741, 'n_tokens_neox': 713, 'n_words': 189}