Skip to content
This repository has been archived by the owner on Dec 12, 2023. It is now read-only.

Commit

Permalink
Merge pull request #1 from thinkific/add-contact-hard-delete
Browse files Browse the repository at this point in the history
Add contact hard delete
  • Loading branch information
mattapayne authored Aug 18, 2018
2 parents c36ee04 + a52f500 commit 5082572
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
freshdesk_api_v2 (0.1.0)
freshdesk_api_v2 (0.1.1)
addressable (~> 2.5, >= 2.5.2)
excon (~> 0.62.0)
json (~> 1.8)
Expand Down
9 changes: 9 additions & 0 deletions lib/freshdesk_api_v2/contacts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ def list(options = {})
fix_list_response(@http.get(url))
end

# Hard delete a cotact
# Normally, a contact must be soft-deleted before that can be called,
# but by providing the force attribute, that can be bypassed.
def hard_delete(id, force = false)
uri = "#{endpoint}/#{id}/hard_delete"
uri = "#{uri}?force=true" if force
@http.delete(uri)
end

protected

def endpoint
Expand Down
2 changes: 1 addition & 1 deletion lib/freshdesk_api_v2/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module FreshdeskApiV2
VERSION = '0.1.0'
VERSION = '0.1.1'
end
35 changes: 35 additions & 0 deletions spec/freshdesk_api_v2/contacts_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,41 @@ def contact_attributes(overrides = {})
}.merge(overrides)
end

context 'hard_delete' do
let(:contact_response) { contact_attributes(id: 1) }

it 'returns a status code of 204 without force' do
Excon.stub(
{
method: :delete,
path: '/api/v2/contacts/1/hard_delete',
headers: headers
},
{
body: contact_response.to_json,
status: 204
}
)
expect(subject.hard_delete(1).status).to eq(204)
end

it 'returns a status code of 204 with force' do
Excon.stub(
{
method: :delete,
path: '/api/v2/contacts/1/hard_delete',
headers: headers,
query: "force=true"
},
{
body: contact_response.to_json,
status: 204
}
)
expect(subject.hard_delete(1, force = true).status).to eq(204)
end
end

context 'list' do
let(:contacts) do
[
Expand Down

0 comments on commit 5082572

Please sign in to comment.