Skip to content

Commit 36aa8c4

Browse files
authored
Merge branch 'master' into seanhealy/opedSubscription
2 parents d5fe9b3 + b6ab09c commit 36aa8c4

File tree

7 files changed

+44
-0
lines changed

7 files changed

+44
-0
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,9 @@ intercom.contacts.unarchive(contact)
114114
# Delete a contact permanently
115115
intercom.contacts.delete(contact)
116116

117+
# Deletes an archived contact permanently
118+
contact.delete_archived_contact("124")
119+
117120
# List all contacts
118121
contacts = intercom.contacts.all
119122
contacts.each { |contact| p contact.name }
@@ -312,6 +315,13 @@ tag = intercom.tags.tag(name: 'blue', companies: [{company_id: "42ea2f1b93891f6a
312315

313316
# Untag Companies
314317
tag = intercom.tags.untag(name: 'blue', companies: [{ company_id: "42ea2f1b93891f6a99000427" }])
318+
319+
320+
# Delete Tags
321+
322+
# Note : If there any depedent objects for the tag we are trying to delete, then an error TagHasDependentObjects will be thrown.
323+
tag = intercom.tags.find(id:"123")
324+
intercom.tags.delete(tag)
315325
```
316326

317327
#### Notes

lib/intercom/errors.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ class InvalidDocumentError < IntercomError; end
9999
# Raised when a merge is invalid
100100
class InvalidMergeError < IntercomError; end
101101

102+
# Raised when a tag has dependent objects
103+
class TagHasDependentObjects < IntercomError; end
104+
102105
#
103106
# Non-public errors (internal to the gem)
104107
#

lib/intercom/request.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,8 @@ def execute(target_base_url = nil, token:, read_timeout: 90, open_timeout: 30, a
222222
raise Intercom::ApiVersionInvalid.new(error_details['message'], error_context)
223223
when 'scroll_exists'
224224
raise Intercom::ScrollAlreadyExistsError.new(error_details['message'], error_context)
225+
when 'tag_has_dependent_objects'
226+
raise Intercom::TagHasDependentObjects.new(error_details['message'], error_context)
225227
when nil, ''
226228
raise Intercom::UnexpectedError.new(message_for_unexpected_error_without_type(error_details, parsed_http_code), error_context)
227229
else

lib/intercom/service/contact.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ def unarchive(contact)
4343
contact
4444
end
4545

46+
def delete_archived_contact(id)
47+
@client.delete("/#{collection_name}/#{id}", {})
48+
end
49+
4650
private def raise_invalid_merge_error
4751
raise Intercom::InvalidMergeError, 'Merging can only be performed on a lead into a user'
4852
end

spec/unit/intercom/contact_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,12 @@
260260
client.contacts.unarchive(contact)
261261
end
262262

263+
it 'deletes an archived contact' do
264+
contact = Intercom::Contact.new('id' => '1','archived' =>true)
265+
client.expects(:delete).with('/contacts/1', {})
266+
client.contacts.delete_archived_contact("1")
267+
end
268+
263269
describe 'merging' do
264270
let(:lead) { Intercom::Contact.from_api(external_id: 'contact_id', role: 'lead') }
265271
let(:user) { Intercom::Contact.from_api(id: 'external_id', role: 'user') }

spec/unit/intercom/request_spec.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,9 @@ def execute!
124124
let(:uri) {"https://api.intercom.io/conversations/reply"}
125125
let(:req) { Intercom::Request.put(uri, {}) }
126126

127+
let(:tag_uri) {"https://api.intercom.io/tags/"}
128+
let(:del_req) { Intercom::Request.delete(tag_uri, {}) }
129+
127130
it 'should raise ResourceNotUniqueError error on resource_conflict code' do
128131
stub_request(:put, uri).to_return(
129132
status: [409, "Resource Already Exists"],
@@ -153,5 +156,15 @@ def execute!
153156

154157
expect { execute! }.must_raise(Intercom::ResourceNotFound)
155158
end
159+
160+
it 'should raise TagHasDependentObjects error on tag_has_dependent_objects code' do
161+
stub_request(:delete, tag_uri).to_return(
162+
status: [400, "Bad Request"],
163+
headers: { 'X-RateLimit-Reset' => (Time.now.utc + 10).to_i.to_s },
164+
body: { type: "error.list", errors: [ code: "tag_has_dependent_objects" ] }.to_json
165+
)
166+
167+
expect { del_req.execute(tag_uri, token: 'test-token') }.must_raise(Intercom::TagHasDependentObjects)
168+
end
156169
end
157170
end

spec/unit/intercom/tag_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,10 @@
2828
client.expects(:post).with('/tags', 'name' => 'Test Tag', 'companies' => [{ company_id: 'abc123', untag: true }, { company_id: 'def456', untag: true }], 'tag_or_untag' => 'untag').returns(test_tag)
2929
client.tags.untag(name: 'Test Tag', companies: [{ company_id: 'abc123' }, { company_id: 'def456' }])
3030
end
31+
32+
it 'delete tags' do
33+
tag = Intercom::Tag.new('id' => '1')
34+
client.expects(:delete).with('/tags/1', {}).returns(tag)
35+
client.tags.delete(tag)
36+
end
3137
end

0 commit comments

Comments
 (0)