Class: PreviewAdd::Dns
- Inherits:
-
Object
- Object
- PreviewAdd::Dns
- Defined in:
- lib/preview_add/dns.rb
Instance Method Summary collapse
- #add_cname ⇒ Object
- #create_if_not_exists ⇒ Object
-
#initialize(options, host) ⇒ Dns
constructor
A new instance of Dns.
- #record_exists?(hostname) ⇒ Boolean
Constructor Details
#initialize(options, host) ⇒ Dns
Returns a new instance of Dns.
7 8 9 10 11 12 13 14 15 |
# File 'lib/preview_add/dns.rb', line 7 def initialize(, host) Zerigo::DNS::Base.user = [:zerigo][:user] Zerigo::DNS::Base.password = [:zerigo][:api_key] Zerigo::DNS::Base.format = :xml @zone_id = [:zerigo][:zone_id] @host = host @cname = [:zerigo][:cname] end |
Instance Method Details
#add_cname ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/preview_add/dns.rb', line 17 def add_cname vals = { :hostname => @host, :host_type => 'CNAME', :data => @cname, :zone_id => @zone_id } begin Zerigo::DNS::Host.create(vals) rescue Exception => e if e.to_s.include? 'wrong number of arguments (2 for 1)' puts "Successfully created #{@host}.#{@cname}" else puts e end end end |
#create_if_not_exists ⇒ Object
47 48 49 50 51 |
# File 'lib/preview_add/dns.rb', line 47 def create_if_not_exists unless record_exists? @host add_cname end end |
#record_exists?(hostname) ⇒ Boolean
37 38 39 40 41 42 43 44 45 |
# File 'lib/preview_add/dns.rb', line 37 def record_exists?(hostname) begin hosts = Zerigo::DNS::Host.find(:all, :params=>{:zone_id => @zone_id}) hosts.any? { |hash| hash.hostname == hostname } rescue Exception => e puts e exit 1 end end |