<commit_before>require 'sinatra/reloader' if development?
require 'ohm'
require 'json'
require 'haml'

require File.join(File.dirname(__FILE__), 'config/db')
require File.join(File.dirname(__FILE__), 'models')
require File.join(File.dirname(__FILE__), 'helpers')

get '/' do
  before do
    content_type "text/html"
  end

  haml :index, :format => :html5
end

before do
  content_type "application/json"
end

namespace "/h" do

  get '/:hostname/:servicename/?' do |hostname, servicename|
    host_service(hostname, servicename).to_json
  end

  get '/:hostname/?' do |hostname|
    host(:name => hostname).to_json
  end

  get '/?' do
    hosts.map {|h| h.to_hash}
    hosts.to_json
  end

  put '/?' do
    begin
      required_params = ["name", "status"]
      data = JSON.parse(request.body.read)
      data.keys.sort == required_params.sort  ? (host = Host.find_or_create(:name => data['name'], :status => data['status'])) : (raise "Missing Parameters")
      if host.valid?
        status 200
        r = {"result" => "success","id" => "#{host.id}","status" => "#{host.status}", "name" => "#{host.name}"}
        r.to_json
      else
        status 500
        r = {"result" => "failure","error" => "#{app.errors}"}
        r.to_json
      end
    rescue Exception => e
      status 500
      r = {"result" => "failure","error" => "#{e.message}"}
      r.to_json
    end
  end
<commit_msg>DELETE support for Hosts<commit_after>require 'sinatra/reloader' if development?
require 'ohm'
require 'json'
require 'haml'

require File.join(File.dirname(__FILE__), 'config/db')
require File.join(File.dirname(__FILE__), 'models')
require File.join(File.dirname(__FILE__), 'helpers')

get '/' do
  before do
    content_type "text/html"
  end

  haml :index, :format => :html5
end

before do
  content_type "application/json"
end

namespace "/h" do

  get '/:hostname/:servicename/?' do |hostname, servicename|
    host_service(hostname, servicename).to_json
  end

  get '/:hostname/?' do |hostname|
    host(:name => hostname).to_json
  end

  get '/?' do
    hosts.map {|h| h.to_hash}
    hosts.to_json
  end

  put '/?' do
    begin
      required_params = ["name", "status"]
      data = JSON.parse(request.body.read)
      data.keys.sort == required_params.sort  ? (host = Host.find_or_create(:name => data['name'], :status => data['status'])) : (raise "Missing Parameters")
      if host.valid?
        status 200
        r = {"result" => "success","id" => "#{host.id}","status" => "#{host.status}", "name" => "#{host.name}"}
        r.to_json
      else
        status 500
        r = {"result" => "failure","error" => "#{app.errors}"}
        r.to_json
      end
    rescue Exception => e
      status 500
      r = {"result" => "failure","error" => "#{e.message}"}
      r.to_json
    end
  end

  delete '/:hostname/?' do
    begin
      host = Host.find(:name => params[:hostname]).first
      if host
        services = []
        Service.find(:host_id => host.id).sort.each {|x| services << x; x.delete} if host.services.size > 0
        host.delete
        status 200
        r = {"result" => "success", "id" => "#{host.id}", "name" => "#{host.name}", "service_count" => "#{services.size}"}
        r.to_json
      else
        status 404
        r = {"result" => "failure","error" => "Host not found"}
        r.to_json
      end
    rescue Exception => e
      status 500
      r = {"result" => "failure", "error" => "#{e.message}"}
      r.to_json
    end
  end

{'fraction_non_alphanumeric': 0.1725129384703853, 'fraction_numerical': 0.008625646923519264, 'mean_word_length': 2.7856365614798695, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 41, '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': '4339042', 'n_tokens_mistral': 1192, 'n_tokens_neox': 1167, 'n_words': 283}