Class: Domrobot::Cli

Inherits:
Thor
  • Object
show all
Defined in:
lib/domrobot/cli.rb

Instance Method Summary collapse

Instance Method Details

#configure(file = nil) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/domrobot/cli.rb', line 10

def configure file=nil
  config   = file and Config.load file 
  config ||= Config
  config.general.username = options["username"] if options["username"]
  config.general.password = options["password"] if options["password"]
  config.general.server   = options["server"]   if options["server"]
  if file
    config.save(file)
  else
    config.save
  end
end

#updateRecord(name) ⇒ Object

Raises:

  • (Exceptions)


31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/domrobot/cli.rb', line 31

def updateRecord name
  success_callbacks = []
  if options["touch"]
    require "fileutils"
    success_callbacks << Proc.new do |message,data|
      FileUtils.mkdir_p File.dirname options["touch"]
      File.write options["touch"], [message,data].join("\n")
    end
  end
  if options["default_address"]
    require "domrobot/address"
    address = Domrobot::Address.default
  else
    address = options["address"]
  end
  raise Exceptions unless address
  subdomain = Subdomain.construct options["subdomain"]
  domain    = options["domain"]
  name      = [name,subdomain,domain].join(".")
  type      = options["type"]
  record    = Record.find_by domain:domain, name:name
  unless record
    puts "NEW"
    record = Record.new domain:domain,name:name,type:type,content:address
    result = record.save
    if result["code"] = 1000
      m,d = "OK NOOP","#{address} A #{name}."
      puts m
      success_callbacks.map{|cb| cb.call(m,d)} and exit 0
    end
    exit 1
  end
  if record.content == address
    m,d = "OK NOOP","#{address} A #{name}."
    puts m
    success_callbacks.map{|cb| cb.call(m,d) } and exit 0
  end
end