Class: KRL_CMD::Check

Inherits:
Object
  • Object
show all
Defined in:
lib/check.rb

Class Method Summary collapse

Class Method Details

.go(args) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/check.rb', line 3

def self.go(args)
  require LIB_DIR + 'common'
  require 'json'
  app = KRL_COMMON::get_app
  krl_file = File.join(Dir.pwd, app.application_id + ".krl")
  raise "Cannot find .krl file." unless File.exists?(krl_file)
  if args.to_s == ""
    apiurl = "http://krl.kobj.net/manage/parse/ruleset"
  else
    apiurl = args.to_s
  end
  apiargs = { "krl" => File.open(krl_file, 'r') { |f| f.read } }
  validateresponse = Net::HTTP.post_form(URI.parse(apiurl), apiargs).body.to_s
  jdata = JSON.parse(validateresponse, { :max_nesting => false })
  if jdata["error"]
    puts "Errors:"
    puts jdata["error"]
  else
    puts "OK"
  end
end