Skip to content

Commit

Permalink
Added support for removeCollaborator
Browse files Browse the repository at this point in the history
  • Loading branch information
jodosha committed Nov 21, 2016
1 parent 2aa2ea0 commit 6436e1b
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 3 deletions.
24 changes: 22 additions & 2 deletions lib/dnsimple/client/collaborators.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module Collaborators
# client.collaborators.collaborators(1010, "example.com", page: 2)
#
# @param [Fixnum] account_id the account ID
# @param [#to_s] domain_name the domain name
# @param [#to_s] domain_id the domain ID or name
# @param [Hash] request options
# @option options [Integer] :page current page (pagination)
# @option options [Integer] :per_page number of entries to return (pagination)
Expand All @@ -34,7 +34,7 @@ def collaborators(account_id, domain_id, options = {})
# client.collaborators.add_collaborator(1010, "example.com", email: "user@example.com")
#
# @param [Fixnum] account_id the account ID
# @param [#to_s] domain_name the domain name
# @param [#to_s] domain_id the domain ID or name
# @param [Hash] user attributes
# @param attributes [String] :email user email (mandatory)
# @param [Hash] request options
Expand All @@ -48,6 +48,26 @@ def add_collaborator(account_id, domain_id, attributes, options = {})
Dnsimple::Response.new(response, Struct::Collaborator.new(response["data"]))
end

# Removes a collaborator from the domain.
#
# WARNING: this cannot be undone.
#
# @see https://developer.dnsimple.com/v2/domains/collaborators/#remove
#
# @param [Fixnum] account_id the account ID
# @param [#to_s] domain_id the domain ID or name
# @param [#to_s] contact_id the contact ID
# @param [Hash] request options
# @return [Dnsimple::Response<nil>]
#
# @raise [Dnsimple::NotFoundError]
# @raise [Dnsimple::RequestError]
def remove_collaborator(account_id, domain_id, contact_id, options = {})
response = client.delete(Client.versioned("/%s/domains/%s/collaborators/%s" % [account_id, domain_id, contact_id]), options)

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

end
end
end
37 changes: 37 additions & 0 deletions spec/dnsimple/client/collaborators_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,41 @@
end
end

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

before do
stub_request(:delete, %r{/v2/#{account_id}/domains/#{domain_id}/collaborators/.+$}).
to_return(read_http_fixture("removeCollaborator/success.http"))
end

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

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

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

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

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

expect {
subject.remove_collaborator(account_id, domain_id, collaborator_id)
}.to raise_error(Dnsimple::NotFoundError)
end
end
end

end
16 changes: 16 additions & 0 deletions spec/fixtures.http/notfound-collaborator.http
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
HTTP/1.1 404 Not Found
Server: nginx
Date: Mon, 21 Nov 2016 09:32:48 GMT
Content-Type: application/json; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
Cache-Control: no-cache
X-Request-Id: 3e76b10b-412c-42ef-87d1-f8ff327df997
X-Runtime: 0.030250
X-Content-Type-Options: nosniff
X-Download-Options: noopen
X-Frame-Options: DENY
X-Permitted-Cross-Domain-Policies: none
X-XSS-Protection: 1; mode=block

{"message":"Membership `0` not found"}
2 changes: 1 addition & 1 deletion spec/fixtures.http/notfound-contact.http
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ Cache-Control: no-cache
X-Request-Id: a57d4e23-3155-477e-8469-e897b27c03e5
X-Runtime: 0.014159

{"message":"Contact `0` not found"}
{"message":"Contact `0` not found"}
17 changes: 17 additions & 0 deletions spec/fixtures.http/removeCollaborator/success.http
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
HTTP/1.1 204 No Content
Server: nginx
Date: Fri, 07 Oct 2016 09:08:51 GMT
Connection: keep-alive
X-RateLimit-Limit: 2400
X-RateLimit-Remaining: 2395
X-RateLimit-Reset: 1475833773
Cache-Control: no-cache
X-Request-Id: 732cdd0a-9ae5-4853-93ef-3511652b687a
X-Runtime: 0.098437
X-Content-Type-Options: nosniff
X-Download-Options: noopen
X-Frame-Options: DENY
X-Permitted-Cross-Domain-Policies: none
X-XSS-Protection: 1; mode=block
Strict-Transport-Security: max-age=31536000

0 comments on commit 6436e1b

Please sign in to comment.