dnsimple 2.0.0.alpha2 → 2.0.0.alpha3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.markdown +6 -2
- data/README.markdown +32 -30
- data/dnsimple.gemspec +1 -2
- data/lib/dnsimple.rb +2 -13
- data/lib/dnsimple/client.rb +164 -53
- data/lib/dnsimple/client/certificates_service.rb +98 -0
- data/lib/dnsimple/client/client_service.rb +8 -0
- data/lib/dnsimple/client/contacts_service.rb +82 -0
- data/lib/dnsimple/client/domains_service.rb +333 -0
- data/lib/dnsimple/client/name_servers_service.rb +69 -0
- data/lib/dnsimple/client/registrars_service.rb +105 -0
- data/lib/dnsimple/client/services_service.rb +95 -0
- data/lib/dnsimple/client/templates_service.rb +180 -0
- data/lib/dnsimple/client/users_service.rb +37 -0
- data/lib/dnsimple/compatibility.rb +46 -0
- data/lib/dnsimple/default.rb +86 -0
- data/lib/dnsimple/error.rb +7 -11
- data/lib/dnsimple/extra.rb +54 -0
- data/lib/dnsimple/struct.rb +29 -0
- data/lib/dnsimple/struct/certificate.rb +56 -0
- data/lib/dnsimple/struct/contact.rb +61 -0
- data/lib/dnsimple/struct/domain.rb +40 -0
- data/lib/dnsimple/struct/email_forward.rb +14 -0
- data/lib/dnsimple/struct/extended_attribute.rb +39 -0
- data/lib/dnsimple/struct/membership.rb +22 -0
- data/lib/dnsimple/struct/price.rb +16 -0
- data/lib/dnsimple/struct/record.rb +22 -0
- data/lib/dnsimple/struct/service.rb +19 -0
- data/lib/dnsimple/struct/template.rb +19 -0
- data/lib/dnsimple/struct/template_record.rb +24 -0
- data/lib/dnsimple/struct/transfer_order.rb +10 -0
- data/lib/dnsimple/struct/user.rb +17 -0
- data/lib/dnsimple/struct/whois_privacy.rb +19 -0
- data/lib/dnsimple/version.rb +1 -1
- data/spec/dnsimple/client/certificates_service_spec.rb +196 -0
- data/spec/dnsimple/client/contacts_service_spec.rb +179 -0
- data/spec/dnsimple/client/domains_service_spec.rb +662 -0
- data/spec/dnsimple/client/name_servers_service_spec.rb +131 -0
- data/spec/dnsimple/client/registrars_service_spec.rb +160 -0
- data/spec/dnsimple/client/services_service_spec.rb +162 -0
- data/spec/dnsimple/client/templates_service_spec.rb +371 -0
- data/spec/dnsimple/client/users_service_spec.rb +70 -0
- data/spec/dnsimple/client_spec.rb +108 -99
- data/spec/dnsimple/compatibility_spec.rb +57 -0
- data/spec/files/2fa/exchange-token.http +8 -11
- data/spec/files/badgateway.http +14 -0
- data/spec/files/certificates/configure/success.http +19 -0
- data/spec/files/certificates/index/success.http +1 -1
- data/spec/files/certificates/notfound.http +19 -0
- data/spec/files/certificates/purchase/success.http +19 -0
- data/spec/files/certificates/show/success.http +1 -1
- data/spec/files/certificates/submit/success.http +19 -0
- data/spec/files/contacts/create/badrequest-missingcontact.http +19 -0
- data/spec/files/contacts/create/badrequest-validationerror.http +19 -0
- data/spec/files/contacts/create/created.http +22 -0
- data/spec/files/contacts/delete/success-204.http +18 -0
- data/spec/files/{extended_attributes/com.http → contacts/delete/success.http} +5 -5
- data/spec/files/{domains/auto_renewal_enable → contacts/index}/success.http +6 -6
- data/spec/files/contacts/notfound.http +19 -0
- data/spec/files/contacts/update/success.http +21 -0
- data/spec/files/domains/create/created.http +21 -0
- data/spec/files/domains/index/success.http +11 -9
- data/spec/files/domains/notfound.http +11 -9
- data/spec/files/domains/show/success.http +12 -10
- data/spec/files/domains_autorenewal/disable/success.http +21 -0
- data/spec/files/domains_autorenewal/enable/success.http +21 -0
- data/spec/files/domains_autorenewal/notfound-domain.http +19 -0
- data/spec/files/domains_forwards/create/created.http +22 -0
- data/spec/files/domains_forwards/delete/success.http +17 -0
- data/spec/files/domains_forwards/get/success.http +21 -0
- data/spec/files/domains_forwards/list/success.http +21 -0
- data/spec/files/domains_forwards/notfound-domain.http +19 -0
- data/spec/files/domains_forwards/notfound.http +19 -0
- data/spec/files/domains_records/create/created.http +21 -0
- data/spec/files/domains_records/delete/success-204.http +18 -0
- data/spec/files/{contacts/show/notfound.http → domains_records/delete/success.http} +9 -7
- data/spec/files/{records → domains_records}/index/success.http +0 -0
- data/spec/files/{records/show → domains_records}/notfound.http +1 -1
- data/spec/files/{records → domains_records}/show/success.http +0 -0
- data/spec/files/domains_records/update/success.http +21 -0
- data/spec/files/domains_sharing/create/success.http +21 -0
- data/spec/files/domains_sharing/delete/success.http +17 -0
- data/spec/files/domains_sharing/list/success.http +21 -0
- data/spec/files/domains_sharing/notfound-domain.http +19 -0
- data/spec/files/domains_sharing/notfound.http +19 -0
- data/spec/files/domains_whois_privacy/disable/success.http +21 -0
- data/spec/files/domains_whois_privacy/enable/success.http +22 -0
- data/spec/files/domains_zones/get/success.http +21 -0
- data/spec/files/domains_zones/notfound-domain.http +19 -0
- data/spec/files/{domains/auto_renewal_disable/notfound.http → nameservers/change/success.http} +23 -21
- data/spec/files/nameservers/deregister/success.http +17 -0
- data/spec/files/{domains/auto_renewal_enable/notfound.http → nameservers/list/success.http} +23 -21
- data/spec/files/nameservers/notfound-domain.http +19 -0
- data/spec/files/nameservers/register/badrequest-valueerror.http +19 -0
- data/spec/files/nameservers/register/success.http +21 -0
- data/spec/files/registrars/check/available.http +19 -0
- data/spec/files/registrars/check/registered.http +21 -0
- data/spec/files/registrars/register/badrequest-missingdomain.http +19 -0
- data/spec/files/registrars/register/badrequest-missingregistrant.http +19 -0
- data/spec/files/registrars/register/success.http +21 -0
- data/spec/files/registrars/renew/badrequest-missingrenewal.http +19 -0
- data/spec/files/registrars/renew/badrequest-unable.http +19 -0
- data/spec/files/registrars/renew/success.http +21 -0
- data/spec/files/registrars/transfer/success.http +21 -0
- data/spec/files/registrars_extended_attributes/list/success.http +21 -0
- data/spec/files/registrars_prices/list/success.http +21 -0
- data/spec/files/services/applied/success.http +21 -0
- data/spec/files/services/apply/success.http +21 -0
- data/spec/files/services/available/success.http +21 -0
- data/spec/files/services/index/success.http +21 -0
- data/spec/files/services/notfound.http +19 -0
- data/spec/files/services/show/success.http +21 -0
- data/spec/files/services/unapply/success.http +21 -0
- data/spec/files/subscription/show/success.http +21 -0
- data/spec/files/templates/apply/success.http +21 -0
- data/spec/files/templates/create/created.http +22 -0
- data/spec/files/templates/delete/success-204.http +21 -0
- data/spec/files/templates/delete/success.http +21 -0
- data/spec/files/templates/index/success.http +21 -0
- data/spec/files/templates/notfound.http +19 -0
- data/spec/files/templates/show/success.http +12 -10
- data/spec/files/templates/update/success.http +21 -0
- data/spec/files/templates_records/create/created.http +22 -0
- data/spec/files/templates_records/delete/success-204.http +19 -0
- data/spec/files/templates_records/delete/success.http +21 -0
- data/spec/files/templates_records/index/success.http +21 -0
- data/spec/files/templates_records/notfound.http +19 -0
- data/spec/files/templates_records/show/success.http +21 -0
- data/spec/files/templates_records/update/success.http +21 -0
- data/spec/files/users/user/success.http +21 -0
- data/spec/spec_helper.rb +0 -2
- metadata +206 -73
- data/lib/dnsimple/base.rb +0 -10
- data/lib/dnsimple/certificate.rb +0 -143
- data/lib/dnsimple/contact.rb +0 -157
- data/lib/dnsimple/domain.rb +0 -252
- 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 -65
- data/lib/dnsimple/template_record.rb +0 -80
- data/lib/dnsimple/transfer_order.rb +0 -34
- data/lib/dnsimple/user.rb +0 -50
- data/spec/dnsimple/certificate_spec.rb +0 -59
- data/spec/dnsimple/contact_spec.rb +0 -45
- data/spec/dnsimple/domain_spec.rb +0 -241
- 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/account/user/success.http +0 -19
- data/spec/files/certificates/show/notfound.http +0 -17
- data/spec/files/domains/auto_renewal_disable/success.http +0 -23
- data/spec/files/domains/create/success.http +0 -19
- data/spec/files/extended_attributes/ca.http +0 -19
- data/spec/files/extended_attributes/success.http +0 -19
- data/spec/files/templates/show/notfound.http +0 -17
@@ -0,0 +1,22 @@
|
|
1
|
+
module Dnsimple
|
2
|
+
module Struct
|
3
|
+
|
4
|
+
class Record < Base
|
5
|
+
attr_accessor :id
|
6
|
+
attr_accessor :domain_id
|
7
|
+
attr_accessor :name
|
8
|
+
attr_accessor :type
|
9
|
+
attr_accessor :content
|
10
|
+
attr_accessor :ttl
|
11
|
+
attr_accessor :priority
|
12
|
+
attr_accessor :created_at
|
13
|
+
attr_accessor :updated_at
|
14
|
+
|
15
|
+
alias :prio :priority
|
16
|
+
alias :prio= :priority=
|
17
|
+
alias :record_type :type
|
18
|
+
alias :record_type= :type=
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Dnsimple
|
2
|
+
module Struct
|
3
|
+
|
4
|
+
class Service < Base
|
5
|
+
# @return [Fixnum] The service ID in DNSimple.
|
6
|
+
attr_accessor :id
|
7
|
+
|
8
|
+
# @return [String] The service name.
|
9
|
+
attr_accessor :name
|
10
|
+
|
11
|
+
# @return [String] The URI-compatible slug.
|
12
|
+
attr_accessor :short_name
|
13
|
+
|
14
|
+
# @return [String] The description.
|
15
|
+
attr_accessor :description
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Dnsimple
|
2
|
+
module Struct
|
3
|
+
|
4
|
+
class Template < Base
|
5
|
+
# @return [Fixnum] The template ID in DNSimple.
|
6
|
+
attr_accessor :id
|
7
|
+
|
8
|
+
# @return [String] The template name.
|
9
|
+
attr_accessor :name
|
10
|
+
|
11
|
+
# @return [String] The URI-compatible slug.
|
12
|
+
attr_accessor :short_name
|
13
|
+
|
14
|
+
# @return [String] The description.
|
15
|
+
attr_accessor :description
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Dnsimple
|
2
|
+
module Struct
|
3
|
+
|
4
|
+
class TemplateRecord < Base
|
5
|
+
attr_accessor :id
|
6
|
+
attr_accessor :dns_template_id
|
7
|
+
attr_accessor :name
|
8
|
+
attr_accessor :type
|
9
|
+
attr_accessor :content
|
10
|
+
attr_accessor :ttl
|
11
|
+
attr_accessor :priority
|
12
|
+
attr_accessor :created_at
|
13
|
+
attr_accessor :updated_at
|
14
|
+
|
15
|
+
alias :template_id :dns_template_id
|
16
|
+
alias :template_id= :dns_template_id=
|
17
|
+
alias :prio :priority
|
18
|
+
alias :prio= :priority=
|
19
|
+
alias :record_type :type
|
20
|
+
alias :record_type= :type=
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Dnsimple
|
2
|
+
module Struct
|
3
|
+
|
4
|
+
class User < Base
|
5
|
+
attr_accessor :id
|
6
|
+
attr_accessor :email
|
7
|
+
attr_accessor :api_token
|
8
|
+
attr_accessor :domain_count
|
9
|
+
attr_accessor :domain_limit
|
10
|
+
attr_accessor :login_count
|
11
|
+
attr_accessor :failed_login_count
|
12
|
+
attr_accessor :created_at
|
13
|
+
attr_accessor :updated_at
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Dnsimple
|
2
|
+
module Struct
|
3
|
+
|
4
|
+
class WhoisPrivacy < Base
|
5
|
+
# @return [Fixnum] The WHOIS privacy ID in DNSimple.
|
6
|
+
attr_accessor :id
|
7
|
+
|
8
|
+
# @return [Fixnum] The associated domain ID.
|
9
|
+
attr_accessor :domain_id
|
10
|
+
|
11
|
+
# @return [Bool] Whether the WHOIS privacy is enabled.
|
12
|
+
attr_accessor :enabled
|
13
|
+
|
14
|
+
# @return [String] The date the domain will expire.
|
15
|
+
attr_accessor :expires_on
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
data/lib/dnsimple/version.rb
CHANGED
@@ -0,0 +1,196 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Dnsimple::Client, ".certificates" do
|
4
|
+
|
5
|
+
subject { described_class.new(api_endpoint: "https://api.zone", username: "user", api_token: "token").certificates }
|
6
|
+
|
7
|
+
|
8
|
+
describe "#list" do
|
9
|
+
before do
|
10
|
+
stub_request(:get, %r[/v1/domains/.+/certificates$]).
|
11
|
+
to_return(read_fixture("certificates/index/success.http"))
|
12
|
+
end
|
13
|
+
|
14
|
+
it "builds the correct request" do
|
15
|
+
subject.list("example.com")
|
16
|
+
|
17
|
+
expect(WebMock).to have_requested(:get, "https://api.zone/v1/domains/example.com/certificates").
|
18
|
+
with(headers: { 'Accept' => 'application/json' })
|
19
|
+
end
|
20
|
+
|
21
|
+
it "returns the records" do
|
22
|
+
results = subject.list("example.com")
|
23
|
+
|
24
|
+
expect(results).to be_a(Array)
|
25
|
+
expect(results.size).to eq(2)
|
26
|
+
|
27
|
+
results.each do |result|
|
28
|
+
expect(result).to be_a(Dnsimple::Struct::Certificate)
|
29
|
+
expect(result.id).to be_a(Fixnum)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
context "when something does not exist" do
|
34
|
+
it "raises RecordNotFound" do
|
35
|
+
stub_request(:get, %r[/v1]).
|
36
|
+
to_return(read_fixture("domains/notfound.http"))
|
37
|
+
|
38
|
+
expect {
|
39
|
+
subject.list("example.com")
|
40
|
+
}.to raise_error(Dnsimple::RecordNotFound)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe "#find" do
|
46
|
+
before do
|
47
|
+
stub_request(:get, %r[/v1/domains/.+/certificates/.+$]).
|
48
|
+
to_return(read_fixture("certificates/show/success.http"))
|
49
|
+
end
|
50
|
+
|
51
|
+
it "builds the correct request" do
|
52
|
+
subject.find("example.com", 2)
|
53
|
+
|
54
|
+
expect(WebMock).to have_requested(:get, "https://api.zone/v1/domains/example.com/certificates/2").
|
55
|
+
with(headers: { 'Accept' => 'application/json' })
|
56
|
+
end
|
57
|
+
|
58
|
+
it "returns the certificate" do
|
59
|
+
result = subject.find("example.com", 2)
|
60
|
+
|
61
|
+
expect(result).to be_a(Dnsimple::Struct::Certificate)
|
62
|
+
expect(result.id).to eq(4576)
|
63
|
+
expect(result.domain_id).to eq(79569)
|
64
|
+
expect(result.contact_id).to eq(11549)
|
65
|
+
expect(result.name).to eq("www")
|
66
|
+
expect(result.state).to eq("cancelled")
|
67
|
+
expect(result.csr).to eq("-----BEGIN NEW CERTIFICATE REQUEST-----\nRHr2akB4KMba6FMAsvlStnO/2ika16hNx+d3smPNsER+HA==\n-----END NEW CERTIFICATE REQUEST-----\n")
|
68
|
+
expect(result.ssl_certificate).to eq("-----BEGIN CERTIFICATE-----\nXwTkw5UCPpaVyUYcwHlvaprOe9ZbwIyEHm2AT1rW+70=\n-----END CERTIFICATE-----\n")
|
69
|
+
expect(result.private_key).to eq("-----BEGIN RSA PRIVATE KEY-----\nUeXbFi7o+nuPfRhpBFQEKwacKFc3Hnc1hH6UsnC0KY25cUif7yz38A==\n-----END RSA PRIVATE KEY-----\n")
|
70
|
+
expect(result.approver_email).to eq("example@example.net")
|
71
|
+
expect(result.created_at).to eq("2013-09-17T21:54:42Z")
|
72
|
+
expect(result.updated_at).to eq("2013-09-17T22:25:36Z")
|
73
|
+
expect(result.configured_at).to eq("2013-09-17T22:25:01Z")
|
74
|
+
expect(result.expires_on).to eq("2014-09-17")
|
75
|
+
end
|
76
|
+
|
77
|
+
context "when something does not exist" do
|
78
|
+
it "raises RecordNotFound" do
|
79
|
+
stub_request(:get, %r[/v1]).
|
80
|
+
to_return(read_fixture("certificates/notfound.http"))
|
81
|
+
|
82
|
+
expect {
|
83
|
+
subject.find("example.com", 2)
|
84
|
+
}.to raise_error(Dnsimple::RecordNotFound)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
describe "#purchase" do
|
90
|
+
before do
|
91
|
+
stub_request(:post, %r[/v1/domains/.+/certificates$]).
|
92
|
+
to_return(read_fixture("certificates/purchase/success.http"))
|
93
|
+
end
|
94
|
+
|
95
|
+
it "builds the correct request" do
|
96
|
+
subject.purchase("example.com", "www", 100)
|
97
|
+
|
98
|
+
expect(WebMock).to have_requested(:post, "https://api.zone/v1/domains/example.com/certificates").
|
99
|
+
with(body: { certificate: { name: "www", contact_id: "100" } }).
|
100
|
+
with(headers: { 'Accept' => 'application/json' })
|
101
|
+
end
|
102
|
+
|
103
|
+
it "merges custom options" do
|
104
|
+
subject.purchase("example.com", "www", 100, certificate: { csr: "CUSTOM" }, something: "else")
|
105
|
+
|
106
|
+
expect(WebMock).to have_requested(:post, "https://api.zone/v1/domains/example.com/certificates").
|
107
|
+
with(body: { certificate: { name: "www", contact_id: "100", csr: "CUSTOM" }, something: "else"}).
|
108
|
+
with(headers: { 'Accept' => 'application/json' })
|
109
|
+
end
|
110
|
+
|
111
|
+
it "returns the certificate" do
|
112
|
+
result = subject.purchase("example.com", "www", 100)
|
113
|
+
|
114
|
+
expect(result).to be_a(Dnsimple::Struct::Certificate)
|
115
|
+
expect(result.id).to be_a(Fixnum)
|
116
|
+
end
|
117
|
+
|
118
|
+
context "when something does not exist" do
|
119
|
+
it "raises RecordNotFound" do
|
120
|
+
stub_request(:post, %r[/v1]).
|
121
|
+
to_return(read_fixture("domains/notfound.http"))
|
122
|
+
|
123
|
+
expect {
|
124
|
+
subject.purchase("example.com", "www", 100)
|
125
|
+
}.to raise_error(Dnsimple::RecordNotFound)
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
describe "#configure" do
|
131
|
+
before do
|
132
|
+
stub_request(:put, %r[/v1/domains/.+/certificates/.+/configure$]).
|
133
|
+
to_return(read_fixture("certificates/configure/success.http"))
|
134
|
+
end
|
135
|
+
|
136
|
+
it "builds the correct request" do
|
137
|
+
subject.configure("example.com", 2)
|
138
|
+
|
139
|
+
expect(WebMock).to have_requested(:put, "https://api.zone/v1/domains/example.com/certificates/2/configure").
|
140
|
+
with(body: {}).
|
141
|
+
with(headers: { 'Accept' => 'application/json' })
|
142
|
+
end
|
143
|
+
|
144
|
+
it "returns the certificate" do
|
145
|
+
result = subject.configure("example.com", 2)
|
146
|
+
|
147
|
+
expect(result).to be_a(Dnsimple::Struct::Certificate)
|
148
|
+
expect(result.id).to be_a(Fixnum)
|
149
|
+
end
|
150
|
+
|
151
|
+
context "when something does not exist" do
|
152
|
+
it "raises RecordNotFound" do
|
153
|
+
stub_request(:put, %r[/v1]).
|
154
|
+
to_return(read_fixture("certificates/notfound.http"))
|
155
|
+
|
156
|
+
expect {
|
157
|
+
subject.configure("example.com", 2)
|
158
|
+
}.to raise_error(Dnsimple::RecordNotFound)
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
describe "#submit" do
|
164
|
+
before do
|
165
|
+
stub_request(:put, %r[/v1/domains/.+/certificates/.+/submit]).
|
166
|
+
to_return(read_fixture("certificates/submit/success.http"))
|
167
|
+
end
|
168
|
+
|
169
|
+
it "builds the correct request" do
|
170
|
+
subject.submit("example.com", 2, "admin@example.com")
|
171
|
+
|
172
|
+
expect(WebMock).to have_requested(:put, "https://api.zone/v1/domains/example.com/certificates/2/submit").
|
173
|
+
with(body: { certificate: { approver_email: "admin@example.com" } }).
|
174
|
+
with(headers: { 'Accept' => 'application/json' })
|
175
|
+
end
|
176
|
+
|
177
|
+
it "returns the certificate" do
|
178
|
+
result = subject.submit("example.com", 2, "admin@example.com")
|
179
|
+
|
180
|
+
expect(result).to be_a(Dnsimple::Struct::Certificate)
|
181
|
+
expect(result.id).to be_a(Fixnum)
|
182
|
+
end
|
183
|
+
|
184
|
+
context "when something does not exist" do
|
185
|
+
it "raises RecordNotFound" do
|
186
|
+
stub_request(:put, %r[/v1]).
|
187
|
+
to_return(read_fixture("certificates/notfound.http"))
|
188
|
+
|
189
|
+
expect {
|
190
|
+
subject.submit("example.com", 2, "admin@example.com")
|
191
|
+
}.to raise_error(Dnsimple::RecordNotFound)
|
192
|
+
end
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
end
|
@@ -0,0 +1,179 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Dnsimple::Client, ".contacts" do
|
4
|
+
|
5
|
+
subject { described_class.new(api_endpoint: "https://api.zone", username: "user", api_token: "token").contacts }
|
6
|
+
|
7
|
+
|
8
|
+
describe "#list" do
|
9
|
+
before do
|
10
|
+
stub_request(:get, %r[/v1/contacts$]).
|
11
|
+
to_return(read_fixture("contacts/index/success.http"))
|
12
|
+
end
|
13
|
+
|
14
|
+
it "builds the correct request" do
|
15
|
+
subject.list
|
16
|
+
|
17
|
+
expect(WebMock).to have_requested(:get, "https://api.zone/v1/contacts").
|
18
|
+
with(headers: { 'Accept' => 'application/json' })
|
19
|
+
end
|
20
|
+
|
21
|
+
it "returns the contacts" do
|
22
|
+
results = subject.list
|
23
|
+
|
24
|
+
expect(results).to be_a(Array)
|
25
|
+
expect(results.size).to eq(1)
|
26
|
+
|
27
|
+
results.each do |result|
|
28
|
+
expect(result).to be_a(Dnsimple::Struct::Contact)
|
29
|
+
expect(result.id).to be_a(Fixnum)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "#create" do
|
35
|
+
before do
|
36
|
+
stub_request(:post, %r[/v1/contacts]).
|
37
|
+
to_return(read_fixture("contacts/create/created.http"))
|
38
|
+
end
|
39
|
+
|
40
|
+
let(:attributes) { { first_name: "Simone", last_name: "Carletti", address1: "", city: "Rome", state_province: "RM", postal_code: "00171", country: "IT", email_address: "", phone: "" } }
|
41
|
+
|
42
|
+
it "builds the correct request" do
|
43
|
+
subject.create(attributes)
|
44
|
+
|
45
|
+
expect(WebMock).to have_requested(:post, "https://api.zone/v1/contacts").
|
46
|
+
with(body: { contact: attributes }).
|
47
|
+
with(headers: { 'Accept' => 'application/json' })
|
48
|
+
end
|
49
|
+
|
50
|
+
it "returns the contact" do
|
51
|
+
result = subject.create(attributes)
|
52
|
+
|
53
|
+
expect(result).to be_a(Dnsimple::Struct::Contact)
|
54
|
+
expect(result.id).to be_a(Fixnum)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
describe "#find" do
|
59
|
+
before do
|
60
|
+
stub_request(:get, %r[/v1/contacts/.+$]).
|
61
|
+
to_return(read_fixture("contacts/show/success.http"))
|
62
|
+
end
|
63
|
+
|
64
|
+
it "builds the correct request" do
|
65
|
+
subject.find(1)
|
66
|
+
|
67
|
+
expect(WebMock).to have_requested(:get, "https://api.zone/v1/contacts/1").
|
68
|
+
with(headers: { 'Accept' => 'application/json' })
|
69
|
+
end
|
70
|
+
|
71
|
+
it "returns the contact" do
|
72
|
+
result = subject.find(1)
|
73
|
+
|
74
|
+
expect(result).to be_a(Dnsimple::Struct::Contact)
|
75
|
+
expect(result.id).to eq(2)
|
76
|
+
expect(result.label).to eq("Default")
|
77
|
+
expect(result.first_name).to eq("Simone")
|
78
|
+
expect(result.last_name).to eq("Carletti")
|
79
|
+
expect(result.job_title).to eq("Underwater Programmer")
|
80
|
+
expect(result.organization_name).to eq("Dnsimple")
|
81
|
+
expect(result.email_address).to eq("example@example.com")
|
82
|
+
expect(result.phone).to eq("+1 111 000000")
|
83
|
+
expect(result.fax).to eq("+1 222 000000")
|
84
|
+
expect(result.address1).to eq("Awesome Street")
|
85
|
+
expect(result.address2).to eq("c/o Someone")
|
86
|
+
expect(result.city).to eq("Rome")
|
87
|
+
expect(result.state_province).to eq("RM")
|
88
|
+
expect(result.postal_code).to eq("00171")
|
89
|
+
expect(result.country).to eq("IT")
|
90
|
+
expect(result.created_at).to eq("2013-11-08T17:23:15Z")
|
91
|
+
expect(result.updated_at).to eq("2013-11-08T17:23:15Z")
|
92
|
+
end
|
93
|
+
|
94
|
+
context "when something does not exist" do
|
95
|
+
it "raises RecordNotFound" do
|
96
|
+
stub_request(:get, %r[/v1]).
|
97
|
+
to_return(read_fixture("contacts/notfound.http"))
|
98
|
+
|
99
|
+
expect {
|
100
|
+
subject.find(1)
|
101
|
+
}.to raise_error(Dnsimple::RecordNotFound)
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
describe "#update" do
|
107
|
+
before do
|
108
|
+
stub_request(:put, %r[/v1/contacts/.+$]).
|
109
|
+
to_return(read_fixture("contacts/update/success.http"))
|
110
|
+
end
|
111
|
+
|
112
|
+
it "builds the correct request" do
|
113
|
+
subject.update(1, { label: "Updated" })
|
114
|
+
|
115
|
+
expect(WebMock).to have_requested(:put, "https://api.zone/v1/contacts/1").
|
116
|
+
with(body: { contact: { label: "Updated" } }).
|
117
|
+
with(headers: { 'Accept' => 'application/json' })
|
118
|
+
end
|
119
|
+
|
120
|
+
it "returns the contact" do
|
121
|
+
result = subject.update(1, {})
|
122
|
+
|
123
|
+
expect(result).to be_a(Dnsimple::Struct::Contact)
|
124
|
+
expect(result.id).to be_a(Fixnum)
|
125
|
+
end
|
126
|
+
|
127
|
+
context "when something does not exist" do
|
128
|
+
it "raises RecordNotFound" do
|
129
|
+
stub_request(:put, %r[/v1]).
|
130
|
+
to_return(read_fixture("contacts/notfound.http"))
|
131
|
+
|
132
|
+
expect {
|
133
|
+
subject.update(1, {})
|
134
|
+
}.to raise_error(Dnsimple::RecordNotFound)
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
describe "#delete" do
|
140
|
+
before do
|
141
|
+
stub_request(:delete, %r[/v1/contacts/1$]).
|
142
|
+
to_return(read_fixture("contacts/delete/success.http"))
|
143
|
+
end
|
144
|
+
|
145
|
+
it "builds the correct request" do
|
146
|
+
subject.delete(1)
|
147
|
+
|
148
|
+
expect(WebMock).to have_requested(:delete, "https://api.zone/v1/contacts/1").
|
149
|
+
with(headers: { 'Accept' => 'application/json' })
|
150
|
+
end
|
151
|
+
|
152
|
+
it "returns nothing" do
|
153
|
+
result = subject.delete(1)
|
154
|
+
|
155
|
+
expect(result).to be_truthy
|
156
|
+
end
|
157
|
+
|
158
|
+
it "supports HTTP 204" do
|
159
|
+
stub_request(:delete, %r[/v1]).
|
160
|
+
to_return(read_fixture("contacts/delete/success-204.http"))
|
161
|
+
|
162
|
+
result = subject.delete(1)
|
163
|
+
|
164
|
+
expect(result).to be_truthy
|
165
|
+
end
|
166
|
+
|
167
|
+
context "when something does not exist" do
|
168
|
+
it "raises RecordNotFound" do
|
169
|
+
stub_request(:delete, %r[/v1]).
|
170
|
+
to_return(read_fixture("contacts/notfound.http"))
|
171
|
+
|
172
|
+
expect {
|
173
|
+
subject.delete(1)
|
174
|
+
}.to raise_error(Dnsimple::RecordNotFound)
|
175
|
+
end
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
end
|