dnsimple-ruby 1.2.6 → 1.3.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/.gitignore +3 -0
- data/Gemfile +2 -13
- data/Gemfile.lock +7 -7
- data/Rakefile +2 -18
- data/dnsimple-ruby.gemspec +24 -178
- data/features/support/env.rb +5 -3
- data/lib/dnsimple-ruby.rb +1 -0
- data/lib/dnsimple.rb +1 -0
- data/lib/dnsimple/base.rb +8 -0
- data/lib/dnsimple/certificate.rb +95 -130
- data/lib/dnsimple/client.rb +94 -56
- data/lib/dnsimple/contact.rb +111 -144
- data/lib/dnsimple/domain.rb +145 -194
- data/lib/dnsimple/extended_attribute.rb +33 -60
- data/lib/dnsimple/record.rb +70 -103
- data/lib/dnsimple/service.rb +24 -47
- data/lib/dnsimple/template.rb +47 -75
- data/lib/dnsimple/template_record.rb +53 -84
- data/lib/dnsimple/transfer_order.rb +17 -34
- data/lib/dnsimple/user.rb +18 -32
- data/lib/dnsimple/version.rb +3 -0
- data/spec/commands/purchase_certificate_spec.rb +16 -4
- data/spec/dnsimple/client_spec.rb +58 -0
- data/spec/spec_helper.rb +4 -2
- metadata +59 -92
- data/.bundle/config +0 -3
- data/.rvmrc +0 -1
- data/VERSION +0 -1
data/lib/dnsimple/domain.rb
CHANGED
@@ -1,220 +1,171 @@
|
|
1
|
-
|
2
|
-
#
|
3
|
-
|
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
|
1
|
+
class DNSimple::Domain < DNSimple::Base # Class representing a single domain in DNSimple.
|
2
|
+
# The domain ID in DNSimple
|
3
|
+
attr_accessor :id
|
28
4
|
|
29
|
-
|
30
|
-
|
31
|
-
def delete(options={})
|
32
|
-
options.merge!(DNSimple::Client.standard_options_with_credentials)
|
33
|
-
self.class.delete("#{DNSimple::Client.base_uri}/domains/#{name}", options)
|
34
|
-
end
|
35
|
-
alias :destroy :delete
|
36
|
-
|
37
|
-
# Apply the given named template to the domain. This will add
|
38
|
-
# all of the records in the template to the domain.
|
39
|
-
def apply(template, options={})
|
40
|
-
options.merge!(DNSimple::Client.standard_options_with_credentials)
|
41
|
-
options.merge!(:body => {})
|
42
|
-
template = resolve_template(template)
|
43
|
-
self.class.post("#{DNSimple::Client.base_uri}/domains/#{name}/templates/#{template.id}/apply", options)
|
44
|
-
end
|
5
|
+
# The domain name
|
6
|
+
attr_accessor :name
|
45
7
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
8
|
+
# When the domain was created in DNSimple
|
9
|
+
attr_accessor :created_at
|
10
|
+
|
11
|
+
# When the domain was last update in DNSimple
|
12
|
+
attr_accessor :updated_at
|
13
|
+
|
14
|
+
# The current known name server status
|
15
|
+
attr_accessor :name_server_status
|
16
|
+
|
17
|
+
# Delete the domain from DNSimple. WARNING: this cannot
|
18
|
+
# be undone.
|
19
|
+
def delete(options={})
|
20
|
+
DNSimple::Client.delete "domains/#{name}", options
|
21
|
+
end
|
22
|
+
alias :destroy :delete
|
23
|
+
|
24
|
+
# Apply the given named template to the domain. This will add
|
25
|
+
# all of the records in the template to the domain.
|
26
|
+
def apply(template, options={})
|
27
|
+
options.merge!(:body => {})
|
28
|
+
template = resolve_template(template)
|
29
|
+
|
30
|
+
DNSimple::Client.post "domains/#{name}/templates/#{template.id}/apply",
|
31
|
+
options
|
32
|
+
end
|
33
|
+
|
34
|
+
#:nodoc:
|
35
|
+
def resolve_template(template)
|
36
|
+
case template
|
37
|
+
when DNSimple::Template
|
38
|
+
template
|
39
|
+
else
|
40
|
+
DNSimple::Template.find(template)
|
54
41
|
end
|
42
|
+
end
|
55
43
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
else
|
66
|
-
raise RuntimeError, "Error: #{response.code}"
|
67
|
-
end
|
44
|
+
def applied_services(options={})
|
45
|
+
response = DNSimple::Client.get "domains/#{name}/applied_services",
|
46
|
+
options
|
47
|
+
|
48
|
+
case response.code
|
49
|
+
when 200
|
50
|
+
response.map { |r| DNSimple::Service.new(r["service"]) }
|
51
|
+
else
|
52
|
+
raise RuntimeError, "Error: #{response.code}"
|
68
53
|
end
|
54
|
+
end
|
69
55
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
else
|
80
|
-
raise RuntimeError, "Error: #{response.code}"
|
81
|
-
end
|
56
|
+
def available_services(options={})
|
57
|
+
response = DNSimple::Client.get "domains/#{name}/available_services",
|
58
|
+
options
|
59
|
+
|
60
|
+
case response.code
|
61
|
+
when 200
|
62
|
+
response.map { |r| DNSimple::Service.new(r["service"]) }
|
63
|
+
else
|
64
|
+
raise RuntimeError, "Error: #{response.code}"
|
82
65
|
end
|
66
|
+
end
|
83
67
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
else
|
95
|
-
raise "Error: #{response.code}"
|
96
|
-
end
|
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",
|
71
|
+
options
|
72
|
+
|
73
|
+
case response.code
|
74
|
+
when 200
|
75
|
+
true
|
76
|
+
else
|
77
|
+
raise "Error: #{response.code}"
|
97
78
|
end
|
79
|
+
end
|
98
80
|
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
raise RuntimeError, "Authentication failed"
|
108
|
-
else
|
109
|
-
raise "Error: #{response.code}"
|
110
|
-
end
|
81
|
+
def remove_service(id, options={})
|
82
|
+
response = DNSimple::Client.delete("domains/#{name}/applied_services/#{id}", options)
|
83
|
+
|
84
|
+
case response.code
|
85
|
+
when 200
|
86
|
+
true
|
87
|
+
else
|
88
|
+
raise "Error: #{response.code}"
|
111
89
|
end
|
90
|
+
end
|
112
91
|
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
"available"
|
125
|
-
else
|
126
|
-
raise "Error: #{response.code}"
|
127
|
-
end
|
92
|
+
# Check the availability of a name
|
93
|
+
def self.check(name, options={})
|
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}"
|
128
103
|
end
|
104
|
+
end
|
129
105
|
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
case response.code
|
144
|
-
when 201
|
145
|
-
return DNSimple::Domain.new(response["domain"])
|
146
|
-
when 401
|
147
|
-
raise RuntimeError, "Authentication failed"
|
148
|
-
else
|
149
|
-
raise DNSimple::DomainError.new(name, response["errors"])
|
150
|
-
end
|
106
|
+
# Create the domain with the given name in DNSimple. This
|
107
|
+
# method returns a Domain instance if the name is created
|
108
|
+
# and raises an error otherwise.
|
109
|
+
def self.create(name, options={})
|
110
|
+
options.merge!({:body => {:domain => {:name => name}}})
|
111
|
+
|
112
|
+
response = DNSimple::Client.post('domains', options)
|
113
|
+
|
114
|
+
case response.code
|
115
|
+
when 201
|
116
|
+
return new(response["domain"])
|
117
|
+
else
|
118
|
+
raise DNSimple::DomainError.new(name, response["errors"])
|
151
119
|
end
|
120
|
+
end
|
152
121
|
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
if registrant[:id]
|
160
|
-
body[:domain][:registrant_id] = registrant[:id]
|
161
|
-
else
|
162
|
-
body.merge!(:contact => Contact.resolve_attributes(registrant))
|
163
|
-
end
|
164
|
-
end
|
165
|
-
body.merge!(:extended_attribute => extended_attributes)
|
166
|
-
options.merge!({:body => body})
|
167
|
-
|
168
|
-
response = self.post("#{DNSimple::Client.base_uri}/domain_registrations", options)
|
169
|
-
|
170
|
-
pp response if DNSimple::Client.debug?
|
171
|
-
|
172
|
-
case response.code
|
173
|
-
when 201
|
174
|
-
return DNSimple::Domain.new(response["domain"])
|
175
|
-
when 401
|
176
|
-
raise RuntimeError, "Authentication failed"
|
122
|
+
# Purchase a domain name.
|
123
|
+
def self.register(name, registrant={}, extended_attributes={}, options={})
|
124
|
+
body = {:domain => {:name => name}}
|
125
|
+
if registrant
|
126
|
+
if registrant[:id]
|
127
|
+
body[:domain][:registrant_id] = registrant[:id]
|
177
128
|
else
|
178
|
-
|
129
|
+
body.merge!(:contact => DNSimple::Contact.resolve_attributes(registrant))
|
179
130
|
end
|
180
131
|
end
|
132
|
+
body.merge!(:extended_attribute => extended_attributes)
|
133
|
+
options.merge!({:body => body})
|
181
134
|
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
case response.code
|
191
|
-
when 200
|
192
|
-
return DNSimple::Domain.new(response["domain"])
|
193
|
-
when 401
|
194
|
-
raise RuntimeError, "Authentication failed"
|
195
|
-
when 404
|
196
|
-
raise RuntimeError, "Could not find domain #{id_or_name}"
|
197
|
-
else
|
198
|
-
raise DNSimple::DomainError.new(id_or_name, response["errors"])
|
199
|
-
end
|
135
|
+
response = DNSimple::Client.post('domain_registrations', options)
|
136
|
+
|
137
|
+
case response.code
|
138
|
+
when 201
|
139
|
+
return DNSimple::Domain.new(response["domain"])
|
140
|
+
else
|
141
|
+
raise DNSimple::DomainError.new(name, response["errors"])
|
200
142
|
end
|
143
|
+
end
|
201
144
|
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
else
|
215
|
-
raise RuntimeError, "Error: #{response.code}"
|
216
|
-
end
|
145
|
+
# Find a specific domain in the account either by the numeric ID
|
146
|
+
# or by the fully-qualified domain name.
|
147
|
+
def self.find(id_or_name, options={})
|
148
|
+
response = DNSimple::Client.get "domains/#{id_or_name}", options
|
149
|
+
|
150
|
+
case response.code
|
151
|
+
when 200
|
152
|
+
return new(response["domain"])
|
153
|
+
when 404
|
154
|
+
raise RuntimeError, "Could not find domain #{id_or_name}"
|
155
|
+
else
|
156
|
+
raise DNSimple::Error.new(id_or_name, response["errors"])
|
217
157
|
end
|
158
|
+
end
|
159
|
+
|
160
|
+
# Get all domains for the account.
|
161
|
+
def self.all(options={})
|
162
|
+
response = DNSimple::Client.get 'domains', options
|
218
163
|
|
164
|
+
case response.code
|
165
|
+
when 200
|
166
|
+
response.map { |r| new(r["domain"]) }
|
167
|
+
else
|
168
|
+
raise RuntimeError, "Error: #{response.code}"
|
169
|
+
end
|
219
170
|
end
|
220
171
|
end
|
@@ -1,73 +1,46 @@
|
|
1
|
-
|
2
|
-
#
|
3
|
-
class
|
4
|
-
#
|
5
|
-
|
6
|
-
# The option name
|
7
|
-
attr_accessor :title
|
1
|
+
class DNSimple::ExtendedAttribute < DNSimple::Base # Used for domains that require extended attributes.
|
2
|
+
# An option for an extended attribute
|
3
|
+
class Option < DNSimple::Base
|
4
|
+
# The option name
|
5
|
+
attr_accessor :title
|
8
6
|
|
9
|
-
|
10
|
-
|
7
|
+
# The option value
|
8
|
+
attr_accessor :value
|
11
9
|
|
12
|
-
|
13
|
-
attr_accessor :description
|
14
|
-
|
15
|
-
#:nodoc:
|
16
|
-
def initialize(attributes)
|
17
|
-
attributes.each do |key, value|
|
18
|
-
m = "#{key}=".to_sym
|
19
|
-
self.send(m, value) if self.respond_to?(m)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
include HTTParty
|
25
|
-
|
26
|
-
# The extended attribute name
|
27
|
-
attr_accessor :name
|
28
|
-
|
29
|
-
# A description of the extended attribute
|
10
|
+
# A long description of the option
|
30
11
|
attr_accessor :description
|
12
|
+
end
|
31
13
|
|
32
|
-
|
33
|
-
|
14
|
+
# The extended attribute name
|
15
|
+
attr_accessor :name
|
34
16
|
|
35
|
-
|
36
|
-
|
37
|
-
attributes.each do |key, value|
|
38
|
-
m = "#{key}=".to_sym
|
39
|
-
self.send(m, value) if self.respond_to?(m)
|
40
|
-
end
|
41
|
-
end
|
17
|
+
# A description of the extended attribute
|
18
|
+
attr_accessor :description
|
42
19
|
|
43
|
-
|
44
|
-
|
45
|
-
@options ||= []
|
46
|
-
end
|
20
|
+
# Boolean indicating if the extended attribute is required
|
21
|
+
attr_accessor :required
|
47
22
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
end
|
53
|
-
end
|
23
|
+
# An array of options for the extended attribute
|
24
|
+
def options
|
25
|
+
@options ||= []
|
26
|
+
end
|
54
27
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
28
|
+
def options=(opts)
|
29
|
+
@options = []
|
30
|
+
opts.each do |opt|
|
31
|
+
@options << DNSimple::ExtendedAttribute::Option.new(opt)
|
32
|
+
end
|
33
|
+
end
|
60
34
|
|
61
|
-
|
35
|
+
# Find the extended attributes for the given TLD
|
36
|
+
def self.find(tld, options={})
|
37
|
+
response = DNSimple::Client.get "extended_attributes/#{tld}.json", options
|
62
38
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
else
|
69
|
-
raise RuntimeError, "Error: #{response.code}"
|
70
|
-
end
|
39
|
+
case response.code
|
40
|
+
when 200
|
41
|
+
response.map { |r| new(r) }
|
42
|
+
else
|
43
|
+
raise RuntimeError, "Error: #{response.code}"
|
71
44
|
end
|
72
45
|
end
|
73
46
|
end
|