def create_bulk(self, zendesk, organizations): url = "organizations/create_many.json" groups = separete_into_groups(organizations, 100) has_pendent_groups = True while has_pendent_groups: errors = [] for orgs in groups: try: data = {"organizations": orgs} resp = zendesk.Organizations.base._request(url, 'PUT', **data) except Exception: errors.append(orgs) if errors: groups = map(lambda x: x, errors) else: has_pendent_groups = False return jobs
def delete_many(self, list_ids, resource=None, name_field='ids', limit=100): resource = resource or self.resource groups = separete_into_groups(list_ids, limit) has_pendent_groups = True responses = [] while has_pendent_groups: errors = [] for group in groups: try: url = "{}/destroy_many.json?{}={}.json".format( resource, name_field, ','.join(group)) resp = self.base._request(url, 'DELETE') responses.append(resp.json()) except Exception: errors.append(group) if errors: groups = map(lambda x: x, errors) else: has_pendent_groups = False return responses
def create_many(self, list_objects, resource=None): jobs = [] resource = resource or self.resource url = "{}/create_many.json".format(resource) groups = separete_into_groups(list_objects, 100) has_pendent_groups = True while has_pendent_groups: errors = [] for group in groups: try: data = {resource: group} resp = self.base._request(url, 'POST', **data) jobs.append(resp.json()) except Exception: errors.append(group) if errors: groups = map(lambda x: x, errors) else: has_pendent_groups = False return jobs
def bulk_put_many(self, documents, resource=None, limit=100): if limit > 100: raise BulkExceededLimit resource = resource or self.resource url = "{}/update_many.json".format(resource) groups = separete_into_groups(documents, limit) has_pendent_groups = True jobs = [] while has_pendent_groups: errors = [] for group in groups: try: data = {resource: group} resp = self.base._request(url, 'PUT', **data) jobs.append(resp.json()) except Exception: errors.append(group) if errors: groups = map(lambda x: x, errors) else: has_pendent_groups = False return jobs