example/sample.rb in zerigo_dns-1.0.5 vs example/sample.rb in zerigo_dns-1.0.6
- old
+ new
@@ -1,11 +1,11 @@
# Copyright 2009 Zerigo, Inc. See MIT-LICENSE for license information.
# Visit http://www.zerigo.com/docs/managed-dns for updates and documentation.
# First, require the Zerigo DNS library for ActiveResource.
-require 'zerigo_ns'
+require 'zerigo_dns'
# All API request require a Zerigo account and an Account API key. We'll set
# them here for later reference. The 'user' is your regular login email.
# The 'password' is your API key and comes from the Preferences page
# (Manage Account -> NS -> Preferences).
@@ -26,11 +26,11 @@
# instance methods: the_zone.domain
# All attributes will have underscores in the name instead of dashes.
# eg: zone.default_ttl, not zone.default-ttl
puts '', "Retrieving list of first 20 zones..."
-zones = Zerigo::NS::Zone.find(:all, :params=>{:per_page=>20, :page=>1})
+zones = Zerigo::DNS::Zone.find(:all, :params=>{:per_page=>20, :page=>1})
# Now print a list of those zones
zones.each do |zone|
puts " #{zone.domain} (id: #{zone.id})"
end
@@ -47,11 +47,11 @@
# We'll list all hosts for the first zone from the last request.
zone = zones.first
puts '', "Hosts for zone #{zone.domain} (id: #{zone.id})"
-hosts = Zerigo::NS::Host.find(:all, :params=>{:zone_id=>zone.id, :per_page=>20, :page=>1})
+hosts = Zerigo::DNS::Host.find(:all, :params=>{:zone_id=>zone.id, :per_page=>20, :page=>1})
hosts.each do |host|
puts " #{host.hostname} (id: #{host.id})"
end
# While not demonstrated here, host.last_count works just like for
@@ -60,20 +60,20 @@
# Now we'll load a single zone. In this case, it's the first zone returned in
# the last request.
puts '', "Loading a single zone..."
-zone = Zerigo::NS::Zone.find(zones.first.id)
+zone = Zerigo::DNS::Zone.find(zones.first.id)
puts " Loaded zone #{zone.id} (#{zone.domain})"
# Now we'll try to load a non-existent zone and catch the error.
puts '', "Loading a non-existent zone..."
begin
- zone2 = Zerigo::NS::Zone.find(987654321)
+ zone2 = Zerigo::DNS::Zone.find(987654321)
puts " Loaded zone #{zone2.id} (#{zone2.domain})"
rescue ActiveResource::ResourceNotFound
puts " Zone not found"
end
@@ -83,11 +83,11 @@
puts '', "Creating a random zone that is invalid..."
now = Time.now.to_i
vals = {:domain=>"example-#{now}.org", :ns_type=>'not_valid' }
-newzone = Zerigo::NS::Zone.create(vals)
+newzone = Zerigo::DNS::Zone.create(vals)
if newzone.errors.empty?
puts " Zone #{newzone.domain} created successfully with id #{newzone.id}."
else
puts " There was an error saving the new zone."
newzone.errors.each {|attr, msg| puts " #{attr} #{msg}"}
@@ -97,11 +97,11 @@
puts '', "Fixing and resubmitting that random zone..."
vals[:ns_type] = 'pri_sec' # options for this are 'pri_sec' (the default and most common), 'pri', and 'sec' -- see the API docs for details
-newzone = Zerigo::NS::Zone.create(vals)
+newzone = Zerigo::DNS::Zone.create(vals)
if newzone.errors.empty?
puts " Zone #{newzone.domain} created successfully with id #{newzone.id}."
else
puts " There was an error saving the new zone."
newzone.errors.each {|attr, msg| puts " #{attr} #{msg}"}
@@ -133,10 +133,10 @@
:zone_id=>newzone.id
}
# A host has to be assigned to a zone. This is done by including 'zone_id'
# in the vals2 hash.
-newhost = Zerigo::NS::Host.create(vals2)
+newhost = Zerigo::DNS::Host.create(vals2)
if newhost.errors.empty?
puts " Host #{newhost.hostname} created successfully with id #{newhost.id}."
else
puts " There was an error saving the new host."
newhost.errors.each {|attr, msg| puts " #{attr} #{msg}"}