dnsimple-ruby 1.3.2 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +9 -2
- data/.rspec +1 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +7 -0
- data/CHANGELOG.md +20 -0
- data/Gemfile +0 -2
- data/LICENSE +2 -2
- data/README.md +121 -0
- data/Rakefile +30 -14
- data/bin/dnsimple.rb +1 -1
- data/dnsimple-ruby.gemspec +9 -8
- data/features/README +1 -1
- data/features/step_definitions/cli_steps.rb +1 -1
- data/features/support/env.rb +4 -4
- data/fixtures/vcr_cassettes/DNSimple_Certificate/_all.yml +45 -32
- data/fixtures/vcr_cassettes/DNSimple_Certificate/_purchase.yml +45 -32
- data/fixtures/vcr_cassettes/DNSimple_Certificate/_submit.yml +45 -32
- data/fixtures/vcr_cassettes/DNSimple_Contact/a_new_contact.yml +39 -31
- data/fixtures/vcr_cassettes/DNSimple_Contact/an_existing_contact.yml +39 -31
- data/fixtures/vcr_cassettes/DNSimple_Domain/_all.yml +113 -94
- data/fixtures/vcr_cassettes/DNSimple_Domain/applying_templates.yml +186 -156
- data/fixtures/vcr_cassettes/DNSimple_Domain/creating_a_new_domain.yml +39 -32
- data/fixtures/vcr_cassettes/DNSimple_Domain/finding_an_existing_domain/by_id.yml +39 -32
- data/fixtures/vcr_cassettes/DNSimple_Domain/finding_an_existing_domain/by_name.yml +39 -32
- data/fixtures/vcr_cassettes/DNSimple_Domain/registration/with_a_new_registrant_contact.yml +40 -32
- data/fixtures/vcr_cassettes/DNSimple_Domain/registration/with_an_existing_contact.yml +40 -32
- data/fixtures/vcr_cassettes/DNSimple_ExtendedAttribute/list_extended_attributes/for_ca.yml +262 -29
- data/fixtures/vcr_cassettes/DNSimple_ExtendedAttribute/list_extended_attributes/for_com.yml +35 -29
- data/fixtures/vcr_cassettes/DNSimple_Record/_all.yml +147 -125
- data/fixtures/vcr_cassettes/DNSimple_Record/creating_a_new_record.yml +39 -32
- data/fixtures/vcr_cassettes/DNSimple_Record/find_a_record.yml +39 -32
- data/fixtures/vcr_cassettes/DNSimple_Template/a_template.yml +41 -32
- data/fixtures/vcr_cassettes/DNSimple_User/_me.yml +38 -31
- data/lib/dnsimple.rb +14 -1
- data/lib/dnsimple/base.rb +7 -5
- data/lib/dnsimple/certificate.rb +100 -95
- data/lib/dnsimple/cli.rb +92 -93
- data/lib/dnsimple/client.rb +109 -99
- data/lib/dnsimple/commands/{describe_certificate.rb → certificate_describe.rb} +2 -2
- data/lib/dnsimple/commands/{list_certificates.rb → certificate_list.rb} +2 -2
- data/lib/dnsimple/commands/{purchase_certificate.rb → certificate_purchase.rb} +3 -5
- data/lib/dnsimple/commands/{submit_certificate.rb → certificate_submit.rb} +3 -5
- data/lib/dnsimple/commands/{create_contact.rb → contact_create.rb} +8 -6
- data/lib/dnsimple/commands/{delete_contact.rb → contact_delete.rb} +2 -2
- data/lib/dnsimple/commands/{describe_contact.rb → contact_describe.rb} +2 -2
- data/lib/dnsimple/commands/{list_contacts.rb → contact_list.rb} +2 -2
- data/lib/dnsimple/commands/{update_contact.rb → contact_update.rb} +2 -2
- data/lib/dnsimple/commands/{apply_template.rb → domain_apply_template.rb} +2 -2
- data/lib/dnsimple/commands/{check_domain.rb → domain_check.rb} +2 -2
- data/lib/dnsimple/commands/{clear_domain.rb → domain_clear.rb} +2 -2
- data/lib/dnsimple/commands/{create_domain.rb → domain_create.rb} +2 -2
- data/lib/dnsimple/commands/{delete_domain.rb → domain_delete.rb} +2 -2
- data/lib/dnsimple/commands/{describe_domain.rb → domain_describe.rb} +2 -2
- data/lib/dnsimple/commands/{list_domains.rb → domain_list.rb} +2 -2
- data/lib/dnsimple/commands/{register_domain.rb → domain_register.rb} +2 -2
- data/lib/dnsimple/commands/{transfer_domain.rb → domain_transfer.rb} +2 -2
- data/lib/dnsimple/commands/{list_extended_attributes.rb → extended_attribute_list.rb} +2 -2
- data/lib/dnsimple/commands/{describe_user.rb → me.rb} +2 -2
- data/lib/dnsimple/commands/{create_record.rb → record_create.rb} +5 -7
- data/lib/dnsimple/commands/{delete_record.rb → record_delete.rb} +2 -2
- data/lib/dnsimple/commands/{describe_record.rb → record_describe.rb} +2 -2
- data/lib/dnsimple/commands/{list_records.rb → record_list.rb} +4 -6
- data/lib/dnsimple/commands/{update_record.rb → record_update.rb} +2 -2
- data/lib/dnsimple/commands/{add_service.rb → service_add.rb} +3 -5
- data/lib/dnsimple/commands/{describe_service.rb → service_describe.rb} +2 -2
- data/lib/dnsimple/commands/{list_services.rb → service_list.rb} +2 -2
- data/lib/dnsimple/commands/{list_applied_services.rb → service_list_applied.rb} +2 -2
- data/lib/dnsimple/commands/{list_available_services.rb → service_list_available.rb} +2 -2
- data/lib/dnsimple/commands/{remove_service.rb → service_remove.rb} +2 -2
- data/lib/dnsimple/commands/{create_template.rb → template_create.rb} +2 -2
- data/lib/dnsimple/commands/{delete_template.rb → template_delete.rb} +2 -2
- data/lib/dnsimple/commands/{add_template_record.rb → template_record_create.rb} +2 -2
- data/lib/dnsimple/commands/{delete_template_record.rb → template_record_delete.rb} +2 -2
- data/lib/dnsimple/commands/{list_template_records.rb → template_record_list.rb} +2 -2
- data/lib/dnsimple/commands/{list_templates.rb → templates_list.rb} +2 -2
- data/lib/dnsimple/contact.rb +115 -110
- data/lib/dnsimple/domain.rb +134 -132
- data/lib/dnsimple/error.rb +8 -19
- data/lib/dnsimple/extended_attribute.rb +39 -33
- data/lib/dnsimple/record.rb +71 -67
- data/lib/dnsimple/service.rb +31 -24
- data/lib/dnsimple/template.rb +52 -46
- data/lib/dnsimple/template_record.rb +61 -53
- data/lib/dnsimple/transfer_order.rb +24 -18
- data/lib/dnsimple/user.rb +22 -18
- data/lib/dnsimple/version.rb +1 -1
- data/spec/README +1 -1
- data/spec/ci/.dnsimple.test +3 -0
- data/spec/commands/{purchase_certificate_spec.rb → certificate_purchase_spec.rb} +3 -4
- data/spec/commands/{submit_certificate_spec.rb → certificate_submit_spec.rb} +3 -4
- data/spec/commands/{create_record_spec.rb → record_create_spec.rb} +4 -4
- data/spec/commands/{list_records_spec.rb → records_list_spec.rb} +2 -13
- data/spec/commands/{add_service_spec.rb → service_add_spec.rb} +3 -12
- data/spec/{certificate_spec.rb → dnsimple/certificate_spec.rb} +0 -0
- data/spec/dnsimple/client_spec.rb +45 -18
- data/spec/{contact_spec.rb → dnsimple/contact_spec.rb} +3 -1
- data/spec/{domain_spec.rb → dnsimple/domain_spec.rb} +2 -0
- data/spec/{extended_attributes_spec.rb → dnsimple/extended_attributes_spec.rb} +4 -0
- data/spec/{record_spec.rb → dnsimple/record_spec.rb} +2 -0
- data/spec/{template_spec.rb → dnsimple/template_spec.rb} +0 -0
- data/spec/{user_spec.rb → dnsimple/user_spec.rb} +2 -0
- data/spec/spec_helper.rb +24 -10
- metadata +96 -99
- data/Gemfile.lock +0 -71
- data/README +0 -108
- data/README.rdoc +0 -108
- data/README.textile +0 -138
- data/lib/dnsimple/command.rb +0 -10
- data/spec/command_spec.rb +0 -19
@@ -1,7 +1,7 @@
|
|
1
1
|
module DNSimple
|
2
2
|
module Commands
|
3
|
-
class
|
4
|
-
def execute(args, options={})
|
3
|
+
class TemplateRecordList
|
4
|
+
def execute(args, options = {})
|
5
5
|
short_name = args.shift
|
6
6
|
template_records = TemplateRecord.all(short_name)
|
7
7
|
puts "Found #{template_records.length} records for #{short_name}"
|
data/lib/dnsimple/contact.rb
CHANGED
@@ -1,148 +1,153 @@
|
|
1
|
-
|
1
|
+
module DNSimple
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
'last' => 'last_name',
|
6
|
-
'state' => 'state_province',
|
7
|
-
'province' => 'state_province',
|
8
|
-
'state_or_province' => 'state_province',
|
9
|
-
'email' => 'email_address',
|
10
|
-
}
|
3
|
+
# Represents a contact.
|
4
|
+
class Contact < Base
|
11
5
|
|
12
|
-
|
13
|
-
|
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
14
|
|
15
|
-
|
16
|
-
|
17
|
-
attr_accessor :organization_name
|
15
|
+
# The contact ID in DNSimple
|
16
|
+
attr_accessor :id
|
18
17
|
|
19
|
-
|
20
|
-
|
18
|
+
# The name of the organization in which the contact works
|
19
|
+
# (may be omitted)
|
20
|
+
attr_accessor :organization_name
|
21
21
|
|
22
|
-
|
23
|
-
|
22
|
+
# The contact first name
|
23
|
+
attr_accessor :first_name
|
24
24
|
|
25
|
-
|
26
|
-
|
25
|
+
# The contact last name
|
26
|
+
attr_accessor :last_name
|
27
27
|
|
28
|
-
|
29
|
-
|
28
|
+
# The contact's job title (may be omitted)
|
29
|
+
attr_accessor :job_title
|
30
30
|
|
31
|
-
|
32
|
-
|
31
|
+
# The contact street address
|
32
|
+
attr_accessor :address1
|
33
33
|
|
34
|
-
|
35
|
-
|
34
|
+
# Apartment or suite number
|
35
|
+
attr_accessor :address2
|
36
36
|
|
37
|
-
|
38
|
-
|
37
|
+
# The city name
|
38
|
+
attr_accessor :city
|
39
39
|
|
40
|
-
|
41
|
-
|
40
|
+
# The state or province name
|
41
|
+
attr_accessor :state_province
|
42
42
|
|
43
|
-
|
44
|
-
|
43
|
+
# The contact postal code
|
44
|
+
attr_accessor :postal_code
|
45
45
|
|
46
|
-
|
47
|
-
|
46
|
+
# The contact country (as a 2-character country code)
|
47
|
+
attr_accessor :country
|
48
48
|
|
49
|
-
|
50
|
-
|
49
|
+
# The contact email address
|
50
|
+
attr_accessor :email_address
|
51
51
|
|
52
|
-
|
53
|
-
|
52
|
+
# The contact phone number
|
53
|
+
attr_accessor :phone
|
54
54
|
|
55
|
-
|
56
|
-
|
55
|
+
# The contact phone extension (may be omitted)
|
56
|
+
attr_accessor :phone_ext
|
57
57
|
|
58
|
-
|
59
|
-
|
58
|
+
# The contact fax number (may be omitted)
|
59
|
+
attr_accessor :fax
|
60
60
|
|
61
|
-
|
62
|
-
|
61
|
+
# When the contact was created in DNSimple
|
62
|
+
attr_accessor :created_at
|
63
63
|
|
64
|
-
|
65
|
-
|
66
|
-
end
|
64
|
+
# When the contact was last updated in DNSimple
|
65
|
+
attr_accessor :updated_at
|
67
66
|
|
68
|
-
|
69
|
-
|
70
|
-
%w(first_name last_name organization_name job_title address1 address2 city
|
71
|
-
state_province postal_code country email_address phone phone_ext fax).each do |attribute|
|
72
|
-
contact_hash[DNSimple::Contact.resolve(attribute)] = self.send(attribute)
|
67
|
+
def name
|
68
|
+
[first_name, last_name].join(' ')
|
73
69
|
end
|
74
70
|
|
75
|
-
options
|
76
|
-
|
77
|
-
|
71
|
+
def save(options={})
|
72
|
+
contact_hash = {}
|
73
|
+
%w(first_name last_name organization_name job_title address1 address2 city
|
74
|
+
state_province postal_code country email_address phone phone_ext fax).each do |attribute|
|
75
|
+
contact_hash[DNSimple::Contact.resolve(attribute)] = self.send(attribute)
|
76
|
+
end
|
78
77
|
|
79
|
-
|
80
|
-
when 200
|
81
|
-
return self
|
82
|
-
else
|
83
|
-
raise RuntimeError, "Failed to update contact: #{response.inspect}"
|
84
|
-
end
|
85
|
-
end
|
78
|
+
options.merge!({:body => {:contact => contact_hash}})
|
86
79
|
|
87
|
-
|
88
|
-
def delete(options={})
|
89
|
-
DNSimple::Client.delete("contacts/#{id}.json", options)
|
90
|
-
end
|
91
|
-
alias :destroy :delete
|
92
|
-
|
93
|
-
# Map an aliased field name to it's real name. For example, if you
|
94
|
-
# pass "first" it will be resolved to "first_name", "email" is resolved
|
95
|
-
# to "email_address" and so on.
|
96
|
-
def self.resolve(name)
|
97
|
-
DNSimple::Contact::Aliases[name.to_s] || name
|
98
|
-
end
|
80
|
+
response = DNSimple::Client.put("contacts/#{id}", options)
|
99
81
|
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
82
|
+
case response.code
|
83
|
+
when 200
|
84
|
+
return self
|
85
|
+
else
|
86
|
+
raise RequestError.new("Error updating contact", response)
|
87
|
+
end
|
104
88
|
end
|
105
|
-
resolved_attributes
|
106
|
-
end
|
107
89
|
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
90
|
+
# Delete the contact from DNSimple. WARNING: this cannot be undone.
|
91
|
+
def delete(options={})
|
92
|
+
DNSimple::Client.delete("contacts/#{id}", options)
|
93
|
+
end
|
94
|
+
alias :destroy :delete
|
113
95
|
|
114
|
-
|
115
|
-
|
96
|
+
# Map an aliased field name to it's real name. For example, if you
|
97
|
+
# pass "first" it will be resolved to "first_name", "email" is resolved
|
98
|
+
# to "email_address" and so on.
|
99
|
+
def self.resolve(name)
|
100
|
+
DNSimple::Contact::Aliases[name.to_s] || name
|
101
|
+
end
|
116
102
|
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
103
|
+
def self.resolve_attributes(attributes)
|
104
|
+
resolved_attributes = {}
|
105
|
+
attributes.each do |k, v|
|
106
|
+
resolved_attributes[resolve(k)] = v
|
107
|
+
end
|
108
|
+
resolved_attributes
|
122
109
|
end
|
123
|
-
end
|
124
110
|
|
125
|
-
|
126
|
-
|
111
|
+
# Create the contact with the given attributes in DNSimple.
|
112
|
+
# This method returns a Contact instance of the contact is created
|
113
|
+
# and raises an error otherwise.
|
114
|
+
def self.create(attributes, options={})
|
115
|
+
contact_hash = resolve_attributes(attributes)
|
116
|
+
|
117
|
+
options.merge!({:body => {:contact => contact_hash}})
|
118
|
+
response = DNSimple::Client.post("contacts", options)
|
119
|
+
|
120
|
+
case response.code
|
121
|
+
when 201
|
122
|
+
new(response["contact"])
|
123
|
+
else
|
124
|
+
raise RequestError.new("Error creating contact", response)
|
125
|
+
end
|
126
|
+
end
|
127
127
|
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
128
|
+
def self.find(id, options={})
|
129
|
+
response = DNSimple::Client.get("contacts/#{id}", options)
|
130
|
+
|
131
|
+
case response.code
|
132
|
+
when 200
|
133
|
+
new(response["contact"])
|
134
|
+
when 404
|
135
|
+
raise RecordNotFound, "Could not find contact #{id}"
|
136
|
+
else
|
137
|
+
raise RequestError.new("Error finding contact", response)
|
138
|
+
end
|
135
139
|
end
|
136
|
-
end
|
137
140
|
|
138
|
-
|
139
|
-
|
141
|
+
def self.all(options={})
|
142
|
+
response = DNSimple::Client.get("contacts", options)
|
140
143
|
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
144
|
+
case response.code
|
145
|
+
when 200
|
146
|
+
response.map { |r| new(r["contact"]) }
|
147
|
+
else
|
148
|
+
raise RequestError.new("Error listing contacts", response)
|
149
|
+
end
|
146
150
|
end
|
151
|
+
|
147
152
|
end
|
148
153
|
end
|
data/lib/dnsimple/domain.rb
CHANGED
@@ -1,171 +1,173 @@
|
|
1
|
-
|
2
|
-
# The domain ID in DNSimple
|
3
|
-
attr_accessor :id
|
1
|
+
module DNSimple
|
4
2
|
|
5
|
-
#
|
6
|
-
|
3
|
+
# Represents a single domain.
|
4
|
+
class Domain < Base
|
5
|
+
# The domain ID in DNSimple
|
6
|
+
attr_accessor :id
|
7
7
|
|
8
|
-
|
9
|
-
|
8
|
+
# The domain name
|
9
|
+
attr_accessor :name
|
10
10
|
|
11
|
-
|
12
|
-
|
11
|
+
# When the domain was created in DNSimple
|
12
|
+
attr_accessor :created_at
|
13
13
|
|
14
|
-
|
15
|
-
|
14
|
+
# When the domain was last update in DNSimple
|
15
|
+
attr_accessor :updated_at
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
def delete(options={})
|
20
|
-
DNSimple::Client.delete "domains/#{name}", options
|
21
|
-
end
|
22
|
-
alias :destroy :delete
|
17
|
+
# The current known name server status
|
18
|
+
attr_accessor :name_server_status
|
23
19
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
20
|
+
# Delete the domain from DNSimple. WARNING: this cannot
|
21
|
+
# be undone.
|
22
|
+
def delete(options={})
|
23
|
+
DNSimple::Client.delete("domains/#{name}", options)
|
24
|
+
end
|
25
|
+
alias :destroy :delete
|
29
26
|
|
30
|
-
|
31
|
-
|
32
|
-
|
27
|
+
# Apply the given named template to the domain. This will add
|
28
|
+
# all of the records in the template to the domain.
|
29
|
+
def apply(template, options={})
|
30
|
+
options.merge!(:body => {})
|
31
|
+
template = resolve_template(template)
|
33
32
|
|
34
|
-
|
35
|
-
def resolve_template(template)
|
36
|
-
case template
|
37
|
-
when DNSimple::Template
|
38
|
-
template
|
39
|
-
else
|
40
|
-
DNSimple::Template.find(template)
|
33
|
+
DNSimple::Client.post("domains/#{name}/templates/#{template.id}/apply", options)
|
41
34
|
end
|
42
|
-
end
|
43
|
-
|
44
|
-
def applied_services(options={})
|
45
|
-
response = DNSimple::Client.get "domains/#{name}/applied_services",
|
46
|
-
options
|
47
35
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
36
|
+
#:nodoc:
|
37
|
+
def resolve_template(template)
|
38
|
+
case template
|
39
|
+
when DNSimple::Template
|
40
|
+
template
|
41
|
+
else
|
42
|
+
DNSimple::Template.find(template)
|
43
|
+
end
|
53
44
|
end
|
54
|
-
end
|
55
45
|
|
56
|
-
|
57
|
-
|
58
|
-
options
|
46
|
+
def applied_services(options={})
|
47
|
+
response = DNSimple::Client.get("domains/#{name}/applied_services", options)
|
59
48
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
49
|
+
case response.code
|
50
|
+
when 200
|
51
|
+
response.map { |r| DNSimple::Service.new(r["service"]) }
|
52
|
+
else
|
53
|
+
raise RequestError.new("Error listing applied services", response)
|
54
|
+
end
|
65
55
|
end
|
66
|
-
end
|
67
56
|
|
68
|
-
|
69
|
-
|
70
|
-
response = DNSimple::Client.post "domains/#{name}/applied_services",
|
71
|
-
options
|
57
|
+
def available_services(options={})
|
58
|
+
response = DNSimple::Client.get("domains/#{name}/available_services", options)
|
72
59
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
60
|
+
case response.code
|
61
|
+
when 200
|
62
|
+
response.map { |r| DNSimple::Service.new(r["service"]) }
|
63
|
+
else
|
64
|
+
raise RequestError.new("Error listing available services", response)
|
65
|
+
end
|
78
66
|
end
|
79
|
-
end
|
80
67
|
|
81
|
-
|
82
|
-
|
68
|
+
def add_service(id_or_short_name, options={})
|
69
|
+
options.merge!(:body => {:service => {:id => id_or_short_name}})
|
70
|
+
response = DNSimple::Client.post("domains/#{name}/applied_services", options)
|
83
71
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
72
|
+
case response.code
|
73
|
+
when 200
|
74
|
+
true
|
75
|
+
else
|
76
|
+
raise RequestError.new("Error adding service", response)
|
77
|
+
end
|
89
78
|
end
|
90
|
-
end
|
91
79
|
|
92
|
-
|
93
|
-
|
94
|
-
response = DNSimple::Client.get("domains/#{name}/check", options)
|
95
|
-
|
96
|
-
case response.code
|
97
|
-
when 200
|
98
|
-
"registered"
|
99
|
-
when 404
|
100
|
-
"available"
|
101
|
-
else
|
102
|
-
raise "Error: #{response.code}"
|
103
|
-
end
|
104
|
-
end
|
80
|
+
def remove_service(id, options={})
|
81
|
+
response = DNSimple::Client.delete("domains/#{name}/applied_services/#{id}", options)
|
105
82
|
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
83
|
+
case response.code
|
84
|
+
when 200
|
85
|
+
true
|
86
|
+
else
|
87
|
+
raise RequestError.new("Error removing service", response)
|
88
|
+
end
|
89
|
+
end
|
111
90
|
|
112
|
-
|
91
|
+
# Check the availability of a name
|
92
|
+
def self.check(name, options={})
|
93
|
+
response = DNSimple::Client.get("domains/#{name}/check", options)
|
113
94
|
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
95
|
+
case response.code
|
96
|
+
when 200
|
97
|
+
"registered"
|
98
|
+
when 404
|
99
|
+
"available"
|
100
|
+
else
|
101
|
+
raise RequestError.new("Error checking availability", response)
|
102
|
+
end
|
119
103
|
end
|
120
|
-
end
|
121
104
|
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
105
|
+
# Create the domain with the given name in DNSimple. This
|
106
|
+
# method returns a Domain instance if the name is created
|
107
|
+
# and raises an error otherwise.
|
108
|
+
def self.create(name, options={})
|
109
|
+
options.merge!({:body => {:domain => {:name => name}}})
|
110
|
+
|
111
|
+
response = DNSimple::Client.post("domains", options)
|
112
|
+
|
113
|
+
case response.code
|
114
|
+
when 201
|
115
|
+
new(response["domain"])
|
128
116
|
else
|
129
|
-
|
117
|
+
raise RequestError.new("Error creating domain", response)
|
130
118
|
end
|
131
119
|
end
|
132
|
-
body.merge!(:extended_attribute => extended_attributes)
|
133
|
-
options.merge!({:body => body})
|
134
120
|
|
135
|
-
|
121
|
+
# Purchase a domain name.
|
122
|
+
def self.register(name, registrant={}, extended_attributes={}, options={})
|
123
|
+
body = {:domain => {:name => name}}
|
124
|
+
if registrant
|
125
|
+
if registrant[:id]
|
126
|
+
body[:domain][:registrant_id] = registrant[:id]
|
127
|
+
else
|
128
|
+
body.merge!(:contact => DNSimple::Contact.resolve_attributes(registrant))
|
129
|
+
end
|
130
|
+
end
|
131
|
+
body.merge!(:extended_attribute => extended_attributes)
|
132
|
+
options.merge!({:body => body})
|
133
|
+
|
134
|
+
response = DNSimple::Client.post("domain_registrations", options)
|
136
135
|
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
136
|
+
case response.code
|
137
|
+
when 201
|
138
|
+
return DNSimple::Domain.new(response["domain"])
|
139
|
+
else
|
140
|
+
raise RequestError.new("Error registering domain", response)
|
141
|
+
end
|
142
142
|
end
|
143
|
-
end
|
144
143
|
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
144
|
+
# Find a specific domain in the account either by the numeric ID
|
145
|
+
# or by the fully-qualified domain name.
|
146
|
+
def self.find(id_or_name, options={})
|
147
|
+
id = id_or_name
|
148
|
+
response = DNSimple::Client.get("domains/#{id}", options)
|
149
|
+
|
150
|
+
case response.code
|
151
|
+
when 200
|
152
|
+
new(response["domain"])
|
153
|
+
when 404
|
154
|
+
raise RecordNotFound, "Could not find domain #{id}"
|
155
|
+
else
|
156
|
+
raise RequestError.new("Error finding domain", response)
|
157
|
+
end
|
157
158
|
end
|
158
|
-
end
|
159
159
|
|
160
|
-
|
161
|
-
|
162
|
-
|
160
|
+
# Get all domains for the account.
|
161
|
+
def self.all(options={})
|
162
|
+
response = DNSimple::Client.get("domains", options)
|
163
163
|
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
164
|
+
case response.code
|
165
|
+
when 200
|
166
|
+
response.map { |r| new(r["domain"]) }
|
167
|
+
else
|
168
|
+
raise RequestError.new("Error listing domains", response)
|
169
|
+
end
|
169
170
|
end
|
171
|
+
|
170
172
|
end
|
171
173
|
end
|