dnsimple-ruby 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README +10 -0
- data/VERSION +1 -0
- data/bin/dnsimple +3 -0
- data/bin/dnsimple.rb +50 -0
- data/lib/dnsimple.rb +9 -0
- data/lib/dnsimple/cli.rb +60 -0
- data/lib/dnsimple/client.rb +34 -0
- data/lib/dnsimple/commands/apply_template.rb +15 -0
- data/lib/dnsimple/commands/clear_domain.rb +16 -0
- data/lib/dnsimple/commands/create_domain.rb +16 -0
- data/lib/dnsimple/commands/create_record.rb +18 -0
- data/lib/dnsimple/commands/delete_domain.rb +14 -0
- data/lib/dnsimple/commands/delete_record.rb +16 -0
- data/lib/dnsimple/commands/describe_domain.rb +14 -0
- data/lib/dnsimple/commands/list_domains.rb +14 -0
- data/lib/dnsimple/commands/list_records.rb +17 -0
- data/lib/dnsimple/domain.rb +100 -0
- data/lib/dnsimple/error.rb +9 -0
- data/lib/dnsimple/record.rb +94 -0
- data/lib/dnsimple/template.rb +43 -0
- data/spec/README +6 -0
- data/spec/domain_spec.rb +57 -0
- data/spec/record_spec.rb +50 -0
- data/spec/spec_helper.rb +7 -0
- data/spec/template_spec.rb +10 -0
- metadata +90 -0
data/README
ADDED
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/bin/dnsimple
ADDED
data/bin/dnsimple.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$:.unshift(File.dirname(__FILE__) + '/../lib')
|
4
|
+
require 'dnsimple'
|
5
|
+
require 'dnsimple/cli'
|
6
|
+
|
7
|
+
cli = DNSimple::CLI.new
|
8
|
+
|
9
|
+
require 'optparse'
|
10
|
+
|
11
|
+
options = {}
|
12
|
+
|
13
|
+
global = OptionParser.new do |opts|
|
14
|
+
opts.on("-s", "--site [ARG]") do |site|
|
15
|
+
DNSimple::Client.base_uri site
|
16
|
+
end
|
17
|
+
opts.on("-u", "--username [ARG]") do |username|
|
18
|
+
DNSimple::Client.username = username
|
19
|
+
end
|
20
|
+
opts.on("-p", "--password [ARG]") do |password|
|
21
|
+
DNSimple::Client.password = password
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
subcommands = {
|
26
|
+
'create' => OptionParser.new do |opts|
|
27
|
+
opts.on("--template [ARG]") do |opt|
|
28
|
+
options[:template] = opt
|
29
|
+
end
|
30
|
+
end,
|
31
|
+
'record:create' => OptionParser.new do |opts|
|
32
|
+
opts.on("--prio [ARG]") do |prio|
|
33
|
+
options[:prio] = prio
|
34
|
+
end
|
35
|
+
end,
|
36
|
+
}
|
37
|
+
|
38
|
+
global.order!
|
39
|
+
command = ARGV.shift
|
40
|
+
if command.nil?
|
41
|
+
puts "You must specify a command"
|
42
|
+
else
|
43
|
+
options_parser = subcommands[command]
|
44
|
+
options_parser.order! if options_parser
|
45
|
+
begin
|
46
|
+
cli.execute(command, ARGV, options)
|
47
|
+
rescue DNSimple::CommandNotFound => e
|
48
|
+
puts e.message
|
49
|
+
end
|
50
|
+
end
|
data/lib/dnsimple.rb
ADDED
data/lib/dnsimple/cli.rb
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
3
|
+
module DNSimple
|
4
|
+
|
5
|
+
class CommandNotFound < RuntimeError
|
6
|
+
end
|
7
|
+
|
8
|
+
class CLI
|
9
|
+
def initialize
|
10
|
+
credentials = load_credentials
|
11
|
+
Client.credentials(credentials['username'], credentials['password'])
|
12
|
+
end
|
13
|
+
|
14
|
+
def execute(command_name, args, options={})
|
15
|
+
command = commands[command_name]
|
16
|
+
if command
|
17
|
+
begin
|
18
|
+
command.new.execute(args, options)
|
19
|
+
rescue DNSimple::Error => e
|
20
|
+
puts "An error occurred: #{e.message}"
|
21
|
+
rescue RuntimeError => e
|
22
|
+
puts "An error occurred: #{e.message}"
|
23
|
+
end
|
24
|
+
else
|
25
|
+
raise CommandNotFound, "Unknown command: #{command_name}"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def commands
|
30
|
+
{
|
31
|
+
'create' => DNSimple::Commands::CreateDomain,
|
32
|
+
'describe' => DNSimple::Commands::DescribeDomain,
|
33
|
+
'list' => DNSimple::Commands::ListDomains,
|
34
|
+
'delete' => DNSimple::Commands::DeleteDomain,
|
35
|
+
'clear' => DNSimple::Commands::ClearDomain,
|
36
|
+
'apply' => DNSimple::Commands::ApplyTemplate,
|
37
|
+
|
38
|
+
'record:create' => DNSimple::Commands::CreateRecord,
|
39
|
+
'record:list' => DNSimple::Commands::ListRecords,
|
40
|
+
'record:delete' => DNSimple::Commands::DeleteRecord,
|
41
|
+
}
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
def load_credentials
|
46
|
+
YAML.load(File.new(File.expand_path('~/.dnsimple')))
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
require 'dnsimple/commands/create_domain'
|
52
|
+
require 'dnsimple/commands/describe_domain'
|
53
|
+
require 'dnsimple/commands/list_domains'
|
54
|
+
require 'dnsimple/commands/delete_domain'
|
55
|
+
require 'dnsimple/commands/clear_domain'
|
56
|
+
require 'dnsimple/commands/apply_template'
|
57
|
+
|
58
|
+
require 'dnsimple/commands/create_record'
|
59
|
+
require 'dnsimple/commands/list_records'
|
60
|
+
require 'dnsimple/commands/delete_record'
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module DNSimple
|
2
|
+
class Client
|
3
|
+
def self.debug?
|
4
|
+
@debug
|
5
|
+
end
|
6
|
+
def self.debug=(debug)
|
7
|
+
@debug = debug
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.username=(username)
|
11
|
+
self.credentials[:username] = username
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.password=(password)
|
15
|
+
self.credentials[:password] = password
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.credentials(username=nil, password=nil)
|
19
|
+
@credentials ||= {}
|
20
|
+
@credentials = {:username => username, :password => password} if username && password
|
21
|
+
@credentials
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.base_uri(site=nil)
|
25
|
+
self.base_uri = site if site
|
26
|
+
@@base_uri ||= "http://localhost:3000"
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.base_uri=(base_uri)
|
30
|
+
@@base_uri = base_uri.gsub(/\/$/, '')
|
31
|
+
puts "Using #{@@base_uri}"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module DNSimple
|
2
|
+
module Commands
|
3
|
+
class ApplyTemplate
|
4
|
+
def execute(args, options={})
|
5
|
+
domain_name = args.shift
|
6
|
+
template_name = args.shift
|
7
|
+
|
8
|
+
domain = Domain.find(domain_name)
|
9
|
+
domain.apply(template_name)
|
10
|
+
|
11
|
+
puts "Applied template #{template_name} to #{domain.name}"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module DNSimple
|
2
|
+
module Commands
|
3
|
+
class ClearDomain
|
4
|
+
def execute(args, options={})
|
5
|
+
name = args.shift
|
6
|
+
|
7
|
+
records = Record.all(name)
|
8
|
+
records.each do |record|
|
9
|
+
record.delete
|
10
|
+
end
|
11
|
+
|
12
|
+
puts "Deleted #{records.length} records from #{name}"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module DNSimple
|
2
|
+
module Commands
|
3
|
+
class CreateDomain
|
4
|
+
def execute(args, options={})
|
5
|
+
name = args.shift
|
6
|
+
domain = Domain.create(name)
|
7
|
+
puts "Created #{domain.name}"
|
8
|
+
|
9
|
+
if template = options.delete(:template)
|
10
|
+
domain.apply(template)
|
11
|
+
puts "Applied template #{template} to #{domain.name}"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module DNSimple
|
2
|
+
module Commands
|
3
|
+
class CreateRecord
|
4
|
+
def execute(args, options={})
|
5
|
+
name = args.shift
|
6
|
+
record_name = args.shift
|
7
|
+
record_type = args.shift
|
8
|
+
content = args.shift
|
9
|
+
ttl = args.shift
|
10
|
+
|
11
|
+
domain = Domain.find(name)
|
12
|
+
record = Record.create(domain.name, record_name, record_type, content, :ttl => ttl, :prio => options[:prio])
|
13
|
+
|
14
|
+
puts "Created #{record.record_type} record for #{domain.name}"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module DNSimple
|
2
|
+
module Commands
|
3
|
+
class DeleteRecord
|
4
|
+
def execute(args, options={})
|
5
|
+
domain_name = args.shift
|
6
|
+
id = args.shift
|
7
|
+
|
8
|
+
domain = Domain.find(domain_name)
|
9
|
+
record = Record.find(domain.name, id)
|
10
|
+
record.delete
|
11
|
+
|
12
|
+
puts "Deleted #{record.id} from #{domain.name}"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module DNSimple
|
2
|
+
module Commands
|
3
|
+
class DescribeDomain
|
4
|
+
def execute(args, options={})
|
5
|
+
name = args.shift
|
6
|
+
domain = Domain.find(name)
|
7
|
+
puts "Domain #{domain.name}:"
|
8
|
+
puts "\tID: #{domain.id}"
|
9
|
+
puts "\tCreated: #{domain.created_at}"
|
10
|
+
puts "\tName Server Status: #{domain.name_server_status}"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module DNSimple
|
2
|
+
module Commands
|
3
|
+
class ListDomains
|
4
|
+
def execute(args, options={})
|
5
|
+
puts "Base URI: #{Domain.base_uri}"
|
6
|
+
domains = Domain.all
|
7
|
+
puts "Found #{domains.length} domains:"
|
8
|
+
domains.each do |domain|
|
9
|
+
puts "\t#{domain.name}"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module DNSimple
|
2
|
+
module Commands
|
3
|
+
class ListRecords
|
4
|
+
def execute(args, options={})
|
5
|
+
domain_name = args.shift
|
6
|
+
records = Record.all(domain_name)
|
7
|
+
puts "Found #{records.length} records for #{domain_name}"
|
8
|
+
records.each do |record|
|
9
|
+
extra = ["ttl:#{record.ttl}", "id:#{record.id}"]
|
10
|
+
extra << "prio:#{record.prio}" if record.record_type == "MX"
|
11
|
+
extra = "(#{extra.join(', ')})"
|
12
|
+
puts "\t#{record.name}.#{record.domain.name} (#{record.record_type})-> #{record.content} #{extra}"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,100 @@
|
|
1
|
+
module DNSimple #:nodoc:
|
2
|
+
# Class representing a single domain in DNSimple.
|
3
|
+
class Domain
|
4
|
+
include HTTParty
|
5
|
+
|
6
|
+
# The domain ID in DNSimple
|
7
|
+
attr_accessor :id
|
8
|
+
|
9
|
+
# The domain name
|
10
|
+
attr_accessor :name
|
11
|
+
|
12
|
+
# When the domain was created in DNSimple
|
13
|
+
attr_accessor :created_at
|
14
|
+
|
15
|
+
# When the domain was last update in DNSimple
|
16
|
+
attr_accessor :updated_at
|
17
|
+
|
18
|
+
# The current known name server status
|
19
|
+
attr_accessor :name_server_status
|
20
|
+
|
21
|
+
#:nodoc:
|
22
|
+
def initialize(attributes)
|
23
|
+
attributes.each do |key, value|
|
24
|
+
m = "#{key}=".to_sym
|
25
|
+
self.send(m, value) if self.respond_to?(m)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
# Delete the domain from DNSimple. WARNING: this cannot
|
30
|
+
# be undone.
|
31
|
+
def delete(options={})
|
32
|
+
options.merge!({:basic_auth => Client.credentials})
|
33
|
+
self.class.delete("#{Client.base_uri}/domains/#{id}.json", options)
|
34
|
+
end
|
35
|
+
alias :destroy :delete
|
36
|
+
|
37
|
+
def apply(template_name, options={})
|
38
|
+
template = DNSimple::Template.find(template_name)
|
39
|
+
options.merge!({:basic_auth => Client.credentials})
|
40
|
+
self.class.post("#{Client.base_uri}/domains/#{id}/templates/#{template.id}/apply", options)
|
41
|
+
end
|
42
|
+
|
43
|
+
# Create the domain with the given name in DNSimple. This
|
44
|
+
# method returns a Domain instance if the name is created
|
45
|
+
# and raises
|
46
|
+
def self.create(name, options={})
|
47
|
+
domain_hash = {:name => name}
|
48
|
+
|
49
|
+
options.merge!({:query => {:domain => domain_hash}})
|
50
|
+
options.merge!({:basic_auth => Client.credentials})
|
51
|
+
|
52
|
+
response = self.post("#{Client.base_uri}/domains.json", options)
|
53
|
+
|
54
|
+
pp response if Client.debug?
|
55
|
+
|
56
|
+
case response.code
|
57
|
+
when 201
|
58
|
+
return Domain.new(response["domain"])
|
59
|
+
when 401
|
60
|
+
raise RuntimeError, "Authentication failed"
|
61
|
+
else
|
62
|
+
raise DNSimple::Error.new(name, response["errors"])
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def self.find(id_or_name, options={})
|
67
|
+
options.merge!({:basic_auth => Client.credentials})
|
68
|
+
response = self.get("#{Client.base_uri}/domains/#{id_or_name}.json", options)
|
69
|
+
|
70
|
+
pp response if Client.debug?
|
71
|
+
|
72
|
+
case response.code
|
73
|
+
when 200
|
74
|
+
return Domain.new(response["domain"])
|
75
|
+
when 401
|
76
|
+
raise RuntimeError, "Authentication failed"
|
77
|
+
when 404
|
78
|
+
raise RuntimeError, "Could not find domain #{id_or_name}"
|
79
|
+
else
|
80
|
+
raise DNSimple::Error.new(id_or_name, response["errors"])
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def self.all(options={})
|
85
|
+
options.merge!({:basic_auth => Client.credentials})
|
86
|
+
response = self.get("#{Client.base_uri}/domains.json", options)
|
87
|
+
|
88
|
+
pp response if Client.debug?
|
89
|
+
|
90
|
+
case response.code
|
91
|
+
when 200
|
92
|
+
response.map { |r| Domain.new(r["domain"]) }
|
93
|
+
when 401
|
94
|
+
raise RuntimeError, "Authentication failed"
|
95
|
+
else
|
96
|
+
raise RuntimeError, "Error: #{response.code}"
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
module DNSimple
|
2
|
+
class Record
|
3
|
+
include HTTParty
|
4
|
+
|
5
|
+
attr_accessor :id
|
6
|
+
|
7
|
+
attr_accessor :domain
|
8
|
+
|
9
|
+
attr_accessor :name
|
10
|
+
|
11
|
+
attr_accessor :content
|
12
|
+
|
13
|
+
attr_accessor :record_type
|
14
|
+
|
15
|
+
attr_accessor :ttl
|
16
|
+
|
17
|
+
attr_accessor :prio
|
18
|
+
|
19
|
+
#:nodoc:
|
20
|
+
def initialize(attributes)
|
21
|
+
attributes.each do |key, value|
|
22
|
+
m = "#{key}=".to_sym
|
23
|
+
self.send(m, value) if self.respond_to?(m)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def delete(options={})
|
28
|
+
options.merge!({:basic_auth => Client.credentials})
|
29
|
+
self.class.delete("#{Client.base_uri}/domains/#{domain.id}/records/#{id}.json", options)
|
30
|
+
end
|
31
|
+
alias :destroy :delete
|
32
|
+
|
33
|
+
def self.create(domain_name, name, record_type, content, options={})
|
34
|
+
domain = Domain.find(domain_name)
|
35
|
+
|
36
|
+
record_hash = {:name => name, :record_type => record_type, :content => content}
|
37
|
+
record_hash[:ttl] = options.delete(:ttl) || 3600
|
38
|
+
record_hash[:prio] = options.delete(:prio) || ''
|
39
|
+
|
40
|
+
options.merge!({:query => {:record => record_hash}})
|
41
|
+
options.merge!({:basic_auth => Client.credentials})
|
42
|
+
|
43
|
+
response = self.post("#{Client.base_uri}/domains/#{domain.id}/records.json", options)
|
44
|
+
|
45
|
+
pp response if Client.debug?
|
46
|
+
|
47
|
+
case response.code
|
48
|
+
when 201
|
49
|
+
return Record.new({:domain => domain}.merge(response["record"]))
|
50
|
+
when 401
|
51
|
+
raise RuntimeError, "Authentication failed"
|
52
|
+
else
|
53
|
+
raise DNSimple::Error.new("#{name}.#{domain_name}", response["errors"])
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def self.find(domain_name, id, options={})
|
58
|
+
domain = Domain.find(domain_name)
|
59
|
+
options.merge!({:basic_auth => Client.credentials})
|
60
|
+
response = self.get("#{Client.base_uri}/domains/#{domain.id}/records/#{id}", options)
|
61
|
+
|
62
|
+
pp response if Client.debug?
|
63
|
+
|
64
|
+
case response.code
|
65
|
+
when 200
|
66
|
+
return Record.new({:domain => domain}.merge(response["record"]))
|
67
|
+
when 401
|
68
|
+
raise RuntimeError, "Authentication failed"
|
69
|
+
when 404
|
70
|
+
raise RuntimeError, "Could not find record #{id} for domain #{domain_name}"
|
71
|
+
else
|
72
|
+
raise DNSimple::Error.new("#{domain_name}/#{id}", response["errors"])
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def self.all(domain_name, options={})
|
77
|
+
domain = Domain.find(domain_name)
|
78
|
+
options.merge!({:basic_auth => Client.credentials})
|
79
|
+
response = self.get("#{Client.base_uri}/domains/#{domain.id}/records.json", options)
|
80
|
+
|
81
|
+
pp response if Client.debug?
|
82
|
+
|
83
|
+
case response.code
|
84
|
+
when 200
|
85
|
+
response.map { |r| Record.new({:domain => domain}.merge(r["record"])) }
|
86
|
+
when 401
|
87
|
+
raise RuntimeError, "Authentication failed"
|
88
|
+
else
|
89
|
+
raise RuntimeError, "Error: #{response.code}"
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
end
|
94
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module DNSimple
|
2
|
+
class Template
|
3
|
+
include HTTParty
|
4
|
+
|
5
|
+
# The template ID in DNSimple
|
6
|
+
attr_accessor :id
|
7
|
+
|
8
|
+
# The template name
|
9
|
+
attr_accessor :name
|
10
|
+
|
11
|
+
# The template short name
|
12
|
+
attr_accessor :short_name
|
13
|
+
|
14
|
+
# The template description
|
15
|
+
attr_accessor :description
|
16
|
+
|
17
|
+
#:nodoc:
|
18
|
+
def initialize(attributes)
|
19
|
+
attributes.each do |key, value|
|
20
|
+
m = "#{key}=".to_sym
|
21
|
+
self.send(m, value) if self.respond_to?(m)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.find(id_or_short_name, options={})
|
26
|
+
options.merge!({:basic_auth => Client.credentials})
|
27
|
+
response = self.get("#{Client.base_uri}/templates/#{id_or_short_name}.json", options)
|
28
|
+
|
29
|
+
pp response if Client.debug?
|
30
|
+
|
31
|
+
case response.code
|
32
|
+
when 200
|
33
|
+
return Template.new(response["dns_template"])
|
34
|
+
when 401
|
35
|
+
raise RuntimeError, "Authentication failed"
|
36
|
+
when 404
|
37
|
+
raise RuntimeError, "Could not find template #{id_or_short_name}"
|
38
|
+
else
|
39
|
+
raise DNSimple::Error.new(id_or_short_name, response["errors"])
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
data/spec/README
ADDED
data/spec/domain_spec.rb
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'spec_helper')
|
2
|
+
|
3
|
+
describe DNSimple::Domain do
|
4
|
+
|
5
|
+
describe "a new domain" do
|
6
|
+
before do
|
7
|
+
@domain = DNSimple::Domain.create("testdomain.com")
|
8
|
+
end
|
9
|
+
after do
|
10
|
+
@domain.delete
|
11
|
+
end
|
12
|
+
it "has specific attributes" do
|
13
|
+
@domain.name.should eql("testdomain.com")
|
14
|
+
@domain.id.should_not be_nil
|
15
|
+
end
|
16
|
+
it "can be found by id" do
|
17
|
+
domain = DNSimple::Domain.find(@domain.id)
|
18
|
+
domain.name.should eql("testdomain.com")
|
19
|
+
domain.id.should_not be_nil
|
20
|
+
end
|
21
|
+
it "can be found by name" do
|
22
|
+
domain = DNSimple::Domain.find(@domain.name)
|
23
|
+
domain.name.should eql("testdomain.com")
|
24
|
+
domain.id.should_not be_nil
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe ".all" do
|
29
|
+
before do
|
30
|
+
@domains = []
|
31
|
+
3.times do |n|
|
32
|
+
@domains << DNSimple::Domain.create("testdomain#{n}.com")
|
33
|
+
end
|
34
|
+
end
|
35
|
+
after do
|
36
|
+
@domains.each { |d| d.destroy }
|
37
|
+
end
|
38
|
+
it "returns a list of domains" do
|
39
|
+
domains = DNSimple::Domain.all
|
40
|
+
domains.map { |d| d.name }.should include(*@domains.map { |d| d.name })
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe "applying templates" do
|
45
|
+
before do
|
46
|
+
@domain = DNSimple::Domain.create("testdomain.com")
|
47
|
+
end
|
48
|
+
after do
|
49
|
+
@domain.delete
|
50
|
+
end
|
51
|
+
it "applies a named template" do
|
52
|
+
DNSimple::Record.all(@domain.name).should be_empty
|
53
|
+
@domain.apply("googleapps")
|
54
|
+
DNSimple::Record.all(@domain.name).should_not be_empty
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
data/spec/record_spec.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'spec_helper')
|
2
|
+
|
3
|
+
describe DNSimple::Record do
|
4
|
+
before do
|
5
|
+
@domain = DNSimple::Domain.create("testdomain.com")
|
6
|
+
end
|
7
|
+
|
8
|
+
after do
|
9
|
+
@domain.delete
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "a new record" do
|
13
|
+
before do
|
14
|
+
@record = DNSimple::Record.create(@domain.name, "", "A", "1.2.3.4", :ttl => 600)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "has specific attributes" do
|
18
|
+
@record.name.should eql("")
|
19
|
+
@record.record_type.should eql("A")
|
20
|
+
@record.content.should eql("1.2.3.4")
|
21
|
+
@record.ttl.should eql(600)
|
22
|
+
@record.id.should_not be_nil
|
23
|
+
end
|
24
|
+
it "can be found by id" do
|
25
|
+
record = DNSimple::Record.find(@domain.name, @record.id)
|
26
|
+
record.name.should eql("")
|
27
|
+
record.record_type.should eql("A")
|
28
|
+
record.content.should eql("1.2.3.4")
|
29
|
+
record.ttl.should eql(600)
|
30
|
+
record.id.should_not be_nil
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe ".all" do
|
35
|
+
before do
|
36
|
+
@records = []
|
37
|
+
|
38
|
+
@records << DNSimple::Record.create("testdomain.com", "", "A", "4.5.6.7")
|
39
|
+
@records << DNSimple::Record.create("testdomain.com", "www", "CNAME", "testdomain.com")
|
40
|
+
@records << DNSimple::Record.create("testdomain.com", "", "MX", "mail.foo.com", :prio => 10)
|
41
|
+
end
|
42
|
+
|
43
|
+
it "returns a list of records" do
|
44
|
+
records = DNSimple::Record.all(@domain.name)
|
45
|
+
records.should_not be_empty
|
46
|
+
records.length.should eql(@records.length)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
require 'lib/dnsimple'
|
2
|
+
|
3
|
+
config = YAML.load(File.new(File.expand_path('~/.dnsimple.localhost')))
|
4
|
+
|
5
|
+
DNSimple::Client.base_uri = config['site'] || "http://localhost:3000/"
|
6
|
+
DNSimple::Client.username = config['username']
|
7
|
+
DNSimple::Client.password = config['password']
|
metadata
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dnsimple-ruby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
version: 0.1.0
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Anthony Eden
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-07-10 00:00:00 -10:00
|
18
|
+
default_executable:
|
19
|
+
dependencies: []
|
20
|
+
|
21
|
+
description: A ruby wrapper for the DNSimple API that also includes a command-line client.
|
22
|
+
email: anthony.eden@dnsimple.com
|
23
|
+
executables:
|
24
|
+
- dnsimple
|
25
|
+
- dnsimple.rb
|
26
|
+
extensions: []
|
27
|
+
|
28
|
+
extra_rdoc_files:
|
29
|
+
- README
|
30
|
+
files:
|
31
|
+
- README
|
32
|
+
- VERSION
|
33
|
+
- bin/dnsimple
|
34
|
+
- bin/dnsimple.rb
|
35
|
+
- lib/dnsimple.rb
|
36
|
+
- lib/dnsimple/cli.rb
|
37
|
+
- lib/dnsimple/client.rb
|
38
|
+
- lib/dnsimple/commands/apply_template.rb
|
39
|
+
- lib/dnsimple/commands/clear_domain.rb
|
40
|
+
- lib/dnsimple/commands/create_domain.rb
|
41
|
+
- lib/dnsimple/commands/create_record.rb
|
42
|
+
- lib/dnsimple/commands/delete_domain.rb
|
43
|
+
- lib/dnsimple/commands/delete_record.rb
|
44
|
+
- lib/dnsimple/commands/describe_domain.rb
|
45
|
+
- lib/dnsimple/commands/list_domains.rb
|
46
|
+
- lib/dnsimple/commands/list_records.rb
|
47
|
+
- lib/dnsimple/domain.rb
|
48
|
+
- lib/dnsimple/error.rb
|
49
|
+
- lib/dnsimple/record.rb
|
50
|
+
- lib/dnsimple/template.rb
|
51
|
+
- spec/README
|
52
|
+
- spec/domain_spec.rb
|
53
|
+
- spec/record_spec.rb
|
54
|
+
- spec/spec_helper.rb
|
55
|
+
- spec/template_spec.rb
|
56
|
+
has_rdoc: true
|
57
|
+
homepage: http://github.com/aetrion/dnsimple-ruby
|
58
|
+
licenses: []
|
59
|
+
|
60
|
+
post_install_message:
|
61
|
+
rdoc_options:
|
62
|
+
- --charset=UTF-8
|
63
|
+
require_paths:
|
64
|
+
- lib
|
65
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
segments:
|
70
|
+
- 0
|
71
|
+
version: "0"
|
72
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
segments:
|
77
|
+
- 0
|
78
|
+
version: "0"
|
79
|
+
requirements: []
|
80
|
+
|
81
|
+
rubyforge_project:
|
82
|
+
rubygems_version: 1.3.6
|
83
|
+
signing_key:
|
84
|
+
specification_version: 3
|
85
|
+
summary: A ruby wrapper for the DNSimple API
|
86
|
+
test_files:
|
87
|
+
- spec/domain_spec.rb
|
88
|
+
- spec/record_spec.rb
|
89
|
+
- spec/spec_helper.rb
|
90
|
+
- spec/template_spec.rb
|