designate 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +20 -0
- data/README.rdoc +7 -0
- data/Rakefile +12 -0
- data/lib/designate/client.rb +86 -0
- data/lib/designate/host.rb +22 -0
- data/lib/designate/template.rb +14 -0
- data/lib/designate/zone.rb +46 -0
- data/lib/designate.rb +10 -0
- data/lib/test.rb +23 -0
- data/test/helper.rb +10 -0
- data/test/test_zdns.rb +4 -0
- metadata +121 -0
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2010 James Miller
|
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
data/Rakefile
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
require 'cgi'
|
2
|
+
module Designate
|
3
|
+
|
4
|
+
class Client
|
5
|
+
|
6
|
+
API_VERSION = "1.1"
|
7
|
+
DOMAIN = "ns.zerigo.com"
|
8
|
+
|
9
|
+
def initialize(email, key)
|
10
|
+
@@auth_string = CGI.escape(email) + ':' + CGI.escape(key)
|
11
|
+
end
|
12
|
+
|
13
|
+
def zones
|
14
|
+
zones = []
|
15
|
+
get('zones.xml')['zones'].each { |zone| zones << Zone.new(zone) }
|
16
|
+
return zones
|
17
|
+
end
|
18
|
+
|
19
|
+
def find_zone_by_id(id)
|
20
|
+
if zone = get("zones/#{id}.xml")['zone']
|
21
|
+
Zone.new(zone)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def find_zone_by_domain(domain)
|
26
|
+
if zone = get("zones/#{domain}.xml")['zone']
|
27
|
+
Zone.new(zone)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def create_zone(domain, options = {})
|
32
|
+
options[:domain] = domain
|
33
|
+
options[:default_ttl] ||= 14400
|
34
|
+
options[:nx_ttl] ||= 900
|
35
|
+
if options[:zone_template_id]
|
36
|
+
options[:follow_template] ||= 'no'
|
37
|
+
end
|
38
|
+
if zone = post("zones.xml", { :zone => options })['zone']
|
39
|
+
Zone.new(zone)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def find_or_create_zone(domain)
|
44
|
+
if zone = find_zone_by_domain(domain)
|
45
|
+
return zone
|
46
|
+
else
|
47
|
+
create_zone(domain)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def templates
|
52
|
+
templates = []
|
53
|
+
get('zone_templates.xml')['zone_templates'].each { |template| templates << Template.new(template) }
|
54
|
+
return templates
|
55
|
+
end
|
56
|
+
|
57
|
+
def find_template_by_id(id)
|
58
|
+
if template = get("zone_templates/#{id}.xml")['zone_template']
|
59
|
+
Template.new(template)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
private
|
64
|
+
|
65
|
+
def get(path)
|
66
|
+
Crack::XML.parse(RestClient.get(url(path)))
|
67
|
+
end
|
68
|
+
|
69
|
+
def post(path, params = {})
|
70
|
+
Crack::XML.parse(RestClient.post(url(path), params))
|
71
|
+
end
|
72
|
+
|
73
|
+
def put(path, params = {})
|
74
|
+
Crack::XML.parse(RestClient.put(url(path), params))
|
75
|
+
end
|
76
|
+
|
77
|
+
def delete(path)
|
78
|
+
Crack::XML.parse(RestClient.delete(url(path)))
|
79
|
+
end
|
80
|
+
|
81
|
+
def url(path)
|
82
|
+
"https://#{@@auth_string}@#{DOMAIN}/api/#{API_VERSION}/#{path}"
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
86
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Designate
|
2
|
+
class Host < Client
|
3
|
+
|
4
|
+
def initialize(data)
|
5
|
+
data.each do |key, value|
|
6
|
+
instance_variable_set("@#{key}", value)
|
7
|
+
Host.instance_eval do
|
8
|
+
attr_reader key.to_sym
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def update(options = {})
|
14
|
+
put("hosts/#{id}.xml", { :host => options })
|
15
|
+
end
|
16
|
+
|
17
|
+
def destroy
|
18
|
+
delete("hosts/#{id}.xml")
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module Designate
|
2
|
+
class Zone < Client
|
3
|
+
|
4
|
+
def initialize(data)
|
5
|
+
data.each do |key, value|
|
6
|
+
instance_variable_set("@#{key}", value)
|
7
|
+
Zone.instance_eval do
|
8
|
+
attr_reader key.to_sym
|
9
|
+
end
|
10
|
+
end
|
11
|
+
hosts = []
|
12
|
+
data['hosts'].each { |host| hosts << Host.new(host) }
|
13
|
+
@hosts = hosts
|
14
|
+
end
|
15
|
+
|
16
|
+
def update(options = {})
|
17
|
+
options[:default_ttl] ||= 14400
|
18
|
+
options[:nx_ttl] ||= 900
|
19
|
+
if options[:zone_template_id]
|
20
|
+
options[:follow_template] ||= 'no'
|
21
|
+
end
|
22
|
+
put("zones/#{id}.xml", { :zone => options })
|
23
|
+
end
|
24
|
+
|
25
|
+
def destroy
|
26
|
+
delete("zones/#{id}.xml")
|
27
|
+
end
|
28
|
+
|
29
|
+
def host(host_id)
|
30
|
+
if host = get("hosts/#{host_id}.xml")['host']
|
31
|
+
Host.new(host)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def create_host(host_type, data, options = {})
|
36
|
+
raise InvalidHostType unless %w(A AAAA CNAME MX NS SRV TXT).include?(host_type)
|
37
|
+
options[:host_type] = host_type
|
38
|
+
options[:hostname] ||= nil
|
39
|
+
options[:data] = data
|
40
|
+
if host = post("zones/#{id}/hosts.xml", { :host => options })
|
41
|
+
return Host.new(host)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
end
|
data/lib/designate.rb
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'rest_client'
|
2
|
+
require 'crack/xml'
|
3
|
+
require File.expand_path(File.dirname(__FILE__) + '/designate/client')
|
4
|
+
require File.expand_path(File.dirname(__FILE__) + '/designate/zone')
|
5
|
+
require File.expand_path(File.dirname(__FILE__) + '/designate/template')
|
6
|
+
require File.expand_path(File.dirname(__FILE__) + '/designate/host')
|
7
|
+
|
8
|
+
module Designate
|
9
|
+
class InvalidHostType < StandardError; end
|
10
|
+
end
|
data/lib/test.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'designate'
|
3
|
+
|
4
|
+
@d = Designate::Client.new("james@jk-tech.com", "30f1b76a010d062c22b07bda66c1d9f0")
|
5
|
+
#p @d.zones
|
6
|
+
#p @d.find_zone_by_domain("allisonmillerphotography.com")
|
7
|
+
#p @d.find_zone_by_id(1195055426)
|
8
|
+
#p @d.templates
|
9
|
+
#p @d.find_template_by_id(796679622).host_templates.map{|ht| ht['data']}
|
10
|
+
#p @d.create_zone("testtesttesttestt.com")
|
11
|
+
#p @d.create_zone("testtesttesttestt.com", :zone_template_id => @d.templates.first.id, :follow_template => "follow")
|
12
|
+
#p @d.find_zone_by_domain("bensie.com").hosts
|
13
|
+
#p @d.find_zone_by_domain("bensie.com").host(1995323332)
|
14
|
+
|
15
|
+
# @zone = @d.find_zone_by_domain("bensie.com")
|
16
|
+
# p @zone.update
|
17
|
+
|
18
|
+
# p @d.find_zone_by_domain("bensie.com").create_host("A", "4.2.2.2", :hostname => "dnstest")
|
19
|
+
# p @host = @d.find_zone_by_domain("bensie.com").hosts.first
|
20
|
+
# p @host.update
|
21
|
+
|
22
|
+
# p @host = @d.find_zone_by_domain("bensie.com").host(279953139)
|
23
|
+
# p @host.destroy
|
data/test/helper.rb
ADDED
data/test/test_zdns.rb
ADDED
metadata
ADDED
@@ -0,0 +1,121 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: designate
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- James Miller
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-09-13 00:00:00 -07:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: rest-client
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 15
|
30
|
+
segments:
|
31
|
+
- 1
|
32
|
+
- 6
|
33
|
+
- 0
|
34
|
+
version: 1.6.0
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id001
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: crack
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
hash: 9
|
46
|
+
segments:
|
47
|
+
- 0
|
48
|
+
- 1
|
49
|
+
version: "0.1"
|
50
|
+
type: :runtime
|
51
|
+
version_requirements: *id002
|
52
|
+
- !ruby/object:Gem::Dependency
|
53
|
+
name: shoulda
|
54
|
+
prerelease: false
|
55
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
56
|
+
none: false
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
hash: 3
|
61
|
+
segments:
|
62
|
+
- 0
|
63
|
+
version: "0"
|
64
|
+
type: :development
|
65
|
+
version_requirements: *id003
|
66
|
+
description: Designate is a simple Ruby wrapper for the Zerigo DNS API v1.1 specification.
|
67
|
+
email: bensie@gmail.com
|
68
|
+
executables: []
|
69
|
+
|
70
|
+
extensions: []
|
71
|
+
|
72
|
+
extra_rdoc_files: []
|
73
|
+
|
74
|
+
files:
|
75
|
+
- README.rdoc
|
76
|
+
- Rakefile
|
77
|
+
- LICENSE
|
78
|
+
- lib/designate/client.rb
|
79
|
+
- lib/designate/host.rb
|
80
|
+
- lib/designate/template.rb
|
81
|
+
- lib/designate/zone.rb
|
82
|
+
- lib/designate.rb
|
83
|
+
- lib/test.rb
|
84
|
+
- test/helper.rb
|
85
|
+
- test/test_zdns.rb
|
86
|
+
has_rdoc: true
|
87
|
+
homepage: http://github.com/bensie/designate
|
88
|
+
licenses: []
|
89
|
+
|
90
|
+
post_install_message:
|
91
|
+
rdoc_options: []
|
92
|
+
|
93
|
+
require_paths:
|
94
|
+
- lib
|
95
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
96
|
+
none: false
|
97
|
+
requirements:
|
98
|
+
- - ">="
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
hash: 3
|
101
|
+
segments:
|
102
|
+
- 0
|
103
|
+
version: "0"
|
104
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ">="
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
hash: 3
|
110
|
+
segments:
|
111
|
+
- 0
|
112
|
+
version: "0"
|
113
|
+
requirements: []
|
114
|
+
|
115
|
+
rubyforge_project:
|
116
|
+
rubygems_version: 1.3.7
|
117
|
+
signing_key:
|
118
|
+
specification_version: 3
|
119
|
+
summary: Ruby wrapper for the Zerigo DNS API
|
120
|
+
test_files: []
|
121
|
+
|