<commit_before>require 'puppet'
require 'open-uri'
require 'net/http'
require 'json'

class Puppet::Provider::XLReleaseRestProvider < Puppet::Provider

  # def rest_get(service)
  #   begin
  #     response = RestClient.get "#{resource[:rest_url]}/#{service}", {:accept => :xml, :content_type => :xml }
  #   rescue Exception => e
  #     return e.message
  #   end
  # end
  #
  # def rest_post(service, body='')
  #   RestClient.post "#{resource[:rest_url]}/#{service}", body, {:content_type => :xml }
  # end
  #
  # def rest_put(service, body='')
  #   RestClient.put "#{resource[:rest_url]}/#{service}", body, {:content_type => :xml }
  # end
  #
  # def rest_delete(service)
  #   RestClient.delete "#{resource[:rest_url]}/#{service}", {:accept => :xml, :content_type => :xml }
  # end

  def rest_get(service)
    execute_rest(service, 'get')
  end

  def rest_post(service, body='')
    execute_rest(service, 'post', body)
  end

  def rest_put(service, body='')
    execute_rest(service, 'put', body)
  end

  def rest_delete(service)
    execute_rest(service, 'delete')
  end

  def execute_rest(service, method, body='')

    uri = URI.parse("#{resource[:rest_url]}/#{service}")

    http = Net::HTTP.new(uri.host, uri.port)
    request = case method
                when 'get'    then Net::HTTP::Get.new(uri.request_uri)
                when 'post'   then Net::HTTP::Post.new(uri.request_uri)
                when 'put'    then Net::HTTP::Put.new(uri.request_uri)
                when 'delete' then Net::HTTP::Delete.new(uri.request_uri)
              end
    #p request.pretty_print_inspect

    request.basic_auth(uri.user, uri.password) if uri.user and uri.password
    request.body = body unless body == ''
    request.content_type = 'application/json'

    begin
      res = http.request(request)
      raise Puppet::Error, "cannot send request to deployit server #{res.code}/#{res.message}:#{res.body}" unless res.is_a?(Net::HTTPSuccess)
      return res.body
    rescue Exception => e
      p e.message
      return e.message
    end

  end

  def to_json(id, type, properties)
    json_hash = {"id" => id, "type" => type}.merge(properties)
    p json_hash
    return json_hash
  end

  def to_hash(json)
    p JSON.parse(json)
    JSON.parse(json)
  end


end

<commit_msg> added some ci stuff<commit_after>require 'puppet'
require 'open-uri'
require 'net/http'
require 'json'

class Puppet::Provider::XLReleaseRestProvider < Puppet::Provider

  # def rest_get(service)
  #   begin
  #     response = RestClient.get "#{resource[:rest_url]}/#{service}", {:accept => :xml, :content_type => :xml }
  #   rescue Exception => e
  #     return e.message
  #   end
  # end
  #
  # def rest_post(service, body='')
  #   RestClient.post "#{resource[:rest_url]}/#{service}", body, {:content_type => :xml }
  # end
  #
  # def rest_put(service, body='')
  #   RestClient.put "#{resource[:rest_url]}/#{service}", body, {:content_type => :xml }
  # end
  #
  # def rest_delete(service)
  #   RestClient.delete "#{resource[:rest_url]}/#{service}", {:accept => :xml, :content_type => :xml }
  # end

  def rest_get(service)
    execute_rest(service, 'get')
  end

  def rest_post(service, body='')
    execute_rest(service, 'post', body)
  end

  def rest_put(service, body='')
    execute_rest(service, 'put', body)
  end

  def rest_delete(service)
    execute_rest(service, 'delete')
  end

  def execute_rest(service, method, body='')

    uri = URI.parse("#{resource[:rest_url]}/#{service}")

    http = Net::HTTP.new(uri.host, uri.port)
    request = case method
                when 'get'    then Net::HTTP::Get.new(uri.request_uri)
                when 'post'   then Net::HTTP::Post.new(uri.request_uri)
                when 'put'    then Net::HTTP::Put.new(uri.request_uri)
                when 'delete' then Net::HTTP::Delete.new(uri.request_uri)
              end
    #p request.pretty_print_inspect

    request.basic_auth(uri.user, uri.password) if uri.user and uri.password
    request.body = body unless body == ''
    request.content_type = 'application/json'

    begin
      p request
      res = http.request(request)
      raise Puppet::Error, "cannot send request to deployit server #{res.code}/#{res.message}:#{res.body}" unless res.is_a?(Net::HTTPSuccess)
      return res.body
    rescue Exception => e
      p e.message
      return e.message
    end

  end

  def to_json(id, type, properties)
    json_hash = {"id" => id, "type" => type}.merge(properties)
    p json_hash
    return json_hash
  end

  def to_hash(json)
    p JSON.parse(json)
    JSON.parse(json)
  end


end


{'fraction_non_alphanumeric': 0.14927316120633544, 'fraction_numerical': 0.0, 'mean_word_length': 3.1271262309758283, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 12}, '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': '5382593', 'n_tokens_mistral': 1576, 'n_tokens_neox': 1550, 'n_words': 344}