dnsimple 2.0.0.a → 2.0.0.alpha2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.ruby-version +1 -1
- data/.travis.yml +1 -2
- data/CHANGELOG.markdown +26 -2
- data/Gemfile +2 -0
- data/README.markdown +56 -36
- data/Rakefile +0 -1
- data/{dnsimple-ruby.gemspec → dnsimple.gemspec} +6 -4
- data/lib/dnsimple.rb +1 -1
- data/lib/dnsimple/base.rb +1 -1
- data/lib/dnsimple/certificate.rb +49 -35
- data/lib/dnsimple/client.rb +25 -72
- data/lib/dnsimple/contact.rb +12 -9
- data/lib/dnsimple/domain.rb +117 -82
- data/lib/dnsimple/error.rb +13 -2
- data/lib/dnsimple/extended_attribute.rb +3 -3
- data/lib/dnsimple/record.rb +9 -9
- data/lib/dnsimple/service.rb +3 -3
- data/lib/dnsimple/template.rb +8 -6
- data/lib/dnsimple/template_record.rb +8 -8
- data/lib/dnsimple/transfer_order.rb +2 -2
- data/lib/dnsimple/user.rb +26 -2
- data/lib/dnsimple/version.rb +2 -2
- data/spec/dnsimple/certificate_spec.rb +8 -5
- data/spec/dnsimple/client_spec.rb +56 -9
- data/spec/dnsimple/contact_spec.rb +2 -2
- data/spec/dnsimple/domain_spec.rb +140 -32
- data/spec/dnsimple/extended_attributes_spec.rb +1 -1
- data/spec/dnsimple/record_spec.rb +2 -2
- data/spec/dnsimple/template_spec.rb +1 -1
- data/spec/dnsimple/user_spec.rb +40 -1
- data/spec/files/2fa/error-badtoken.http +22 -0
- data/spec/files/2fa/error-required.http +23 -0
- data/spec/files/2fa/exchange-token.http +25 -0
- data/spec/files/account/user/success.http +3 -3
- data/spec/files/certificates/index/success.http +2 -2
- data/spec/files/certificates/show/notfound.http +2 -2
- data/spec/files/certificates/show/success.http +2 -2
- data/spec/files/contacts/show/notfound.http +2 -2
- data/spec/files/contacts/show/success.http +3 -3
- data/spec/files/domains/auto_renewal_disable/notfound.http +1 -1
- data/spec/files/domains/auto_renewal_disable/success.http +1 -1
- data/spec/files/domains/auto_renewal_enable/notfound.http +1 -1
- data/spec/files/domains/auto_renewal_enable/success.http +1 -1
- data/spec/files/domains/create/success.http +19 -0
- data/spec/files/domains/delete/success-204.http +18 -0
- data/spec/files/domains/delete/success.http +19 -0
- data/spec/files/domains/index/success.http +19 -0
- data/spec/files/domains/{show/notfound.http → notfound.http} +2 -2
- data/spec/files/domains/show/success.http +2 -2
- data/spec/files/extended_attributes/ca.http +2 -2
- data/spec/files/extended_attributes/com.http +2 -2
- data/spec/files/extended_attributes/success.http +2 -2
- data/spec/files/records/index/success.http +2 -2
- data/spec/files/records/show/notfound.http +2 -2
- data/spec/files/records/show/success.http +2 -2
- data/spec/files/templates/show/notfound.http +2 -2
- data/spec/files/templates/show/success.http +2 -2
- data/spec/spec_helper.rb +9 -9
- metadata +45 -33
- data/lib/dnsimple-ruby.rb +0 -1
- data/spec/ci/.dnsimple.test +0 -3
data/lib/dnsimple/service.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
module
|
1
|
+
module Dnsimple
|
2
2
|
|
3
3
|
# Represents a service that can be applied to a domain.
|
4
4
|
class Service < Base
|
@@ -14,7 +14,7 @@ module DNSimple
|
|
14
14
|
# Find a service by its ID or short name
|
15
15
|
def self.find(id_or_short_name, options={})
|
16
16
|
id = id_or_short_name
|
17
|
-
response =
|
17
|
+
response = Client.get("/v1/services/#{id}", options)
|
18
18
|
|
19
19
|
case response.code
|
20
20
|
when 200
|
@@ -28,7 +28,7 @@ module DNSimple
|
|
28
28
|
|
29
29
|
# Get all of the services that can be applied to a domain
|
30
30
|
def self.all(options={})
|
31
|
-
response =
|
31
|
+
response = Client.get("/v1/services", options)
|
32
32
|
|
33
33
|
case response.code
|
34
34
|
when 200
|
data/lib/dnsimple/template.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
module
|
1
|
+
module Dnsimple
|
2
2
|
class Template < Base
|
3
3
|
|
4
4
|
attr_accessor :id
|
@@ -16,7 +16,7 @@ module DNSimple
|
|
16
16
|
|
17
17
|
options.merge!(:body => {:dns_template => template_hash})
|
18
18
|
|
19
|
-
response =
|
19
|
+
response = Client.post("/v1/templates", options)
|
20
20
|
|
21
21
|
case response.code
|
22
22
|
when 201
|
@@ -28,7 +28,7 @@ module DNSimple
|
|
28
28
|
|
29
29
|
def self.find(id_or_short_name, options={})
|
30
30
|
id = id_or_short_name
|
31
|
-
response =
|
31
|
+
response = Client.get("/v1/templates/#{id}", options)
|
32
32
|
|
33
33
|
case response.code
|
34
34
|
when 200
|
@@ -41,7 +41,7 @@ module DNSimple
|
|
41
41
|
end
|
42
42
|
|
43
43
|
def self.all(options={})
|
44
|
-
response =
|
44
|
+
response = Client.get("/v1/templates", options)
|
45
45
|
|
46
46
|
case response.code
|
47
47
|
when 200
|
@@ -52,10 +52,12 @@ module DNSimple
|
|
52
52
|
end
|
53
53
|
|
54
54
|
|
55
|
-
#
|
55
|
+
# #delete the template from DNSimple.
|
56
|
+
#
|
56
57
|
# WARNING: this cannot be undone.
|
58
|
+
#
|
57
59
|
def delete(options={})
|
58
|
-
|
60
|
+
Client.delete("/v1/templates/#{id}", options)
|
59
61
|
end
|
60
62
|
alias :destroy :delete
|
61
63
|
|
@@ -1,4 +1,4 @@
|
|
1
|
-
module
|
1
|
+
module Dnsimple
|
2
2
|
|
3
3
|
# A single record in a template.
|
4
4
|
class TemplateRecord < Base
|
@@ -25,12 +25,12 @@ module DNSimple
|
|
25
25
|
attr_accessor :prio
|
26
26
|
|
27
27
|
def delete(options={})
|
28
|
-
|
28
|
+
Client.delete("/v1/templates/#{template.id}/template_records/#{id}", options)
|
29
29
|
end
|
30
30
|
alias :destroy :delete
|
31
31
|
|
32
32
|
def self.create(short_name, name, record_type, content, options={})
|
33
|
-
template =
|
33
|
+
template = Template.find(short_name)
|
34
34
|
|
35
35
|
record_hash = {:name => name, :record_type => record_type, :content => content}
|
36
36
|
record_hash[:ttl] = options.delete(:ttl) || 3600
|
@@ -38,7 +38,7 @@ module DNSimple
|
|
38
38
|
|
39
39
|
options.merge!({:query => {:dns_template_record => record_hash}})
|
40
40
|
|
41
|
-
response =
|
41
|
+
response = Client.post("/v1/templates/#{template.id}/template_records", options)
|
42
42
|
|
43
43
|
case response.code
|
44
44
|
when 201
|
@@ -49,8 +49,8 @@ module DNSimple
|
|
49
49
|
end
|
50
50
|
|
51
51
|
def self.find(short_name, id, options={})
|
52
|
-
template =
|
53
|
-
response =
|
52
|
+
template = Template.find(short_name)
|
53
|
+
response = Client.get("/v1/templates/#{template.id}/template_records/#{id}", options)
|
54
54
|
|
55
55
|
case response.code
|
56
56
|
when 200
|
@@ -65,8 +65,8 @@ module DNSimple
|
|
65
65
|
# Get all of the template records for the template with the
|
66
66
|
# given short name.
|
67
67
|
def self.all(short_name, options={})
|
68
|
-
template =
|
69
|
-
response =
|
68
|
+
template = Template.find(short_name)
|
69
|
+
response = Client.get("/v1/templates/#{template.id}/template_records", options)
|
70
70
|
|
71
71
|
case response.code
|
72
72
|
when 200
|
@@ -1,4 +1,4 @@
|
|
1
|
-
module
|
1
|
+
module Dnsimple
|
2
2
|
|
3
3
|
# Represents a transfer order.
|
4
4
|
class TransferOrder < Base
|
@@ -20,7 +20,7 @@ module DNSimple
|
|
20
20
|
|
21
21
|
options.merge!({:body => body})
|
22
22
|
|
23
|
-
response =
|
23
|
+
response = Client.post("/v1/domain_transfers", options)
|
24
24
|
|
25
25
|
case response.code
|
26
26
|
when 201
|
data/lib/dnsimple/user.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
module
|
1
|
+
module Dnsimple
|
2
2
|
class User < Base
|
3
3
|
|
4
4
|
attr_accessor :id
|
@@ -11,8 +11,12 @@ module DNSimple
|
|
11
11
|
attr_accessor :updated_at
|
12
12
|
|
13
13
|
|
14
|
+
# Fetches the information about the authenticated user.
|
15
|
+
#
|
16
|
+
# @return [User] the authenticated user
|
17
|
+
# @raise [RequestError] if the user doesn't exist
|
14
18
|
def self.me
|
15
|
-
response =
|
19
|
+
response = Client.get("/v1/user")
|
16
20
|
|
17
21
|
case response.code
|
18
22
|
when 200
|
@@ -22,5 +26,25 @@ module DNSimple
|
|
22
26
|
end
|
23
27
|
end
|
24
28
|
|
29
|
+
# Requests a new two-factor authentication exchange token.
|
30
|
+
#
|
31
|
+
# The exchange-token is required to validate API requests
|
32
|
+
# using HTTP Basic Authentication when the account has two-factor authentication enabled.
|
33
|
+
#
|
34
|
+
# @see http://developer.dnsimple.com/authentication/#twofa
|
35
|
+
#
|
36
|
+
# @example Request an Exchange Token
|
37
|
+
# Dnsimple::User.two_factor_exchange_token('0000000')
|
38
|
+
# # => "cda038832591e34f5df642ce2b61dc78"
|
39
|
+
#
|
40
|
+
# @param [String] otp_token the two-factor one time (OTP) token
|
41
|
+
#
|
42
|
+
# @return [String] the two-factor API exchange token
|
43
|
+
# @raise [AuthenticationFailed] if the provided OTP token is invalid
|
44
|
+
def self.two_factor_exchange_token(otp_token)
|
45
|
+
response = Client.get("/v1/user", :headers => { Client::HEADER_2FA_STRICT => "1", Client::HEADER_OTP_TOKEN => otp_token })
|
46
|
+
response.headers[Client::HEADER_EXCHANGE_TOKEN]
|
47
|
+
end
|
48
|
+
|
25
49
|
end
|
26
50
|
end
|
data/lib/dnsimple/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
module
|
2
|
-
VERSION = '2.0.0.
|
1
|
+
module Dnsimple
|
2
|
+
VERSION = '2.0.0.alpha2'
|
3
3
|
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe Dnsimple::Certificate do
|
4
4
|
|
5
|
-
let(:domain) {
|
5
|
+
let(:domain) { Dnsimple::Domain.new(:name => "example.com") }
|
6
6
|
|
7
7
|
|
8
8
|
describe ".find" do
|
@@ -23,17 +23,20 @@ describe DNSimple::Certificate do
|
|
23
23
|
result = described_class.find(domain, "2")
|
24
24
|
|
25
25
|
expect(result.id).to eq(4576)
|
26
|
-
expect(result.
|
26
|
+
expect(result.domain_id).to eq(79569)
|
27
|
+
expect(result.contact_id).to eq(11549)
|
27
28
|
expect(result.name).to eq("www")
|
29
|
+
expect(result.state).to eq("cancelled")
|
28
30
|
expect(result.csr).to eq("-----BEGIN NEW CERTIFICATE REQUEST-----\nRHr2akB4KMba6FMAsvlStnO/2ika16hNx+d3smPNsER+HA==\n-----END NEW CERTIFICATE REQUEST-----\n")
|
29
31
|
expect(result.ssl_certificate).to eq("-----BEGIN CERTIFICATE-----\nXwTkw5UCPpaVyUYcwHlvaprOe9ZbwIyEHm2AT1rW+70=\n-----END CERTIFICATE-----\n")
|
30
32
|
expect(result.private_key).to eq("-----BEGIN RSA PRIVATE KEY-----\nUeXbFi7o+nuPfRhpBFQEKwacKFc3Hnc1hH6UsnC0KY25cUif7yz38A==\n-----END RSA PRIVATE KEY-----\n")
|
31
33
|
expect(result.approver_email).to eq("example@example.net")
|
32
34
|
expect(result.created_at).to eq("2013-09-17T21:54:42Z")
|
33
35
|
expect(result.updated_at).to eq("2013-09-17T22:25:36Z")
|
36
|
+
expect(result.configured_at).to eq("2013-09-17T22:25:01Z")
|
37
|
+
expect(result.expires_on).to eq("2014-09-17")
|
34
38
|
|
35
|
-
expect(result.
|
36
|
-
expect(result.certificate_status).to be_nil
|
39
|
+
expect(result.domain).to eq(domain)
|
37
40
|
end
|
38
41
|
end
|
39
42
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe Dnsimple::Client do
|
4
4
|
|
5
5
|
let(:klass) { described_class }
|
6
6
|
let(:response) { stub('response', :code => 200) }
|
@@ -29,10 +29,15 @@ describe DNSimple::Client do
|
|
29
29
|
end
|
30
30
|
|
31
31
|
describe ".request" do
|
32
|
+
before do
|
33
|
+
[:username, :password, :exchange_token, :api_token, :domain_api_token].each do |attribute|
|
34
|
+
described_class.send("#{attribute}=", nil)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
32
38
|
it "uses HTTP authentication if there's a password provided" do
|
33
39
|
described_class.username = 'user'
|
34
40
|
described_class.password = 'pass'
|
35
|
-
described_class.api_token = nil
|
36
41
|
described_class.base_uri = 'https://api.example.com/'
|
37
42
|
|
38
43
|
HTTParty.expects(:get).
|
@@ -42,9 +47,19 @@ describe DNSimple::Client do
|
|
42
47
|
described_class.request(:get, '/domains', {})
|
43
48
|
end
|
44
49
|
|
50
|
+
it "uses header authentication if there's a domain api token provided" do
|
51
|
+
described_class.domain_api_token = 'domaintoken'
|
52
|
+
described_class.base_uri = 'https://api.example.com/'
|
53
|
+
|
54
|
+
HTTParty.expects(:get).
|
55
|
+
with('https://api.example.com/domains', has_entries(:headers => has_entries({ 'X-DNSimple-Domain-Token' => 'domaintoken' }))).
|
56
|
+
returns(response)
|
57
|
+
|
58
|
+
described_class.request(:get, '/domains', {})
|
59
|
+
end
|
60
|
+
|
45
61
|
it "uses header authentication if there's an api token provided" do
|
46
62
|
described_class.username = 'user'
|
47
|
-
described_class.password = nil
|
48
63
|
described_class.api_token = 'token'
|
49
64
|
described_class.base_uri = 'https://api.example.com/'
|
50
65
|
|
@@ -55,32 +70,48 @@ describe DNSimple::Client do
|
|
55
70
|
described_class.request(:get, '/domains', {})
|
56
71
|
end
|
57
72
|
|
73
|
+
it "uses HTTP authentication via exchange token if there's an exchange token provided" do
|
74
|
+
described_class.username = 'user'
|
75
|
+
described_class.password = 'pass'
|
76
|
+
described_class.exchange_token = 'exchange-token'
|
77
|
+
described_class.base_uri = 'https://api.example.com/'
|
78
|
+
|
79
|
+
HTTParty.expects(:get).
|
80
|
+
with('https://api.example.com/domains', has_entries(:basic_auth => { :username => 'exchange-token', :password => 'x-2fa-basic' })).
|
81
|
+
returns(response)
|
82
|
+
|
83
|
+
described_class.request(:get, '/domains', {})
|
84
|
+
end
|
85
|
+
|
58
86
|
it "raises an error if there's no password or api token provided" do
|
59
87
|
described_class.username = 'user'
|
60
|
-
described_class.password = nil
|
61
|
-
described_class.api_token = nil
|
62
88
|
described_class.base_uri = 'https://api.example.com/'
|
63
89
|
|
64
90
|
expect {
|
65
91
|
described_class.request(:get, '/domains', {})
|
66
|
-
}.to raise_error(
|
92
|
+
}.to raise_error(Dnsimple::Error, 'A password or API token is required for all API requests.')
|
67
93
|
end
|
68
94
|
|
69
95
|
it "adds a custom user-agent" do
|
96
|
+
described_class.api_token = 'token'
|
97
|
+
|
70
98
|
HTTParty.expects(:get).
|
71
|
-
with(is_a(String), has_entries(:headers => has_entries({ 'User-Agent' => "dnsimple-ruby/#{
|
99
|
+
with(is_a(String), has_entries(:headers => has_entries({ 'User-Agent' => "dnsimple-ruby/#{Dnsimple::VERSION}" }))).
|
72
100
|
returns(response)
|
73
101
|
|
74
102
|
described_class.request(:get, '/foo', {})
|
75
103
|
end
|
76
104
|
|
77
105
|
it "performs a request" do
|
106
|
+
described_class.username = 'user'
|
107
|
+
described_class.password = 'pass'
|
108
|
+
|
78
109
|
HTTParty.expects(:get).
|
79
110
|
with("#{described_class.base_uri}/foo",
|
80
111
|
:format => :json,
|
81
112
|
:basic_auth => { :username => described_class.username, :password => described_class.password },
|
82
|
-
:headers => { 'Accept' => 'application/json', 'User-Agent' => "dnsimple-ruby/#{
|
83
|
-
|
113
|
+
:headers => { 'Accept' => 'application/json', 'User-Agent' => "dnsimple-ruby/#{Dnsimple::VERSION}" }
|
114
|
+
).
|
84
115
|
returns(response)
|
85
116
|
|
86
117
|
described_class.request(:get, '/foo', {})
|
@@ -104,4 +135,20 @@ describe DNSimple::Client do
|
|
104
135
|
end
|
105
136
|
end
|
106
137
|
|
138
|
+
|
139
|
+
describe "authentication" do
|
140
|
+
context "when 2FA is required" do
|
141
|
+
before do
|
142
|
+
stub_request(:get, %r[/foo]).
|
143
|
+
to_return(read_fixture("2fa/error-required.http"))
|
144
|
+
end
|
145
|
+
|
146
|
+
it "raises a TwoFactorAuthenticationRequired error" do
|
147
|
+
expect {
|
148
|
+
described_class.get('/foo', {})
|
149
|
+
}.to raise_error(Dnsimple::TwoFactorAuthenticationRequired)
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
107
154
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe Dnsimple::Contact do
|
4
4
|
|
5
5
|
describe ".find" do
|
6
6
|
before do
|
@@ -24,7 +24,7 @@ describe DNSimple::Contact do
|
|
24
24
|
expect(result.first_name).to eq("Simone")
|
25
25
|
expect(result.last_name).to eq("Carletti")
|
26
26
|
expect(result.job_title).to eq("Underwater Programmer")
|
27
|
-
expect(result.organization_name).to eq("
|
27
|
+
expect(result.organization_name).to eq("Dnsimple")
|
28
28
|
expect(result.email_address).to eq("example@example.com")
|
29
29
|
expect(result.phone).to eq("+1 111 000000")
|
30
30
|
expect(result.fax).to eq("+1 222 000000")
|
@@ -1,9 +1,59 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe Dnsimple::Domain do
|
4
4
|
|
5
5
|
let(:contact_id) { 1001 }
|
6
6
|
|
7
|
+
|
8
|
+
describe ".list" do
|
9
|
+
before do
|
10
|
+
stub_request(:get, %r[/v1/domains$]).
|
11
|
+
to_return(read_fixture("domains/index/success.http"))
|
12
|
+
end
|
13
|
+
|
14
|
+
it "builds the correct request" do
|
15
|
+
described_class.list
|
16
|
+
|
17
|
+
expect(WebMock).to have_requested(:get, "https://#{CONFIG['username']}:#{CONFIG['password']}@#{CONFIG['host']}/v1/domains").
|
18
|
+
with(headers: { 'Accept' => 'application/json' })
|
19
|
+
end
|
20
|
+
|
21
|
+
it "returns the list of domains" do
|
22
|
+
results = described_class.list
|
23
|
+
|
24
|
+
expect(results).to be_a(Array)
|
25
|
+
expect(results.size).to eq(2)
|
26
|
+
|
27
|
+
result = results[0]
|
28
|
+
expect(result.id).to eq(228)
|
29
|
+
|
30
|
+
result = results[1]
|
31
|
+
expect(result.id).to eq(227)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe ".create" do
|
36
|
+
before do
|
37
|
+
stub_request(:post, %r[/v1/domains$]).
|
38
|
+
to_return(read_fixture("domains/create/success.http"))
|
39
|
+
end
|
40
|
+
|
41
|
+
it "builds the correct request" do
|
42
|
+
described_class.create("example.com")
|
43
|
+
|
44
|
+
expect(WebMock).to have_requested(:post, "https://#{CONFIG['username']}:#{CONFIG['password']}@#{CONFIG['host']}/v1/domains").
|
45
|
+
with(headers: { 'Accept' => 'application/json' }).
|
46
|
+
with(body: { "domain" => { "name" => "example.com" }})
|
47
|
+
end
|
48
|
+
|
49
|
+
it "returns the domain" do
|
50
|
+
result = described_class.create("example.com")
|
51
|
+
|
52
|
+
expect(result).to be_a(described_class)
|
53
|
+
expect(result.id).to eq(6)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
7
57
|
describe ".find" do
|
8
58
|
before do
|
9
59
|
stub_request(:get, %r[/v1/domains/example.com]).
|
@@ -14,33 +64,90 @@ describe DNSimple::Domain do
|
|
14
64
|
described_class.find("example.com")
|
15
65
|
|
16
66
|
expect(WebMock).to have_requested(:get, "https://#{CONFIG['username']}:#{CONFIG['password']}@#{CONFIG['host']}/v1/domains/example.com").
|
17
|
-
with(:
|
18
|
-
end
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
67
|
+
with(headers: { 'Accept' => 'application/json' })
|
68
|
+
end
|
69
|
+
|
70
|
+
it "returns the domain" do
|
71
|
+
result = described_class.find("example.com")
|
72
|
+
|
73
|
+
expect(result).to be_a(described_class)
|
74
|
+
expect(result.id).to eq(6)
|
75
|
+
expect(result.user_id).to eq(2)
|
76
|
+
expect(result.registrant_id).to eq(2)
|
77
|
+
expect(result.user_id).to eq(2)
|
78
|
+
expect(result.name).to eq("test-1383931357.com")
|
79
|
+
expect(result.state).to eq("registered")
|
80
|
+
expect(result.auto_renew).to eq(true)
|
81
|
+
expect(result.whois_protected).to eq(false)
|
82
|
+
expect(result.expires_on).to eq("2015-11-08")
|
83
|
+
expect(result.created_at).to eq("2013-11-08T17:22:48Z")
|
84
|
+
expect(result.updated_at).to eq("2014-01-14T18:27:04Z")
|
85
|
+
end
|
86
|
+
|
87
|
+
context "when the domain does not exist" do
|
88
|
+
it "raises RecordNotFound" do
|
89
|
+
stub_request(:get, %r[/v1/domains/example.com]).
|
90
|
+
to_return(read_fixture("domains/notfound.http"))
|
91
|
+
|
92
|
+
expect {
|
93
|
+
described_class.find("example.com")
|
94
|
+
}.to raise_error(Dnsimple::RecordNotFound)
|
38
95
|
end
|
39
96
|
end
|
40
97
|
end
|
41
98
|
|
99
|
+
describe ".delete" do
|
100
|
+
before do
|
101
|
+
stub_request(:delete, %r[/v1/domains/example.com]).
|
102
|
+
to_return(read_fixture("domains/delete/success.http"))
|
103
|
+
end
|
104
|
+
|
105
|
+
it "builds the correct request" do
|
106
|
+
described_class.delete("example.com")
|
107
|
+
|
108
|
+
expect(WebMock).to have_requested(:delete, "https://#{CONFIG['username']}:#{CONFIG['password']}@#{CONFIG['host']}/v1/domains/example.com").
|
109
|
+
with(headers: { 'Accept' => 'application/json' })
|
110
|
+
end
|
111
|
+
|
112
|
+
it "returns nothing" do
|
113
|
+
result = described_class.delete("example.com")
|
114
|
+
|
115
|
+
expect(result).to be_truthy
|
116
|
+
end
|
117
|
+
|
118
|
+
it "supports HTTP 204" do
|
119
|
+
stub_request(:delete, %r[/v1/domains/example.com]).
|
120
|
+
to_return(read_fixture("domains/delete/success-204.http"))
|
121
|
+
|
122
|
+
result = described_class.delete("example.com")
|
123
|
+
|
124
|
+
expect(result).to be_truthy
|
125
|
+
end
|
126
|
+
|
127
|
+
context "when the domain does not exist" do
|
128
|
+
it "raises RecordNotFound" do
|
129
|
+
stub_request(:delete, %r[/v1/domains/example.com]).
|
130
|
+
to_return(read_fixture("domains/notfound.http"))
|
131
|
+
|
132
|
+
expect {
|
133
|
+
described_class.delete("example.com")
|
134
|
+
}.to raise_error(Dnsimple::RecordNotFound)
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
|
140
|
+
describe "#delete" do
|
141
|
+
it "delegates to .delete" do
|
142
|
+
subject = described_class.new(name: "example.com")
|
143
|
+
described_class.expects(:delete).with(subject.name).returns(:returned)
|
144
|
+
|
145
|
+
expect(subject.delete).to eq(:returned)
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
42
149
|
describe "#enable_auto_renew" do
|
43
|
-
let(:domain) { described_class.new(name
|
150
|
+
let(:domain) { described_class.new(:name => 'example.com', :auto_renew => false) }
|
44
151
|
|
45
152
|
context "when response is not 200" do
|
46
153
|
before do
|
@@ -49,12 +156,12 @@ describe DNSimple::Domain do
|
|
49
156
|
end
|
50
157
|
|
51
158
|
it "raises a RequestError" do
|
52
|
-
expect { domain.enable_auto_renew }.to raise_error(
|
159
|
+
expect { domain.enable_auto_renew }.to raise_error(Dnsimple::RequestError)
|
53
160
|
end
|
54
161
|
end
|
55
162
|
|
56
163
|
context "when auto_renew is true" do
|
57
|
-
let(:domain) { described_class.new(name
|
164
|
+
let(:domain) { described_class.new(:name => 'example.com', :auto_renew => true) }
|
58
165
|
|
59
166
|
it "does not send a web request" do
|
60
167
|
domain.enable_auto_renew
|
@@ -63,7 +170,7 @@ describe DNSimple::Domain do
|
|
63
170
|
end
|
64
171
|
|
65
172
|
context "when auto_renew is false" do
|
66
|
-
let(:domain) { described_class.new(name
|
173
|
+
let(:domain) { described_class.new(:name => 'example.com', :auto_renew => false) }
|
67
174
|
|
68
175
|
before do
|
69
176
|
stub_request(:post, %r[/v1/domains/example.com/auto_renewal]).
|
@@ -74,7 +181,7 @@ describe DNSimple::Domain do
|
|
74
181
|
domain.enable_auto_renew
|
75
182
|
|
76
183
|
expect(WebMock).to have_requested(:post, "https://#{CONFIG['username']}:#{CONFIG['password']}@#{CONFIG['host']}/v1/domains/example.com/auto_renewal").
|
77
|
-
with(:
|
184
|
+
with(headers: { 'Accept' => 'application/json' })
|
78
185
|
end
|
79
186
|
|
80
187
|
it "sets auto_renew to true on the domain" do
|
@@ -86,7 +193,7 @@ describe DNSimple::Domain do
|
|
86
193
|
end
|
87
194
|
|
88
195
|
describe "#disable_auto_renew" do
|
89
|
-
let(:domain) { described_class.new(name
|
196
|
+
let(:domain) { described_class.new(:name => 'example.com', :auto_renew => true) }
|
90
197
|
|
91
198
|
context "when response is not 200" do
|
92
199
|
before do
|
@@ -95,12 +202,12 @@ describe DNSimple::Domain do
|
|
95
202
|
end
|
96
203
|
|
97
204
|
it "raises a RequestError" do
|
98
|
-
expect { domain.disable_auto_renew }.to raise_error(
|
205
|
+
expect { domain.disable_auto_renew }.to raise_error(Dnsimple::RequestError)
|
99
206
|
end
|
100
207
|
end
|
101
208
|
|
102
209
|
context "when auto_renew is false" do
|
103
|
-
let(:domain) { described_class.new(name
|
210
|
+
let(:domain) { described_class.new(:name => 'example.com', :auto_renew => false) }
|
104
211
|
|
105
212
|
it "does not send a web request" do
|
106
213
|
domain.disable_auto_renew
|
@@ -109,7 +216,7 @@ describe DNSimple::Domain do
|
|
109
216
|
end
|
110
217
|
|
111
218
|
context "when auto_renew is true" do
|
112
|
-
let(:domain) { described_class.new(name
|
219
|
+
let(:domain) { described_class.new(:name => 'example.com', :auto_renew => true) }
|
113
220
|
|
114
221
|
before do
|
115
222
|
stub_request(:delete, %r[/v1/domains/example.com/auto_renewal]).
|
@@ -120,7 +227,7 @@ describe DNSimple::Domain do
|
|
120
227
|
domain.disable_auto_renew
|
121
228
|
|
122
229
|
expect(WebMock).to have_requested(:delete, "https://#{CONFIG['username']}:#{CONFIG['password']}@#{CONFIG['host']}/v1/domains/example.com/auto_renewal").
|
123
|
-
with(:
|
230
|
+
with(headers: { 'Accept' => 'application/json' })
|
124
231
|
end
|
125
232
|
|
126
233
|
it "sets auto_renew to false on the domain" do
|
@@ -130,4 +237,5 @@ describe DNSimple::Domain do
|
|
130
237
|
end
|
131
238
|
|
132
239
|
end
|
240
|
+
|
133
241
|
end
|