dnsimple 2.2.0 → 3.0.0.pre.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -1
- data/.travis.yml +3 -1
- data/CHANGELOG.md +13 -2
- data/CONTRIBUTING.md +35 -0
- data/Gemfile +2 -0
- data/LICENSE.txt +1 -1
- data/README.md +30 -82
- data/dnsimple.gemspec +2 -1
- data/lib/dnsimple.rb +0 -2
- data/lib/dnsimple/client.rb +64 -64
- data/lib/dnsimple/client/clients.rb +82 -58
- data/lib/dnsimple/client/contacts.rb +74 -37
- data/lib/dnsimple/client/domains.rb +82 -28
- data/lib/dnsimple/client/domains_email_forwards.rb +107 -0
- data/lib/dnsimple/client/identity.rb +38 -0
- data/lib/dnsimple/client/oauth.rb +42 -0
- data/lib/dnsimple/client/registrar.rb +64 -72
- data/lib/dnsimple/client/registrar_auto_renewal.rb +41 -0
- data/lib/dnsimple/client/registrar_whois_privacy.rb +74 -0
- data/lib/dnsimple/client/tlds.rb +88 -0
- data/lib/dnsimple/client/webhooks.rb +82 -0
- data/lib/dnsimple/client/zones.rb +68 -0
- data/lib/dnsimple/client/zones_records.rb +127 -0
- data/lib/dnsimple/default.rb +10 -17
- data/lib/dnsimple/error.rb +5 -8
- data/lib/dnsimple/extra.rb +1 -1
- data/lib/dnsimple/response.rb +80 -0
- data/lib/dnsimple/struct.rb +13 -14
- data/lib/dnsimple/struct/account.rb +13 -0
- data/lib/dnsimple/struct/contact.rb +6 -3
- data/lib/dnsimple/struct/domain.rb +10 -10
- data/lib/dnsimple/struct/domain_check.rb +16 -0
- data/lib/dnsimple/struct/email_forward.rb +11 -1
- data/lib/dnsimple/struct/oauth_token.rb +19 -0
- data/lib/dnsimple/struct/record.rb +25 -7
- data/lib/dnsimple/struct/tld.rb +22 -0
- data/lib/dnsimple/struct/user.rb +3 -7
- data/lib/dnsimple/struct/webhook.rb +13 -0
- data/lib/dnsimple/struct/whois_privacy.rb +8 -5
- data/lib/dnsimple/struct/zone.rb +25 -0
- data/lib/dnsimple/version.rb +1 -1
- data/spec/dnsimple/client/client_service_spec.rb +37 -0
- data/spec/dnsimple/client/contacts_spec.rb +108 -78
- data/spec/dnsimple/client/domains_email_forwards_spec.rb +190 -0
- data/spec/dnsimple/client/domains_spec.rb +121 -58
- data/spec/dnsimple/client/identity_spec.rb +56 -0
- data/spec/dnsimple/client/oauth_spec.rb +48 -0
- data/spec/dnsimple/client/registrar_auto_renewal_spec.rb +80 -0
- data/spec/dnsimple/client/registrar_spec.rb +109 -122
- data/spec/dnsimple/client/registrar_whois_privacy_spec.rb +119 -0
- data/spec/dnsimple/client/tlds_spec.rb +139 -0
- data/spec/dnsimple/client/webhooks_spec.rb +142 -0
- data/spec/dnsimple/client/zones_records_spec.rb +277 -0
- data/spec/dnsimple/client/zones_spec.rb +109 -0
- data/spec/dnsimple/client_spec.rb +34 -46
- data/spec/dnsimple/extra_spec.rb +22 -0
- data/spec/{files → fixtures.http}/badgateway.http +14 -14
- data/spec/fixtures.http/checkDomain/success.http +17 -0
- data/spec/fixtures.http/createContact/created.http +17 -0
- data/spec/fixtures.http/createDomain/created.http +16 -0
- data/spec/fixtures.http/createEmailForward/created.http +17 -0
- data/spec/fixtures.http/createWebhook/created.http +17 -0
- data/spec/fixtures.http/createZoneRecord/created.http +17 -0
- data/spec/fixtures.http/deleteContact/success.http +13 -0
- data/spec/fixtures.http/deleteDomain/success.http +13 -0
- data/spec/fixtures.http/deleteEmailForward/success.http +12 -0
- data/spec/fixtures.http/deleteWebhook/success.http +13 -0
- data/spec/fixtures.http/deleteZoneRecord/success.http +13 -0
- data/spec/fixtures.http/disableAutoRenewal/success.http +12 -0
- data/spec/fixtures.http/disableWhoisPrivacy/success.http +17 -0
- data/spec/fixtures.http/enableAutoRenewal/success.http +12 -0
- data/spec/fixtures.http/enableWhoisPrivacy/created.http +17 -0
- data/spec/fixtures.http/enableWhoisPrivacy/success.http +17 -0
- data/spec/fixtures.http/getContact/success.http +17 -0
- data/spec/fixtures.http/getDomain/success.http +16 -0
- data/spec/fixtures.http/getEmailForward/success.http +17 -0
- data/spec/fixtures.http/getTld/success.http +17 -0
- data/spec/fixtures.http/getTldExtendedAttributes/success-noattributes.http +17 -0
- data/spec/fixtures.http/getTldExtendedAttributes/success.http +17 -0
- data/spec/fixtures.http/getWebhook/success.http +17 -0
- data/spec/fixtures.http/getWhoisPrivacy/success.http +17 -0
- data/spec/fixtures.http/getZone/success.http +17 -0
- data/spec/fixtures.http/getZoneRecord/success.http +17 -0
- data/spec/fixtures.http/listContacts/success.http +17 -0
- data/spec/fixtures.http/listDomains/success.http +16 -0
- data/spec/fixtures.http/listEmailForwards/success.http +17 -0
- data/spec/fixtures.http/listTlds/success.http +17 -0
- data/spec/fixtures.http/listWebhooks/success.http +17 -0
- data/spec/fixtures.http/listZoneRecords/success.http +17 -0
- data/spec/fixtures.http/listZones/success.http +17 -0
- data/spec/fixtures.http/notfound-contact.http +12 -0
- data/spec/fixtures.http/notfound-domain.http +12 -0
- data/spec/fixtures.http/notfound-emailforward.http +12 -0
- data/spec/fixtures.http/notfound-record.http +12 -0
- data/spec/fixtures.http/notfound-webhook.http +12 -0
- data/spec/fixtures.http/notfound-zone.http +12 -0
- data/spec/fixtures.http/oauthAccessToken/success.http +17 -0
- data/spec/fixtures.http/pages-1of3.http +16 -0
- data/spec/fixtures.http/pages-2of3.http +16 -0
- data/spec/fixtures.http/pages-3of3.http +16 -0
- data/spec/fixtures.http/registerDomain/success.http +17 -0
- data/spec/fixtures.http/renewDomain/error-tooearly.http +15 -0
- data/spec/fixtures.http/renewDomain/success.http +17 -0
- data/spec/fixtures.http/resetDomainToken/success.http +17 -0
- data/spec/fixtures.http/response.http +16 -0
- data/spec/fixtures.http/transferDomain/error-indnsimple.http +15 -0
- data/spec/fixtures.http/transferDomain/error-missing-authcode.http +15 -0
- data/spec/fixtures.http/transferDomain/success.http +17 -0
- data/spec/fixtures.http/transferDomainOut/success.http +13 -0
- data/spec/fixtures.http/updateContact/success.http +17 -0
- data/spec/fixtures.http/updateZoneRecord/success.http +17 -0
- data/spec/fixtures.http/whoami/success.http +16 -0
- data/spec/fixtures.http/whoami/success_account.http +16 -0
- data/spec/fixtures.http/whoami/success_user.http +16 -0
- data/spec/spec_helper.rb +0 -6
- data/spec/support/helpers.rb +4 -4
- metadata +161 -238
- data/lib/dnsimple/client/certificates.rb +0 -100
- data/lib/dnsimple/client/domains_autorenewal.rb +0 -35
- data/lib/dnsimple/client/domains_forwards.rb +0 -71
- data/lib/dnsimple/client/domains_privacy.rb +0 -35
- data/lib/dnsimple/client/domains_records.rb +0 -90
- data/lib/dnsimple/client/domains_sharing.rb +0 -54
- data/lib/dnsimple/client/domains_zones.rb +0 -22
- data/lib/dnsimple/client/name_servers.rb +0 -71
- data/lib/dnsimple/client/services.rb +0 -37
- data/lib/dnsimple/client/services_domains.rb +0 -68
- data/lib/dnsimple/client/templates.rb +0 -88
- data/lib/dnsimple/client/templates_domains.rb +0 -23
- data/lib/dnsimple/client/templates_records.rb +0 -88
- data/lib/dnsimple/client/users.rb +0 -39
- data/lib/dnsimple/client/vanity_name_servers.rb +0 -39
- data/lib/dnsimple/compatibility.rb +0 -46
- data/lib/dnsimple/struct/certificate.rb +0 -56
- data/lib/dnsimple/struct/membership.rb +0 -22
- data/lib/dnsimple/struct/price.rb +0 -16
- data/lib/dnsimple/struct/service.rb +0 -19
- data/lib/dnsimple/struct/template.rb +0 -19
- data/lib/dnsimple/struct/template_record.rb +0 -24
- data/lib/dnsimple/struct/transfer_order.rb +0 -10
- data/spec/dnsimple/client/certificates_spec.rb +0 -196
- data/spec/dnsimple/client/domains_autorenewals_spec.rb +0 -72
- data/spec/dnsimple/client/domains_forwards_spec.rb +0 -146
- data/spec/dnsimple/client/domains_privacy_spec.rb +0 -74
- data/spec/dnsimple/client/domains_records_spec.rb +0 -191
- data/spec/dnsimple/client/domains_sharing_spec.rb +0 -109
- data/spec/dnsimple/client/domains_zones_spec.rb +0 -40
- data/spec/dnsimple/client/name_servers_spec.rb +0 -131
- data/spec/dnsimple/client/services_domains_spec.rb +0 -101
- data/spec/dnsimple/client/services_spec.rb +0 -69
- data/spec/dnsimple/client/templates_domains_spec.rb +0 -38
- data/spec/dnsimple/client/templates_records_spec.rb +0 -180
- data/spec/dnsimple/client/templates_spec.rb +0 -166
- data/spec/dnsimple/client/users_spec.rb +0 -70
- data/spec/dnsimple/client/vanity_name_servers_spec.rb +0 -61
- data/spec/dnsimple/compatibility_spec.rb +0 -57
- data/spec/files/2fa/error-badtoken.http +0 -22
- data/spec/files/2fa/error-required.http +0 -23
- data/spec/files/2fa/exchange-token.http +0 -22
- data/spec/files/certificates/configure/success.http +0 -19
- data/spec/files/certificates/get/success.http +0 -19
- data/spec/files/certificates/list/success.http +0 -19
- data/spec/files/certificates/notfound.http +0 -19
- data/spec/files/certificates/purchase/success.http +0 -19
- data/spec/files/certificates/submit/success.http +0 -19
- data/spec/files/contacts/contact/success.http +0 -19
- data/spec/files/contacts/contacts/success.http +0 -23
- data/spec/files/contacts/create_contact/badrequest-missingcontact.http +0 -19
- data/spec/files/contacts/create_contact/badrequest-validationerror.http +0 -19
- data/spec/files/contacts/create_contact/created.http +0 -22
- data/spec/files/contacts/delete_contact/success-204.http +0 -18
- data/spec/files/contacts/delete_contact/success.http +0 -19
- data/spec/files/contacts/notfound-contact.http +0 -19
- data/spec/files/contacts/update_contact/success.http +0 -21
- data/spec/files/domains/create_domain/created.http +0 -21
- data/spec/files/domains/create_forward/created.http +0 -22
- data/spec/files/domains/create_membership/success.http +0 -21
- data/spec/files/domains/create_record/created.http +0 -21
- data/spec/files/domains/delete_domain/success-204.http +0 -18
- data/spec/files/domains/delete_domain/success.http +0 -19
- data/spec/files/domains/delete_forward/success.http +0 -17
- data/spec/files/domains/delete_membership/success.http +0 -17
- data/spec/files/domains/delete_record/success-204.http +0 -18
- data/spec/files/domains/delete_record/success.http +0 -19
- data/spec/files/domains/disable_auto_renewal/success.http +0 -21
- data/spec/files/domains/disable_whois_privacy/success.http +0 -21
- data/spec/files/domains/domain/success.http +0 -21
- data/spec/files/domains/domains/success.http +0 -21
- data/spec/files/domains/enable_auto_renewal/success.http +0 -21
- data/spec/files/domains/enable_whois_privacy/success.http +0 -22
- data/spec/files/domains/forward/success.http +0 -21
- data/spec/files/domains/forwards/success.http +0 -21
- data/spec/files/domains/memberships/success.http +0 -21
- data/spec/files/domains/notfound-domain.http +0 -19
- data/spec/files/domains/notfound-forward.http +0 -19
- data/spec/files/domains/notfound-membership.http +0 -19
- data/spec/files/domains/record/success.http +0 -19
- data/spec/files/domains/records/success.http +0 -19
- data/spec/files/domains/update_record/success.http +0 -21
- data/spec/files/domains/zone/success.http +0 -21
- data/spec/files/nameservers/change/success.http +0 -23
- data/spec/files/nameservers/deregister/success.http +0 -17
- data/spec/files/nameservers/name_servers/success.http +0 -23
- data/spec/files/nameservers/notfound-domain.http +0 -19
- data/spec/files/nameservers/register/badrequest-valueerror.http +0 -19
- data/spec/files/nameservers/register/success.http +0 -21
- data/spec/files/nameservers/vanity_name_servers/disabled.http +0 -23
- data/spec/files/nameservers/vanity_name_servers/enabled.http +0 -23
- data/spec/files/registrar/check/available.http +0 -19
- data/spec/files/registrar/check/registered.http +0 -21
- data/spec/files/registrar/extended_attributes/success.http +0 -21
- data/spec/files/registrar/prices/success.http +0 -21
- data/spec/files/registrar/register/badrequest-missingdomain.http +0 -19
- data/spec/files/registrar/register/badrequest-missingregistrant.http +0 -19
- data/spec/files/registrar/register/success.http +0 -21
- data/spec/files/registrar/renew/badrequest-missingrenewal.http +0 -19
- data/spec/files/registrar/renew/badrequest-unable.http +0 -19
- data/spec/files/registrar/renew/success.http +0 -21
- data/spec/files/registrar/transfer/success.http +0 -21
- data/spec/files/services/applied/success.http +0 -21
- data/spec/files/services/apply/success.http +0 -21
- data/spec/files/services/available/success.http +0 -21
- data/spec/files/services/notfound-service.http +0 -19
- data/spec/files/services/service/success.http +0 -21
- data/spec/files/services/services/success.http +0 -21
- data/spec/files/services/unapply/success.http +0 -21
- data/spec/files/subscriptions/subscription/success.http +0 -21
- data/spec/files/templates/apply_template/success.http +0 -21
- data/spec/files/templates/create_template/created.http +0 -22
- data/spec/files/templates/delete_template/success-204.http +0 -21
- data/spec/files/templates/delete_template/success.http +0 -21
- data/spec/files/templates/notfound-template.http +0 -19
- data/spec/files/templates/template/success.http +0 -21
- data/spec/files/templates/templates/success.http +0 -21
- data/spec/files/templates/update_template/success.http +0 -21
- data/spec/files/templates_records/create_record/created.http +0 -22
- data/spec/files/templates_records/delete_record/success-204.http +0 -19
- data/spec/files/templates_records/delete_record/success.http +0 -21
- data/spec/files/templates_records/notfound-template-record.http +0 -19
- data/spec/files/templates_records/record/success.http +0 -21
- data/spec/files/templates_records/records/success.http +0 -21
- data/spec/files/templates_records/update_record/success.http +0 -21
- data/spec/files/users/user/success.http +0 -21
@@ -0,0 +1,109 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Dnsimple::Client, ".zones" do
|
4
|
+
|
5
|
+
subject { described_class.new(base_url: "https://api.dnsimple.test", access_token: "a1b2c3").zones }
|
6
|
+
|
7
|
+
|
8
|
+
describe "#zones" do
|
9
|
+
let(:account_id) { 1010 }
|
10
|
+
|
11
|
+
before do
|
12
|
+
stub_request(:get, %r[/v2/#{account_id}/zones])
|
13
|
+
.to_return(read_http_fixture("listZones/success.http"))
|
14
|
+
end
|
15
|
+
|
16
|
+
it "builds the correct request" do
|
17
|
+
subject.zones(account_id)
|
18
|
+
|
19
|
+
expect(WebMock).to have_requested(:get, "https://api.dnsimple.test/v2/#{account_id}/zones")
|
20
|
+
.with(headers: { 'Accept' => 'application/json' })
|
21
|
+
end
|
22
|
+
|
23
|
+
it "supports pagination" do
|
24
|
+
subject.zones(account_id, query: { page: 2 })
|
25
|
+
|
26
|
+
expect(WebMock).to have_requested(:get, "https://api.dnsimple.test/v2/#{account_id}/zones?page=2")
|
27
|
+
end
|
28
|
+
|
29
|
+
it "supports extra request options" do
|
30
|
+
subject.zones(account_id, query: { foo: "bar" })
|
31
|
+
|
32
|
+
expect(WebMock).to have_requested(:get, "https://api.dnsimple.test/v2/#{account_id}/zones?foo=bar")
|
33
|
+
end
|
34
|
+
|
35
|
+
it "returns the zones" do
|
36
|
+
response = subject.zones(account_id)
|
37
|
+
|
38
|
+
expect(response).to be_a(Dnsimple::PaginatedResponse)
|
39
|
+
expect(response.data).to be_a(Array)
|
40
|
+
expect(response.data.size).to eq(2)
|
41
|
+
|
42
|
+
response.data.each do |result|
|
43
|
+
expect(result).to be_a(Dnsimple::Struct::Zone)
|
44
|
+
expect(result.id).to be_a(Fixnum)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
it "exposes the pagination information" do
|
49
|
+
response = subject.zones(account_id)
|
50
|
+
|
51
|
+
expect(response.respond_to?(:page)).to be_truthy
|
52
|
+
expect(response.page).to eq(1)
|
53
|
+
expect(response.per_page).to be_a(Fixnum)
|
54
|
+
expect(response.total_entries).to be_a(Fixnum)
|
55
|
+
expect(response.total_pages).to be_a(Fixnum)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe "#all_zones" do
|
60
|
+
let(:account_id) { 1010 }
|
61
|
+
|
62
|
+
it "delegates to client.paginate" do
|
63
|
+
expect(subject).to receive(:paginate).with(:zones, account_id, { foo: "bar" })
|
64
|
+
subject.all_zones(account_id, { foo: "bar" })
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
describe "#zone" do
|
69
|
+
let(:account_id) { 1010 }
|
70
|
+
|
71
|
+
before do
|
72
|
+
stub_request(:get, %r[/v2/#{account_id}/zones/.+$])
|
73
|
+
.to_return(read_http_fixture("getZone/success.http"))
|
74
|
+
end
|
75
|
+
|
76
|
+
it "builds the correct request" do
|
77
|
+
subject.zone(account_id, zone = "example.com")
|
78
|
+
|
79
|
+
expect(WebMock).to have_requested(:get, "https://api.dnsimple.test/v2/#{account_id}/zones/#{zone}")
|
80
|
+
.with(headers: { 'Accept' => 'application/json' })
|
81
|
+
end
|
82
|
+
|
83
|
+
it "returns the zone" do
|
84
|
+
response = subject.zone(account_id, "example.com")
|
85
|
+
expect(response).to be_a(Dnsimple::Response)
|
86
|
+
|
87
|
+
result = response.data
|
88
|
+
expect(result).to be_a(Dnsimple::Struct::Zone)
|
89
|
+
expect(result.id).to eq(1)
|
90
|
+
expect(result.account_id).to eq(1010)
|
91
|
+
expect(result.name).to eq("example-alpha.com")
|
92
|
+
expect(result.reverse).to eq(false)
|
93
|
+
expect(result.created_at).to eq("2015-04-23T07:40:03.045Z")
|
94
|
+
expect(result.updated_at).to eq("2015-04-23T07:40:03.051Z")
|
95
|
+
end
|
96
|
+
|
97
|
+
context "when the zone does not exist" do
|
98
|
+
it "raises NotFoundError" do
|
99
|
+
stub_request(:get, %r[/v2])
|
100
|
+
.to_return(read_http_fixture("notfound-zone.http"))
|
101
|
+
|
102
|
+
expect {
|
103
|
+
subject.zone(account_id, "example.com")
|
104
|
+
}.to raise_error(Dnsimple::NotFoundError)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
end
|
@@ -3,19 +3,24 @@ require 'spec_helper'
|
|
3
3
|
describe Dnsimple::Client do
|
4
4
|
|
5
5
|
describe "initialization" do
|
6
|
-
it "accepts :
|
7
|
-
subject = described_class.new(
|
8
|
-
expect(subject.
|
6
|
+
it "accepts :base_url option" do
|
7
|
+
subject = described_class.new(base_url: "https://api.example.com/")
|
8
|
+
expect(subject.base_url).to eq("https://api.example.com/")
|
9
9
|
end
|
10
10
|
|
11
|
-
it "
|
12
|
-
subject = described_class.new(
|
13
|
-
expect(subject.
|
11
|
+
it "access :access_token option" do
|
12
|
+
subject = described_class.new(access_token: "token")
|
13
|
+
expect(subject.access_token).to eq("token")
|
14
14
|
end
|
15
15
|
|
16
|
-
it "
|
16
|
+
it "normalizes :base_url trailing slash" do
|
17
|
+
subject = described_class.new(base_url: "https://api.example.com/missing/slash")
|
18
|
+
expect(subject.base_url).to eq("https://api.example.com/missing/slash/")
|
19
|
+
end
|
20
|
+
|
21
|
+
it "defaults :base_url to production API" do
|
17
22
|
subject = described_class.new
|
18
|
-
expect(subject.
|
23
|
+
expect(subject.base_url).to eq("https://api.dnsimple.com/")
|
19
24
|
end
|
20
25
|
end
|
21
26
|
|
@@ -39,73 +44,56 @@ describe Dnsimple::Client do
|
|
39
44
|
with { |req| req.headers["X-Dnsimple-Domain-Token"] == "domaintoken" }
|
40
45
|
end
|
41
46
|
|
42
|
-
it "uses
|
47
|
+
it "uses access token if there's an access token provided" do
|
43
48
|
stub_request(:any, %r[/test])
|
44
49
|
|
45
|
-
subject = described_class.new(
|
50
|
+
subject = described_class.new(access_token: "access-token")
|
46
51
|
subject.execute(:get, "test", {})
|
47
52
|
|
48
53
|
expect(WebMock).to have_requested(:get, "https://api.dnsimple.com/test").
|
49
|
-
with { |req| req.headers["
|
54
|
+
with { |req| req.headers["Authorization"] == "Bearer access-token" }
|
50
55
|
end
|
51
56
|
|
52
|
-
it "
|
53
|
-
|
54
|
-
|
55
|
-
subject = described_class.new(username: "user", password: "pass", exchange_token: "exchange-token")
|
56
|
-
subject.execute(:get, "test", {})
|
57
|
-
|
58
|
-
expect(WebMock).to have_requested(:get, "https://exchange-token:x-2fa-basic@api.dnsimple.com/test")
|
59
|
-
end
|
60
|
-
|
61
|
-
it "raises an error if there's no password or api token provided" do
|
62
|
-
subject = described_class.new(username: "user")
|
57
|
+
it "raises an error if there's no password, domain token or access token provided" do
|
58
|
+
subject = described_class.new(username: "user", oauth_client_id: "id", oauth_client_secret: "secret")
|
63
59
|
|
64
60
|
expect {
|
65
61
|
subject.execute(:get, "test", {})
|
66
|
-
}.to raise_error(Dnsimple::Error,
|
67
|
-
end
|
68
|
-
|
69
|
-
context "when 2FA is required" do
|
70
|
-
subject { described_class.new(username: "user", password: "pass") }
|
71
|
-
|
72
|
-
before do
|
73
|
-
stub_request(:any, %r[/test]).
|
74
|
-
to_return(read_fixture("2fa/error-required.http"))
|
75
|
-
end
|
76
|
-
|
77
|
-
it "raises a TwoFactorAuthenticationRequired error" do
|
78
|
-
expect {
|
79
|
-
subject.execute(:get, "test", {})
|
80
|
-
}.to raise_error(Dnsimple::TwoFactorAuthenticationRequired)
|
81
|
-
end
|
62
|
+
}.to raise_error(Dnsimple::Error, "A password, domain API token or access token is required for all API requests.")
|
82
63
|
end
|
83
64
|
end
|
84
65
|
|
85
66
|
describe "#get" do
|
86
67
|
it "delegates to #request" do
|
87
|
-
expect(subject).to receive(:execute).with(:get, "path", { foo: "bar" }).and_return(:returned)
|
68
|
+
expect(subject).to receive(:execute).with(:get, "path", nil, { foo: "bar" }).and_return(:returned)
|
88
69
|
expect(subject.get("path", foo: "bar")).to eq(:returned)
|
89
70
|
end
|
90
71
|
end
|
91
72
|
|
92
73
|
describe "#post" do
|
93
74
|
it "delegates to #request" do
|
94
|
-
expect(subject).to receive(:execute).with(:post, "path", { foo: "bar" }).and_return(:returned)
|
75
|
+
expect(subject).to receive(:execute).with(:post, "path", { foo: "bar" }, {}).and_return(:returned)
|
95
76
|
expect(subject.post("path", foo: "bar")).to eq(:returned)
|
96
77
|
end
|
97
78
|
end
|
98
79
|
|
99
80
|
describe "#put" do
|
100
81
|
it "delegates to #request" do
|
101
|
-
expect(subject).to receive(:execute).with(:put, "path", { foo: "bar" }).and_return(:returned)
|
82
|
+
expect(subject).to receive(:execute).with(:put, "path", { foo: "bar" }, {}).and_return(:returned)
|
102
83
|
expect(subject.put("path", foo: "bar")).to eq(:returned)
|
103
84
|
end
|
104
85
|
end
|
105
86
|
|
87
|
+
describe "#patch" do
|
88
|
+
it "delegates to #request" do
|
89
|
+
expect(subject).to receive(:execute).with(:patch, "path", { foo: "bar" }, {}).and_return(:returned)
|
90
|
+
expect(subject.patch("path", foo: "bar")).to eq(:returned)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
106
94
|
describe "#delete" do
|
107
95
|
it "delegates to #request" do
|
108
|
-
expect(subject).to receive(:execute).with(:delete, "path", { foo: "bar" }).and_return(:returned)
|
96
|
+
expect(subject).to receive(:execute).with(:delete, "path", { foo: "bar" }, {}).and_return(:returned)
|
109
97
|
expect(subject.delete("path", foo: "bar")).to eq(:returned)
|
110
98
|
end
|
111
99
|
end
|
@@ -139,19 +127,19 @@ describe Dnsimple::Client do
|
|
139
127
|
stub_request(:get, %r[/foo])
|
140
128
|
|
141
129
|
expect(HTTParty).to receive(:get).
|
142
|
-
with("#{subject.
|
130
|
+
with("#{subject.base_url}foo",
|
143
131
|
format: :json,
|
144
132
|
basic_auth: { username: "user", password: "pass" },
|
145
133
|
headers: { 'Accept' => 'application/json', 'User-Agent' => "dnsimple-ruby/#{Dnsimple::VERSION}" }
|
146
134
|
).
|
147
135
|
and_return(double('response', code: 200))
|
148
136
|
|
149
|
-
subject.request(:get, 'foo'
|
137
|
+
subject.request(:get, 'foo')
|
150
138
|
end
|
151
139
|
|
152
140
|
it "properly extracts options from data" do
|
153
141
|
expect(HTTParty).to receive(:put).
|
154
|
-
with("#{subject.
|
142
|
+
with("#{subject.base_url}foo",
|
155
143
|
format: :json,
|
156
144
|
body: { something: "else" },
|
157
145
|
query: { foo: "bar" },
|
@@ -160,7 +148,7 @@ describe Dnsimple::Client do
|
|
160
148
|
).
|
161
149
|
and_return(double('response', code: 200))
|
162
150
|
|
163
|
-
subject.request(:put, 'foo', { something: "else", query: { foo: "bar" }, headers: { "Custom" => "Header" } })
|
151
|
+
subject.request(:put, 'foo', { something: "else" }, { query: { foo: "bar" }, headers: { "Custom" => "Header" } })
|
164
152
|
end
|
165
153
|
end
|
166
154
|
|
data/spec/dnsimple/extra_spec.rb
CHANGED
@@ -21,4 +21,26 @@ describe Dnsimple::Extra do
|
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
|
+
describe ".validate_mandatory_attributes" do
|
25
|
+
let(:mandatory_attributes) { %i{name email} }
|
26
|
+
|
27
|
+
it "raises an error if a mandatory attribute is not present " do
|
28
|
+
expect {
|
29
|
+
described_class.validate_mandatory_attributes({name: "foo"}, mandatory_attributes)
|
30
|
+
}.to raise_error(ArgumentError, ":email is required")
|
31
|
+
end
|
32
|
+
|
33
|
+
it "does not raise an error if all attributes are present" do
|
34
|
+
expect {
|
35
|
+
described_class.validate_mandatory_attributes({name: "foo", email: "bar"}, mandatory_attributes)
|
36
|
+
}.not_to raise_error
|
37
|
+
end
|
38
|
+
|
39
|
+
it "handles nil as attributes value" do
|
40
|
+
expect {
|
41
|
+
described_class.validate_mandatory_attributes(nil, mandatory_attributes)
|
42
|
+
}.to raise_error(ArgumentError, ":name is required")
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
24
46
|
end
|
@@ -1,14 +1,14 @@
|
|
1
|
-
HTTP/1.1 502 Bad Gateway
|
2
|
-
Server: nginx
|
3
|
-
Date: Mon, 22 Dec 2014 14:16:12 GMT
|
4
|
-
Content-Type: text/html
|
5
|
-
Content-Length: 166
|
6
|
-
Connection: close
|
7
|
-
|
8
|
-
<html>
|
9
|
-
<head><title>502 Bad Gateway</title></head>
|
10
|
-
<body bgcolor="white">
|
11
|
-
<center><h1>502 Bad Gateway</h1></center>
|
12
|
-
<hr><center>nginx</center>
|
13
|
-
</body>
|
14
|
-
</html>
|
1
|
+
HTTP/1.1 502 Bad Gateway
|
2
|
+
Server: nginx
|
3
|
+
Date: Mon, 22 Dec 2014 14:16:12 GMT
|
4
|
+
Content-Type: text/html
|
5
|
+
Content-Length: 166
|
6
|
+
Connection: close
|
7
|
+
|
8
|
+
<html>
|
9
|
+
<head><title>502 Bad Gateway</title></head>
|
10
|
+
<body bgcolor="white">
|
11
|
+
<center><h1>502 Bad Gateway</h1></center>
|
12
|
+
<hr><center>nginx</center>
|
13
|
+
</body>
|
14
|
+
</html>
|
@@ -0,0 +1,17 @@
|
|
1
|
+
HTTP/1.1 200 OK
|
2
|
+
Server: nginx
|
3
|
+
Date: Fri, 26 Feb 2016 16:04:05 GMT
|
4
|
+
Content-Type: application/json; charset=utf-8
|
5
|
+
Transfer-Encoding: chunked
|
6
|
+
Connection: keep-alive
|
7
|
+
Status: 200 OK
|
8
|
+
X-RateLimit-Limit: 4000
|
9
|
+
X-RateLimit-Remaining: 3999
|
10
|
+
X-RateLimit-Reset: 1456506245
|
11
|
+
ETag: W/"f3cf8499e935e48401aae26842f712c4"
|
12
|
+
Cache-Control: max-age=0, private, must-revalidate
|
13
|
+
X-Request-Id: e3c6fac1-a36d-42c3-8a04-d68f127add18
|
14
|
+
X-Runtime: 0.605907
|
15
|
+
Strict-Transport-Security: max-age=31536000
|
16
|
+
|
17
|
+
{"data":{"domain":"example.com","available":true,"premium":false}}
|
@@ -0,0 +1,17 @@
|
|
1
|
+
HTTP/1.1 201 Created
|
2
|
+
Server: nginx
|
3
|
+
Date: Tue, 19 Jan 2016 20:50:26 GMT
|
4
|
+
Content-Type: application/json; charset=utf-8
|
5
|
+
Transfer-Encoding: chunked
|
6
|
+
Connection: keep-alive
|
7
|
+
Status: 201 Created
|
8
|
+
X-RateLimit-Limit: 4000
|
9
|
+
X-RateLimit-Remaining: 3997
|
10
|
+
X-RateLimit-Reset: 1453239045
|
11
|
+
ETag: W/"165299b0ea3e5c1c80f1ae622146626f"
|
12
|
+
Cache-Control: max-age=0, private, must-revalidate
|
13
|
+
X-Request-Id: 9f577b9e-5bc4-4a8f-adfb-09dbb1992b0e
|
14
|
+
X-Runtime: 0.061482
|
15
|
+
Strict-Transport-Security: max-age=31536000
|
16
|
+
|
17
|
+
{"data":{"id":1,"account_id":1010,"label":"Default","first_name":"First","last_name":"User","job_title":"CEO","organization_name":"Awesome Company","email_address":"first@example.com","phone":"+18001234567","fax":"+18011234567","address1":"Italian Street, 10","address2":"","city":"Roma","state_province":"RM","postal_code":"00100","country":"IT","created_at":"2016-01-19T20:50:26.066Z","updated_at":"2016-01-19T20:50:26.066Z"}}
|
@@ -0,0 +1,16 @@
|
|
1
|
+
HTTP/1.1 201 Created
|
2
|
+
Server: nginx
|
3
|
+
Date: Fri, 18 Dec 2015 16:38:07 GMT
|
4
|
+
Content-Type: application/json; charset=utf-8
|
5
|
+
Transfer-Encoding: chunked
|
6
|
+
Connection: keep-alive
|
7
|
+
X-RateLimit-Limit: 4000
|
8
|
+
X-RateLimit-Remaining: 3986
|
9
|
+
X-RateLimit-Reset: 1450456686
|
10
|
+
ETag: W/"87e018b900e5f210c3236f63d3b2f4df"
|
11
|
+
Cache-Control: max-age=0, private, must-revalidate
|
12
|
+
X-Request-Id: 0d6f1ea7-f702-4317-85f0-04874b69315d
|
13
|
+
X-Runtime: 0.257489
|
14
|
+
Strict-Transport-Security: max-age=31536000
|
15
|
+
|
16
|
+
{"data":{"id":1,"account_id":1010,"registrant_id":null,"name":"example-alpha.com","unicode_name":"example-alpha.com","token":"domain-token","state":"hosted","auto_renew":false,"private_whois":false,"expires_on":null,"created_at":"2014-12-06T15:56:55.573Z","updated_at":"2015-12-09T00:20:56.056Z"}}
|
@@ -0,0 +1,17 @@
|
|
1
|
+
HTTP/1.1 201 Created
|
2
|
+
Server: nginx
|
3
|
+
Date: Thu, 04 Feb 2016 14:26:51 GMT
|
4
|
+
Content-Type: application/json; charset=utf-8
|
5
|
+
Transfer-Encoding: chunked
|
6
|
+
Connection: keep-alive
|
7
|
+
Status: 201 Created
|
8
|
+
X-RateLimit-Limit: 4000
|
9
|
+
X-RateLimit-Remaining: 3991
|
10
|
+
X-RateLimit-Reset: 1454596042
|
11
|
+
ETag: W/"10dd958c5a3a43eec0af1d8da655cab0"
|
12
|
+
Cache-Control: max-age=0, private, must-revalidate
|
13
|
+
X-Request-Id: fca523a2-aad9-49e6-a828-a0e7711a8501
|
14
|
+
X-Runtime: 1.711621
|
15
|
+
Strict-Transport-Security: max-age=31536000
|
16
|
+
|
17
|
+
{"data":{"id":17706,"domain_id":228963,"from":"jim@a-domain.com","to":"jim@another.com","created_at":"2016-02-04T14:26:50.282Z","updated_at":"2016-02-04T14:26:50.282Z"}}
|
@@ -0,0 +1,17 @@
|
|
1
|
+
HTTP/1.1 201 Created
|
2
|
+
Server: nginx
|
3
|
+
Date: Mon, 15 Feb 2016 17:04:38 GMT
|
4
|
+
Content-Type: application/json; charset=utf-8
|
5
|
+
Transfer-Encoding: chunked
|
6
|
+
Connection: keep-alive
|
7
|
+
Status: 201 Created
|
8
|
+
X-RateLimit-Limit: 4000
|
9
|
+
X-RateLimit-Remaining: 3996
|
10
|
+
X-RateLimit-Reset: 1455559348
|
11
|
+
ETag: W/"a4b43ee926d18d0839f1eae08e78c66b"
|
12
|
+
Cache-Control: max-age=0, private, must-revalidate
|
13
|
+
X-Request-Id: dca89281-416a-4766-9428-d0295f58586e
|
14
|
+
X-Runtime: 0.175179
|
15
|
+
Strict-Transport-Security: max-age=31536000
|
16
|
+
|
17
|
+
{"data":{"id":1,"url":"https://webhook.test"}}
|
@@ -0,0 +1,17 @@
|
|
1
|
+
HTTP/1.1 201 Created
|
2
|
+
Server: nginx
|
3
|
+
Date: Thu, 07 Jan 2016 17:45:13 GMT
|
4
|
+
Content-Type: application/json; charset=utf-8
|
5
|
+
Transfer-Encoding: chunked
|
6
|
+
Connection: keep-alive
|
7
|
+
Status: 201 Created
|
8
|
+
X-RateLimit-Limit: 4000
|
9
|
+
X-RateLimit-Remaining: 3990
|
10
|
+
X-RateLimit-Reset: 1452188712
|
11
|
+
ETag: W/"a7ddff4ee5dc28bbebf3d416e8bd0f04"
|
12
|
+
Cache-Control: max-age=0, private, must-revalidate
|
13
|
+
X-Request-Id: f96f5034-bf0c-4201-9564-493c162e3cb4
|
14
|
+
X-Runtime: 0.099095
|
15
|
+
Strict-Transport-Security: max-age=31536000
|
16
|
+
|
17
|
+
{"data":{"id":64784,"zone_id":"example.com","parent_id":null,"name":"www","content":"127.0.0.1","ttl":600,"priority":null,"type":"A","system_record":false,"created_at":"2016-01-07T17:45:13.653Z","updated_at":"2016-01-07T17:45:13.653Z"}}
|
@@ -0,0 +1,13 @@
|
|
1
|
+
HTTP/1.1 204 No Content
|
2
|
+
Server: nginx
|
3
|
+
Date: Tue, 19 Jan 2016 21:49:42 GMT
|
4
|
+
Connection: keep-alive
|
5
|
+
Status: 204 No Content
|
6
|
+
X-RateLimit-Limit: 4000
|
7
|
+
X-RateLimit-Remaining: 3999
|
8
|
+
X-RateLimit-Reset: 1453243782
|
9
|
+
Cache-Control: no-cache
|
10
|
+
X-Request-Id: 10c8528b-569b-4152-a89c-fc9c5f94afe9
|
11
|
+
X-Runtime: 0.029858
|
12
|
+
Strict-Transport-Security: max-age=31536000
|
13
|
+
|