zerigo_dns 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Tom Wilson
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,18 @@
1
+ = zerigo_dns
2
+
3
+ Zerigo DNS Gem
4
+
5
+ == Credit goes to Zerigo DNS
6
+
7
+ Copyright 2009 Zerigo, Inc. See MIT-LICENSE for license information.
8
+ Visit http://www.zerigo.com/docs/managed-dns for updates and documentation.
9
+
10
+ I just put there sample code into a gem library for deployment ease. And chef
11
+ integration.
12
+
13
+ If you have any questions contact zerigo_dns_gem@jackhq.com
14
+
15
+
16
+ == Copyright
17
+
18
+ Copyright 2009 Zerigo, Inc. See MIT-LICENSE for license information.
data/Rakefile ADDED
@@ -0,0 +1,54 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "zerigo_dns"
8
+ gem.summary = %Q{Zerigo DNS Gem}
9
+ gem.description = %Q{This gem is a resource wrapper of the example provide by zerigo dns}
10
+ gem.email = "tom@jackhq.com"
11
+ gem.homepage = "http://github.com/twilson63/zerigo_dns"
12
+ gem.authors = ["Tom Wilson"]
13
+ gem.add_dependency "active_resource"
14
+ gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
15
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
16
+ end
17
+ Jeweler::GemcutterTasks.new
18
+ rescue LoadError
19
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
20
+ end
21
+
22
+ require 'rake/testtask'
23
+ Rake::TestTask.new(:test) do |test|
24
+ test.libs << 'lib' << 'test'
25
+ test.pattern = 'test/**/test_*.rb'
26
+ test.verbose = true
27
+ end
28
+
29
+ begin
30
+ require 'rcov/rcovtask'
31
+ Rcov::RcovTask.new do |test|
32
+ test.libs << 'test'
33
+ test.pattern = 'test/**/test_*.rb'
34
+ test.verbose = true
35
+ end
36
+ rescue LoadError
37
+ task :rcov do
38
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
39
+ end
40
+ end
41
+
42
+ task :test => :check_dependencies
43
+
44
+ task :default => :test
45
+
46
+ require 'rake/rdoctask'
47
+ Rake::RDocTask.new do |rdoc|
48
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
49
+
50
+ rdoc.rdoc_dir = 'rdoc'
51
+ rdoc.title = "zerigo_dns #{version}"
52
+ rdoc.rdoc_files.include('README*')
53
+ rdoc.rdoc_files.include('lib/**/*.rb')
54
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.0.0
data/example/sample.rb ADDED
@@ -0,0 +1,194 @@
1
+ # Copyright 2009 Zerigo, Inc. See MIT-LICENSE for license information.
2
+ # Visit http://www.zerigo.com/docs/managed-dns for updates and documentation.
3
+
4
+ # First, require the Zerigo DNS library for ActiveResource.
5
+
6
+ require 'zerigo_ns'
7
+
8
+ # All API request require a Zerigo account and an Account API key. We'll set
9
+ # them here for later reference. The 'user' is your regular login email.
10
+ # The 'password' is your API key and comes from the Preferences page
11
+ # (Manage Account -> NS -> Preferences).
12
+
13
+ Zerigo::NS::Base.user = 'you@email.com'
14
+
15
+ Zerigo::NS::Base.password = 'api_token'
16
+
17
+
18
+
19
+ # Note: This example assumes that there is at least one domain/zone already
20
+ # existing for the above referenced account.
21
+
22
+
23
+
24
+ # We'll start by retrieving a list of domains for this account. Note that the
25
+ # API refers to domains as zones. Note that API attributes are addressed as
26
+ # instance methods: the_zone.domain
27
+ # All attributes will have underscores in the name instead of dashes.
28
+ # eg: zone.default_ttl, not zone.default-ttl
29
+
30
+ puts '', "Retrieving list of first 20 zones..."
31
+ zones = Zerigo::NS::Zone.find(:all, :params=>{:per_page=>20, :page=>1})
32
+
33
+ # Now print a list of those zones
34
+ zones.each do |zone|
35
+ puts " #{zone.domain} (id: #{zone.id})"
36
+ end
37
+
38
+ # And show exactly how many results there were. Note that total_count is
39
+ # attached to each zone object, so we just pick the first one here.
40
+ if zones.empty?
41
+ puts " (0 of 0 displayed)"
42
+ else
43
+ puts " (1-#{zones.size} of #{zones.first.last_count} displayed)"
44
+ end
45
+
46
+
47
+ # We'll list all hosts for the first zone from the last request.
48
+
49
+ zone = zones.first
50
+ puts '', "Hosts for zone #{zone.domain} (id: #{zone.id})"
51
+
52
+ hosts = Zerigo::NS::Host.find(:all, :params=>{:zone_id=>zone.id, :per_page=>20, :page=>1})
53
+ hosts.each do |host|
54
+ puts " #{host.hostname} (id: #{host.id})"
55
+ end
56
+
57
+ # While not demonstrated here, host.last_count works just like for
58
+ # zones.
59
+
60
+
61
+ # Now we'll load a single zone. In this case, it's the first zone returned in
62
+ # the last request.
63
+
64
+ puts '', "Loading a single zone..."
65
+ zone = Zerigo::NS::Zone.find(zones.first.id)
66
+
67
+ puts " Loaded zone #{zone.id} (#{zone.domain})"
68
+
69
+
70
+ # Now we'll try to load a non-existent zone and catch the error.
71
+
72
+ puts '', "Loading a non-existent zone..."
73
+ begin
74
+ zone2 = Zerigo::NS::Zone.find(987654321)
75
+ puts " Loaded zone #{zone2.id} (#{zone2.domain})"
76
+ rescue ActiveResource::ResourceNotFound
77
+ puts " Zone not found"
78
+ end
79
+
80
+
81
+ # Let's create a random zone with a validation error
82
+
83
+ puts '', "Creating a random zone that is invalid..."
84
+
85
+ now = Time.now.to_i
86
+ vals = {:domain=>"example-#{now}.org", :ns_type=>'not_valid' }
87
+
88
+ newzone = Zerigo::NS::Zone.create(vals)
89
+ if newzone.errors.empty?
90
+ puts " Zone #{newzone.domain} created successfully with id #{newzone.id}."
91
+ else
92
+ puts " There was an error saving the new zone."
93
+ newzone.errors.each {|attr, msg| puts " #{attr} #{msg}"}
94
+ end
95
+
96
+ # now do it right
97
+
98
+ puts '', "Fixing and resubmitting that random zone..."
99
+
100
+ 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
101
+
102
+ newzone = Zerigo::NS::Zone.create(vals)
103
+ if newzone.errors.empty?
104
+ puts " Zone #{newzone.domain} created successfully with id #{newzone.id}."
105
+ else
106
+ puts " There was an error saving the new zone."
107
+ newzone.errors.each {|attr, msg| puts " #{attr} #{msg}"}
108
+ end
109
+
110
+
111
+ # Then we'll update that same zone.
112
+
113
+ puts '', "Now adding slave_nameservers and changing to 'pri'..."
114
+
115
+ newzone.ns_type = 'pri'
116
+ newzone.slave_nameservers = "ns8.example-#{now}.org,ns9.example-#{now}.org"
117
+ if newzone.save
118
+ puts " Changes saved successfully."
119
+ else
120
+ puts " There was an error saving the changes."
121
+ newzone.errors.each {|attr, msg| puts " #{attr} #{msg}"}
122
+ end
123
+
124
+
125
+ # Add a host to the zone.
126
+
127
+ puts '', "Adding a host to the zone."
128
+
129
+ vals2 = {:hostname=>'www',
130
+ :host_type=>'A',
131
+ :data=>'10.10.10.10',
132
+ :ttl=>86400,
133
+ :zone_id=>newzone.id
134
+ }
135
+
136
+ # A host has to be assigned to a zone. This is done by including 'zone_id'
137
+ # in the vals2 hash.
138
+ newhost = Zerigo::NS::Host.create(vals2)
139
+ if newhost.errors.empty?
140
+ puts " Host #{newhost.hostname} created successfully with id #{newhost.id}."
141
+ else
142
+ puts " There was an error saving the new host."
143
+ newhost.errors.each {|attr, msg| puts " #{attr} #{msg}"}
144
+ end
145
+
146
+
147
+ # To make the new host show up in the zone, either the zone needs to be
148
+ # reloaded or just the hosts can be reloaded. We'll also reload the host
149
+ # just for fun.
150
+
151
+ puts '', "Reloading the host..."
152
+
153
+ newhost.reload
154
+
155
+ puts '', "Reloading the zone..."
156
+
157
+ newzone.reload
158
+
159
+
160
+ # Update the host.
161
+
162
+ puts '', "Changing the host ttl to use the zone's default..."
163
+
164
+ host = newzone.hosts.first
165
+ host.ttl = nil
166
+ if host.save
167
+ puts " Changes saved successfully."
168
+ else
169
+ puts " There was an error saving the changes."
170
+ host.errors.each {|attr, msg| puts " #{attr} #{msg}"}
171
+ end
172
+
173
+
174
+ # Delete the host.
175
+
176
+ puts '', "Deleting this host..."
177
+
178
+ if newhost.destroy
179
+ puts " Successful."
180
+ else
181
+ puts " Failed."
182
+ end
183
+
184
+
185
+ # Now delete this zone.
186
+
187
+ puts '', "Deleting the zone..."
188
+
189
+ if newzone.destroy
190
+ puts " Successful."
191
+ else
192
+ puts " Failed."
193
+ end
194
+
data/lib/zerigo_ns.rb ADDED
@@ -0,0 +1,52 @@
1
+ # Copyright 2009 Zerigo, Inc. See MIT-LICENSE for license information.
2
+ # Visit http://www.zerigo.com/docs/managed-dns for updates and documentation.
3
+
4
+ require 'activeresource-ext'
5
+
6
+ module Zerigo
7
+ module NS
8
+
9
+ class Base < ActiveResource::Base
10
+ self.site='http://ns.zerigo.com/api/1.1/'
11
+ self.user = 'test@example.com'
12
+ self.password = 'ca01ffae311a7854ea366b05cd02bd50'
13
+ self.timeout = 5 # timeout after 5 seconds
14
+
15
+
16
+ # fix load() so that it no longer clobbers @prefix_options
17
+ # also fix bug exposed by reload() where attributes is effectively parsed twice, causing the first line to raise an exception the 2nd time
18
+ def load(attributes)
19
+ raise ArgumentError, "expected an attributes Hash, got #{attributes.inspect}" unless attributes.is_a?(Hash)
20
+ new_prefix_options, attributes = split_options(attributes)
21
+ @prefix_options.merge!(new_prefix_options)
22
+ attributes.each do |key, value|
23
+ @attributes[key.to_s] =
24
+ case value
25
+ when Array
26
+ if value.all?{|v2| v2.kind_of?(ActiveResource::Base)}
27
+ value.dup rescue value
28
+ else
29
+ resource = find_or_create_resource_for_collection(key)
30
+ value.map { |attrs| attrs.is_a?(String) ? attrs.dup : resource.new(attrs) }
31
+ end
32
+ when Hash
33
+ resource = find_or_create_resource_for(key)
34
+ resource.new(value)
35
+ else
36
+ value.dup rescue value
37
+ end
38
+ end
39
+ self
40
+ end
41
+
42
+ end
43
+
44
+
45
+ class Zone < Base
46
+ end
47
+
48
+ class Host < Base
49
+ end
50
+
51
+ end
52
+ end
data/test/helper.rb ADDED
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require 'zerigo_dns'
8
+
9
+ class Test::Unit::TestCase
10
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestZerigoDns < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: zerigo_dns
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Tom Wilson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-02-06 00:00:00 -05:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: active_resource
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: thoughtbot-shoulda
27
+ type: :development
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: "0"
34
+ version:
35
+ description: This gem is a resource wrapper of the example provide by zerigo dns
36
+ email: tom@jackhq.com
37
+ executables: []
38
+
39
+ extensions: []
40
+
41
+ extra_rdoc_files:
42
+ - LICENSE
43
+ - README.rdoc
44
+ files:
45
+ - .document
46
+ - .gitignore
47
+ - LICENSE
48
+ - README.rdoc
49
+ - Rakefile
50
+ - VERSION
51
+ - example/sample.rb
52
+ - lib/zerigo_ns.rb
53
+ - test/helper.rb
54
+ - test/test_zerigo_dns.rb
55
+ has_rdoc: true
56
+ homepage: http://github.com/twilson63/zerigo_dns
57
+ licenses: []
58
+
59
+ post_install_message:
60
+ rdoc_options:
61
+ - --charset=UTF-8
62
+ require_paths:
63
+ - lib
64
+ required_ruby_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: "0"
69
+ version:
70
+ required_rubygems_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: "0"
75
+ version:
76
+ requirements: []
77
+
78
+ rubyforge_project:
79
+ rubygems_version: 1.3.5
80
+ signing_key:
81
+ specification_version: 3
82
+ summary: Zerigo DNS Gem
83
+ test_files:
84
+ - test/helper.rb
85
+ - test/test_zerigo_dns.rb