@@ -143,11 +143,32 @@ def _patch(self, url: str, data: dict, entity_type: Optional[ENTITY_TYPE] = None
143143
144144 def _delete (self , url : str ) -> Optional [str ]:
145145 response = self .client .delete (url )
146+ return self ._location (response )
147+
148+ @staticmethod
149+ def _location (response ):
146150 try :
147151 return response .headers ["Location" ]
148152 except (AttributeError , KeyError ):
149153 return None
150154
155+ def _remove (self , resource_id : str , asynchronous : bool = True ) -> Optional [str ]:
156+ url = "%s%s/%s" % (self .target_endpoint , self .entity_uri , resource_id )
157+ job_location = self ._delete (url )
158+ if job_location is not None :
159+ job_guid = self ._extract_job_guid (job_location )
160+ if not asynchronous :
161+ self .client .v3 .jobs .wait_for_job_completion (job_guid )
162+ else :
163+ return job_guid
164+ return None
165+
166+ @staticmethod
167+ def _extract_job_guid (job_location ):
168+ job_url = urlparse (job_location )
169+ job_guid = job_url .path .rsplit ("/" , 1 )[- 1 ]
170+ return job_guid
171+
151172 def _list (self , requested_path : str , entity_type : Optional [ENTITY_TYPE ] = None , ** kwargs ) -> PaginateEntities :
152173 url_requested = EntityManager ._get_url_with_encoded_params ("%s%s" % (self .target_endpoint , requested_path ), ** kwargs )
153174 for element in self ._paginate (url_requested , entity_type ):
@@ -194,14 +215,6 @@ def _update(self, resource_id: str, data: dict) -> Entity:
194215 url = "%s%s/%s" % (self .target_endpoint , self .entity_uri , resource_id )
195216 return self ._patch (url , data )
196217
197- def _remove (self , resource_id : str , asynchronous : bool = True ):
198- url = "%s%s/%s" % (self .target_endpoint , self .entity_uri , resource_id )
199- job_location = self ._delete (url )
200- if not asynchronous and job_location is not None :
201- job_url = urlparse (job_location )
202- job_guid = job_url .path .rsplit ("/" , 1 )[- 1 ]
203- self .client .v3 .jobs .wait_for_job_completion (job_guid )
204-
205218 def __iter__ (self ) -> PaginateEntities :
206219 return self .list ()
207220
0 commit comments