-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
148 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
module Dnsimple | ||
class Client | ||
module VanityNameServers | ||
|
||
# Enable vanity name servers for a domain. | ||
# | ||
# @see https://developer.dnsimple.com/v1/nameservers/vanity-nameservers/#enable | ||
# | ||
# @param [#to_s] domain The domain id or domain name. | ||
# @param [Hash] names A hash of up to 4 external name servers; hash keys | ||
# are ns1 through ns4, e.g. | ||
# { | ||
# "ns1" => "ns1.example.com", | ||
# "ns2" => "ns2.example.com" | ||
# } | ||
# | ||
# @return [void] | ||
# @raise [RequestError] When the request fails. | ||
def enable_vanity_name_servers(domain, names, options={}) | ||
options["vanity_nameserver_configuration"] = {"server_source" => "external"} | ||
options["vanity_nameserver_configuration"].merge!(names) | ||
client.post(Client.versioned("domains/#{domain}/vanity_name_servers"), options) | ||
end | ||
|
||
# Disable vanity name servers for a domain. | ||
# | ||
# @see https://developer.dnsimple.com/v1/nameservers/vanity-nameservers/#disable | ||
# | ||
# @param [#to_s] domain The domain id or domain name. | ||
# | ||
# @return [void] | ||
# @raise [RequestError] When the request fails. | ||
def disable_vanity_name_servers(domain, options={}) | ||
client.delete("v1/domains/#{domain}/vanity_name_servers", options) | ||
end | ||
|
||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
require 'spec_helper' | ||
|
||
describe Dnsimple::Client, ".nameservers / vanity_name_servers" do | ||
subject { described_class.new(api_endpoint: "https://api.zone", username: "user", api_token: "token").name_servers } | ||
|
||
describe "#enable_vanity_name_servers" do | ||
before do | ||
stub_request(:post, %r[/v1/domains/.+/vanity_name_servers]). | ||
to_return(read_fixture("nameservers/vanity_name_servers/enabled.http")) | ||
end | ||
|
||
it "builds the correct request" do | ||
subject.enable_vanity_name_servers("example.com", { "ns1" => "ns1.example.com", "ns2" => "ns2.example.com" }) | ||
|
||
expect(WebMock).to have_requested(:post, "https://api.zone/v1/domains/example.com/vanity_name_servers"). | ||
with(body: { "vanity_nameserver_configuration" => { "server_source" => "external", "ns1" => "ns1.example.com", "ns2" => "ns2.example.com" } }). | ||
with(headers: { 'Accept' => 'application/json' }) | ||
end | ||
|
||
it "allows submission of extra options" do | ||
subject.enable_vanity_name_servers("example.com", { "ns1" => "ns1.example.com", "ns2" => "ns2.example.com" }, {headers: { "X-FAKE-HEADER" => "Some value" }}) | ||
|
||
expect(WebMock).to have_requested(:post, "https://api.zone/v1/domains/example.com/vanity_name_servers"). | ||
with(body: { "vanity_nameserver_configuration" => { "server_source" => "external", "ns1" => "ns1.example.com", "ns2" => "ns2.example.com" } }). | ||
with(headers: { 'Accept' => 'application/json', "X-FAKE-HEADER" => "Some value" }) | ||
end | ||
|
||
it "returns nothing" do | ||
result = subject.enable_vanity_name_servers("example.com", { ns1: "ns1.example.com", ns2: "ns2.example.com" }) | ||
|
||
expect(result).to be_truthy | ||
end | ||
end | ||
|
||
describe "#disable_vanity_name_servers" do | ||
before do | ||
stub_request(:delete, %r[/v1/domains/.+/vanity_name_servers]). | ||
to_return(read_fixture("nameservers/vanity_name_servers/disabled.http")) | ||
end | ||
|
||
it "builds the correct request" do | ||
subject.disable_vanity_name_servers("example.com") | ||
|
||
expect(WebMock).to have_requested(:delete, "https://api.zone/v1/domains/example.com/vanity_name_servers"). | ||
with(headers: { 'Accept' => 'application/json' }) | ||
end | ||
|
||
it "allows submission of extra options" do | ||
subject.disable_vanity_name_servers("example.com", {headers: { "X-FAKE-HEADER" => "Some value" }}) | ||
|
||
expect(WebMock).to have_requested(:delete, "https://api.zone/v1/domains/example.com/vanity_name_servers"). | ||
with(headers: { 'Accept' => 'application/json', "X-FAKE-HEADER" => "Some value" }) | ||
end | ||
|
||
it "returns nothing" do | ||
result = subject.disable_vanity_name_servers("example.com") | ||
|
||
expect(result).to be_truthy | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
HTTP/1.1 200 OK | ||
Date: Thu, 10 Dec 2015 20:14:05 GMT | ||
Status: 200 OK | ||
Connection: close | ||
Access-Control-Allow-Origin: * | ||
Access-Control-Allow-Headers: Authorization,Accepts,Content-Type,X-DNSimple-Token,X-DNSimple-Domain-Token,X-CSRF-Token,x-requested-with | ||
Access-Control-Allow-Methods: GET,POST,PUT,DELETE,OPTIONS | ||
X-Frame-Options: SAMEORIGIN | ||
X-XSS-Protection: 1 | ||
X-Content-Type-Options: nosniff | ||
X-Download-Options: noopen | ||
X-Permitted-Cross-Domain-Policies: none | ||
Content-Type: application/json; charset=utf-8 | ||
Cache-Control: no-store, must-revalidate, private, max-age=0 | ||
X-Request-Id: 360532fd-7df5-4b9d-82d9-707495232709 | ||
X-Runtime: 0.351830 | ||
Set-Cookie: __profilin=p%3Dt; path=/ | ||
Set-Cookie: __profilin=p%3Dt; path=/ | ||
Set-Cookie: __profilin=p%3Dt; path=/ | ||
X-MiniProfiler-Ids: ["57flfc4miao2xtm0qi6t","3ob7yssth2tgz18xdhmh","lcx8amyy6mysu1rsv7d5","2qsm2f2xvqh224oqcnq9","qmhq7a2rqv5mtlz7e8bb"] | ||
Transfer-Encoding: chunked | ||
|
||
{"status":"disabled"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
HTTP/1.1 200 OK | ||
Date: Thu, 10 Dec 2015 20:13:43 GMT | ||
Status: 200 OK | ||
Connection: close | ||
Access-Control-Allow-Origin: * | ||
Access-Control-Allow-Headers: Authorization,Accepts,Content-Type,X-DNSimple-Token,X-DNSimple-Domain-Token,X-CSRF-Token,x-requested-with | ||
Access-Control-Allow-Methods: GET,POST,PUT,DELETE,OPTIONS | ||
X-Frame-Options: SAMEORIGIN | ||
X-XSS-Protection: 1 | ||
X-Content-Type-Options: nosniff | ||
X-Download-Options: noopen | ||
X-Permitted-Cross-Domain-Policies: none | ||
Content-Type: application/json; charset=utf-8 | ||
Cache-Control: no-store, must-revalidate, private, max-age=0 | ||
X-Request-Id: 765d10fb-5e1d-456a-8bb8-653712cd07ae | ||
X-Runtime: 0.386822 | ||
Set-Cookie: __profilin=p%3Dt; path=/ | ||
Set-Cookie: __profilin=p%3Dt; path=/ | ||
Set-Cookie: __profilin=p%3Dt; path=/ | ||
X-MiniProfiler-Ids: ["qmhq7a2rqv5mtlz7e8bb","3ob7yssth2tgz18xdhmh","lcx8amyy6mysu1rsv7d5","2qsm2f2xvqh224oqcnq9"] | ||
Transfer-Encoding: chunked | ||
|
||
{"status":"enabled"} |