class Classification
Public Class Methods
new(nc_api_url, puppet_https)
click to toggle source
# File lib/puppetclassify/classification.rb, line 4 def initialize(nc_api_url, puppet_https) @nc_api_url = nc_api_url @puppet_https = puppet_https end
Public Instance Methods
explain(name, facts={})
click to toggle source
# File lib/puppetclassify/classification.rb, line 25 def explain(name, facts={}) unless facts.class == Hash STDERR.puts "Facts should be a hash, not a #{facts.class}" return false end class_res = @puppet_https.post("#{@nc_api_url}/v1/classified/nodes/#{name}/explanation", facts.to_json) unless class_res.code.to_i == 200 STDERR.puts "An error occured retreiving the classification explanation of node #{name}: HTTP #{class_res.code} #{class_res.message}" STDERR.puts class_res.body else JSON.parse(class_res.body) end end
get(name, facts={})
click to toggle source
# File lib/puppetclassify/classification.rb, line 9 def get(name, facts={}) unless facts.class == Hash STDERR.puts "Facts should be a hash, not a #{facts.class}" return false end class_res = @puppet_https.post("#{@nc_api_url}/v1/classified/nodes/#{name}", facts.to_json) unless class_res.code.to_i == 200 STDERR.puts "An error occured retreiving the classification of node #{name}: HTTP #{class_res.code} #{class_res.message}" STDERR.puts class_res.body else JSON.parse(class_res.body) end end