dnsimple 2.0.0.alpha3 → 2.0.0.alpha4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +3 -2
  3. data/CHANGELOG.markdown +5 -3
  4. data/lib/dnsimple/client.rb +6 -55
  5. data/lib/dnsimple/client/{certificates_service.rb → certificates.rb} +1 -1
  6. data/lib/dnsimple/client/clients.rb +121 -0
  7. data/lib/dnsimple/client/{contacts_service.rb → contacts.rb} +1 -1
  8. data/lib/dnsimple/client/domains.rb +65 -0
  9. data/lib/dnsimple/client/domains_autorenewals.rb +35 -0
  10. data/lib/dnsimple/client/domains_forwards.rb +70 -0
  11. data/lib/dnsimple/client/domains_privacy.rb +35 -0
  12. data/lib/dnsimple/client/domains_records.rb +89 -0
  13. data/lib/dnsimple/client/domains_sharing.rb +53 -0
  14. data/lib/dnsimple/client/domains_zones.rb +22 -0
  15. data/lib/dnsimple/client/{name_servers_service.rb → name_servers.rb} +1 -1
  16. data/lib/dnsimple/client/{registrars_service.rb → registrar.rb} +1 -1
  17. data/lib/dnsimple/client/services.rb +34 -0
  18. data/lib/dnsimple/client/{services_service.rb → services_domains.rb} +1 -28
  19. data/lib/dnsimple/client/templates.rb +98 -0
  20. data/lib/dnsimple/client/{templates_service.rb → templates_records.rb} +1 -93
  21. data/lib/dnsimple/client/{users_service.rb → users.rb} +1 -1
  22. data/lib/dnsimple/version.rb +1 -1
  23. data/spec/dnsimple/client/{certificates_service_spec.rb → certificates_spec.rb} +0 -0
  24. data/spec/dnsimple/client/{contacts_service_spec.rb → contacts_spec.rb} +0 -0
  25. data/spec/dnsimple/client/domains_autorenewals_spec.rb +72 -0
  26. data/spec/dnsimple/client/domains_forwards_spec.rb +146 -0
  27. data/spec/dnsimple/client/domains_privacy_spec.rb +74 -0
  28. data/spec/dnsimple/client/domains_records_spec.rb +191 -0
  29. data/spec/dnsimple/client/domains_sharing_spec.rb +109 -0
  30. data/spec/dnsimple/client/domains_spec.rb +139 -0
  31. data/spec/dnsimple/client/domains_zones_spec.rb +40 -0
  32. data/spec/dnsimple/client/{name_servers_service_spec.rb → name_servers_spec.rb} +0 -0
  33. data/spec/dnsimple/client/{registrars_service_spec.rb → registrar_spec.rb} +9 -9
  34. data/spec/dnsimple/client/{services_service_spec.rb → services_domains_spec.rb} +1 -62
  35. data/spec/dnsimple/client/services_spec.rb +69 -0
  36. data/spec/dnsimple/client/{templates_service_spec.rb → templates_records_spec.rb} +1 -192
  37. data/spec/dnsimple/client/templates_spec.rb +198 -0
  38. data/spec/dnsimple/client/{users_service_spec.rb → users_spec.rb} +0 -0
  39. data/spec/files/{domains_whois_privacy → domains_privacy}/disable/success.http +0 -0
  40. data/spec/files/{domains_whois_privacy → domains_privacy}/enable/success.http +0 -0
  41. data/spec/files/domains_privacy/notfound-domain.http +19 -0
  42. data/spec/files/{registrars → registrar}/check/available.http +0 -0
  43. data/spec/files/{registrars → registrar}/check/registered.http +0 -0
  44. data/spec/files/{registrars → registrar}/register/badrequest-missingdomain.http +0 -0
  45. data/spec/files/{registrars → registrar}/register/badrequest-missingregistrant.http +0 -0
  46. data/spec/files/{registrars → registrar}/register/success.http +0 -0
  47. data/spec/files/{registrars → registrar}/renew/badrequest-missingrenewal.http +0 -0
  48. data/spec/files/{registrars → registrar}/renew/badrequest-unable.http +0 -0
  49. data/spec/files/{registrars → registrar}/renew/success.http +0 -0
  50. data/spec/files/{registrars → registrar}/transfer/success.http +0 -0
  51. data/spec/files/{registrars_extended_attributes → registrar_extended_attributes}/list/success.http +0 -0
  52. data/spec/files/{registrars_prices → registrar_prices}/list/success.http +0 -0
  53. data/spec/files/{subscription → subscriptions}/show/success.http +0 -0
  54. metadata +82 -56
  55. data/lib/dnsimple/client/client_service.rb +0 -8
  56. data/lib/dnsimple/client/domains_service.rb +0 -333
  57. data/spec/dnsimple/client/domains_service_spec.rb +0 -662
@@ -1,6 +1,6 @@
1
1
  module Dnsimple
2
2
  class Client
3
- class UsersService < ClientService
3
+ module Users
4
4
 
5
5
  # Fetches the information about the authenticated user.
6
6
  #
@@ -1,3 +1,3 @@
1
1
  module Dnsimple
2
- VERSION = '2.0.0.alpha3'
2
+ VERSION = '2.0.0.alpha4'
3
3
  end
@@ -0,0 +1,72 @@
1
+ require 'spec_helper'
2
+
3
+ describe Dnsimple::Client, ".domains / autorenewals" do
4
+
5
+ subject { described_class.new(api_endpoint: "https://api.zone", username: "user", api_token: "token").domains }
6
+
7
+
8
+ describe "#enable_auto_renewal" do
9
+ before do
10
+ stub_request(:post, %r[/v1/domains/.+/auto_renewal$]).
11
+ to_return(read_fixture("domains_autorenewal/enable/success.http"))
12
+ end
13
+
14
+ it "builds the correct request" do
15
+ subject.enable_auto_renewal("example.com")
16
+
17
+ expect(WebMock).to have_requested(:post, "https://api.zone/v1/domains/example.com/auto_renewal").
18
+ with(headers: { 'Accept' => 'application/json' })
19
+ end
20
+
21
+ it "returns the domain" do
22
+ result = subject.enable_auto_renewal("example.com")
23
+
24
+ expect(result).to be_a(Dnsimple::Struct::Domain)
25
+ expect(result.id).to be_a(Fixnum)
26
+ end
27
+
28
+ context "when the domain does not exist" do
29
+ it "raises RecordNotFound" do
30
+ stub_request(:post, %r[/v1]).
31
+ to_return(read_fixture("domains_autorenewal/notfound-domain.http"))
32
+
33
+ expect {
34
+ subject.enable_auto_renewal("example.com")
35
+ }.to raise_error(Dnsimple::RecordNotFound)
36
+ end
37
+ end
38
+ end
39
+
40
+ describe "#disable_auto_renewal" do
41
+ before do
42
+ stub_request(:delete, %r[/v1/domains/.+/auto_renewal$]).
43
+ to_return(read_fixture("domains_autorenewal/disable/success.http"))
44
+ end
45
+
46
+ it "builds the correct request" do
47
+ subject.disable_auto_renewal("example.com")
48
+
49
+ expect(WebMock).to have_requested(:delete, "https://api.zone/v1/domains/example.com/auto_renewal").
50
+ with(headers: { 'Accept' => 'application/json' })
51
+ end
52
+
53
+ it "returns the domain" do
54
+ result = subject.disable_auto_renewal("example.com")
55
+
56
+ expect(result).to be_a(Dnsimple::Struct::Domain)
57
+ expect(result.id).to be_a(Fixnum)
58
+ end
59
+
60
+ context "when the domain does not exist" do
61
+ it "raises RecordNotFound" do
62
+ stub_request(:delete, %r[/v1]).
63
+ to_return(read_fixture("domains_autorenewal/notfound-domain.http"))
64
+
65
+ expect {
66
+ subject.disable_auto_renewal("example.com")
67
+ }.to raise_error(Dnsimple::RecordNotFound)
68
+ end
69
+ end
70
+ end
71
+
72
+ end
@@ -0,0 +1,146 @@
1
+ require 'spec_helper'
2
+
3
+ describe Dnsimple::Client, ".domains / forwards" do
4
+
5
+ subject { described_class.new(api_endpoint: "https://api.zone", username: "user", api_token: "token").domains }
6
+
7
+
8
+ describe "#list_email_forwards" do
9
+ before do
10
+ stub_request(:get, %r[/v1/domains/.+/email_forwards]).
11
+ to_return(read_fixture("domains_forwards/list/success.http"))
12
+ end
13
+
14
+ it "builds the correct request" do
15
+ subject.list_email_forwards("example.com")
16
+
17
+ expect(WebMock).to have_requested(:get, "https://api.zone/v1/domains/example.com/email_forwards").
18
+ with(headers: { 'Accept' => 'application/json' })
19
+ end
20
+
21
+ it "returns the records" do
22
+ results = subject.list_email_forwards("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::EmailForward)
29
+ expect(result.id).to be_a(Fixnum)
30
+ end
31
+ end
32
+
33
+ context "when the domain does not exist" do
34
+ it "raises RecordNotFound" do
35
+ stub_request(:get, %r[/v1]).
36
+ to_return(read_fixture("domains_forwards/notfound-domain.http"))
37
+
38
+ expect {
39
+ subject.list_email_forwards("example.com")
40
+ }.to raise_error(Dnsimple::RecordNotFound)
41
+ end
42
+ end
43
+ end
44
+
45
+ describe "#create_email_forward" do
46
+ before do
47
+ stub_request(:post, %r[/v1/domains/.+/email_forwards$]).
48
+ to_return(read_fixture("domains_forwards/create/created.http"))
49
+ end
50
+
51
+ it "builds the correct request" do
52
+ subject.create_email_forward("example.com", { from: "john", to: "someone@example.com" })
53
+
54
+ expect(WebMock).to have_requested(:post, "https://api.zone/v1/domains/example.com/email_forwards").
55
+ with(body: { email_forward: { from: "john", to: "someone@example.com" } }).
56
+ with(headers: { 'Accept' => 'application/json' })
57
+ end
58
+
59
+ it "returns the record" do
60
+ result = subject.create_email_forward("example.com", { from: "", to: "" })
61
+
62
+ expect(result).to be_a(Dnsimple::Struct::EmailForward)
63
+ expect(result.id).to be_a(Fixnum)
64
+ end
65
+
66
+ context "when the domain does not exist" do
67
+ it "raises RecordNotFound" do
68
+ stub_request(:post, %r[/v1]).
69
+ to_return(read_fixture("domains_forwards/notfound-domain.http"))
70
+
71
+ expect {
72
+ subject.create_email_forward("example.com", { from: "", to: "" })
73
+ }.to raise_error(Dnsimple::RecordNotFound)
74
+ end
75
+ end
76
+ end
77
+
78
+ describe "#find_email_forward" do
79
+ before do
80
+ stub_request(:get, %r[/v1/domains/.+/email_forwards/.+$]).
81
+ to_return(read_fixture("domains_forwards/get/success.http"))
82
+ end
83
+
84
+ it "builds the correct request" do
85
+ subject.find_email_forward("example.com", 2)
86
+
87
+ expect(WebMock).to have_requested(:get, "https://api.zone/v1/domains/example.com/email_forwards/2").
88
+ with(headers: { 'Accept' => 'application/json' })
89
+ end
90
+
91
+ it "returns the record" do
92
+ result = subject.find_email_forward("example.com", 2)
93
+
94
+ expect(result).to be_a(Dnsimple::Struct::EmailForward)
95
+ expect(result.id).to eq(1)
96
+ expect(result.domain_id).to eq(1111)
97
+ expect(result.from).to eq("sender@dnsimple-sandbox.com")
98
+ expect(result.to).to eq("receiver@example.com")
99
+ expect(result.created_at).to eq("2014-12-16T12:55:13.697Z")
100
+ expect(result.updated_at).to eq("2014-12-16T12:55:13.697Z")
101
+ end
102
+
103
+ context "when forward does not exist" do
104
+ it "raises RecordNotFound" do
105
+ stub_request(:get, %r[/v1]).
106
+ to_return(read_fixture("domains_forwards/notfound.http"))
107
+
108
+ expect {
109
+ subject.find_email_forward("example.com", 2)
110
+ }.to raise_error(Dnsimple::RecordNotFound)
111
+ end
112
+ end
113
+ end
114
+
115
+ describe "#delete_email_forward" do
116
+ before do
117
+ stub_request(:delete, %r[/v1/domains/.+/email_forwards/.+$]).
118
+ to_return(read_fixture("domains_forwards/delete/success.http"))
119
+ end
120
+
121
+ it "builds the correct request" do
122
+ subject.delete_email_forward("example.com", 2)
123
+
124
+ expect(WebMock).to have_requested(:delete, "https://api.zone/v1/domains/example.com/email_forwards/2").
125
+ with(headers: { 'Accept' => 'application/json' })
126
+ end
127
+
128
+ it "returns nothing" do
129
+ result = subject.delete_email_forward("example.com", 2)
130
+
131
+ expect(result).to be_truthy
132
+ end
133
+
134
+ context "when the forward does not exist" do
135
+ it "raises RecordNotFound" do
136
+ stub_request(:delete, %r[/v1]).
137
+ to_return(read_fixture("domains_forwards/notfound.http"))
138
+
139
+ expect {
140
+ subject.delete_email_forward("example.com", 2)
141
+ }.to raise_error(Dnsimple::RecordNotFound)
142
+ end
143
+ end
144
+ end
145
+
146
+ end
@@ -0,0 +1,74 @@
1
+ require 'spec_helper'
2
+
3
+ describe Dnsimple::Client, ".domains / privacy" do
4
+
5
+ subject { described_class.new(api_endpoint: "https://api.zone", username: "user", api_token: "token").domains }
6
+
7
+
8
+ describe "#enable_whois_privacy" do
9
+ before do
10
+ stub_request(:post, %r[/v1/domains/.+/whois_privacy$]).
11
+ to_return(read_fixture("domains_privacy/enable/success.http"))
12
+ end
13
+
14
+ it "builds the correct request" do
15
+ subject.enable_whois_privacy("example.com")
16
+
17
+ expect(WebMock).to have_requested(:post, "https://api.zone/v1/domains/example.com/whois_privacy").
18
+ with(headers: { 'Accept' => 'application/json' })
19
+ end
20
+
21
+ it "returns the domain" do
22
+ result = subject.enable_whois_privacy("example.com")
23
+
24
+ expect(result).to be_a(Dnsimple::Struct::WhoisPrivacy)
25
+ expect(result.id).to be_a(Fixnum)
26
+ end
27
+
28
+ context "when the domain does not exist" do
29
+ it "raises RecordNotFound" do
30
+ stub_request(:post, %r[/v1]).
31
+ to_return(read_fixture("domains_privacy/notfound-domain.http"))
32
+
33
+ expect {
34
+ subject.enable_whois_privacy("example.com")
35
+ }.to raise_error(Dnsimple::RecordNotFound)
36
+ end
37
+ end
38
+ end
39
+
40
+ describe "#disable_whois_privacy" do
41
+ before do
42
+ stub_request(:delete, %r[/v1/domains/.+/whois_privacy]).
43
+ to_return(read_fixture("domains_privacy/disable/success.http"))
44
+ end
45
+
46
+ it "builds the correct request" do
47
+ subject.disable_whois_privacy("example.com")
48
+
49
+ expect(WebMock).to have_requested(:delete, "https://api.zone/v1/domains/example.com/whois_privacy").
50
+ with(headers: { 'Accept' => 'application/json' })
51
+ end
52
+
53
+ it "returns the domain" do
54
+ result = subject.disable_whois_privacy("example.com")
55
+
56
+ expect(result).to be_a(Dnsimple::Struct::WhoisPrivacy)
57
+ expect(result.id).to be_a(Fixnum)
58
+ end
59
+
60
+ context "when the domain does not exist" do
61
+ it "raises RecordNotFound" do
62
+ stub_request(:delete, %r[/v1]).
63
+ to_return(read_fixture("domains_privacy/notfound-domain.http"))
64
+
65
+ expect {
66
+ subject.disable_whois_privacy("example.com")
67
+ }.to raise_error(Dnsimple::RecordNotFound)
68
+ end
69
+ end
70
+ end
71
+
72
+
73
+
74
+ end
@@ -0,0 +1,191 @@
1
+ require 'spec_helper'
2
+
3
+ describe Dnsimple::Client, ".domains / records" do
4
+
5
+ subject { described_class.new(api_endpoint: "https://api.zone", username: "user", api_token: "token").domains }
6
+
7
+
8
+ describe "#list_records" do
9
+ before do
10
+ stub_request(:get, %r[/v1/domains/.+/records$]).
11
+ to_return(read_fixture("domains_records/index/success.http"))
12
+ end
13
+
14
+ it "builds the correct request" do
15
+ subject.list_records("example.com")
16
+
17
+ expect(WebMock).to have_requested(:get, "https://api.zone/v1/domains/example.com/records").
18
+ with(headers: { 'Accept' => 'application/json' })
19
+ end
20
+
21
+ it "returns the records" do
22
+ results = subject.list_records("example.com")
23
+
24
+ expect(results).to be_a(Array)
25
+ expect(results.size).to eq(7)
26
+
27
+ results.each do |result|
28
+ expect(result).to be_a(Dnsimple::Struct::Record)
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_records/notfound.http"))
37
+
38
+ expect {
39
+ subject.list_records("example.com")
40
+ }.to raise_error(Dnsimple::RecordNotFound)
41
+ end
42
+ end
43
+ end
44
+
45
+ describe "#create_record" do
46
+ before do
47
+ stub_request(:post, %r[/v1/domains/.+/records$]).
48
+ to_return(read_fixture("domains_records/create/created.http"))
49
+ end
50
+
51
+ it "builds the correct request" do
52
+ subject.create_record("example.com", { name: "", record_type: "A", content: "127.0.0.1", prio: "1" })
53
+
54
+ expect(WebMock).to have_requested(:post, "https://api.zone/v1/domains/example.com/records").
55
+ with(body: { record: { name: "", record_type: "A", content: "127.0.0.1", prio: "1" } }).
56
+ with(headers: { 'Accept' => 'application/json' })
57
+ end
58
+
59
+ it "returns the record" do
60
+ result = subject.create_record("example.com", { name: "", record_type: "", content: "" })
61
+
62
+ expect(result).to be_a(Dnsimple::Struct::Record)
63
+ expect(result.id).to be_a(Fixnum)
64
+ end
65
+
66
+ context "when something does not exist" do
67
+ it "raises RecordNotFound" do
68
+ stub_request(:post, %r[/v1]).
69
+ to_return(read_fixture("domains/notfound.http"))
70
+
71
+ expect {
72
+ subject.create_record("example.com", { name: "", record_type: "", content: "" })
73
+ }.to raise_error(Dnsimple::RecordNotFound)
74
+ end
75
+ end
76
+ end
77
+
78
+ describe "#find_record" do
79
+ before do
80
+ stub_request(:get, %r[/v1/domains/.+/records/.+$]).
81
+ to_return(read_fixture("domains_records/show/success.http"))
82
+ end
83
+
84
+ it "builds the correct request" do
85
+ subject.find_record("example.com", 2)
86
+
87
+ expect(WebMock).to have_requested(:get, "https://api.zone/v1/domains/example.com/records/2").
88
+ with(headers: { 'Accept' => 'application/json' })
89
+ end
90
+
91
+ it "returns the record" do
92
+ result = subject.find_record("example.com", 2)
93
+
94
+ expect(result).to be_a(Dnsimple::Struct::Record)
95
+ expect(result.id).to eq(1495)
96
+ expect(result.domain_id).to eq(6)
97
+ expect(result.name).to eq("www")
98
+ expect(result.content).to eq("1.2.3.4")
99
+ expect(result.ttl).to eq(3600)
100
+ expect(result.prio).to be_nil
101
+ expect(result.record_type).to eq("A")
102
+ expect(result.created_at).to eq("2014-01-14T18:25:56Z")
103
+ expect(result.updated_at).to eq("2014-01-14T18:26:04Z")
104
+ end
105
+
106
+ context "when something does not exist" do
107
+ it "raises RecordNotFound" do
108
+ stub_request(:get, %r[/v1]).
109
+ to_return(read_fixture("domains_records/notfound.http"))
110
+
111
+ expect {
112
+ subject.find_record("example.com", 2)
113
+ }.to raise_error(Dnsimple::RecordNotFound)
114
+ end
115
+ end
116
+ end
117
+
118
+ describe "#update_record" do
119
+ before do
120
+ stub_request(:put, %r[/v1/domains/.+/records/.+$]).
121
+ to_return(read_fixture("domains_records/update/success.http"))
122
+ end
123
+
124
+ it "builds the correct request" do
125
+ subject.update_record("example.com", 2, { content: "127.0.0.1", prio: "1" })
126
+
127
+ expect(WebMock).to have_requested(:put, "https://api.zone/v1/domains/example.com/records/2").
128
+ with(body: { record: { content: "127.0.0.1", prio: "1" } }).
129
+ with(headers: { 'Accept' => 'application/json' })
130
+ end
131
+
132
+ it "returns the record" do
133
+ result = subject.update_record("example.com", 2, {})
134
+
135
+ expect(result).to be_a(Dnsimple::Struct::Record)
136
+ expect(result.id).to be_a(Fixnum)
137
+ end
138
+
139
+ context "when something does not exist" do
140
+ it "raises RecordNotFound" do
141
+ stub_request(:put, %r[/v1]).
142
+ to_return(read_fixture("domains_records/notfound.http"))
143
+
144
+ expect {
145
+ subject.update_record("example.com", 2, {})
146
+ }.to raise_error(Dnsimple::RecordNotFound)
147
+ end
148
+ end
149
+ end
150
+
151
+ describe "#delete_record" do
152
+ before do
153
+ stub_request(:delete, %r[/v1/domains/.+/records/.+$]).
154
+ to_return(read_fixture("domains/delete/success.http"))
155
+ end
156
+
157
+ it "builds the correct request" do
158
+ subject.delete_record("example.com", 2)
159
+
160
+ expect(WebMock).to have_requested(:delete, "https://api.zone/v1/domains/example.com/records/2").
161
+ with(headers: { 'Accept' => 'application/json' })
162
+ end
163
+
164
+ it "returns nothing" do
165
+ result = subject.delete_record("example.com", 2)
166
+
167
+ expect(result).to be_truthy
168
+ end
169
+
170
+ it "supports HTTP 204" do
171
+ stub_request(:delete, %r[/v1]).
172
+ to_return(read_fixture("domains_records/delete/success-204.http"))
173
+
174
+ result = subject.delete_record("example.com", 2)
175
+
176
+ expect(result).to be_truthy
177
+ end
178
+
179
+ context "when something does not exist" do
180
+ it "raises RecordNotFound" do
181
+ stub_request(:delete, %r[/v1]).
182
+ to_return(read_fixture("domains_records/notfound.http"))
183
+
184
+ expect {
185
+ subject.delete_record("example.com", 2)
186
+ }.to raise_error(Dnsimple::RecordNotFound)
187
+ end
188
+ end
189
+ end
190
+
191
+ end