Skip to content

Commit

Permalink
Add deleteContact
Browse files Browse the repository at this point in the history
  • Loading branch information
weppos committed Jan 19, 2016
1 parent 0494d1d commit 167f3b2
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 0 deletions.
20 changes: 20 additions & 0 deletions lib/dnsimple/client/contacts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,26 @@ def update_contact(account_id, contact_id, attributes = {}, options = {})
end
alias :update :update_contact

# Deletes a contact from the account.
#
# WARNING: this cannot be undone.
#
# @see https://developer.dnsimple.com/v2/contacts/#delete
#
# @param [Fixnum, Dnsimple::Client::WILDCARD_ACCOUNT] account_id the account ID or wildcard
# @param [#to_s] contact_id The contact id.
# @param [Hash] options
# @return [Dnsimple::Response<nil>]
#
# @raise [Dnsimple::NotFoundError]
# @raise [Dnsimple::RequestError]
def delete_contact(account_id, contact_id, options = {})
response = client.delete(Client.versioned("/%s/contacts/%s" % [account_id, contact_id]), options)

Dnsimple::Response.new(response, nil)
end
alias :delete :delete_contact

end
end
end
35 changes: 35 additions & 0 deletions spec/dnsimple/client/contacts_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -171,4 +171,39 @@
end
end

describe "#delete_contact" do
let(:account_id) { 1010 }

before do
stub_request(:delete, %r[/v2/#{account_id}/contacts/.+$])
.to_return(read_http_fixture("deleteContact/success.http"))
end

it "builds the correct request" do
subject.delete_contact(account_id, domain = "example.com")

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

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

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

context "when the contact does not exist" do
it "raises NotFoundError" do
stub_request(:delete, %r[/v2])
.to_return(read_http_fixture("notfound-contact.http"))

expect {
subject.delete_contact(account_id, 0)
}.to raise_error(Dnsimple::NotFoundError)
end
end
end

end
13 changes: 13 additions & 0 deletions spec/fixtures.http/deleteContact/success.http
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
HTTP/1.1 204 No Content
Server: nginx
Date: Tue, 19 Jan 2016 21:49:42 GMT
Connection: keep-alive
Status: 204 No Content
X-RateLimit-Limit: 4000
X-RateLimit-Remaining: 3999
X-RateLimit-Reset: 1453243782
Cache-Control: no-cache
X-Request-Id: 10c8528b-569b-4152-a89c-fc9c5f94afe9
X-Runtime: 0.029858
Strict-Transport-Security: max-age=31536000

0 comments on commit 167f3b2

Please sign in to comment.