def available_recipients(self) -> List[dict]: """List available recipients for subscription content.""" body = {"contents": self.contents} delivery_type = self.delivery['mode'] response = subscriptions.available_recipients(self.connection, self.application_id, body, delivery_type) if response.ok and config.verbose: return response.json()['recipients']
def available_recipients(self) -> List[dict]: """List available recipients for subscription content.""" body = {"contents": [content.to_dict() for content in self.contents]} delivery_type = self.delivery.mode response = subscriptions.available_recipients(self.connection, self.project_id, body, delivery_type) if response.ok and config.verbose: return response.json()['recipients']
def _validate_recipients(connection, contents: Content, recipients, application_id, delivery_mode): recipients = recipients if isinstance(recipients, list) else [recipients] body = {"contents": contents} available_recipients = subscriptions.available_recipients( connection, application_id, body, delivery_mode) available_recipients = available_recipients.json()['recipients'] available_recipients_ids = [rec['id'] for rec in available_recipients] # Format recipients list if needed formatted_recipients = [] if recipients: for recipient in recipients: if isinstance(recipient, dict): if recipient['id'] in available_recipients_ids: formatted_recipients.append(recipient) else: helper.exception_handler( "'{}' is not a valid recipient ID for selected content and delivery mode. Available recipients: \n{}" .format(recipient['id'], pformat(available_recipients, indent=2)), ValueError) pprint(available_recipients) elif isinstance(recipient, str): if recipient in available_recipients_ids: rec = helper.filter_list_of_dicts(available_recipients, id=recipient) formatted_recipients.append(rec[0]) else: helper.exception_handler( "'{}' is not a valid recipient ID for selected content and delivery mode. Available recipients: \n{}" .format(recipient, pformat(available_recipients, indent=2)), ValueError) pprint(available_recipients) else: helper.exception_handler( "Recipients must be a dictionaries or a strings, not a {}" .format(type(recipient)), exception_type=TypeError) return formatted_recipients
def _validate_recipients(connection, contents: List[Union[Content, dict]], recipients, project_id, delivery_mode): def __not_available(recipient): if recipient in available_recipients_ids: rec = helper.filter_list_of_dicts(available_recipients, id=recipient) formatted_recipients.append(rec[0]) else: msg = ( f"'{recipient}' is not a valid recipient ID for selected content " "and delivery mode. Available recipients: \n" f"{pformat(available_recipients,indent=2)}") helper.exception_handler(msg, ValueError) recipients = recipients if isinstance(recipients, list) else [recipients] body = { "contents": [ cont.to_dict() if isinstance(cont, Content) else cont for cont in contents ] } available_recipients = subscriptions.available_recipients( connection, project_id, body, delivery_mode) available_recipients = available_recipients.json()['recipients'] available_recipients_ids = [rec['id'] for rec in available_recipients] # Format recipients list if needed formatted_recipients = [] if recipients: for recipient in recipients: if isinstance(recipient, dict): __not_available(recipient['id']) elif isinstance(recipient, str): __not_available(recipient) else: helper.exception_handler( "Recipients must be a dictionaries or a strings, not a {}" .format(type(recipient)), exception_type=TypeError) return formatted_recipients
def available_recipients(self, content_id: str = None, content_type: str = None, content: "Content" = None, delivery_type='EMAIL') -> List[dict]: """List available recipients for a subscription contents. Specify either both `content_id` and `content_type` or just `content` object. Args: content_id: ID of the content content_type: type of the content content: Content object delivery_type: The delivery of the subscription, available values are: [EMAIL, FILE, PRINTER, HISTORY_LIST, CACHE, MOBILE, FTP]. """ if content_id and content_type: pass elif isinstance(content, Content): content_id = content.id content_type = content.type else: helper.exception_handler( 'Specify either a content ID and type or content object.', ValueError) body = { "contents": [{ "id": content_id, "type": content_type }], } response = subscriptions_.available_recipients(self.connection, self.application_id, body, delivery_type) if response.ok and config.verbose: return response.json()['recipients']