dnsimple-ruby 1.7.1 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -1
- data/.travis.yml +3 -9
- data/{CHANGELOG.markdown → CHANGELOG.md} +4 -0
- data/Gemfile +0 -2
- data/LICENSE +1 -1
- data/README.md +5 -0
- data/Rakefile +0 -15
- data/dnsimple-ruby.gemspec +11 -19
- data/lib/dnsimple-ruby.rb +2 -0
- metadata +20 -288
- data/README.markdown +0 -159
- data/bin/dnsimple +0 -4
- data/bin/dnsimple.rb +0 -156
- data/features/README.md +0 -9
- data/features/cli/certificates/purchase_certificate.feature +0 -10
- data/features/cli/contacts/create_contact.feature +0 -10
- data/features/cli/domains/check_domain.feature +0 -10
- data/features/cli/domains/create_domain.feature +0 -10
- data/features/cli/domains/delete_domain.feature +0 -11
- data/features/cli/domains/register_domain.feature +0 -10
- data/features/cli/records/create_ptr_record.feature +0 -11
- data/features/cli/records/create_record.feature +0 -12
- data/features/cli/records/delete_record.feature +0 -14
- data/features/cli/templates/apply_template.feature +0 -11
- data/features/step_definitions/certificate_steps.rb +0 -3
- data/features/step_definitions/cli_steps.rb +0 -8
- data/features/step_definitions/domain_steps.rb +0 -32
- data/features/step_definitions/record_steps.rb +0 -38
- data/features/step_definitions/template_steps.rb +0 -9
- data/features/support/env.rb +0 -19
- data/lib/dnsimple.rb +0 -33
- data/lib/dnsimple/base.rb +0 -10
- data/lib/dnsimple/certificate.rb +0 -140
- data/lib/dnsimple/cli.rb +0 -121
- data/lib/dnsimple/client.rb +0 -128
- data/lib/dnsimple/commands/certificate_describe.rb +0 -34
- data/lib/dnsimple/commands/certificate_list.rb +0 -15
- data/lib/dnsimple/commands/certificate_purchase.rb +0 -17
- data/lib/dnsimple/commands/certificate_submit.rb +0 -17
- data/lib/dnsimple/commands/contact_create.rb +0 -23
- data/lib/dnsimple/commands/contact_delete.rb +0 -14
- data/lib/dnsimple/commands/contact_describe.rb +0 -25
- data/lib/dnsimple/commands/contact_list.rb +0 -13
- data/lib/dnsimple/commands/contact_update.rb +0 -25
- data/lib/dnsimple/commands/domain_apply_template.rb +0 -15
- data/lib/dnsimple/commands/domain_check.rb +0 -11
- data/lib/dnsimple/commands/domain_clear.rb +0 -16
- data/lib/dnsimple/commands/domain_create.rb +0 -16
- data/lib/dnsimple/commands/domain_delete.rb +0 -14
- data/lib/dnsimple/commands/domain_describe.rb +0 -14
- data/lib/dnsimple/commands/domain_list.rb +0 -13
- data/lib/dnsimple/commands/domain_register.rb +0 -33
- data/lib/dnsimple/commands/domain_transfer.rb +0 -21
- data/lib/dnsimple/commands/extended_attribute_list.rb +0 -25
- data/lib/dnsimple/commands/me.rb +0 -18
- data/lib/dnsimple/commands/record_create.rb +0 -18
- data/lib/dnsimple/commands/record_delete.rb +0 -16
- data/lib/dnsimple/commands/record_describe.rb +0 -16
- data/lib/dnsimple/commands/record_list.rb +0 -19
- data/lib/dnsimple/commands/record_update.rb +0 -23
- data/lib/dnsimple/commands/service_add.rb +0 -14
- data/lib/dnsimple/commands/service_describe.rb +0 -12
- data/lib/dnsimple/commands/service_list.rb +0 -14
- data/lib/dnsimple/commands/service_list_applied.rb +0 -16
- data/lib/dnsimple/commands/service_list_available.rb +0 -16
- data/lib/dnsimple/commands/service_remove.rb +0 -14
- data/lib/dnsimple/commands/template_create.rb +0 -14
- data/lib/dnsimple/commands/template_delete.rb +0 -13
- data/lib/dnsimple/commands/template_list.rb +0 -13
- data/lib/dnsimple/commands/template_record_create.rb +0 -18
- data/lib/dnsimple/commands/template_record_delete.rb +0 -16
- data/lib/dnsimple/commands/template_record_list.rb +0 -17
- data/lib/dnsimple/contact.rb +0 -154
- data/lib/dnsimple/domain.rb +0 -217
- data/lib/dnsimple/error.rb +0 -32
- data/lib/dnsimple/extended_attribute.rb +0 -52
- data/lib/dnsimple/record.rb +0 -94
- data/lib/dnsimple/service.rb +0 -42
- data/lib/dnsimple/template.rb +0 -63
- data/lib/dnsimple/template_record.rb +0 -80
- data/lib/dnsimple/transfer_order.rb +0 -34
- data/lib/dnsimple/user.rb +0 -51
- data/lib/dnsimple/version.rb +0 -3
- data/spec/ci/.dnsimple.test +0 -3
- data/spec/commands/certificate_purchase_spec.rb +0 -25
- data/spec/commands/certificate_submit_spec.rb +0 -18
- data/spec/commands/record_create_spec.rb +0 -23
- data/spec/commands/record_list_spec.rb +0 -23
- data/spec/commands/service_add_spec.rb +0 -20
- data/spec/dnsimple/certificate_spec.rb +0 -59
- data/spec/dnsimple/client_spec.rb +0 -154
- data/spec/dnsimple/contact_spec.rb +0 -45
- data/spec/dnsimple/domain_spec.rb +0 -133
- data/spec/dnsimple/extended_attributes_spec.rb +0 -54
- data/spec/dnsimple/record_spec.rb +0 -51
- data/spec/dnsimple/template_spec.rb +0 -31
- data/spec/dnsimple/user_spec.rb +0 -70
- data/spec/files/2fa/error-badtoken.http +0 -22
- data/spec/files/2fa/error-required.http +0 -23
- data/spec/files/2fa/exchange-token.http +0 -25
- data/spec/files/account/user/success.http +0 -19
- data/spec/files/certificates/index/success.http +0 -19
- data/spec/files/certificates/show/notfound.http +0 -17
- data/spec/files/certificates/show/success.http +0 -19
- data/spec/files/contacts/show/notfound.http +0 -17
- data/spec/files/contacts/show/success.http +0 -19
- data/spec/files/domains/auto_renewal_disable/notfound.http +0 -21
- data/spec/files/domains/auto_renewal_disable/success.http +0 -23
- data/spec/files/domains/auto_renewal_enable/notfound.http +0 -21
- data/spec/files/domains/auto_renewal_enable/success.http +0 -23
- data/spec/files/domains/show/notfound.http +0 -17
- data/spec/files/domains/show/success.http +0 -19
- data/spec/files/extended_attributes/ca.http +0 -19
- data/spec/files/extended_attributes/com.http +0 -19
- data/spec/files/extended_attributes/success.http +0 -19
- data/spec/files/records/index/success.http +0 -19
- data/spec/files/records/show/notfound.http +0 -17
- data/spec/files/records/show/success.http +0 -19
- data/spec/files/templates/show/notfound.http +0 -17
- data/spec/files/templates/show/success.http +0 -19
- data/spec/spec_helper.rb +0 -39
- data/spec/support/helpers.rb +0 -15
- data/spec/support/webmock.rb +0 -11
@@ -1,16 +0,0 @@
|
|
1
|
-
module DNSimple
|
2
|
-
module Commands
|
3
|
-
class RecordDescribe
|
4
|
-
def execute(args, options = {})
|
5
|
-
name = args.shift
|
6
|
-
id = args.shift
|
7
|
-
record = Record.find(name, id)
|
8
|
-
puts "Record #{record.fqdn}:"
|
9
|
-
puts "\tID: #{record.id}"
|
10
|
-
puts "\tTTL: #{record.ttl}"
|
11
|
-
puts "\tPrio: #{record.prio}"
|
12
|
-
puts "\tContent: #{record.content}"
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
module DNSimple
|
2
|
-
module Commands
|
3
|
-
class RecordList
|
4
|
-
def execute(args, options = {})
|
5
|
-
domain_name = args.shift
|
6
|
-
|
7
|
-
records = Record.all(DNSimple::Domain.new(:name => domain_name))
|
8
|
-
|
9
|
-
puts "Found #{records.length} records for #{domain_name}"
|
10
|
-
records.each do |record|
|
11
|
-
extra = ["ttl:#{record.ttl}", "id:#{record.id}"]
|
12
|
-
extra << "prio:#{record.prio}" if record.record_type == "MX"
|
13
|
-
extra = "(#{extra.join(', ')})"
|
14
|
-
puts "\t#{record.name}.#{record.domain.name} (#{record.record_type})-> #{record.content} #{extra}"
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
module DNSimple
|
2
|
-
module Commands
|
3
|
-
class RecordUpdate
|
4
|
-
def execute(args, options = {})
|
5
|
-
attributes = {}
|
6
|
-
domain_name = args.shift
|
7
|
-
id = args.shift
|
8
|
-
args.each do |arg|
|
9
|
-
name, value = arg.split(":")
|
10
|
-
attributes[Record.resolve(name)] = value
|
11
|
-
end
|
12
|
-
|
13
|
-
domain = Domain.find(domain_name)
|
14
|
-
record = Record.find(domain, id)
|
15
|
-
attributes.each do |name, value|
|
16
|
-
record.send("#{name}=", value)
|
17
|
-
end
|
18
|
-
record.save
|
19
|
-
puts "Updated record #{record.fqdn} (id: #{record.id})"
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
@@ -1,14 +0,0 @@
|
|
1
|
-
module DNSimple
|
2
|
-
module Commands
|
3
|
-
class ServiceAdd
|
4
|
-
def execute(args, options = {})
|
5
|
-
domain_name = args.shift
|
6
|
-
domain = Domain.find(domain_name)
|
7
|
-
short_name = args.shift
|
8
|
-
service = Service.find(short_name)
|
9
|
-
domain.add_service(short_name)
|
10
|
-
puts "Added #{service.name} to #{domain_name}"
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
@@ -1,12 +0,0 @@
|
|
1
|
-
module DNSimple
|
2
|
-
module Commands
|
3
|
-
class ServiceDescribe
|
4
|
-
def execute(args, options = {})
|
5
|
-
short_name = args.shift
|
6
|
-
service = Service.find(short_name)
|
7
|
-
puts "\t#{service.name} (short: #{service.short_name}, id: #{service.id})"
|
8
|
-
puts "\t\t#{service.description}"
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
@@ -1,14 +0,0 @@
|
|
1
|
-
module DNSimple
|
2
|
-
module Commands
|
3
|
-
class ServiceList
|
4
|
-
def execute(args, options = {})
|
5
|
-
services = Service.all
|
6
|
-
puts "Found #{services.length} services:"
|
7
|
-
services.each do |service|
|
8
|
-
puts "\t#{service.name} (short: #{service.short_name}, id: #{service.id})"
|
9
|
-
puts "\t\t#{service.description}"
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
module DNSimple
|
2
|
-
module Commands
|
3
|
-
class ServiceListApplied
|
4
|
-
def execute(args, options = {})
|
5
|
-
domain_name = args.shift
|
6
|
-
domain = Domain.find(domain_name)
|
7
|
-
services = domain.applied_services
|
8
|
-
puts "Found #{services.length} applied services for #{domain_name}"
|
9
|
-
services.each do |service|
|
10
|
-
puts "\t#{service.name} (short: #{service.short_name}, id: #{service.id})"
|
11
|
-
puts "\t\t#{service.description}"
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
module DNSimple
|
2
|
-
module Commands
|
3
|
-
class ServiceListAvailable
|
4
|
-
def execute(args, options = {})
|
5
|
-
domain_name = args.shift
|
6
|
-
domain = Domain.find(domain_name)
|
7
|
-
services = domain.available_services
|
8
|
-
puts "Found #{services.length} available services for #{domain_name}"
|
9
|
-
services.each do |service|
|
10
|
-
puts "\t#{service.name} (short: #{service.short_name}, id: #{service.id})"
|
11
|
-
puts "\t\t#{service.description}"
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
@@ -1,14 +0,0 @@
|
|
1
|
-
module DNSimple
|
2
|
-
module Commands
|
3
|
-
class ServiceRemove
|
4
|
-
def execute(args, options = {})
|
5
|
-
domain_name = args.shift
|
6
|
-
domain = Domain.find(domain_name)
|
7
|
-
short_name = args.shift
|
8
|
-
service = Service.find(short_name)
|
9
|
-
domain.remove_service(service.id)
|
10
|
-
puts "Removed #{service.name} from #{domain_name}"
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
@@ -1,14 +0,0 @@
|
|
1
|
-
module DNSimple
|
2
|
-
module Commands
|
3
|
-
class TemplateCreate
|
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
|
@@ -1,13 +0,0 @@
|
|
1
|
-
module DNSimple
|
2
|
-
module Commands
|
3
|
-
class TemplateList
|
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
|
@@ -1,18 +0,0 @@
|
|
1
|
-
module DNSimple
|
2
|
-
module Commands
|
3
|
-
class TemplateRecordCreate
|
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
|
@@ -1,16 +0,0 @@
|
|
1
|
-
module DNSimple
|
2
|
-
module Commands
|
3
|
-
class TemplateRecordDelete
|
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
|
@@ -1,17 +0,0 @@
|
|
1
|
-
module DNSimple
|
2
|
-
module Commands
|
3
|
-
class TemplateRecordList
|
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
|
data/lib/dnsimple/contact.rb
DELETED
@@ -1,154 +0,0 @@
|
|
1
|
-
module DNSimple
|
2
|
-
|
3
|
-
# Represents a contact.
|
4
|
-
class Contact < Base
|
5
|
-
|
6
|
-
Aliases = {
|
7
|
-
'first' => 'first_name',
|
8
|
-
'last' => 'last_name',
|
9
|
-
'state' => 'state_province',
|
10
|
-
'province' => 'state_province',
|
11
|
-
'state_or_province' => 'state_province',
|
12
|
-
'email' => 'email_address',
|
13
|
-
}
|
14
|
-
|
15
|
-
# The contact ID in DNSimple
|
16
|
-
attr_accessor :id
|
17
|
-
|
18
|
-
# The contact first name
|
19
|
-
attr_accessor :first_name
|
20
|
-
|
21
|
-
# The contact last name
|
22
|
-
attr_accessor :last_name
|
23
|
-
|
24
|
-
# The contact's job title
|
25
|
-
attr_accessor :job_title
|
26
|
-
|
27
|
-
# The name of the organization in which the contact works
|
28
|
-
attr_accessor :organization_name
|
29
|
-
|
30
|
-
# The contact email address
|
31
|
-
attr_accessor :email_address
|
32
|
-
|
33
|
-
# The contact phone number
|
34
|
-
attr_accessor :phone
|
35
|
-
|
36
|
-
# The contact phone extension (may be omitted)
|
37
|
-
attr_accessor :phone_ext
|
38
|
-
|
39
|
-
# The contact fax number (may be omitted)
|
40
|
-
attr_accessor :fax
|
41
|
-
|
42
|
-
# The contact street address
|
43
|
-
attr_accessor :address1
|
44
|
-
|
45
|
-
# Apartment or suite number
|
46
|
-
attr_accessor :address2
|
47
|
-
|
48
|
-
# The city name
|
49
|
-
attr_accessor :city
|
50
|
-
|
51
|
-
# The state or province name
|
52
|
-
attr_accessor :state_province
|
53
|
-
|
54
|
-
# The contact postal code
|
55
|
-
attr_accessor :postal_code
|
56
|
-
|
57
|
-
# The contact country (as a 2-character country code)
|
58
|
-
attr_accessor :country
|
59
|
-
|
60
|
-
# When the contact was created in DNSimple
|
61
|
-
attr_accessor :created_at
|
62
|
-
|
63
|
-
# When the contact was last updated in DNSimple
|
64
|
-
attr_accessor :updated_at
|
65
|
-
|
66
|
-
|
67
|
-
# Map an aliased field name to it's real name. For example, if you
|
68
|
-
# pass "first" it will be resolved to "first_name", "email" is resolved
|
69
|
-
# to "email_address" and so on.
|
70
|
-
def self.resolve(name)
|
71
|
-
DNSimple::Contact::Aliases[name.to_s] || name
|
72
|
-
end
|
73
|
-
|
74
|
-
def self.resolve_attributes(attributes)
|
75
|
-
resolved_attributes = {}
|
76
|
-
attributes.each do |k, v|
|
77
|
-
resolved_attributes[resolve(k)] = v
|
78
|
-
end
|
79
|
-
resolved_attributes
|
80
|
-
end
|
81
|
-
|
82
|
-
# Create the contact with the given attributes in DNSimple.
|
83
|
-
# This method returns a Contact instance of the contact is created
|
84
|
-
# and raises an error otherwise.
|
85
|
-
def self.create(attributes, options={})
|
86
|
-
contact_hash = resolve_attributes(attributes)
|
87
|
-
|
88
|
-
options.merge!({:body => {:contact => contact_hash}})
|
89
|
-
response = DNSimple::Client.post("/v1/contacts", options)
|
90
|
-
|
91
|
-
case response.code
|
92
|
-
when 201
|
93
|
-
new(response["contact"])
|
94
|
-
else
|
95
|
-
raise RequestError.new("Error creating contact", response)
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
def self.find(id, options={})
|
100
|
-
response = DNSimple::Client.get("/v1/contacts/#{id}", options)
|
101
|
-
|
102
|
-
case response.code
|
103
|
-
when 200
|
104
|
-
new(response["contact"])
|
105
|
-
when 404
|
106
|
-
raise RecordNotFound, "Could not find contact #{id}"
|
107
|
-
else
|
108
|
-
raise RequestError.new("Error finding contact", response)
|
109
|
-
end
|
110
|
-
end
|
111
|
-
|
112
|
-
def self.all(options={})
|
113
|
-
response = DNSimple::Client.get("/v1/contacts", options)
|
114
|
-
|
115
|
-
case response.code
|
116
|
-
when 200
|
117
|
-
response.map { |r| new(r["contact"]) }
|
118
|
-
else
|
119
|
-
raise RequestError.new("Error listing contacts", response)
|
120
|
-
end
|
121
|
-
end
|
122
|
-
|
123
|
-
|
124
|
-
def name
|
125
|
-
[first_name, last_name].join(' ')
|
126
|
-
end
|
127
|
-
|
128
|
-
def save(options={})
|
129
|
-
contact_hash = {}
|
130
|
-
%w(first_name last_name organization_name job_title address1 address2 city
|
131
|
-
state_province postal_code country email_address phone phone_ext fax).each do |attribute|
|
132
|
-
contact_hash[DNSimple::Contact.resolve(attribute)] = self.send(attribute)
|
133
|
-
end
|
134
|
-
|
135
|
-
options.merge!({:body => {:contact => contact_hash}})
|
136
|
-
|
137
|
-
response = DNSimple::Client.put("/v1/contacts/#{id}", options)
|
138
|
-
|
139
|
-
case response.code
|
140
|
-
when 200
|
141
|
-
return self
|
142
|
-
else
|
143
|
-
raise RequestError.new("Error updating contact", response)
|
144
|
-
end
|
145
|
-
end
|
146
|
-
|
147
|
-
# Delete the contact from DNSimple. WARNING: this cannot be undone.
|
148
|
-
def delete(options={})
|
149
|
-
DNSimple::Client.delete("/v1/contacts/#{id}", options)
|
150
|
-
end
|
151
|
-
alias :destroy :delete
|
152
|
-
|
153
|
-
end
|
154
|
-
end
|
data/lib/dnsimple/domain.rb
DELETED
@@ -1,217 +0,0 @@
|
|
1
|
-
module DNSimple
|
2
|
-
class Domain < Base
|
3
|
-
|
4
|
-
# The domain ID in DNSimple
|
5
|
-
attr_accessor :id
|
6
|
-
|
7
|
-
# The domain name
|
8
|
-
attr_accessor :name
|
9
|
-
|
10
|
-
# When the domain was created in DNSimple
|
11
|
-
attr_accessor :created_at
|
12
|
-
|
13
|
-
# When the domain was last update in DNSimple
|
14
|
-
attr_accessor :updated_at
|
15
|
-
|
16
|
-
# The current known name server status
|
17
|
-
attr_accessor :name_server_status
|
18
|
-
|
19
|
-
# When the domain is due to expire
|
20
|
-
attr_accessor :expires_on
|
21
|
-
|
22
|
-
# The state of the domain in DNSimple
|
23
|
-
attr_accessor :state
|
24
|
-
|
25
|
-
# ID of the registrant in DNSimple
|
26
|
-
attr_accessor :registrant_id
|
27
|
-
|
28
|
-
# User ID in DNSimple
|
29
|
-
attr_accessor :user_id
|
30
|
-
|
31
|
-
# Is the domain lockable
|
32
|
-
attr_accessor :lockable
|
33
|
-
|
34
|
-
# Is the domain set to autorenew
|
35
|
-
attr_accessor :auto_renew
|
36
|
-
|
37
|
-
# Is the whois information protected
|
38
|
-
attr_accessor :whois_protected
|
39
|
-
|
40
|
-
|
41
|
-
# Check the availability of a name
|
42
|
-
def self.check(name, options={})
|
43
|
-
response = DNSimple::Client.get("/v1/domains/#{name}/check", options)
|
44
|
-
|
45
|
-
case response.code
|
46
|
-
when 200
|
47
|
-
"registered"
|
48
|
-
when 404
|
49
|
-
"available"
|
50
|
-
else
|
51
|
-
raise RequestError.new("Error checking availability", response)
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
# Create the domain with the given name in DNSimple. This
|
56
|
-
# method returns a Domain instance if the name is created
|
57
|
-
# and raises an error otherwise.
|
58
|
-
def self.create(name, options={})
|
59
|
-
options.merge!({:body => {:domain => {:name => name}}})
|
60
|
-
|
61
|
-
response = DNSimple::Client.post("/v1/domains", options)
|
62
|
-
|
63
|
-
case response.code
|
64
|
-
when 201
|
65
|
-
new(response["domain"])
|
66
|
-
else
|
67
|
-
raise RequestError.new("Error creating domain", response)
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
# Purchase a domain name.
|
72
|
-
def self.register(name, registrant={}, extended_attributes={}, options={})
|
73
|
-
body = {:domain => {:name => name}}
|
74
|
-
if registrant
|
75
|
-
if registrant[:id]
|
76
|
-
body[:domain][:registrant_id] = registrant[:id]
|
77
|
-
else
|
78
|
-
body.merge!(:contact => DNSimple::Contact.resolve_attributes(registrant))
|
79
|
-
end
|
80
|
-
end
|
81
|
-
body.merge!(:extended_attribute => extended_attributes)
|
82
|
-
options.merge!({:body => body})
|
83
|
-
|
84
|
-
response = DNSimple::Client.post("/v1/domain_registrations", options)
|
85
|
-
|
86
|
-
case response.code
|
87
|
-
when 201
|
88
|
-
return DNSimple::Domain.new(response["domain"])
|
89
|
-
else
|
90
|
-
raise RequestError.new("Error registering domain", response)
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
# Find a specific domain in the account either by the numeric ID
|
95
|
-
# or by the fully-qualified domain name.
|
96
|
-
def self.find(id, options={})
|
97
|
-
response = DNSimple::Client.get("/v1/domains/#{id}", options)
|
98
|
-
|
99
|
-
case response.code
|
100
|
-
when 200
|
101
|
-
new(response["domain"])
|
102
|
-
when 404
|
103
|
-
raise RecordNotFound, "Could not find domain #{id}"
|
104
|
-
else
|
105
|
-
raise RequestError.new("Error finding domain", response)
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
# Get all domains for the account.
|
110
|
-
def self.all(options={})
|
111
|
-
response = DNSimple::Client.get("/v1/domains", options)
|
112
|
-
|
113
|
-
case response.code
|
114
|
-
when 200
|
115
|
-
response.map { |r| new(r["domain"]) }
|
116
|
-
else
|
117
|
-
raise RequestError.new("Error listing domains", response)
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
# Enable auto_renew on the domain
|
122
|
-
def enable_auto_renew
|
123
|
-
return if auto_renew
|
124
|
-
auto_renew!(:post)
|
125
|
-
end
|
126
|
-
|
127
|
-
# Disable auto_renew on the domain
|
128
|
-
def disable_auto_renew
|
129
|
-
return unless auto_renew
|
130
|
-
auto_renew!(:delete)
|
131
|
-
end
|
132
|
-
|
133
|
-
# Delete the domain from DNSimple. WARNING: this cannot
|
134
|
-
# be undone.
|
135
|
-
def delete(options={})
|
136
|
-
DNSimple::Client.delete("/v1/domains/#{name}", options)
|
137
|
-
end
|
138
|
-
alias :destroy :delete
|
139
|
-
|
140
|
-
# Apply the given named template to the domain. This will add
|
141
|
-
# all of the records in the template to the domain.
|
142
|
-
def apply(template, options={})
|
143
|
-
options.merge!(:body => {})
|
144
|
-
template = resolve_template(template)
|
145
|
-
|
146
|
-
DNSimple::Client.post("/v1/domains/#{name}/templates/#{template.id}/apply", options)
|
147
|
-
end
|
148
|
-
|
149
|
-
def resolve_template(template)
|
150
|
-
case template
|
151
|
-
when DNSimple::Template
|
152
|
-
template
|
153
|
-
else
|
154
|
-
DNSimple::Template.find(template)
|
155
|
-
end
|
156
|
-
end
|
157
|
-
|
158
|
-
def applied_services(options={})
|
159
|
-
response = DNSimple::Client.get("/v1/domains/#{name}/applied_services", options)
|
160
|
-
|
161
|
-
case response.code
|
162
|
-
when 200
|
163
|
-
response.map { |r| DNSimple::Service.new(r["service"]) }
|
164
|
-
else
|
165
|
-
raise RequestError.new("Error listing applied services", response)
|
166
|
-
end
|
167
|
-
end
|
168
|
-
|
169
|
-
def available_services(options={})
|
170
|
-
response = DNSimple::Client.get("/v1/domains/#{name}/available_services", options)
|
171
|
-
|
172
|
-
case response.code
|
173
|
-
when 200
|
174
|
-
response.map { |r| DNSimple::Service.new(r["service"]) }
|
175
|
-
else
|
176
|
-
raise RequestError.new("Error listing available services", response)
|
177
|
-
end
|
178
|
-
end
|
179
|
-
|
180
|
-
def add_service(id_or_short_name, options={})
|
181
|
-
options.merge!(:body => {:service => {:id => id_or_short_name}})
|
182
|
-
response = DNSimple::Client.post("/v1/domains/#{name}/applied_services", options)
|
183
|
-
|
184
|
-
case response.code
|
185
|
-
when 200
|
186
|
-
true
|
187
|
-
else
|
188
|
-
raise RequestError.new("Error adding service", response)
|
189
|
-
end
|
190
|
-
end
|
191
|
-
|
192
|
-
def remove_service(id, options={})
|
193
|
-
response = DNSimple::Client.delete("/v1/domains/#{name}/applied_services/#{id}", options)
|
194
|
-
|
195
|
-
case response.code
|
196
|
-
when 200
|
197
|
-
true
|
198
|
-
else
|
199
|
-
raise RequestError.new("Error removing service", response)
|
200
|
-
end
|
201
|
-
end
|
202
|
-
|
203
|
-
|
204
|
-
private
|
205
|
-
|
206
|
-
def auto_renew!(method)
|
207
|
-
response = DNSimple::Client.send(method, "/v1/domains/#{name}/auto_renewal")
|
208
|
-
case response.code
|
209
|
-
when 200
|
210
|
-
self.auto_renew = response['domain']['auto_renew']
|
211
|
-
else
|
212
|
-
raise RequestError.new("Error setting auto_renew", response)
|
213
|
-
end
|
214
|
-
end
|
215
|
-
|
216
|
-
end
|
217
|
-
end
|