Skip to content

Commit

Permalink
Add method for getting a TLD's details
Browse files Browse the repository at this point in the history
  • Loading branch information
jcaudle committed Mar 3, 2016
1 parent 1c38317 commit a29c251
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 0 deletions.
17 changes: 17 additions & 0 deletions lib/dnsimple/client/tlds.rb
Expand Up @@ -42,6 +42,23 @@ def all_tlds(options = {})
paginate(:tlds, options)
end
alias :all :all_tlds

# Gets a TLD's details
#
# @see https://developer.dnsimple.com/v2/tlds/#get
#
# @param tld [#to_s] The TLD name.
# @param options [Hash]
# @return [Dnsimple::Response<Dnsimple::Struct::Tld>]
#
# @raise [Dnsimple::NotFoundError]
# @raise [Dnsimple::RequestError]
def tld(tld, options = {})
response = client.get(Client.versioned("/tlds/%s" % tld), options)

Dnsimple::Response.new(response, Struct::Tld.new(response["data"]))
end

end
end
end
27 changes: 27 additions & 0 deletions spec/dnsimple/client/tlds_spec.rb
Expand Up @@ -59,4 +59,31 @@
subject.all_tlds({ foo: "bar" })
end
end

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

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

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

it "returns the tld" do
response = subject.tld("com")
expect(response).to be_a(Dnsimple::Response)

result = response.data
expect(result).to be_a(Dnsimple::Struct::Tld)
expect(result.tld).to eq('com')
expect(result.tld_type).to eq(1)
expect(result.whois_privacy).to eq(true)
expect(result.auto_renew_only).to eq(false)
expect(result.idn).to eq(true)
end
end
end
17 changes: 17 additions & 0 deletions spec/fixtures.http/getTld/success.http
@@ -0,0 +1,17 @@
HTTP/1.1 200 OK
Server: nginx
Date: Fri, 26 Feb 2016 21:19:42 GMT
Content-Type: application/json; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
Status: 200 OK
X-RateLimit-Limit: 4000
X-RateLimit-Remaining: 3994
X-RateLimit-Reset: 1456524997
ETag: W/"f8997ee6be68083ab74c190c3ef8b799"
Cache-Control: max-age=0, private, must-revalidate
X-Request-Id: 60c905bf-8d9e-4da6-a564-af955f974739
X-Runtime: 0.097922
Strict-Transport-Security: max-age=31536000

{"data":{"tld":"com","tld_type":1,"whois_privacy":true,"auto_renew_only":false,"idn":true}}

0 comments on commit a29c251

Please sign in to comment.