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
@@ -0,0 +1,109 @@
1
+ require 'spec_helper'
2
+
3
+ describe Dnsimple::Client, ".domains / sharing" do
4
+
5
+ subject { described_class.new(api_endpoint: "https://api.zone", username: "user", api_token: "token").domains }
6
+
7
+
8
+ describe "#list_memberships" do
9
+ before do
10
+ stub_request(:get, %r[/v1/domains/.+/memberships]).
11
+ to_return(read_fixture("domains_sharing/list/success.http"))
12
+ end
13
+
14
+ it "builds the correct request" do
15
+ subject.list_memberships("example.com")
16
+
17
+ expect(WebMock).to have_requested(:get, "https://api.zone/v1/domains/example.com/memberships").
18
+ with(headers: { 'Accept' => 'application/json' })
19
+ end
20
+
21
+ it "returns the records" do
22
+ results = subject.list_memberships("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::Membership)
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_sharing/notfound-domain.http"))
37
+
38
+ expect {
39
+ subject.list_memberships("example.com")
40
+ }.to raise_error(Dnsimple::RecordNotFound)
41
+ end
42
+ end
43
+ end
44
+
45
+ describe "#create_membership" do
46
+ before do
47
+ stub_request(:post, %r[/v1/domains/.+/memberships]).
48
+ to_return(read_fixture("domains_sharing/create/success.http"))
49
+ end
50
+
51
+ it "builds the correct request" do
52
+ subject.create_membership("example.com", "someone@example.com")
53
+
54
+ expect(WebMock).to have_requested(:post, "https://api.zone/v1/domains/example.com/memberships").
55
+ with(body: { membership: { email: "someone@example.com" } }).
56
+ with(headers: { 'Accept' => 'application/json' })
57
+ end
58
+
59
+ it "returns the record" do
60
+ result = subject.create_membership("example.com", "someone@example.com")
61
+
62
+ expect(result).to be_a(Dnsimple::Struct::Membership)
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_membership("example.com", "someone@example.com")
73
+ }.to raise_error(Dnsimple::RecordNotFound)
74
+ end
75
+ end
76
+ end
77
+
78
+ describe "#delete_membership" do
79
+ before do
80
+ stub_request(:delete, %r[/v1/domains/.+/memberships/.+$]).
81
+ to_return(read_fixture("domains_sharing/delete/success.http"))
82
+ end
83
+
84
+ it "builds the correct request" do
85
+ subject.delete_membership("example.com", 2)
86
+
87
+ expect(WebMock).to have_requested(:delete, "https://api.zone/v1/domains/example.com/memberships/2").
88
+ with(headers: { 'Accept' => 'application/json' })
89
+ end
90
+
91
+ it "returns nothing" do
92
+ result = subject.delete_membership("example.com", 2)
93
+
94
+ expect(result).to be_truthy
95
+ end
96
+
97
+ context "when the membership does not exist" do
98
+ it "raises RecordNotFound" do
99
+ stub_request(:delete, %r[/v1]).
100
+ to_return(read_fixture("domains_sharing/notfound.http"))
101
+
102
+ expect {
103
+ subject.delete_membership("example.com", 2)
104
+ }.to raise_error(Dnsimple::RecordNotFound)
105
+ end
106
+ end
107
+ end
108
+
109
+ end
@@ -0,0 +1,139 @@
1
+ require 'spec_helper'
2
+
3
+ describe Dnsimple::Client, ".domains" do
4
+
5
+ subject { described_class.new(api_endpoint: "https://api.zone", username: "user", api_token: "token").domains }
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
+ subject.list
16
+
17
+ expect(WebMock).to have_requested(:get, "https://api.zone/v1/domains").
18
+ with(headers: { 'Accept' => 'application/json' })
19
+ end
20
+
21
+ it "returns the domains" do
22
+ results = subject.list
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::Domain)
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/domains]).
37
+ to_return(read_fixture("domains/create/created.http"))
38
+ end
39
+
40
+ let(:attributes) { { name: "example.com" } }
41
+
42
+ it "builds the correct request" do
43
+ subject.create(attributes)
44
+
45
+ expect(WebMock).to have_requested(:post, "https://api.zone/v1/domains").
46
+ with(body: { domain: attributes }).
47
+ with(headers: { 'Accept' => 'application/json' })
48
+ end
49
+
50
+ it "returns the domain" do
51
+ result = subject.create(attributes)
52
+
53
+ expect(result).to be_a(Dnsimple::Struct::Domain)
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/domains/.+$]).
61
+ to_return(read_fixture("domains/show/success.http"))
62
+ end
63
+
64
+ it "builds the correct request" do
65
+ subject.find("example.com")
66
+
67
+ expect(WebMock).to have_requested(:get, "https://api.zone/v1/domains/example.com").
68
+ with(headers: { 'Accept' => 'application/json' })
69
+ end
70
+
71
+ it "returns the domain" do
72
+ result = subject.find("example.com")
73
+
74
+ expect(result).to be_a(Dnsimple::Struct::Domain)
75
+ expect(result.id).to eq(1)
76
+ expect(result.user_id).to eq(21)
77
+ expect(result.registrant_id).to eq(321)
78
+ expect(result.name).to eq("example.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-09-27")
83
+ expect(result.created_at).to eq("2012-09-27T14:25:57.646Z")
84
+ expect(result.updated_at).to eq("2014-12-15T20:27:04.552Z")
85
+ end
86
+
87
+ context "when something does not exist" do
88
+ it "raises RecordNotFound" do
89
+ stub_request(:get, %r[/v1]).
90
+ to_return(read_fixture("domains/notfound.http"))
91
+
92
+ expect {
93
+ subject.find("example.com")
94
+ }.to raise_error(Dnsimple::RecordNotFound)
95
+ end
96
+ end
97
+ end
98
+
99
+ describe "#delete" do
100
+ before do
101
+ stub_request(:delete, %r[/v1/domains/.+$]).
102
+ to_return(read_fixture("domains/delete/success.http"))
103
+ end
104
+
105
+ it "builds the correct request" do
106
+ subject.delete("example.com")
107
+
108
+ expect(WebMock).to have_requested(:delete, "https://api.zone/v1/domains/example.com").
109
+ with(headers: { 'Accept' => 'application/json' })
110
+ end
111
+
112
+ it "returns nothing" do
113
+ result = subject.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]).
120
+ to_return(read_fixture("domains/delete/success-204.http"))
121
+
122
+ result = subject.delete("example.com")
123
+
124
+ expect(result).to be_truthy
125
+ end
126
+
127
+ context "when something does not exist" do
128
+ it "raises RecordNotFound" do
129
+ stub_request(:delete, %r[/v1]).
130
+ to_return(read_fixture("domains/notfound.http"))
131
+
132
+ expect {
133
+ subject.delete("example.com")
134
+ }.to raise_error(Dnsimple::RecordNotFound)
135
+ end
136
+ end
137
+ end
138
+
139
+ end
@@ -0,0 +1,40 @@
1
+ require 'spec_helper'
2
+
3
+ describe Dnsimple::Client, ".domains / zones" do
4
+
5
+ subject { described_class.new(api_endpoint: "https://api.zone", username: "user", api_token: "token").domains }
6
+
7
+
8
+ describe "#zone" do
9
+ before do
10
+ stub_request(:get, %r[/v1/domains/.+/zone$]).
11
+ to_return(read_fixture("domains_zones/get/success.http"))
12
+ end
13
+
14
+ it "builds the correct request" do
15
+ subject.zone("example.com")
16
+
17
+ expect(WebMock).to have_requested(:get, "https://api.zone/v1/domains/example.com/zone").
18
+ with(headers: { 'Accept' => 'application/json' })
19
+ end
20
+
21
+ it "returns the record" do
22
+ result = subject.zone("example.com")
23
+
24
+ expect(result).to be_a(String)
25
+ expect(result).to match(/^#{Regexp.escape("$ORIGIN")}/)
26
+ end
27
+
28
+ context "when domain does not exist" do
29
+ it "raises RecordNotFound" do
30
+ stub_request(:get, %r[/v1]).
31
+ to_return(read_fixture("domains_zones/notfound-domain.http"))
32
+
33
+ expect {
34
+ subject.zone("example.com")
35
+ }.to raise_error(Dnsimple::RecordNotFound)
36
+ end
37
+ end
38
+ end
39
+
40
+ end
@@ -1,14 +1,14 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Dnsimple::Client, ".registrars" do
3
+ describe Dnsimple::Client, ".registrar" do
4
4
 
5
- subject { described_class.new(api_endpoint: "https://api.zone", username: "user", api_token: "token").registrars }
5
+ subject { described_class.new(api_endpoint: "https://api.zone", username: "user", api_token: "token").registrar }
6
6
 
7
7
 
8
8
  describe "#check" do
9
9
  before do
10
10
  stub_request(:get, %r[/v1/domains/.+/check$]).
11
- to_return(read_fixture("registrars/check/registered.http"))
11
+ to_return(read_fixture("registrar/check/registered.http"))
12
12
  end
13
13
 
14
14
  it "builds the correct request" do
@@ -21,7 +21,7 @@ describe Dnsimple::Client, ".registrars" do
21
21
  context "the domain is registered" do
22
22
  before do
23
23
  stub_request(:get, %r[/v1/domains/.+/check$]).
24
- to_return(read_fixture("registrars/check/registered.http"))
24
+ to_return(read_fixture("registrar/check/registered.http"))
25
25
  end
26
26
 
27
27
  it "returns available" do
@@ -32,7 +32,7 @@ describe Dnsimple::Client, ".registrars" do
32
32
  context "the domain is available" do
33
33
  before do
34
34
  stub_request(:get, %r[/v1/domains/.+/check$]).
35
- to_return(read_fixture("registrars/check/available.http"))
35
+ to_return(read_fixture("registrar/check/available.http"))
36
36
  end
37
37
 
38
38
  it "returns available" do
@@ -44,7 +44,7 @@ describe Dnsimple::Client, ".registrars" do
44
44
  describe "#register" do
45
45
  before do
46
46
  stub_request(:post, %r[/v1/domain_registrations]).
47
- to_return(read_fixture("registrars/register/success.http"))
47
+ to_return(read_fixture("registrar/register/success.http"))
48
48
  end
49
49
 
50
50
  it "builds the correct request" do
@@ -66,7 +66,7 @@ describe Dnsimple::Client, ".registrars" do
66
66
  describe "#renew" do
67
67
  before do
68
68
  stub_request(:post, %r[/v1/domain_renewals]).
69
- to_return(read_fixture("registrars/renew/success.http"))
69
+ to_return(read_fixture("registrar/renew/success.http"))
70
70
  end
71
71
 
72
72
  it "builds the correct request" do
@@ -99,7 +99,7 @@ describe Dnsimple::Client, ".registrars" do
99
99
  describe "#list_extended_attributes" do
100
100
  before do
101
101
  stub_request(:get, %r[/v1/extended_attributes/.+$]).
102
- to_return(read_fixture("registrars_extended_attributes/list/success.http"))
102
+ to_return(read_fixture("registrar_extended_attributes/list/success.http"))
103
103
  end
104
104
 
105
105
  it "builds the correct request" do
@@ -134,7 +134,7 @@ describe Dnsimple::Client, ".registrars" do
134
134
  describe "#list_prices" do
135
135
  before do
136
136
  stub_request(:get, %r[/v1/prices$]).
137
- to_return(read_fixture("registrars_prices/list/success.http"))
137
+ to_return(read_fixture("registrar_prices/list/success.http"))
138
138
  end
139
139
 
140
140
  it "builds the correct request" do
@@ -1,71 +1,10 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Dnsimple::Client, ".services" do
3
+ describe Dnsimple::Client, ".services / domains" do
4
4
 
5
5
  subject { described_class.new(api_endpoint: "https://api.zone", username: "user", api_token: "token").services }
6
6
 
7
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
8
  describe "#applied" do
70
9
  before do
71
10
  stub_request(:get, %r[/v1/domains/.+/applied_services$]).
@@ -0,0 +1,69 @@
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
+ end