Skip to content

Commit

Permalink
Merge 7edb58e into 4f548dc
Browse files Browse the repository at this point in the history
  • Loading branch information
jcaudle committed Dec 11, 2015
2 parents 4f548dc + 7edb58e commit b9d4444
Show file tree
Hide file tree
Showing 5 changed files with 148 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/dnsimple/client/clients.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,11 @@ class DomainsService < ClientService


require 'dnsimple/client/name_servers'
require 'dnsimple/client/vanity_name_servers'

class NameServersService < ClientService
include Client::NameServers
include Client::VanityNameServers
end


Expand Down
39 changes: 39 additions & 0 deletions lib/dnsimple/client/vanity_name_servers.rb
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
61 changes: 61 additions & 0 deletions spec/dnsimple/client/vanity_name_servers_spec.rb
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
23 changes: 23 additions & 0 deletions spec/files/nameservers/vanity_name_servers/disabled.http
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"}
23 changes: 23 additions & 0 deletions spec/files/nameservers/vanity_name_servers/enabled.http
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"}

0 comments on commit b9d4444

Please sign in to comment.