Class: DNSimple::Commands::RegisterDomain

Inherits:
Object
  • Object
show all
Defined in:
lib/dnsimple/commands/register_domain.rb

Instance Method Summary collapse

Instance Method Details

#execute(args, options = {}) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/dnsimple/commands/register_domain.rb', line 4

def execute(args, options={})
  name = args.shift
  registrant = nil

  registrant_id_or_attribute = args.shift
  if registrant_id_or_attribute
    if registrant_id_or_attribute =~ /^\d+$/
      registrant = {:id => registrant_id_or_attribute}
    else
      args.unshift(registrant_id_or_attribute)
    end
  end

  extended_attributes = {}
  args.each do |arg|
    n, v = arg.split(":")
    extended_attributes[n] = v
  end

  domain = Domain.register(name, registrant, extended_attributes)
  puts "Registered #{domain.name}"

  if template = options.delete(:template)
    domain.apply(template)
    puts "Applied template #{template} to #{domain.name}"
  end
end