<commit_before>require 'cgi'
require 'net/https'

module Intercom
  class Request
    attr_accessor :path, :net_http_method

    def initialize(path, net_http_method)
      self.path = path
      self.net_http_method = net_http_method
    end

    def set_common_headers(method, base_uri)
      method.basic_auth(CGI.unescape(base_uri.user), CGI.unescape(base_uri.password))
      method.add_field('AcceptEncoding', 'gzip, deflate')
    end

    def self.get(path, params)
      new(path, Net::HTTP::Get.new(append_query_string_to_url(path, params), default_headers))
    end

    def self.post(path, form_data)
      new(path, method_with_body(Net::HTTP::Post, path, form_data))
    end

    def self.delete(path, params)
      new(path, method_with_body(Net::HTTP::Delete, path, params))
    end

    def self.put(path, form_data)
      new(path, method_with_body(Net::HTTP::Put, path, form_data))
    end

    def self.method_with_body(http_method, path, params)
      request = http_method.send(:new, path, default_headers)
      request.body = params.to_json
      request["Content-Type"] = "application/json"
      request
    end

    def self.default_headers
      {'Accept-Encoding' => 'gzip, deflate', 'Accept' => 'application/vnd.intercom.3+json'}
    end

    def client(uri)
      net = Net::HTTP.new(uri.host, uri.port)
      if uri.is_a?(URI::HTTPS)<commit_msg>Add user agent header.<commit_after>require 'cgi'
require 'net/https'

module Intercom
  class Request
    attr_accessor :path, :net_http_method

    def initialize(path, net_http_method)
      self.path = path
      self.net_http_method = net_http_method
    end

    def set_common_headers(method, base_uri)
      method.basic_auth(CGI.unescape(base_uri.user), CGI.unescape(base_uri.password))
      method.add_field('AcceptEncoding', 'gzip, deflate')
    end

    def self.get(path, params)
      new(path, Net::HTTP::Get.new(append_query_string_to_url(path, params), default_headers))
    end

    def self.post(path, form_data)
      new(path, method_with_body(Net::HTTP::Post, path, form_data))
    end

    def self.delete(path, params)
      new(path, method_with_body(Net::HTTP::Delete, path, params))
    end

    def self.put(path, form_data)
      new(path, method_with_body(Net::HTTP::Put, path, form_data))
    end

    def self.method_with_body(http_method, path, params)
      request = http_method.send(:new, path, default_headers)
      request.body = params.to_json
      request["Content-Type"] = "application/json"
      request
    end

    def self.default_headers
      {'Accept-Encoding' => 'gzip, deflate', 'Accept' => 'application/vnd.intercom.3+json', 'User-Agent' => "Intercom-Ruby/#{Intercom::VERSION}"}
    end

    def client(uri)
      net = Net::HTTP.new(uri.host, uri.port)
      if uri.is_a?(URI::HTTPS)
{'fraction_non_alphanumeric': 0.125044404973357, 'fraction_numerical': 0.0007104795737122557, 'mean_word_length': 3.6239737274220034, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 8, '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': '2096331', 'n_tokens_mistral': 967, 'n_tokens_neox': 947, 'n_words': 182}