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
@@ -2,175 +2,205 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Dnsimple::Client, ".contacts" do
|
4
4
|
|
5
|
-
subject { described_class.new(
|
5
|
+
subject { described_class.new(base_url: "https://api.dnsimple.test", access_token: "a1b2c3").contacts }
|
6
6
|
|
7
7
|
|
8
8
|
describe "#contacts" do
|
9
|
+
let(:account_id) { 1010 }
|
10
|
+
|
9
11
|
before do
|
10
|
-
stub_request(:get, %r[/
|
11
|
-
to_return(
|
12
|
+
stub_request(:get, %r[/v2/#{account_id}/contacts])
|
13
|
+
.to_return(read_http_fixture("listContacts/success.http"))
|
12
14
|
end
|
13
15
|
|
14
16
|
it "builds the correct request" do
|
15
|
-
subject.contacts
|
17
|
+
subject.contacts(account_id)
|
18
|
+
|
19
|
+
expect(WebMock).to have_requested(:get, "https://api.dnsimple.test/v2/#{account_id}/contacts")
|
20
|
+
.with(headers: { 'Accept' => 'application/json' })
|
21
|
+
end
|
22
|
+
|
23
|
+
it "supports pagination" do
|
24
|
+
subject.contacts(account_id, query: { page: 2 })
|
25
|
+
|
26
|
+
expect(WebMock).to have_requested(:get, "https://api.dnsimple.test/v2/#{account_id}/contacts?page=2")
|
27
|
+
end
|
28
|
+
|
29
|
+
it "supports extra request options" do
|
30
|
+
subject.contacts(account_id, query: { foo: "bar" })
|
16
31
|
|
17
|
-
expect(WebMock).to have_requested(:get, "https://api.
|
18
|
-
with(headers: { 'Accept' => 'application/json' })
|
32
|
+
expect(WebMock).to have_requested(:get, "https://api.dnsimple.test/v2/#{account_id}/contacts?foo=bar")
|
19
33
|
end
|
20
34
|
|
21
35
|
it "returns the contacts" do
|
22
|
-
|
36
|
+
response = subject.contacts(account_id)
|
23
37
|
|
24
|
-
expect(
|
25
|
-
expect(
|
38
|
+
expect(response).to be_a(Dnsimple::PaginatedResponse)
|
39
|
+
expect(response.data).to be_a(Array)
|
40
|
+
expect(response.data.size).to eq(2)
|
26
41
|
|
27
|
-
|
42
|
+
response.data.each do |result|
|
28
43
|
expect(result).to be_a(Dnsimple::Struct::Contact)
|
29
44
|
expect(result.id).to be_a(Fixnum)
|
30
45
|
end
|
31
46
|
end
|
47
|
+
|
48
|
+
it "exposes the pagination information" do
|
49
|
+
response = subject.contacts(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_contacts" do
|
60
|
+
let(:account_id) { 1010 }
|
61
|
+
|
62
|
+
it "delegates to client.paginate" do
|
63
|
+
expect(subject).to receive(:paginate).with(:contacts, account_id, { foo: "bar" })
|
64
|
+
subject.all_contacts(account_id, { foo: "bar" })
|
65
|
+
end
|
32
66
|
end
|
33
67
|
|
34
68
|
describe "#create_contact" do
|
69
|
+
let(:account_id) { 1010 }
|
70
|
+
|
35
71
|
before do
|
36
|
-
stub_request(:post, %r[/
|
37
|
-
to_return(
|
72
|
+
stub_request(:post, %r[/v2/#{account_id}/contacts$])
|
73
|
+
.to_return(read_http_fixture("createContact/created.http"))
|
38
74
|
end
|
39
75
|
|
40
|
-
let(:attributes) { { first_name: "Simone", last_name: "Carletti", address1: "", city: "Rome", state_province: "RM", postal_code: "00171", country: "IT", email_address: "", phone: "" } }
|
76
|
+
let(:attributes) { { first_name: "Simone", last_name: "Carletti", address1: "Italian Street", city: "Rome", state_province: "RM", postal_code: "00171", country: "IT", email_address: "example@example.com", phone: "+393391234567" } }
|
41
77
|
|
42
78
|
it "builds the correct request" do
|
43
|
-
subject.create_contact(attributes)
|
79
|
+
subject.create_contact(account_id, attributes)
|
44
80
|
|
45
|
-
expect(WebMock).to have_requested(:post, "https://api.
|
46
|
-
|
47
|
-
|
81
|
+
expect(WebMock).to have_requested(:post, "https://api.dnsimple.test/v2/#{account_id}/contacts")
|
82
|
+
.with(body: attributes)
|
83
|
+
.with(headers: { 'Accept' => 'application/json' })
|
48
84
|
end
|
49
85
|
|
50
86
|
it "returns the contact" do
|
51
|
-
|
87
|
+
response = subject.create_contact(account_id, attributes)
|
88
|
+
expect(response).to be_a(Dnsimple::Response)
|
52
89
|
|
90
|
+
result = response.data
|
53
91
|
expect(result).to be_a(Dnsimple::Struct::Contact)
|
54
92
|
expect(result.id).to be_a(Fixnum)
|
55
93
|
end
|
56
94
|
end
|
57
95
|
|
58
96
|
describe "#contact" do
|
97
|
+
let(:account_id) { 1010 }
|
98
|
+
|
59
99
|
before do
|
60
|
-
stub_request(:get, %r[/
|
61
|
-
to_return(
|
100
|
+
stub_request(:get, %r[/v2/#{account_id}/contacts/.+$])
|
101
|
+
.to_return(read_http_fixture("getContact/success.http"))
|
62
102
|
end
|
63
103
|
|
64
104
|
it "builds the correct request" do
|
65
|
-
subject.contact(1)
|
105
|
+
subject.contact(account_id, contact = 1)
|
66
106
|
|
67
|
-
expect(WebMock).to have_requested(:get, "https://api.
|
68
|
-
|
107
|
+
expect(WebMock).to have_requested(:get, "https://api.dnsimple.test/v2/#{account_id}/contacts/#{contact}")
|
108
|
+
.with(headers: { 'Accept' => 'application/json' })
|
69
109
|
end
|
70
110
|
|
71
111
|
it "returns the contact" do
|
72
|
-
|
112
|
+
response = subject.contact(account_id, 0)
|
113
|
+
expect(response).to be_a(Dnsimple::Response)
|
73
114
|
|
115
|
+
result = response.data
|
74
116
|
expect(result).to be_a(Dnsimple::Struct::Contact)
|
75
117
|
expect(result.id).to eq(1)
|
76
|
-
expect(result.
|
77
|
-
expect(result.
|
78
|
-
expect(result.
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
expect(result.phone).to eq("+1 111 4567890")
|
83
|
-
expect(result.fax).to eq("+1 222 4567890")
|
84
|
-
expect(result.address1).to eq("Awesome Street")
|
85
|
-
expect(result.address2).to eq("c/o Someone")
|
86
|
-
expect(result.city).to eq("Rome")
|
87
|
-
expect(result.state_province).to eq("RM")
|
88
|
-
expect(result.postal_code).to eq("00171")
|
89
|
-
expect(result.country).to eq("IT")
|
90
|
-
expect(result.created_at).to eq("2014-01-15T22:08:07.390Z")
|
91
|
-
expect(result.updated_at).to eq("2014-01-15T22:08:07.390Z")
|
92
|
-
end
|
93
|
-
|
94
|
-
context "when something does not exist" do
|
118
|
+
expect(result.account_id).to eq(1010)
|
119
|
+
expect(result.created_at).to eq("2016-01-19T20:50:26.066Z")
|
120
|
+
expect(result.updated_at).to eq("2016-01-19T20:50:26.066Z")
|
121
|
+
end
|
122
|
+
|
123
|
+
context "when the contact does not exist" do
|
95
124
|
it "raises NotFoundError" do
|
96
|
-
stub_request(:get, %r[/
|
97
|
-
to_return(
|
125
|
+
stub_request(:get, %r[/v2])
|
126
|
+
.to_return(read_http_fixture("notfound-contact.http"))
|
98
127
|
|
99
128
|
expect {
|
100
|
-
subject.contact(
|
129
|
+
subject.contact(account_id, 0)
|
101
130
|
}.to raise_error(Dnsimple::NotFoundError)
|
102
131
|
end
|
103
132
|
end
|
104
133
|
end
|
105
134
|
|
106
135
|
describe "#update_contact" do
|
136
|
+
let(:account_id) { 1010 }
|
137
|
+
|
107
138
|
before do
|
108
|
-
stub_request(:
|
109
|
-
to_return(
|
139
|
+
stub_request(:patch, %r[/v2/#{account_id}/contacts/.+$])
|
140
|
+
.to_return(read_http_fixture("updateContact/success.http"))
|
110
141
|
end
|
111
142
|
|
143
|
+
let(:attributes) { { first_name: "Updated" } }
|
144
|
+
|
112
145
|
it "builds the correct request" do
|
113
|
-
subject.
|
146
|
+
subject.update_contact(account_id, contact_id = 1, attributes)
|
114
147
|
|
115
|
-
expect(WebMock).to have_requested(:
|
116
|
-
|
117
|
-
|
148
|
+
expect(WebMock).to have_requested(:patch, "https://api.dnsimple.test/v2/#{account_id}/contacts/#{contact_id}")
|
149
|
+
.with(body: attributes)
|
150
|
+
.with(headers: { 'Accept' => 'application/json' })
|
118
151
|
end
|
119
152
|
|
120
153
|
it "returns the contact" do
|
121
|
-
|
154
|
+
response = subject.update_contact(account_id, 1, attributes)
|
155
|
+
expect(response).to be_a(Dnsimple::Response)
|
122
156
|
|
157
|
+
result = response.data
|
123
158
|
expect(result).to be_a(Dnsimple::Struct::Contact)
|
124
|
-
expect(result.id).to
|
159
|
+
expect(result.id).to eq(1)
|
125
160
|
end
|
126
161
|
|
127
|
-
context "when
|
162
|
+
context "when the contact does not exist" do
|
128
163
|
it "raises NotFoundError" do
|
129
|
-
stub_request(:
|
130
|
-
to_return(
|
164
|
+
stub_request(:patch, %r[/v2])
|
165
|
+
.to_return(read_http_fixture("notfound-contact.http"))
|
131
166
|
|
132
167
|
expect {
|
133
|
-
subject.update_contact(
|
168
|
+
subject.update_contact(account_id, 0, {})
|
134
169
|
}.to raise_error(Dnsimple::NotFoundError)
|
135
170
|
end
|
136
171
|
end
|
137
172
|
end
|
138
173
|
|
139
174
|
describe "#delete_contact" do
|
175
|
+
let(:account_id) { 1010 }
|
176
|
+
|
140
177
|
before do
|
141
|
-
stub_request(:delete, %r[/
|
142
|
-
to_return(
|
178
|
+
stub_request(:delete, %r[/v2/#{account_id}/contacts/.+$])
|
179
|
+
.to_return(read_http_fixture("deleteContact/success.http"))
|
143
180
|
end
|
144
181
|
|
145
182
|
it "builds the correct request" do
|
146
|
-
subject.delete_contact(
|
183
|
+
subject.delete_contact(account_id, domain = "example.com")
|
147
184
|
|
148
|
-
expect(WebMock).to have_requested(:delete, "https://api.
|
149
|
-
|
185
|
+
expect(WebMock).to have_requested(:delete, "https://api.dnsimple.test/v2/#{account_id}/contacts/#{domain}")
|
186
|
+
.with(headers: { 'Accept' => 'application/json' })
|
150
187
|
end
|
151
188
|
|
152
189
|
it "returns nothing" do
|
153
|
-
|
154
|
-
|
155
|
-
expect(result).to be_truthy
|
156
|
-
end
|
157
|
-
|
158
|
-
it "supports HTTP 204" do
|
159
|
-
stub_request(:delete, %r[/v1]).
|
160
|
-
to_return(read_fixture("contacts/delete_contact/success-204.http"))
|
161
|
-
|
162
|
-
result = subject.delete_contact(1)
|
190
|
+
response = subject.delete_contact(account_id, 1)
|
191
|
+
expect(response).to be_a(Dnsimple::Response)
|
163
192
|
|
164
|
-
|
193
|
+
result = response.data
|
194
|
+
expect(result).to be_nil
|
165
195
|
end
|
166
196
|
|
167
|
-
context "when
|
197
|
+
context "when the contact does not exist" do
|
168
198
|
it "raises NotFoundError" do
|
169
|
-
stub_request(:delete, %r[/
|
170
|
-
to_return(
|
199
|
+
stub_request(:delete, %r[/v2])
|
200
|
+
.to_return(read_http_fixture("notfound-contact.http"))
|
171
201
|
|
172
202
|
expect {
|
173
|
-
subject.delete_contact(
|
203
|
+
subject.delete_contact(account_id, 0)
|
174
204
|
}.to raise_error(Dnsimple::NotFoundError)
|
175
205
|
end
|
176
206
|
end
|
@@ -0,0 +1,190 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Dnsimple::Client, ".domains" do
|
4
|
+
|
5
|
+
subject { described_class.new(base_url: "https://api.dnsimple.test", access_token: "a1b2c3").domains }
|
6
|
+
|
7
|
+
|
8
|
+
describe "#email_forwards" do
|
9
|
+
let(:account_id) { 1010 }
|
10
|
+
let(:domain_id) { "example.com" }
|
11
|
+
|
12
|
+
before do
|
13
|
+
stub_request(:get, %r[/v2/#{account_id}/domains/#{domain_id}/email_forwards])
|
14
|
+
.to_return(read_http_fixture("listEmailForwards/success.http"))
|
15
|
+
end
|
16
|
+
|
17
|
+
it "builds the correct request" do
|
18
|
+
subject.email_forwards(account_id, domain_id)
|
19
|
+
|
20
|
+
expect(WebMock).to have_requested(:get, "https://api.dnsimple.test/v2/#{account_id}/domains/#{domain_id}/email_forwards")
|
21
|
+
.with(headers: { 'Accept' => 'application/json' })
|
22
|
+
end
|
23
|
+
|
24
|
+
it "supports pagination" do
|
25
|
+
subject.email_forwards(account_id, domain_id, query: { page: 2 })
|
26
|
+
|
27
|
+
expect(WebMock).to have_requested(:get, "https://api.dnsimple.test/v2/#{account_id}/domains/#{domain_id}/email_forwards?page=2")
|
28
|
+
end
|
29
|
+
|
30
|
+
it "supports extra request options" do
|
31
|
+
subject.email_forwards(account_id, domain_id, query: { foo: "bar" })
|
32
|
+
|
33
|
+
expect(WebMock).to have_requested(:get, "https://api.dnsimple.test/v2/#{account_id}/domains/#{domain_id}/email_forwards?foo=bar")
|
34
|
+
end
|
35
|
+
|
36
|
+
it "returns the email forwards" do
|
37
|
+
response = subject.email_forwards(account_id, domain_id)
|
38
|
+
|
39
|
+
expect(response).to be_a(Dnsimple::PaginatedResponse)
|
40
|
+
expect(response.data).to be_a(Array)
|
41
|
+
expect(response.data.size).to eq(2)
|
42
|
+
|
43
|
+
response.data.each do |result|
|
44
|
+
expect(result).to be_a(Dnsimple::Struct::EmailForward)
|
45
|
+
expect(result.id).to be_a(Fixnum)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
it "exposes the pagination information" do
|
50
|
+
response = subject.email_forwards(account_id, domain_id)
|
51
|
+
|
52
|
+
expect(response.respond_to?(:page)).to be_truthy
|
53
|
+
expect(response.page).to eq(1)
|
54
|
+
expect(response.per_page).to be_a(Fixnum)
|
55
|
+
expect(response.total_entries).to be_a(Fixnum)
|
56
|
+
expect(response.total_pages).to be_a(Fixnum)
|
57
|
+
end
|
58
|
+
|
59
|
+
context "when the domain does not exist" do
|
60
|
+
it "raises NotFoundError" do
|
61
|
+
stub_request(:get, %r[/v2])
|
62
|
+
.to_return(read_http_fixture("notfound-domain.http"))
|
63
|
+
|
64
|
+
expect {
|
65
|
+
subject.email_forwards(account_id, domain_id)
|
66
|
+
}.to raise_error(Dnsimple::NotFoundError)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
describe "#all_email_forwards" do
|
72
|
+
let(:account_id) { 1010 }
|
73
|
+
let(:domain_id) { "example.com" }
|
74
|
+
|
75
|
+
it "delegates to client.paginate" do
|
76
|
+
expect(subject).to receive(:paginate).with(:email_forwards, account_id, domain_id, { foo: "bar" })
|
77
|
+
subject.all_email_forwards(account_id, domain_id, { foo: "bar" })
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
describe "#create_email_forward" do
|
82
|
+
let(:account_id) { 1010 }
|
83
|
+
let(:domain_id) { "example.com" }
|
84
|
+
|
85
|
+
before do
|
86
|
+
stub_request(:post, %r[/v2/#{account_id}/domains/#{domain_id}/email_forwards$])
|
87
|
+
.to_return(read_http_fixture("createEmailForward/created.http"))
|
88
|
+
end
|
89
|
+
|
90
|
+
let(:attributes) { { from: "jim", to: "jim@another.com" } }
|
91
|
+
|
92
|
+
it "builds the correct request" do
|
93
|
+
subject.create_email_forward(account_id, domain_id, attributes)
|
94
|
+
|
95
|
+
expect(WebMock).to have_requested(:post, "https://api.dnsimple.test/v2/#{account_id}/domains/#{domain_id}/email_forwards")
|
96
|
+
.with(body: attributes)
|
97
|
+
.with(headers: { 'Accept' => 'application/json' })
|
98
|
+
end
|
99
|
+
|
100
|
+
it "returns the email forward" do
|
101
|
+
response = subject.create_email_forward(account_id, domain_id, attributes)
|
102
|
+
expect(response).to be_a(Dnsimple::Response)
|
103
|
+
|
104
|
+
result = response.data
|
105
|
+
expect(result).to be_a(Dnsimple::Struct::EmailForward)
|
106
|
+
expect(result.id).to be_a(Fixnum)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
describe "#email_forward" do
|
111
|
+
let(:account_id) { 1010 }
|
112
|
+
let(:domain_id) { "example.com" }
|
113
|
+
let(:email_forward_id) { 17706 }
|
114
|
+
|
115
|
+
before do
|
116
|
+
stub_request(:get, %r[/v2/#{account_id}/domains/#{domain_id}/email_forwards.+$])
|
117
|
+
.to_return(read_http_fixture("getEmailForward/success.http"))
|
118
|
+
end
|
119
|
+
|
120
|
+
it "builds the correct request" do
|
121
|
+
subject.email_forward(account_id, domain_id, email_forward_id)
|
122
|
+
|
123
|
+
expect(WebMock).to have_requested(:get, "https://api.dnsimple.test/v2/#{account_id}/domains/#{domain_id}/email_forwards/#{email_forward_id}")
|
124
|
+
.with(headers: { 'Accept' => 'application/json' })
|
125
|
+
end
|
126
|
+
|
127
|
+
it "returns the email forward" do
|
128
|
+
response = subject.email_forward(account_id, domain_id, email_forward_id)
|
129
|
+
expect(response).to be_a(Dnsimple::Response)
|
130
|
+
|
131
|
+
result = response.data
|
132
|
+
expect(result).to be_a(Dnsimple::Struct::EmailForward)
|
133
|
+
expect(result.id).to eq(17706)
|
134
|
+
expect(result.domain_id).to eq(228963)
|
135
|
+
expect(result.from).to eq("jim@a-domain.com")
|
136
|
+
expect(result.to).to eq("jim@another.com")
|
137
|
+
expect(result.created_at).to eq("2016-02-04T14:26:50.282Z")
|
138
|
+
expect(result.updated_at).to eq("2016-02-04T14:26:50.282Z")
|
139
|
+
end
|
140
|
+
|
141
|
+
context "when the email forward does not exist" do
|
142
|
+
it "raises NotFoundError" do
|
143
|
+
stub_request(:get, %r[/v2])
|
144
|
+
.to_return(read_http_fixture("notfound-emailforward.http"))
|
145
|
+
|
146
|
+
expect {
|
147
|
+
subject.email_forward(account_id, domain_id, email_forward_id)
|
148
|
+
}.to raise_error(Dnsimple::NotFoundError)
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
describe "#delete_email_forward" do
|
154
|
+
let(:account_id) { 1010 }
|
155
|
+
let(:domain_id) { "example.com" }
|
156
|
+
let(:email_forward_id) { 1 }
|
157
|
+
|
158
|
+
before do
|
159
|
+
stub_request(:delete, %r[/v2/#{account_id}/domains/#{domain_id}/email_forwards/#{email_forward_id}$])
|
160
|
+
.to_return(read_http_fixture("deleteEmailForward/success.http"))
|
161
|
+
end
|
162
|
+
|
163
|
+
it "builds the correct request" do
|
164
|
+
subject.delete_email_forward(account_id, domain_id, email_forward_id)
|
165
|
+
|
166
|
+
expect(WebMock).to have_requested(:delete, "https://api.dnsimple.test/v2/#{account_id}/domains/#{domain_id}/email_forwards/#{email_forward_id}")
|
167
|
+
.with(headers: { 'Accept' => 'application/json' })
|
168
|
+
end
|
169
|
+
|
170
|
+
it "returns nothing" do
|
171
|
+
response = subject.delete_email_forward(account_id, domain_id, email_forward_id)
|
172
|
+
expect(response).to be_a(Dnsimple::Response)
|
173
|
+
|
174
|
+
result = response.data
|
175
|
+
expect(result).to be_nil
|
176
|
+
end
|
177
|
+
|
178
|
+
context "when the email forward does not exist" do
|
179
|
+
it "raises NotFoundError" do
|
180
|
+
stub_request(:delete, %r[/v2])
|
181
|
+
.to_return(read_http_fixture("notfound-emailforward.http"))
|
182
|
+
|
183
|
+
expect {
|
184
|
+
subject.delete_email_forward(account_id, domain_id, email_forward_id)
|
185
|
+
}.to raise_error(Dnsimple::NotFoundError)
|
186
|
+
end
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
end
|