<commit_before># This set of classes provides a Ruby interface to Hudson's web xml API
# 
# Author:: <NAME>

require 'net/http'
require 'uri'
require 'rexml/document'
require 'cgi'
require 'yaml'
require 'zlib'
require File.dirname(__FILE__) + '/hudson-remote-api/config.rb'

module Hudson
  # Base class for all Hudson objects
  class HudsonObject
    
    
    def self.load_xml_api
      @@hudson_xml_api_path = File.join(Hudson[:url], "api/xml")
      @@xml_api_create_item_path = File.join(Hudson[:url], "createItem")
    end
    
    load_xml_api
    
    def self.get_xml(url)
      uri = URI.parse(url)
      host = uri.host
      port = uri.port
      path = uri.path
      request = Net::HTTP::Get.new(path)
      request.basic_auth(Hudson[:user], Hudson[:password]) if Hudson[:user] and Hudson[:password]
      request['Content-Type'] = "text/xml"
      response = Net::HTTP.start(host, port){|http| http.request(request)}

      if response.is_a?(Net::HTTPSuccess) or response.is_a?(Net::HTTPRedirection)
        encoding = response.get_fields("Content-Encoding")
        if encoding and encoding.include?("gzip")
          return Zlib::GzipReader.new(StringIO.new(response.body)).read
        else
          return response.body
        end
      else
        puts response
        raise APIError, "Error retrieving #{path}"
      end
    end

    def get_xml(path)
      self.class.get_xml(path)
    end

    def self.send_post_request(url, data={})
      uri = URI.parse(url)
      host = uri.host
      port = uri.port
      path = uri.path
      request = Net::HTTP::Post.new(path)<commit_msg>fixed https support<commit_after># This set of classes provides a Ruby interface to Hudson's web xml API
# 
# Author:: <NAME>

require 'net/http'
require "net/https"
require 'uri'
require 'rexml/document'
require 'cgi'
require 'yaml'
require 'zlib'
require File.dirname(__FILE__) + '/hudson-remote-api/config.rb'

module Hudson
  # Base class for all Hudson objects
  class HudsonObject
    
    
    def self.load_xml_api
      @@hudson_xml_api_path = File.join(Hudson[:url], "api/xml")
      @@xml_api_create_item_path = File.join(Hudson[:url], "createItem")
    end
    
    load_xml_api
    
    def self.get_xml(url)
      uri = URI.parse(url)
      host = uri.host
      port = uri.port
      path = uri.path
      request = Net::HTTP::Get.new(path)
      request.basic_auth(Hudson[:user], Hudson[:password]) if Hudson[:user] and Hudson[:password]
      request['Content-Type'] = "text/xml"
      response = Net::HTTP.start(host, port) do |http| 
        http = Net::HTTP.new(uri.host, uri.port)
        if uri.scheme == 'https'
          http.use_ssl = true
          http.verify_mode = OpenSSL::SSL::VERIFY_NONE
        end
        http.request(request)
      end

      if response.is_a?(Net::HTTPSuccess) or response.is_a?(Net::HTTPRedirection)
        encoding = response.get_fields("Content-Encoding")
        if encoding and encoding.include?("gzip")
          return Zlib::GzipReader.new(StringIO.new(response.body)).read
        else
          return response.body
        end
      else
        puts response
        raise APIError, "Error retrieving #{path}"
      end
    end

    def get_xml(path)
      self.class.get_xml(path)
    end

    def self.send_post_request(url, data={})
      uri = URI.parse(url)
      host = uri.host
      port = uri.port
      path = uri.path
      request = Net::HTTP::Post.new(path)
{'fraction_non_alphanumeric': 0.120429483459083, 'fraction_numerical': 0.0, 'mean_word_length': 2.702470461868958, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 22}, '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': '3709386', 'n_tokens_mistral': 1118, 'n_tokens_neox': 1099, 'n_words': 253}