Skip to content

Commit

Permalink
Merge pull request #71 from aetrion/feature/reset-domain-token
Browse files Browse the repository at this point in the history
Implement resetDomainToken()
  • Loading branch information
aeden committed Feb 4, 2016
2 parents 7761ef1 + a0d7734 commit 8f9f511
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 1 deletion.
19 changes: 18 additions & 1 deletion lib/dnsimple/client/domains.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,23 @@ def delete_domain(account_id, domain_id, options = {})
end
alias :delete :delete_domain

# Resets the domain token.
#
# @see https://developer.dnsimple.com/v2/domains/#reset-token
#
# @param [Fixnum, Dnsimple::Client::WILDCARD_ACCOUNT] account_id the account ID or wildcard
# @param [#to_s] domain_id The domain id or domain name.
# @param [Hash] options
# @return [Dnsimple::Response<nil>]
#
# @raise [Dnsimple::NotFoundError]
# @raise [Dnsimple::RequestError]
def reset_domain_token(account_id, domain_id, options = {})
response = client.post(Client.versioned("/%s/domains/%s/token" % [account_id, domain_id]), options)

Dnsimple::Response.new(response, nil)
end

end
end
end
end
25 changes: 25 additions & 0 deletions spec/dnsimple/client/domains_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -173,4 +173,29 @@
end
end

describe "#reset_domain_token" do
let(:account_id) { 1010 }
let(:domain_id) { "example.com" }

before do
stub_request(:post, %r[/v2/#{account_id}/domains/#{domain_id}/token])
.to_return(read_http_fixture("resetDomainToken/success.http"))
end

it "builds the correct request" do
subject.reset_domain_token(account_id, domain_id)

expect(WebMock).to have_requested(:post, "https://api.dnsimple.test/v2/#{account_id}/domains/#{domain_id}/token")
.with(headers: { 'Accept' => 'application/json' })
end

it "returns nothing" do
response = subject.reset_domain_token(account_id, domain_id)
expect(response).to be_a(Dnsimple::Response)

result = response.data
expect(result).to be_nil
end
end

end
17 changes: 17 additions & 0 deletions spec/fixtures.http/resetDomainToken/success.http
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
HTTP/1.1 201 Created
Server: nginx
Date: Thu, 04 Feb 2016 10:13:19 GMT
Content-Type: application/json; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
Status: 201 Created
X-RateLimit-Limit: 4000
X-RateLimit-Remaining: 3999
X-RateLimit-Reset: 1454584399
ETag: W/"834381fd3fd0896e344e3fad9e77ab97"
Cache-Control: max-age=0, private, must-revalidate
X-Request-Id: bf1b3976-2edd-4ea6-b606-1d60eaa0403d
X-Runtime: 0.075404
Strict-Transport-Security: max-age=31536000

{"data":{"id":1,"account_id":1010,"registrant_id":null,"name":"example-alpha.com","unicode_name":"example-alpha.com","token":"domain-token","state":"hosted","auto_renew":false,"private_whois":false,"expires_on":null,"created_at":""2014-12-06T15:56:55.573Z","updated_at":"2015-12-09T00:20:56.056Z"}}

0 comments on commit 8f9f511

Please sign in to comment.