Skip to content

Commit

Permalink
Add client support for vanity name servers
Browse files Browse the repository at this point in the history
  • Loading branch information
iseem committed Mar 7, 2015
1 parent f2d832f commit 5682736
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/dnsimple/client/clients.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ def name_servers
@services[:name_servers] ||= Client::NameServersService.new(self)
end

# @return [Dnsimple::Client::VanityNameServersService] The vanity name server-related API proxy.
def vanity_name_servers
@services[:vanity_name_servers] ||= Client::VanityNameServersService.new(self)
end

# @return [Dnsimple::Client::RegistrarService] The registrar-related API proxy.
def registrar
@services[:registrar] ||= Client::RegistrarService.new(self)
Expand Down Expand Up @@ -86,6 +91,13 @@ class NameServersService < ClientService
end


require 'dnsimple/client/vanity_name_servers'

class VanityNameServersService < ClientService
include Client::VanityNameServers
end


require 'dnsimple/client/registrar'

class RegistrarService < ClientService
Expand Down
43 changes: 43 additions & 0 deletions lib/dnsimple/client/vanity_name_servers.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
module Dnsimple
class Client
module VanityNameServers

# Enable vanity name servers for a domain.
#
# @see https://developer.dnsimple.com/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(domain, names)
options = {
"vanity_nameserver_configuration": {
"server_source": "external"
}
}
options[:vanity_nameserver_configuration].merge!(names)
client.post("v1/domains/#{domain}/vanity_name_servers", options)
end

# Disable vanity name servers for a domain.
#
# @see https://developer.dnsimple.com/nameservers/vanity-nameservers/#disable
#
# @param [#to_s] domain The domain id or domain name.
#
# @return [void]
# @raise [RequestError] When the request fails.
def disable(domain)
client.delete("v1/domains/#{domain}/vanity_name_servers")
end

end
end
end

0 comments on commit 5682736

Please sign in to comment.