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

class Chef
  module ThalassaAqueduct

    def request(req_type, path, body = nil)
      request = case req_type
        when :get    then Net::HTTP::Get.new(path)
        when :post   then Net::HTTP::Post.new(path)
        when :put    then Net::HTTP::Put.new(path)
        when :delete then Net::HTTP::Delete.new(path)
      end
      request.add_field "Content-Type", "application/json"
      request.body = body
      http = Net::HTTP.new(node[:thalassa_aqueduct][:host], node[:thalassa_aqueduct][:port])
      http.request(request)
    end

    def create_frontend
      response = request(:put, "/frontends/#{new_resource}", {
        :bind => new_resource.bind,
        :backend => new_resource.backend,
        :mode => new_resource.mode,
        :keepalive => new_resource.keepalive,
        :rules => new_resource.rules,
        :natives => new_resource.natives
      }.to_json)

      unless Net::HTTPOK === response || Net::HTTPCreated === response
        raise "Could not create thalassa frontend #{new_resource}: #{response.body}"
      end

      response
    end

    def delete_frontend
      request :delete, "/frontends/#{new_resource}"
    end

    def create_backend
      params = {
        :type => new_resource.type,
        :version => new_resource.version,
        :balance => new_resource.balance,
        :host => new_resource.host,
        :mode => new_resource.mode,
        :health => new_resource.health,
        :members => new_resource.members,
        :natives => new_resource.natives
      }

      params[:role] = new_resource.role unless new_resource.role.nil?

      response = request(:put, "/backends/#{new_resource}", params.to_json)

      unless Net::HTTPOK === response || Net::HTTPCreated === response
        raise "Could not create thalassa backend #{new_resource}: #{response.body}"
      end

      response
    end

    def delete_backend
      request :delete, "/backends/#{new_resource.name}"
    end

  end
end<commit_msg>Using name<commit_after>require 'json'
require 'net/https'

class Chef
  module ThalassaAqueduct

    def request(req_type, path, body = nil)
      request = case req_type
        when :get    then Net::HTTP::Get.new(path)
        when :post   then Net::HTTP::Post.new(path)
        when :put    then Net::HTTP::Put.new(path)
        when :delete then Net::HTTP::Delete.new(path)
      end
      request.add_field "Content-Type", "application/json"
      request.body = body
      http = Net::HTTP.new(node[:thalassa_aqueduct][:host], node[:thalassa_aqueduct][:port])
      http.request(request)
    end

    def create_frontend
      response = request(:put, "/frontends/#{new_resource.name}", {
        :bind => new_resource.bind,
        :backend => new_resource.backend,
        :mode => new_resource.mode,
        :keepalive => new_resource.keepalive,
        :rules => new_resource.rules,
        :natives => new_resource.natives
      }.to_json)

      unless Net::HTTPOK === response || Net::HTTPCreated === response
        raise "Could not create thalassa frontend #{new_resource.name}: #{response.body}"
      end

      response
    end

    def delete_frontend
      request :delete, "/frontends/#{new_resource.name}"
    end

    def create_backend
      params = {
        :type => new_resource.type,
        :version => new_resource.version,
        :balance => new_resource.balance,
        :host => new_resource.host,
        :mode => new_resource.mode,
        :health => new_resource.health,
        :members => new_resource.members,
        :natives => new_resource.natives
      }

      params[:role] = new_resource.role unless new_resource.role.nil?

      response = request(:put, "/backends/#{new_resource.name}", params.to_json)

      unless Net::HTTPOK === response || Net::HTTPCreated === response
        raise "Could not create thalassa backend #{new_resource.name}: #{response.body}"
      end

      response
    end

    def delete_backend
      request :delete, "/backends/#{new_resource.name}"
    end

  end
end
{'fraction_non_alphanumeric': 0.12389597644749754, 'fraction_numerical': 0.0, 'mean_word_length': 2.682926829268293, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 31, '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': '337773', 'n_tokens_mistral': 1254, 'n_tokens_neox': 1211, 'n_words': 268}