From 2f3acb0b9572d2508027013183a440db7055d94c Mon Sep 17 00:00:00 2001 From: lukas-gitl Date: Wed, 25 Oct 2017 16:19:04 -0700 Subject: [PATCH 1/2] Allowing for dynamic object_id for delete call This is according to how intercoms official api supports this https://github.com/jkeyes/python-intercom/issues/158 --- intercom/api_operations/delete.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/intercom/api_operations/delete.py b/intercom/api_operations/delete.py index f9ea71dc..735cfb2b 100644 --- a/intercom/api_operations/delete.py +++ b/intercom/api_operations/delete.py @@ -7,9 +7,11 @@ class Delete(object): """A mixin that provides `delete` functionality.""" - def delete(self, obj): + def delete(self, obj=None, **kwargs): """Delete the specified instance of this resource.""" collection = utils.resource_class_to_collection_name( self.collection_class) - self.client.delete("/%s/%s" % (collection, obj.id), {}) + assert obj is not None or kwargs.keys()[0] == "%s_id" % collection + obj_id = kwargs.values()[0] if obj is None else obj.id + self.client.delete("/%s/%s" % (collection, obj_id), {}) return obj From 62e5f021c6489876ece0b032858f3afc768c4bb8 Mon Sep 17 00:00:00 2001 From: lukas-gitl Date: Thu, 26 Oct 2017 09:41:58 -0700 Subject: [PATCH 2/2] Parameter now singular (e.g. user_id) --- intercom/api_operations/delete.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/intercom/api_operations/delete.py b/intercom/api_operations/delete.py index 735cfb2b..8f726ba3 100644 --- a/intercom/api_operations/delete.py +++ b/intercom/api_operations/delete.py @@ -9,9 +9,10 @@ class Delete(object): def delete(self, obj=None, **kwargs): """Delete the specified instance of this resource.""" + assert obj is not None or kwargs.keys()[0] == "%s_id" % ( + utils.resource_class_to_name(self.collection_class)) + obj_id = kwargs.values()[0] if obj is None else obj.id collection = utils.resource_class_to_collection_name( self.collection_class) - assert obj is not None or kwargs.keys()[0] == "%s_id" % collection - obj_id = kwargs.values()[0] if obj is None else obj.id self.client.delete("/%s/%s" % (collection, obj_id), {}) return obj