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.
Files changed (158) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.markdown +6 -2
  3. data/README.markdown +32 -30
  4. data/dnsimple.gemspec +1 -2
  5. data/lib/dnsimple.rb +2 -13
  6. data/lib/dnsimple/client.rb +164 -53
  7. data/lib/dnsimple/client/certificates_service.rb +98 -0
  8. data/lib/dnsimple/client/client_service.rb +8 -0
  9. data/lib/dnsimple/client/contacts_service.rb +82 -0
  10. data/lib/dnsimple/client/domains_service.rb +333 -0
  11. data/lib/dnsimple/client/name_servers_service.rb +69 -0
  12. data/lib/dnsimple/client/registrars_service.rb +105 -0
  13. data/lib/dnsimple/client/services_service.rb +95 -0
  14. data/lib/dnsimple/client/templates_service.rb +180 -0
  15. data/lib/dnsimple/client/users_service.rb +37 -0
  16. data/lib/dnsimple/compatibility.rb +46 -0
  17. data/lib/dnsimple/default.rb +86 -0
  18. data/lib/dnsimple/error.rb +7 -11
  19. data/lib/dnsimple/extra.rb +54 -0
  20. data/lib/dnsimple/struct.rb +29 -0
  21. data/lib/dnsimple/struct/certificate.rb +56 -0
  22. data/lib/dnsimple/struct/contact.rb +61 -0
  23. data/lib/dnsimple/struct/domain.rb +40 -0
  24. data/lib/dnsimple/struct/email_forward.rb +14 -0
  25. data/lib/dnsimple/struct/extended_attribute.rb +39 -0
  26. data/lib/dnsimple/struct/membership.rb +22 -0
  27. data/lib/dnsimple/struct/price.rb +16 -0
  28. data/lib/dnsimple/struct/record.rb +22 -0
  29. data/lib/dnsimple/struct/service.rb +19 -0
  30. data/lib/dnsimple/struct/template.rb +19 -0
  31. data/lib/dnsimple/struct/template_record.rb +24 -0
  32. data/lib/dnsimple/struct/transfer_order.rb +10 -0
  33. data/lib/dnsimple/struct/user.rb +17 -0
  34. data/lib/dnsimple/struct/whois_privacy.rb +19 -0
  35. data/lib/dnsimple/version.rb +1 -1
  36. data/spec/dnsimple/client/certificates_service_spec.rb +196 -0
  37. data/spec/dnsimple/client/contacts_service_spec.rb +179 -0
  38. data/spec/dnsimple/client/domains_service_spec.rb +662 -0
  39. data/spec/dnsimple/client/name_servers_service_spec.rb +131 -0
  40. data/spec/dnsimple/client/registrars_service_spec.rb +160 -0
  41. data/spec/dnsimple/client/services_service_spec.rb +162 -0
  42. data/spec/dnsimple/client/templates_service_spec.rb +371 -0
  43. data/spec/dnsimple/client/users_service_spec.rb +70 -0
  44. data/spec/dnsimple/client_spec.rb +108 -99
  45. data/spec/dnsimple/compatibility_spec.rb +57 -0
  46. data/spec/files/2fa/exchange-token.http +8 -11
  47. data/spec/files/badgateway.http +14 -0
  48. data/spec/files/certificates/configure/success.http +19 -0
  49. data/spec/files/certificates/index/success.http +1 -1
  50. data/spec/files/certificates/notfound.http +19 -0
  51. data/spec/files/certificates/purchase/success.http +19 -0
  52. data/spec/files/certificates/show/success.http +1 -1
  53. data/spec/files/certificates/submit/success.http +19 -0
  54. data/spec/files/contacts/create/badrequest-missingcontact.http +19 -0
  55. data/spec/files/contacts/create/badrequest-validationerror.http +19 -0
  56. data/spec/files/contacts/create/created.http +22 -0
  57. data/spec/files/contacts/delete/success-204.http +18 -0
  58. data/spec/files/{extended_attributes/com.http → contacts/delete/success.http} +5 -5
  59. data/spec/files/{domains/auto_renewal_enable → contacts/index}/success.http +6 -6
  60. data/spec/files/contacts/notfound.http +19 -0
  61. data/spec/files/contacts/update/success.http +21 -0
  62. data/spec/files/domains/create/created.http +21 -0
  63. data/spec/files/domains/index/success.http +11 -9
  64. data/spec/files/domains/notfound.http +11 -9
  65. data/spec/files/domains/show/success.http +12 -10
  66. data/spec/files/domains_autorenewal/disable/success.http +21 -0
  67. data/spec/files/domains_autorenewal/enable/success.http +21 -0
  68. data/spec/files/domains_autorenewal/notfound-domain.http +19 -0
  69. data/spec/files/domains_forwards/create/created.http +22 -0
  70. data/spec/files/domains_forwards/delete/success.http +17 -0
  71. data/spec/files/domains_forwards/get/success.http +21 -0
  72. data/spec/files/domains_forwards/list/success.http +21 -0
  73. data/spec/files/domains_forwards/notfound-domain.http +19 -0
  74. data/spec/files/domains_forwards/notfound.http +19 -0
  75. data/spec/files/domains_records/create/created.http +21 -0
  76. data/spec/files/domains_records/delete/success-204.http +18 -0
  77. data/spec/files/{contacts/show/notfound.http → domains_records/delete/success.http} +9 -7
  78. data/spec/files/{records → domains_records}/index/success.http +0 -0
  79. data/spec/files/{records/show → domains_records}/notfound.http +1 -1
  80. data/spec/files/{records → domains_records}/show/success.http +0 -0
  81. data/spec/files/domains_records/update/success.http +21 -0
  82. data/spec/files/domains_sharing/create/success.http +21 -0
  83. data/spec/files/domains_sharing/delete/success.http +17 -0
  84. data/spec/files/domains_sharing/list/success.http +21 -0
  85. data/spec/files/domains_sharing/notfound-domain.http +19 -0
  86. data/spec/files/domains_sharing/notfound.http +19 -0
  87. data/spec/files/domains_whois_privacy/disable/success.http +21 -0
  88. data/spec/files/domains_whois_privacy/enable/success.http +22 -0
  89. data/spec/files/domains_zones/get/success.http +21 -0
  90. data/spec/files/domains_zones/notfound-domain.http +19 -0
  91. data/spec/files/{domains/auto_renewal_disable/notfound.http → nameservers/change/success.http} +23 -21
  92. data/spec/files/nameservers/deregister/success.http +17 -0
  93. data/spec/files/{domains/auto_renewal_enable/notfound.http → nameservers/list/success.http} +23 -21
  94. data/spec/files/nameservers/notfound-domain.http +19 -0
  95. data/spec/files/nameservers/register/badrequest-valueerror.http +19 -0
  96. data/spec/files/nameservers/register/success.http +21 -0
  97. data/spec/files/registrars/check/available.http +19 -0
  98. data/spec/files/registrars/check/registered.http +21 -0
  99. data/spec/files/registrars/register/badrequest-missingdomain.http +19 -0
  100. data/spec/files/registrars/register/badrequest-missingregistrant.http +19 -0
  101. data/spec/files/registrars/register/success.http +21 -0
  102. data/spec/files/registrars/renew/badrequest-missingrenewal.http +19 -0
  103. data/spec/files/registrars/renew/badrequest-unable.http +19 -0
  104. data/spec/files/registrars/renew/success.http +21 -0
  105. data/spec/files/registrars/transfer/success.http +21 -0
  106. data/spec/files/registrars_extended_attributes/list/success.http +21 -0
  107. data/spec/files/registrars_prices/list/success.http +21 -0
  108. data/spec/files/services/applied/success.http +21 -0
  109. data/spec/files/services/apply/success.http +21 -0
  110. data/spec/files/services/available/success.http +21 -0
  111. data/spec/files/services/index/success.http +21 -0
  112. data/spec/files/services/notfound.http +19 -0
  113. data/spec/files/services/show/success.http +21 -0
  114. data/spec/files/services/unapply/success.http +21 -0
  115. data/spec/files/subscription/show/success.http +21 -0
  116. data/spec/files/templates/apply/success.http +21 -0
  117. data/spec/files/templates/create/created.http +22 -0
  118. data/spec/files/templates/delete/success-204.http +21 -0
  119. data/spec/files/templates/delete/success.http +21 -0
  120. data/spec/files/templates/index/success.http +21 -0
  121. data/spec/files/templates/notfound.http +19 -0
  122. data/spec/files/templates/show/success.http +12 -10
  123. data/spec/files/templates/update/success.http +21 -0
  124. data/spec/files/templates_records/create/created.http +22 -0
  125. data/spec/files/templates_records/delete/success-204.http +19 -0
  126. data/spec/files/templates_records/delete/success.http +21 -0
  127. data/spec/files/templates_records/index/success.http +21 -0
  128. data/spec/files/templates_records/notfound.http +19 -0
  129. data/spec/files/templates_records/show/success.http +21 -0
  130. data/spec/files/templates_records/update/success.http +21 -0
  131. data/spec/files/users/user/success.http +21 -0
  132. data/spec/spec_helper.rb +0 -2
  133. metadata +206 -73
  134. data/lib/dnsimple/base.rb +0 -10
  135. data/lib/dnsimple/certificate.rb +0 -143
  136. data/lib/dnsimple/contact.rb +0 -157
  137. data/lib/dnsimple/domain.rb +0 -252
  138. data/lib/dnsimple/extended_attribute.rb +0 -52
  139. data/lib/dnsimple/record.rb +0 -94
  140. data/lib/dnsimple/service.rb +0 -42
  141. data/lib/dnsimple/template.rb +0 -65
  142. data/lib/dnsimple/template_record.rb +0 -80
  143. data/lib/dnsimple/transfer_order.rb +0 -34
  144. data/lib/dnsimple/user.rb +0 -50
  145. data/spec/dnsimple/certificate_spec.rb +0 -59
  146. data/spec/dnsimple/contact_spec.rb +0 -45
  147. data/spec/dnsimple/domain_spec.rb +0 -241
  148. data/spec/dnsimple/extended_attributes_spec.rb +0 -54
  149. data/spec/dnsimple/record_spec.rb +0 -51
  150. data/spec/dnsimple/template_spec.rb +0 -31
  151. data/spec/dnsimple/user_spec.rb +0 -70
  152. data/spec/files/account/user/success.http +0 -19
  153. data/spec/files/certificates/show/notfound.http +0 -17
  154. data/spec/files/domains/auto_renewal_disable/success.http +0 -23
  155. data/spec/files/domains/create/success.http +0 -19
  156. data/spec/files/extended_attributes/ca.http +0 -19
  157. data/spec/files/extended_attributes/success.http +0 -19
  158. data/spec/files/templates/show/notfound.http +0 -17
@@ -0,0 +1,131 @@
1
+ require 'spec_helper'
2
+
3
+ describe Dnsimple::Client, ".name_servers" do
4
+
5
+ subject { described_class.new(api_endpoint: "https://api.zone", username: "user", api_token: "token").name_servers }
6
+
7
+
8
+ describe "#list" do
9
+ before do
10
+ stub_request(:get, %r[/v1/domains/.+/name_servers]).
11
+ to_return(read_fixture("nameservers/list/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/name_servers").
18
+ with(headers: { 'Accept' => 'application/json' })
19
+ end
20
+
21
+ it "returns the name servers" do
22
+ expect(subject.list("example.com")).to eq(%w( ns1.dnsimple.com ns2.dnsimple.com ))
23
+ end
24
+
25
+ context "when something does not exist" do
26
+ it "raises RecordNotFound" do
27
+ stub_request(:get, %r[/v1]).
28
+ to_return(read_fixture("nameservers/notfound-domain.http"))
29
+
30
+ expect {
31
+ subject.list("example.com")
32
+ }.to raise_error(Dnsimple::RecordNotFound)
33
+ end
34
+ end
35
+ end
36
+
37
+ describe "#change" do
38
+ before do
39
+ stub_request(:post, %r[/v1/domains/.+/name_servers]).
40
+ to_return(read_fixture("nameservers/change/success.http"))
41
+ end
42
+
43
+ it "builds the correct request" do
44
+ subject.change("example.com", %w( ns1.example.com ns2.example.com ))
45
+
46
+ expect(WebMock).to have_requested(:post, "https://api.zone/v1/domains/example.com/name_servers").
47
+ with(body: { "name_servers" => { "ns1" => "ns1.example.com", "ns2" => "ns2.example.com" }}).
48
+ with(headers: { 'Accept' => 'application/json' })
49
+ end
50
+
51
+ it "returns the name servers" do
52
+ expect(subject.change("example.com", %w())).to eq(%w( ns1.dnsimple.com ns2.dnsimple.com ))
53
+ end
54
+
55
+ context "when something does not exist" do
56
+ it "raises RecordNotFound" do
57
+ stub_request(:post, %r[/v1]).
58
+ to_return(read_fixture("nameservers/notfound-domain.http"))
59
+
60
+ expect {
61
+ subject.change("example.com", %w())
62
+ }.to raise_error(Dnsimple::RecordNotFound)
63
+ end
64
+ end
65
+ end
66
+
67
+
68
+ describe "#register" do
69
+ before do
70
+ stub_request(:post, %r[/v1/domains/.+/registry_name_servers$]).
71
+ to_return(read_fixture("nameservers/register/success.http"))
72
+ end
73
+
74
+ it "builds the correct request" do
75
+ subject.register("example.com", "ns1.example.com", "127.0.0.1")
76
+
77
+ expect(WebMock).to have_requested(:post, "https://api.zone/v1/domains/example.com/registry_name_servers").
78
+ with(body: { "name_server" => { "name" => "ns1.example.com", "ip" => "127.0.0.1" }}).
79
+ with(headers: { 'Accept' => 'application/json' })
80
+ end
81
+
82
+ it "returns nothing" do
83
+ result = subject.register("example.com", "ns1.example.com", "127.0.0.1")
84
+
85
+ expect(result).to be_truthy
86
+ end
87
+
88
+ context "when the domain does not exist" do
89
+ it "raises RecordNotFound" do
90
+ stub_request(:post, %r[/v1]).
91
+ to_return(read_fixture("nameservers/notfound-domain.http"))
92
+
93
+ expect {
94
+ subject.register("example.com", "ns1.example.com", "127.0.0.1")
95
+ }.to raise_error(Dnsimple::RecordNotFound)
96
+ end
97
+ end
98
+ end
99
+
100
+ describe "#deregister" do
101
+ before do
102
+ stub_request(:delete, %r[/v1/domains/.+/registry_name_servers/.+$]).
103
+ to_return(read_fixture("nameservers/deregister/success.http"))
104
+ end
105
+
106
+ it "builds the correct request" do
107
+ subject.deregister("example.com", "ns1.example.com")
108
+
109
+ expect(WebMock).to have_requested(:delete, "https://api.zone/v1/domains/example.com/registry_name_servers/ns1.example.com").
110
+ with(headers: { 'Accept' => 'application/json' })
111
+ end
112
+
113
+ it "returns nothing" do
114
+ result = subject.deregister("example.com", "ns1.example.com")
115
+
116
+ expect(result).to be_truthy
117
+ end
118
+
119
+ context "when the domain does not exist" do
120
+ it "raises RecordNotFound" do
121
+ stub_request(:delete, %r[/v1]).
122
+ to_return(read_fixture("nameservers/notfound-domain.http"))
123
+
124
+ expect {
125
+ subject.deregister("example.com", "ns1.example.com")
126
+ }.to raise_error(Dnsimple::RecordNotFound)
127
+ end
128
+ end
129
+ end
130
+
131
+ end
@@ -0,0 +1,160 @@
1
+ require 'spec_helper'
2
+
3
+ describe Dnsimple::Client, ".registrars" do
4
+
5
+ subject { described_class.new(api_endpoint: "https://api.zone", username: "user", api_token: "token").registrars }
6
+
7
+
8
+ describe "#check" do
9
+ before do
10
+ stub_request(:get, %r[/v1/domains/.+/check$]).
11
+ to_return(read_fixture("registrars/check/registered.http"))
12
+ end
13
+
14
+ it "builds the correct request" do
15
+ subject.check("example.com")
16
+
17
+ expect(WebMock).to have_requested(:get, "https://api.zone/v1/domains/example.com/check").
18
+ with(headers: { 'Accept' => 'application/json' })
19
+ end
20
+
21
+ context "the domain is registered" do
22
+ before do
23
+ stub_request(:get, %r[/v1/domains/.+/check$]).
24
+ to_return(read_fixture("registrars/check/registered.http"))
25
+ end
26
+
27
+ it "returns available" do
28
+ expect(subject.check("example.com")).to eq("registered")
29
+ end
30
+ end
31
+
32
+ context "the domain is available" do
33
+ before do
34
+ stub_request(:get, %r[/v1/domains/.+/check$]).
35
+ to_return(read_fixture("registrars/check/available.http"))
36
+ end
37
+
38
+ it "returns available" do
39
+ expect(subject.check("example.com")).to eq("available")
40
+ end
41
+ end
42
+ end
43
+
44
+ describe "#register" do
45
+ before do
46
+ stub_request(:post, %r[/v1/domain_registrations]).
47
+ to_return(read_fixture("registrars/register/success.http"))
48
+ end
49
+
50
+ it "builds the correct request" do
51
+ subject.register("example.com", 10)
52
+
53
+ expect(WebMock).to have_requested(:post, "https://api.zone/v1/domain_registrations").
54
+ with(body: { domain: { name: "example.com", registrant_id: "10" }}).
55
+ with(headers: { 'Accept' => 'application/json' })
56
+ end
57
+
58
+ it "returns the domain" do
59
+ result = subject.register("example.com", 10)
60
+
61
+ expect(result).to be_a(Dnsimple::Struct::Domain)
62
+ expect(result.id).to be_a(Fixnum)
63
+ end
64
+ end
65
+
66
+ describe "#renew" do
67
+ before do
68
+ stub_request(:post, %r[/v1/domain_renewals]).
69
+ to_return(read_fixture("registrars/renew/success.http"))
70
+ end
71
+
72
+ it "builds the correct request" do
73
+ subject.renew("example.com")
74
+
75
+ expect(WebMock).to have_requested(:post, "https://api.zone/v1/domain_renewals").
76
+ with(headers: { 'Accept' => 'application/json' })
77
+ end
78
+
79
+ it "returns the domain" do
80
+ result = subject.renew("example.com")
81
+
82
+ expect(result).to be_a(Dnsimple::Struct::Domain)
83
+ expect(result.id).to be_a(Fixnum)
84
+ end
85
+
86
+ context "when something does not exist" do
87
+ it "raises RecordNotFound" do
88
+ stub_request(:post, %r[/v1]).
89
+ to_return(read_fixture("domains/notfound.http"))
90
+
91
+ expect {
92
+ subject.renew("example.com")
93
+ }.to raise_error(Dnsimple::RecordNotFound)
94
+ end
95
+ end
96
+ end
97
+
98
+
99
+ describe "#list_extended_attributes" do
100
+ before do
101
+ stub_request(:get, %r[/v1/extended_attributes/.+$]).
102
+ to_return(read_fixture("registrars_extended_attributes/list/success.http"))
103
+ end
104
+
105
+ it "builds the correct request" do
106
+ subject.list_extended_attributes("uk")
107
+
108
+ expect(WebMock).to have_requested(:get, "https://api.zone/v1/extended_attributes/uk").
109
+ with(headers: { 'Accept' => 'application/json' })
110
+ end
111
+
112
+ it "returns the extended attributes" do
113
+ results = subject.list_extended_attributes("uk")
114
+
115
+ expect(results).to be_a(Array)
116
+ expect(results.size).to eq(4)
117
+
118
+ result = results[0]
119
+ expect(result).to be_a(Dnsimple::Struct::ExtendedAttribute)
120
+ expect(result.name).to eq("uk_legal_type")
121
+ expect(result.description).to eq("Legal type of registrant contact")
122
+ expect(result.required).to eq(false)
123
+ expect(result.options).to be_a(Array)
124
+ expect(result.options.size).to eq(17)
125
+
126
+ option = result.options[0]
127
+ expect(option.title).to eq("UK Individual")
128
+ expect(option.value).to eq("IND")
129
+ expect(option.description).to eq("UK Individual (our default value)")
130
+ end
131
+ end
132
+
133
+
134
+ describe "#list_prices" do
135
+ before do
136
+ stub_request(:get, %r[/v1/prices$]).
137
+ to_return(read_fixture("registrars_prices/list/success.http"))
138
+ end
139
+
140
+ it "builds the correct request" do
141
+ subject.list_prices
142
+
143
+ expect(WebMock).to have_requested(:get, "https://api.zone/v1/prices").
144
+ with(headers: { 'Accept' => 'application/json' })
145
+ end
146
+
147
+ it "returns the prices" do
148
+ results = subject.list_prices
149
+
150
+ expect(results).to be_a(Array)
151
+ expect(results.size).to be > 0
152
+
153
+ results.each do |result|
154
+ expect(result).to be_a(Dnsimple::Struct::Price)
155
+ expect(result.tld).to be_a(String)
156
+ end
157
+ end
158
+ end
159
+
160
+ end
@@ -0,0 +1,162 @@
1
+ require 'spec_helper'
2
+
3
+ describe Dnsimple::Client, ".services" do
4
+
5
+ subject { described_class.new(api_endpoint: "https://api.zone", username: "user", api_token: "token").services }
6
+
7
+
8
+ describe "#list" do
9
+ before do
10
+ stub_request(:get, %r[/v1/services$]).
11
+ to_return(read_fixture("services/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/services").
18
+ with(headers: { 'Accept' => 'application/json' })
19
+ end
20
+
21
+ it "returns the services" do
22
+ results = subject.list
23
+
24
+ expect(results).to be_a(Array)
25
+ expect(results.size).to eq(3)
26
+
27
+ results.each do |result|
28
+ expect(result).to be_a(Dnsimple::Struct::Service)
29
+ expect(result.id).to be_a(Fixnum)
30
+ end
31
+ end
32
+ end
33
+
34
+ describe "#find" do
35
+ before do
36
+ stub_request(:get, %r[/v1/services/.+$]).
37
+ to_return(read_fixture("services/show/success.http"))
38
+ end
39
+
40
+ it "builds the correct request" do
41
+ subject.find(1)
42
+
43
+ expect(WebMock).to have_requested(:get, "https://api.zone/v1/services/1").
44
+ with(headers: { 'Accept' => 'application/json' })
45
+ end
46
+
47
+ it "returns the service" do
48
+ result = subject.find(1)
49
+
50
+ expect(result).to be_a(Dnsimple::Struct::Service)
51
+ expect(result.id).to eq(1)
52
+ expect(result.name).to eq("Google Apps")
53
+ expect(result.short_name).to eq("google-apps")
54
+ expect(result.description).to eq("All the records you need for Google Apps to function.")
55
+ end
56
+
57
+ context "when something does not exist" do
58
+ it "raises RecordNotFound" do
59
+ stub_request(:get, %r[/v1]).
60
+ to_return(read_fixture("services/notfound.http"))
61
+
62
+ expect {
63
+ subject.find(1)
64
+ }.to raise_error(Dnsimple::RecordNotFound)
65
+ end
66
+ end
67
+ end
68
+
69
+ describe "#applied" do
70
+ before do
71
+ stub_request(:get, %r[/v1/domains/.+/applied_services$]).
72
+ to_return(read_fixture("services/applied/success.http"))
73
+ end
74
+
75
+ it "builds the correct request" do
76
+ subject.applied("example.com")
77
+
78
+ expect(WebMock).to have_requested(:get, "https://api.zone/v1/domains/example.com/applied_services").
79
+ with(headers: { 'Accept' => 'application/json' })
80
+ end
81
+
82
+ it "returns the services" do
83
+ results = subject.applied("example.com")
84
+
85
+ expect(results).to be_a(Array)
86
+ expect(results.size).to eq(1)
87
+
88
+ results.each do |result|
89
+ expect(result).to be_a(Dnsimple::Struct::Service)
90
+ expect(result.id).to be_a(Fixnum)
91
+ end
92
+ end
93
+ end
94
+
95
+ describe "#available" do
96
+ before do
97
+ stub_request(:get, %r[/v1/domains/.+/available_services$]).
98
+ to_return(read_fixture("services/available/success.http"))
99
+ end
100
+
101
+ it "builds the correct request" do
102
+ subject.available("example.com")
103
+
104
+ expect(WebMock).to have_requested(:get, "https://api.zone/v1/domains/example.com/available_services").
105
+ with(headers: { 'Accept' => 'application/json' })
106
+ end
107
+
108
+ it "returns the services" do
109
+ results = subject.available("example.com")
110
+
111
+ expect(results).to be_a(Array)
112
+ expect(results.size).to eq(1)
113
+
114
+ results.each do |result|
115
+ expect(result).to be_a(Dnsimple::Struct::Service)
116
+ expect(result.id).to be_a(Fixnum)
117
+ end
118
+ end
119
+ end
120
+
121
+ describe "#apply" do
122
+ before do
123
+ stub_request(:post, %r[/v1/domains/.+/applied_services$]).
124
+ to_return(read_fixture("services/apply/success.http"))
125
+ end
126
+
127
+ it "builds the correct request" do
128
+ subject.apply("example.com", "whatever")
129
+
130
+ expect(WebMock).to have_requested(:post, "https://api.zone/v1/domains/example.com/applied_services").
131
+ with(body: { service: { id: "whatever" } }).
132
+ with(headers: { 'Accept' => 'application/json' })
133
+ end
134
+
135
+ it "returns nothing" do
136
+ results = subject.apply("example.com", "whatever")
137
+
138
+ expect(results).to be_truthy
139
+ end
140
+ end
141
+
142
+ describe "#unapply" do
143
+ before do
144
+ stub_request(:delete, %r[/v1/domains/.+/applied_services/.+$]).
145
+ to_return(read_fixture("services/unapply/success.http"))
146
+ end
147
+
148
+ it "builds the correct request" do
149
+ subject.unapply("example.com", "whatever")
150
+
151
+ expect(WebMock).to have_requested(:delete, "https://api.zone/v1/domains/example.com/applied_services/whatever").
152
+ with(headers: { 'Accept' => 'application/json' })
153
+ end
154
+
155
+ it "returns nothing" do
156
+ results = subject.unapply("example.com", "whatever")
157
+
158
+ expect(results).to be_truthy
159
+ end
160
+ end
161
+
162
+ end