dnsimple-ruby 0.4.1 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/LICENSE +22 -0
- data/README.textile +7 -2
- data/VERSION +1 -1
- data/bin/dnsimple.rb +44 -16
- data/lib/dnsimple.rb +2 -0
- data/lib/dnsimple/cli.rb +19 -0
- data/lib/dnsimple/commands/add_template_record.rb +18 -0
- data/lib/dnsimple/commands/create_template.rb +14 -0
- data/lib/dnsimple/commands/delete_template.rb +13 -0
- data/lib/dnsimple/commands/delete_template_record.rb +16 -0
- data/lib/dnsimple/commands/list_template_records.rb +17 -0
- data/lib/dnsimple/commands/list_templates.rb +13 -0
- data/lib/dnsimple/commands/register_domain.rb +17 -0
- data/lib/dnsimple/commands/transfer_domain.rb +15 -0
- data/lib/dnsimple/domain.rb +29 -1
- data/lib/dnsimple/template.rb +48 -0
- data/lib/dnsimple/template_record.rb +103 -0
- data/lib/dnsimple/transfer_order.rb +45 -0
- data/spec/domain_spec.rb +29 -0
- metadata +16 -4
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
The MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2010 Aetrion LLC
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
22
|
+
|
data/README.textile
CHANGED
@@ -16,11 +16,16 @@ In this file add the following:
|
|
16
16
|
password: YOUR_PASSWORD
|
17
17
|
</code></pre>
|
18
18
|
|
19
|
+
Alternatively you can pass the credentials via command-line arguments, as in:
|
20
|
+
|
21
|
+
<pre><code>dnsimple -u username -p password list</code></pre>
|
22
|
+
|
19
23
|
h2. Commands
|
20
24
|
|
21
25
|
There are two ways to interact with the DNSimple Ruby wrapper. The first is
|
22
|
-
to use the command line utility that is included.
|
23
|
-
|
26
|
+
to use the command line utility that is included.
|
27
|
+
|
28
|
+
The commands available are as follows:
|
24
29
|
|
25
30
|
For help:
|
26
31
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.5.0
|
data/bin/dnsimple.rb
CHANGED
@@ -20,6 +20,10 @@ directory and add the following to that file:
|
|
20
20
|
username: YOUR_USERNAME
|
21
21
|
password: YOUR_PASSWORD
|
22
22
|
|
23
|
+
Alternatively you can pass the credentials via command-line arguments, as in:
|
24
|
+
|
25
|
+
dnsimple -u username -p password command
|
26
|
+
|
23
27
|
== Commands
|
24
28
|
|
25
29
|
All commands are executed as dnsimple [options] command [command-options] args
|
@@ -30,17 +34,28 @@ The following commands are available:
|
|
30
34
|
help # Show this usage
|
31
35
|
info # Show your account information
|
32
36
|
|
33
|
-
list
|
37
|
+
list # List all domains
|
38
|
+
describe domain.com # Describe the given domain
|
39
|
+
create [--template=short_name] domain.com # Add the given domain
|
40
|
+
register [--template=short_name] domain.com registrant_id # Register the given domain with DNSimple
|
41
|
+
transfer domain.com registrant_id [authinfo] # Transfer the given domain into DNSimple
|
42
|
+
delete domain.com # Delete the given domain
|
43
|
+
apply domain.com template_short_name # Apply a template to the domain
|
44
|
+
|
45
|
+
record:create [--prio=priority] domain.com name type \\
|
46
|
+
content [ttl] # Create the DNS record on the domain
|
47
|
+
record:list domain.com # List all records for the domain
|
48
|
+
record:delete domain.com record_id # Delete the given domain
|
49
|
+
|
50
|
+
template:create name short_name [description] # Create a template
|
51
|
+
template:list # List all templates
|
52
|
+
template:delete short_name # Delete the given template
|
34
53
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
54
|
+
template:list_records short_name # List all of the records for a template
|
55
|
+
template:add_record [--prio=priority] short_name name \\
|
56
|
+
type content [ttl] # Add a template record to the given template
|
57
|
+
template:delete_record short_name template_record_id # Delete the given template record
|
39
58
|
|
40
|
-
record:create [--prio=priority] \\
|
41
|
-
domain.com name type content [ttl] # Create the DNS record on the domain
|
42
|
-
record:list domain.com # List all records for the domain
|
43
|
-
record:delete domain.com record_id # Delete the given domain
|
44
59
|
|
45
60
|
EOF
|
46
61
|
end
|
@@ -57,18 +72,31 @@ global = OptionParser.new do |opts|
|
|
57
72
|
opts.on("-p", "--password [ARG]") do |password|
|
58
73
|
DNSimple::Client.password = password
|
59
74
|
end
|
75
|
+
opts.on("-d") do
|
76
|
+
DNSimple::Client.debug = true
|
77
|
+
end
|
60
78
|
end
|
61
79
|
|
62
80
|
subcommands = {
|
63
81
|
'create' => OptionParser.new do |opts|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
82
|
+
opts.on("--template [ARG]") do |opt|
|
83
|
+
options[:template] = opt
|
84
|
+
end
|
85
|
+
end,
|
86
|
+
'register' => OptionParser.new do |opts|
|
87
|
+
opts.on("--template [ARG]") do |opt|
|
88
|
+
options[:template] = opt
|
89
|
+
end
|
90
|
+
end,
|
68
91
|
'record:create' => OptionParser.new do |opts|
|
69
|
-
|
70
|
-
|
71
|
-
|
92
|
+
opts.on("--prio [ARG]") do |prio|
|
93
|
+
options[:prio] = prio
|
94
|
+
end
|
95
|
+
end,
|
96
|
+
'template:add_record' => OptionParser.new do |opts|
|
97
|
+
opts.on("--prio [ARG]") do |prio|
|
98
|
+
options[:prio] = prio
|
99
|
+
end
|
72
100
|
end,
|
73
101
|
}
|
74
102
|
|
data/lib/dnsimple.rb
CHANGED
data/lib/dnsimple/cli.rb
CHANGED
@@ -32,6 +32,8 @@ module DNSimple
|
|
32
32
|
'info' => DNSimple::Commands::DescribeUser,
|
33
33
|
|
34
34
|
'create' => DNSimple::Commands::CreateDomain,
|
35
|
+
'register' => DNSimple::Commands::RegisterDomain,
|
36
|
+
'transfer' => DNSimple::Commands::TransferDomain,
|
35
37
|
'describe' => DNSimple::Commands::DescribeDomain,
|
36
38
|
'list' => DNSimple::Commands::ListDomains,
|
37
39
|
'delete' => DNSimple::Commands::DeleteDomain,
|
@@ -41,6 +43,14 @@ module DNSimple
|
|
41
43
|
'record:create' => DNSimple::Commands::CreateRecord,
|
42
44
|
'record:list' => DNSimple::Commands::ListRecords,
|
43
45
|
'record:delete' => DNSimple::Commands::DeleteRecord,
|
46
|
+
|
47
|
+
'template:create' => DNSimple::Commands::CreateTemplate,
|
48
|
+
'template:list' => DNSimple::Commands::ListTemplates,
|
49
|
+
'template:delete' => DNSimple::Commands::DeleteTemplate,
|
50
|
+
|
51
|
+
'template:list_records' => DNSimple::Commands::ListTemplateRecords,
|
52
|
+
'template:add_record' => DNSimple::Commands::AddTemplateRecord,
|
53
|
+
'template:delete_record' => DNSimple::Commands::DeleteTemplateRecord,
|
44
54
|
}
|
45
55
|
end
|
46
56
|
|
@@ -53,6 +63,8 @@ end
|
|
53
63
|
|
54
64
|
require 'dnsimple/commands/describe_user'
|
55
65
|
require 'dnsimple/commands/create_domain'
|
66
|
+
require 'dnsimple/commands/register_domain'
|
67
|
+
require 'dnsimple/commands/transfer_domain'
|
56
68
|
require 'dnsimple/commands/describe_domain'
|
57
69
|
require 'dnsimple/commands/list_domains'
|
58
70
|
require 'dnsimple/commands/delete_domain'
|
@@ -62,3 +74,10 @@ require 'dnsimple/commands/apply_template'
|
|
62
74
|
require 'dnsimple/commands/create_record'
|
63
75
|
require 'dnsimple/commands/list_records'
|
64
76
|
require 'dnsimple/commands/delete_record'
|
77
|
+
|
78
|
+
require 'dnsimple/commands/create_template'
|
79
|
+
require 'dnsimple/commands/list_templates'
|
80
|
+
require 'dnsimple/commands/delete_template'
|
81
|
+
require 'dnsimple/commands/list_template_records'
|
82
|
+
require 'dnsimple/commands/add_template_record'
|
83
|
+
require 'dnsimple/commands/delete_template_record'
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module DNSimple
|
2
|
+
module Commands
|
3
|
+
class AddTemplateRecord
|
4
|
+
def execute(args, options={})
|
5
|
+
short_name = args.shift
|
6
|
+
record_name = args.shift
|
7
|
+
record_type = args.shift
|
8
|
+
content = args.shift
|
9
|
+
ttl = args.shift
|
10
|
+
|
11
|
+
template = Template.find(short_name)
|
12
|
+
record = TemplateRecord.create(template.short_name, record_name, record_type, content, :ttl => ttl, :prio => options[:prio])
|
13
|
+
|
14
|
+
puts "Created #{record.record_type} with content '#{record.content}' record for template #{template.name}"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module DNSimple
|
2
|
+
module Commands
|
3
|
+
class CreateTemplate
|
4
|
+
def execute(args, options={})
|
5
|
+
name = args.shift
|
6
|
+
short_name = args.shift
|
7
|
+
description = args.shift unless args.empty?
|
8
|
+
|
9
|
+
template = Template.create(name, short_name, description)
|
10
|
+
puts "Created #{template.name} (short_name:#{template.short_name})"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module DNSimple
|
2
|
+
module Commands
|
3
|
+
class DeleteTemplateRecord
|
4
|
+
def execute(args, options={})
|
5
|
+
short_name = args.shift
|
6
|
+
id = args.shift
|
7
|
+
|
8
|
+
template = Template.find(short_name)
|
9
|
+
record = TemplateRecord.find(template.short_name, id)
|
10
|
+
record.delete
|
11
|
+
|
12
|
+
puts "Deleted #{record.id} from template #{short_name}"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module DNSimple
|
2
|
+
module Commands
|
3
|
+
class ListTemplateRecords
|
4
|
+
def execute(args, options={})
|
5
|
+
short_name = args.shift
|
6
|
+
template_records = TemplateRecord.all(short_name)
|
7
|
+
puts "Found #{template_records.length} records for #{short_name}"
|
8
|
+
template_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.record_type})-> #{record.content} #{extra}"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module DNSimple
|
2
|
+
module Commands
|
3
|
+
class ListTemplates
|
4
|
+
def execute(args, options={})
|
5
|
+
templates = Template.all
|
6
|
+
puts "Found #{templates.length} templates:"
|
7
|
+
templates.each do |template|
|
8
|
+
puts "\t#{template.name} (short_name:#{template.short_name})"
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module DNSimple
|
2
|
+
module Commands
|
3
|
+
class RegisterDomain
|
4
|
+
def execute(args, options={})
|
5
|
+
name = args.shift
|
6
|
+
registrant = {:id => args.shift}
|
7
|
+
domain = Domain.register(name, registrant)
|
8
|
+
puts "Registered #{domain.name}"
|
9
|
+
|
10
|
+
if template = options.delete(:template)
|
11
|
+
domain.apply(template)
|
12
|
+
puts "Applied template #{template} to #{domain.name}"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module DNSimple
|
2
|
+
module Commands
|
3
|
+
class TransferDomain
|
4
|
+
def execute(args, options={})
|
5
|
+
name = args.shift
|
6
|
+
registrant = {:id => args.shift}
|
7
|
+
authinfo = args.shift unless args.empty?
|
8
|
+
authinfo ||= ''
|
9
|
+
|
10
|
+
transfer_order = TransferOrder.create(name, authinfo, registrant)
|
11
|
+
puts "Transfer order issued for #{name}"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/lib/dnsimple/domain.rb
CHANGED
@@ -42,7 +42,7 @@ module DNSimple #:nodoc:
|
|
42
42
|
|
43
43
|
# Create the domain with the given name in DNSimple. This
|
44
44
|
# method returns a Domain instance if the name is created
|
45
|
-
# and raises
|
45
|
+
# and raises an error otherwise.
|
46
46
|
def self.create(name, options={})
|
47
47
|
domain_hash = {:name => name}
|
48
48
|
|
@@ -63,6 +63,34 @@ module DNSimple #:nodoc:
|
|
63
63
|
end
|
64
64
|
end
|
65
65
|
|
66
|
+
def self.register(name, registrant={}, extended_attributes={}, options={})
|
67
|
+
body = {:domain => {:name => name}}
|
68
|
+
|
69
|
+
if registrant[:id]
|
70
|
+
body[:domain][:registrant_id] = registrant[:id]
|
71
|
+
else
|
72
|
+
body.merge!(:contact => registrant)
|
73
|
+
end
|
74
|
+
|
75
|
+
body.merge!(:extended_attribute => extended_attributes)
|
76
|
+
|
77
|
+
options.merge!({:body => body})
|
78
|
+
options.merge!({:basic_auth => Client.credentials})
|
79
|
+
|
80
|
+
response = self.post("#{Client.base_uri}/domain_registrations.json", options)
|
81
|
+
|
82
|
+
pp response if Client.debug?
|
83
|
+
|
84
|
+
case response.code
|
85
|
+
when 201
|
86
|
+
return Domain.new(response["domain"])
|
87
|
+
when 401
|
88
|
+
raise RuntimeError, "Authentication failed"
|
89
|
+
else
|
90
|
+
raise DNSimple::Error.new(name, response["errors"])
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
66
94
|
def self.find(id_or_name, options={})
|
67
95
|
options.merge!({:basic_auth => Client.credentials})
|
68
96
|
response = self.get("#{Client.base_uri}/domains/#{id_or_name}.json", options)
|
data/lib/dnsimple/template.rb
CHANGED
@@ -21,6 +21,38 @@ module DNSimple
|
|
21
21
|
self.send(m, value) if self.respond_to?(m)
|
22
22
|
end
|
23
23
|
end
|
24
|
+
|
25
|
+
# Delete the template from DNSimple. WARNING: this cannot
|
26
|
+
# be undone.
|
27
|
+
def delete(options={})
|
28
|
+
options.merge!({:basic_auth => Client.credentials})
|
29
|
+
self.class.delete("#{Client.base_uri}/templates/#{id}.json", options)
|
30
|
+
end
|
31
|
+
alias :destroy :delete
|
32
|
+
|
33
|
+
def self.create(name, short_name, description=nil, options={})
|
34
|
+
template_hash = {
|
35
|
+
:name => name,
|
36
|
+
:short_name => short_name,
|
37
|
+
:description => description
|
38
|
+
}
|
39
|
+
|
40
|
+
options.merge!(:body => {:dns_template => template_hash})
|
41
|
+
options.merge!({:basic_auth => Client.credentials})
|
42
|
+
|
43
|
+
response = self.post("#{Client.base_uri}/templates.json", options)
|
44
|
+
|
45
|
+
pp response if Client.debug?
|
46
|
+
|
47
|
+
case response.code
|
48
|
+
when 201
|
49
|
+
return Template.new(response["dns_template"])
|
50
|
+
when 401
|
51
|
+
raise RuntimeError, "Authentication failed"
|
52
|
+
else
|
53
|
+
raise DNSimple::Error.new(name, response["errors"])
|
54
|
+
end
|
55
|
+
end
|
24
56
|
|
25
57
|
def self.find(id_or_short_name, options={})
|
26
58
|
options.merge!({:basic_auth => Client.credentials})
|
@@ -39,5 +71,21 @@ module DNSimple
|
|
39
71
|
raise DNSimple::Error.new(id_or_short_name, response["errors"])
|
40
72
|
end
|
41
73
|
end
|
74
|
+
|
75
|
+
def self.all(options={})
|
76
|
+
options.merge!({:basic_auth => Client.credentials})
|
77
|
+
response = self.get("#{Client.base_uri}/templates.json", options)
|
78
|
+
|
79
|
+
pp response if Client.debug?
|
80
|
+
|
81
|
+
case response.code
|
82
|
+
when 200
|
83
|
+
response.map { |r| Template.new(r["dns_template"]) }
|
84
|
+
when 401
|
85
|
+
raise RuntimeError, "Authentication failed"
|
86
|
+
else
|
87
|
+
raise RuntimeError, "Error: #{response.code}"
|
88
|
+
end
|
89
|
+
end
|
42
90
|
end
|
43
91
|
end
|
@@ -0,0 +1,103 @@
|
|
1
|
+
module DNSimple #:nodoc:
|
2
|
+
# A single record in a template
|
3
|
+
class TemplateRecord
|
4
|
+
include HTTParty
|
5
|
+
|
6
|
+
# The id of the template record
|
7
|
+
attr_accessor :id
|
8
|
+
|
9
|
+
# The template the record belongs to
|
10
|
+
attr_accessor :template
|
11
|
+
|
12
|
+
# The name the record points to. This may be blank.
|
13
|
+
attr_accessor :name
|
14
|
+
|
15
|
+
# The content for the record.
|
16
|
+
attr_accessor :content
|
17
|
+
|
18
|
+
# The record type
|
19
|
+
attr_accessor :record_type
|
20
|
+
|
21
|
+
# The time-to-live
|
22
|
+
attr_accessor :ttl
|
23
|
+
|
24
|
+
# The priority (only for MX records)
|
25
|
+
attr_accessor :prio
|
26
|
+
|
27
|
+
#:nodoc:
|
28
|
+
def initialize(attributes)
|
29
|
+
attributes.each do |key, value|
|
30
|
+
m = "#{key}=".to_sym
|
31
|
+
self.send(m, value) if self.respond_to?(m)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def delete(options={})
|
36
|
+
options.merge!(:basic_auth => Client.credentials)
|
37
|
+
self.class.delete("#{Client.base_uri}/templates/#{template.id}/template_records/#{id}.json", options)
|
38
|
+
end
|
39
|
+
alias :destroy :delete
|
40
|
+
|
41
|
+
def self.create(short_name, name, record_type, content, options={})
|
42
|
+
template = Template.find(short_name)
|
43
|
+
|
44
|
+
record_hash = {:name => name, :record_type => record_type, :content => content}
|
45
|
+
record_hash[:ttl] = options.delete(:ttl) || 3600
|
46
|
+
record_hash[:prio] = options.delete(:prio) || ''
|
47
|
+
|
48
|
+
options.merge!({:query => {:dns_template_record => record_hash}})
|
49
|
+
options.merge!({:basic_auth => Client.credentials})
|
50
|
+
|
51
|
+
response = self.post("#{Client.base_uri}/templates/#{template.id}/template_records.json", options)
|
52
|
+
|
53
|
+
pp response if Client.debug?
|
54
|
+
|
55
|
+
case response.code
|
56
|
+
when 201
|
57
|
+
return TemplateRecord.new({:template => template}.merge(response["dns_template_record"]))
|
58
|
+
when 401
|
59
|
+
raise RuntimeError, "Authentication failed"
|
60
|
+
else
|
61
|
+
raise DNSimple::Error.new("#{name}", response["errors"])
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def self.find(short_name, id, options={})
|
66
|
+
template = Template.find(short_name)
|
67
|
+
options.merge!(:basic_auth => Client.credentials)
|
68
|
+
response = self.get("#{Client.base_uri}/templates/#{template.id}/template_records/#{id}.json", options)
|
69
|
+
|
70
|
+
pp response if Client.debug?
|
71
|
+
|
72
|
+
case response.code
|
73
|
+
when 200
|
74
|
+
return TemplateRecord.new({:template => template}.merge(response["dns_template_record"]))
|
75
|
+
when 401
|
76
|
+
raise RuntimeError, "Authentication failed"
|
77
|
+
when 404
|
78
|
+
raise RuntimeError, "Could not find template record #{id} for template #{short_name}"
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
# Get all of the template records for the template with the
|
83
|
+
# given short name.
|
84
|
+
def self.all(short_name, options={})
|
85
|
+
template = Template.find(short_name)
|
86
|
+
options.merge!({:basic_auth => Client.credentials})
|
87
|
+
response = self.get("#{Client.base_uri}/templates/#{template.id}/template_records.json", options)
|
88
|
+
|
89
|
+
pp response if Client.debug?
|
90
|
+
|
91
|
+
case response.code
|
92
|
+
when 200
|
93
|
+
response.map { |r| TemplateRecord.new({:template => template}.merge(r["dns_template_record"])) }
|
94
|
+
when 401
|
95
|
+
raise RuntimeError, "Authentication failed"
|
96
|
+
else
|
97
|
+
raise RuntimeError, "Error: #{response.code}"
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
|
103
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module DNSimple #:nodoc:
|
2
|
+
# Class representing a transfer order in DNSimple
|
3
|
+
class TransferOrder
|
4
|
+
include HTTParty
|
5
|
+
|
6
|
+
attr_accessor :id
|
7
|
+
|
8
|
+
attr_accessor :status
|
9
|
+
|
10
|
+
def initialize(attributes)
|
11
|
+
attributes.each do |key, value|
|
12
|
+
m = "#{key}=".to_sym
|
13
|
+
self.send(m, value) if self.respond_to?(m)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.create(name, authinfo='', registrant={}, extended_attributes={}, options={})
|
18
|
+
body = {:domain => {:name => name}, :transfer_order => {:authinfo => authinfo}}
|
19
|
+
|
20
|
+
if registrant[:id]
|
21
|
+
body[:domain][:registrant_id] = registrant[:id]
|
22
|
+
else
|
23
|
+
body.merge!(:contact => registrant)
|
24
|
+
end
|
25
|
+
|
26
|
+
body.merge!(:extended_attribute => extended_attributes)
|
27
|
+
|
28
|
+
options.merge!({:body => body})
|
29
|
+
options.merge!({:basic_auth => Client.credentials})
|
30
|
+
|
31
|
+
response = self.post("#{Client.base_uri}/domain_transfers.json", options)
|
32
|
+
|
33
|
+
pp response if Client.debug?
|
34
|
+
|
35
|
+
case response.code
|
36
|
+
when 201
|
37
|
+
return TransferOrder.new(response["transfer_order"])
|
38
|
+
when 401
|
39
|
+
raise RuntimeError, "Authentication failed"
|
40
|
+
else
|
41
|
+
raise DNSimple::Error.new(name, response["errors"])
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
data/spec/domain_spec.rb
CHANGED
@@ -25,6 +25,35 @@ describe DNSimple::Domain do
|
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
|
+
context "registration" do
|
29
|
+
describe "a new domain" do
|
30
|
+
context "with an existing contact" do
|
31
|
+
let(:name) { "testdomain-#{Time.now.to_i}.net" }
|
32
|
+
let(:registrant) { Hash.new(:id => 4) }
|
33
|
+
it "can be registered" do
|
34
|
+
domain = DNSimple::Domain.register(name, registrant)
|
35
|
+
domain.name.should eql(name)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
context "with a new registrant contact" do
|
39
|
+
let(:name) { "testdomain-#{Time.now.to_i}.net" }
|
40
|
+
it "can be registered" do
|
41
|
+
registrant = {
|
42
|
+
:first_name => 'John',
|
43
|
+
:last_name => 'Smith',
|
44
|
+
:address1 => '123 SW 1st Street',
|
45
|
+
:city => 'Miami',
|
46
|
+
:state_or_province => 'FL',
|
47
|
+
:country => 'US',
|
48
|
+
:postal_code => '33143'
|
49
|
+
}
|
50
|
+
domain = DNSimple::Domain.register(name, registrant)
|
51
|
+
domain.name.should eql(name)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
28
57
|
describe ".all" do
|
29
58
|
before do
|
30
59
|
@domains = []
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
8
|
-
-
|
9
|
-
version: 0.
|
7
|
+
- 5
|
8
|
+
- 0
|
9
|
+
version: 0.5.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Anthony Eden
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-
|
17
|
+
date: 2010-09-30 00:00:00 +02:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -37,11 +37,13 @@ executables:
|
|
37
37
|
extensions: []
|
38
38
|
|
39
39
|
extra_rdoc_files:
|
40
|
+
- LICENSE
|
40
41
|
- README
|
41
42
|
- README.rdoc
|
42
43
|
- README.textile
|
43
44
|
files:
|
44
45
|
- .gitignore
|
46
|
+
- LICENSE
|
45
47
|
- README
|
46
48
|
- README.rdoc
|
47
49
|
- README.textile
|
@@ -52,20 +54,30 @@ files:
|
|
52
54
|
- lib/dnsimple.rb
|
53
55
|
- lib/dnsimple/cli.rb
|
54
56
|
- lib/dnsimple/client.rb
|
57
|
+
- lib/dnsimple/commands/add_template_record.rb
|
55
58
|
- lib/dnsimple/commands/apply_template.rb
|
56
59
|
- lib/dnsimple/commands/clear_domain.rb
|
57
60
|
- lib/dnsimple/commands/create_domain.rb
|
58
61
|
- lib/dnsimple/commands/create_record.rb
|
62
|
+
- lib/dnsimple/commands/create_template.rb
|
59
63
|
- lib/dnsimple/commands/delete_domain.rb
|
60
64
|
- lib/dnsimple/commands/delete_record.rb
|
65
|
+
- lib/dnsimple/commands/delete_template.rb
|
66
|
+
- lib/dnsimple/commands/delete_template_record.rb
|
61
67
|
- lib/dnsimple/commands/describe_domain.rb
|
62
68
|
- lib/dnsimple/commands/describe_user.rb
|
63
69
|
- lib/dnsimple/commands/list_domains.rb
|
64
70
|
- lib/dnsimple/commands/list_records.rb
|
71
|
+
- lib/dnsimple/commands/list_template_records.rb
|
72
|
+
- lib/dnsimple/commands/list_templates.rb
|
73
|
+
- lib/dnsimple/commands/register_domain.rb
|
74
|
+
- lib/dnsimple/commands/transfer_domain.rb
|
65
75
|
- lib/dnsimple/domain.rb
|
66
76
|
- lib/dnsimple/error.rb
|
67
77
|
- lib/dnsimple/record.rb
|
68
78
|
- lib/dnsimple/template.rb
|
79
|
+
- lib/dnsimple/template_record.rb
|
80
|
+
- lib/dnsimple/transfer_order.rb
|
69
81
|
- lib/dnsimple/user.rb
|
70
82
|
- spec/README
|
71
83
|
- spec/domain_spec.rb
|