Skip to content

Commit

Permalink
Add command to get extended attributes on a TLD
Browse files Browse the repository at this point in the history
  • Loading branch information
jcaudle committed Mar 6, 2016
1 parent a29c251 commit 577f299
Show file tree
Hide file tree
Showing 6 changed files with 139 additions and 0 deletions.
15 changes: 15 additions & 0 deletions lib/dnsimple/client/tlds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,21 @@ def tld(tld, options = {})
Dnsimple::Response.new(response, Struct::Tld.new(response["data"]))
end

# Gets the extended attributes for a TLD.
#
# @see https://developer.dnsimple.com/v2/tlds/#extended-attributes
#
# @param tld [#to_s] The TLD name.
# @param options [Hash]
# @return [Dnsimple::CollectionResponse<Dnsimple::Struct::ExtendedAttribute>]
#
# @raise [Dnsimple::NotFoundError]
# @raise [Dnsimple::RequestError]
def extended_attributes(tld, options = {})
response = client.get(Client.versioned("/tlds/%s/extended_attributes" % tld), options)

Dnsimple::CollectionResponse.new(response, response["data"].map { |r| Struct::ExtendedAttribute.new(r) })
end
end
end
end
1 change: 1 addition & 0 deletions lib/dnsimple/struct.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def initialize(attributes = {})
require_relative 'struct/domain'
require_relative 'struct/domain_check'
require_relative 'struct/email_forward'
require_relative 'struct/extended_attribute'
require_relative 'struct/oauth_token'
require_relative 'struct/record'
require_relative 'struct/tld'
Expand Down
39 changes: 39 additions & 0 deletions lib/dnsimple/struct/extended_attribute.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
module Dnsimple
module Struct

class ExtendedAttribute < Base

class Option < Base
# The option name
attr_accessor :title

# The option value
attr_accessor :value

# A long description of the option
attr_accessor :description
end

# The extended attribute name
attr_accessor :name

# A description of the extended attribute
attr_accessor :description

# Boolean indicating if the extended attribute is required
attr_accessor :required

def options
@options ||= []
end

def options=(opts)
@options = opts.map do |opt|
ExtendedAttribute::Option.new(opt)
end
end

end

end
end
50 changes: 50 additions & 0 deletions spec/dnsimple/client/tlds_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,54 @@
expect(result.idn).to eq(true)
end
end

describe "#extended_attributes" do
before do
stub_request(:get, %r[/v2/tlds/uk/extended_attributes$])
.to_return(read_http_fixture("getTldExtendedAttributes/success.http"))
end

it "builds the correct request" do
subject.extended_attributes(tld = "uk")

expect(WebMock).to have_requested(:get, "https://api.dnsimple.test/v2/tlds/#{tld}/extended_attributes")
.with(headers: { 'Accept' => 'application/json' })
end

it "returns the extended attributes" do
response = subject.extended_attributes("uk")
expect(response).to be_a(Dnsimple::CollectionResponse)

response.data.each do |result|
expect(result).to be_a(Dnsimple::Struct::ExtendedAttribute)
expect(result.name).to be_a(String)
expect(result.description).to be_a(String)
expect(result).to respond_to(:required)

if !result.options.empty?
result.options.each do |option|
expect(option).to be_a(Dnsimple::Struct::ExtendedAttribute::Option)
expect(option.title).to be_a(String)
expect(option.value).to be_a(String)
expect(option.description).to be_a(String)
end
end
end
end

context "when there are no extended attributes for a TLD" do
before do
stub_request(:get, %r[/v2/tlds/com/extended_attributes$])
.to_return(read_http_fixture("getTldExtendedAttributes/success-noattributes.http"))
end

it "returns an empty CollectionResponse" do
response = subject.extended_attributes("com")
expect(response).to be_a(Dnsimple::CollectionResponse)

result = response.data
expect(result).to be_empty
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
HTTP/1.1 200 OK
Server: nginx
Date: Sun, 28 Feb 2016 13:19:18 GMT
Content-Type: application/json; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
Status: 200 OK
X-RateLimit-Limit: 4000
X-RateLimit-Remaining: 3996
X-RateLimit-Reset: 1456669058
ETag: W/"e0234245cb00aa260ccfa99a9a0b235e"
Cache-Control: max-age=0, private, must-revalidate
X-Request-Id: 414e9bf2-4681-4769-a3e0-ed9b8905edcc
X-Runtime: 0.459391
Strict-Transport-Security: max-age=31536000

{"data":[]}
17 changes: 17 additions & 0 deletions spec/fixtures.http/getTldExtendedAttributes/success.http
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
HTTP/1.1 200 OK
Server: nginx
Date: Sun, 28 Feb 2016 13:19:01 GMT
Content-Type: application/json; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
Status: 200 OK
X-RateLimit-Limit: 4000
X-RateLimit-Remaining: 3997
X-RateLimit-Reset: 1456669059
ETag: W/"8fbf2767d4a37fb8a504dff8709c9f2a"
Cache-Control: max-age=0, private, must-revalidate
X-Request-Id: 46f26f07-a46e-40d6-8d74-f41e75069b8a
X-Runtime: 0.527156
Strict-Transport-Security: max-age=31536000

{"data":[{"name":"uk_legal_type","description":"Legal type of registrant contact","required":false,"options":[{"title":"UK Individual","value":"IND","description":"UK Individual (our default value)"},{"title":"Non-UK Individual (representing self)","value":"FIND","description":"Non-UK Individual (representing self)"},{"title":"UK Limited Company","value":"LTD","description":"UK Limited Company"},{"title":"UK Public Limited Company","value":"PLC","description":"UK Public Limited Company"},{"title":"UK Partnership","value":"PTNR","description":"UK Partnership"},{"title":"UK LLP","value":"LLP","description":"UK Limited Liability Partnership"},{"title":"UK Sole Trader","value":"STRA","description":"UK Sole Trader"},{"title":"UK Registered Charity","value":"RCHAR","description":"UK Registered Charity"},{"title":"UK Industrial/Provident Registered Company","value":"IP","description":"UK Industrial/Provident Registered Company"},{"title":"UK School","value":"SCH","description":"UK School"},{"title":"Other Foreign","value":"FOTHER","description":"Other foreign organizations"},{"title":"UK Government Body","value":"GOV","description":"UK Government Body"},{"title":"UK Corporation by Royal Charter","value":"CRC","description":"UK Corporation by Royal Charter"},{"title":"UK Statutory Body","value":"STAT","description":"UK Statutory Body"},{"title":"UK Entity (other)","value":"OTHER","description":"UK Entity (other)"},{"title":"Non-UK Corporation","value":"FCORP","description":"Non-UK Corporation"},{"title":"Non-UK Organization (other)","value":"FOTHER","description":"Non-UK Organization"}]},{"name":"uk_reg_co_no","description":"Company identification number","required":false,"options":[]},{"name":"registered_for","description":"Company or person domain is registered for (this must be accurate and CANNOT BE CHANGED)","required":true,"options":[]},{"name":"uk_reg_opt_out","description":"Hide registrant data in Nominet WHOIS","required":false,"options":[{"title":"No","value":"n","description":"Do not hide the registrant contact information in Nominet's WHOIS."},{"title":"Yes","value":"y","description":"Hide the registrant contact information in Nominet's WHOIS (only available to individuals)."}]}]}

0 comments on commit 577f299

Please sign in to comment.