コード例 #1
0
ファイル: member.py プロジェクト: Nibblecomm/EmmaPython
    def save(self, groups=None):
        """
        :param groups: List of :class:`Group` objects to save
        :type groups: :class:`list` of :class:`Group` objects
        :rtype: :class:`None`

        Usage::

            >>> from emma.model.account import Account
            >>> acct = Account(1234, "08192a3b4c5d6e7f", "f7e6d5c4b3a29180")
            >>> grps = acct.members[123].groups
            >>> grps.save([
            ...     grps.factory({'member_group_id': 300}),
            ...     grps.factory({'member_group_id': 301}),
            ...     grps.factory({'member_group_id': 302})
            ... ])
            None
        """
        if 'member_id' not in self.member:
            raise ex.NoMemberIdError()
        if not groups:
            return None

        path = '/members/%s/groups' % self.member['member_id']
        data = {'group_ids': [x['member_group_id'] for x in groups]}
        if self.member.account.adapter.put(path, data):
            self.clear()
コード例 #2
0
ファイル: member.py プロジェクト: Nibblecomm/EmmaPython
    def get_opt_out_detail(self):
        """
        Get details about this :class:`Member`'s opt-out history

        :rtype: :class:`list`

        Usage::

            >>> from emma.model.account import Account
            >>> acct = Account(1234, "08192a3b4c5d6e7f", "f7e6d5c4b3a29180")
            >>> mbr = acct.members[123]
            >>> mbr.get_opt_out_detail()
            [...]
        """
        if 'member_id' not in self._dict:
            raise ex.NoMemberIdError()
        if self._dict['member_status_id'] != MemberStatus.OptOut:
            return []

        path = '/members/%s/optout' % self._dict['member_id']
        return self.account.adapter.get(path)
コード例 #3
0
ファイル: member.py プロジェクト: ptomblin/EmmaPython
    def delete(self, group_ids=None):
        """
        :param group_ids: List of group identifiers to delete
        :type group_ids: :class:`list` of :class:`int`
        :rtype: :class:`None`

        Usage::

            >>> from emma.model.account import Account
            >>> acct = Account(1234, "08192a3b4c5d6e7f", "f7e6d5c4b3a29180")
            >>> grps = acct.members[123].groups
            >>> grps.delete([300, 301]) # Delete a specific list of groups
            None
            >>> grps.delete() # Delete all groups
            None
        """
        if 'member_id' not in self.member:
            raise ex.NoMemberIdError()

        return (self._delete_by_list(group_ids)
                if group_ids else self._delete_all_groups())
コード例 #4
0
ファイル: member.py プロジェクト: Nibblecomm/EmmaPython
    def delete(self):
        """
        Delete this member

        :rtype: :class:`None`

        Usage::

            >>> from emma.model.account import Account
            >>> acct = Account(1234, "08192a3b4c5d6e7f", "f7e6d5c4b3a29180")
            >>> mbr = acct.members[123]
            >>> mbr.delete()
            None
        """
        if not 'member_id' in self._dict:
            raise ex.NoMemberIdError()
        if self.is_deleted():
            return None

        path = "/members/%s" % self._dict['member_id']
        if self.account.adapter.delete(path):
            self._dict['deleted_at'] = datetime.now()
コード例 #5
0
ファイル: message.py プロジェクト: ptomblin/EmmaPython
    def forward(self, emails=None, note=None):
        """
        Forward a previous message to additional recipients. If these recipients
        are not already in the audience, they will be added with a status of
        FORWARDED.

        :param emails: The emails to receive this forward
        :type emails: :class:`list` of :class:`str`
        :param note: A note to be sent with this forward
        :type note: :class:`str`
        :rtype: :class:`int`

        Usage::

            >>> from emma.model.account import Account
            >>> acct = Account(1234, "08192a3b4c5d6e7f", "f7e6d5c4b3a29180")
            >>> mssg = acct.mailings[123].messages[12]
            >>> mssg.forward(["*****@*****.**", "*****@*****.**"])
            124
        """
        if 'mailing_id' not in self.mailing:
            raise ex.NoMailingIdError()
        if not self.member_id:
            raise ex.NoMemberIdError()
        if not emails:
            return None

        path = "/forwards/%s/%s" % (self.mailing['mailing_id'], self.member_id)
        data = {'recipient_emails': emails}
        if note:
            data['note'] = note

        result = self.mailing.account.adapter.post(path, data)

        if not result:
            raise ex.MailingForwardError()

        return result['mailing_id']
コード例 #6
0
ファイル: member.py プロジェクト: Nibblecomm/EmmaPython
    def fetch_all(self):
        """
        Lazy-loads the full set of :class:`Group` objects

        :rtype: :class:`dict` of :class:`Group` objects

        Usage::

            >>> from emma.model.account import Account
            >>> acct = Account(1234, "08192a3b4c5d6e7f", "f7e6d5c4b3a29180")
            >>> mbr = acct.members[123]
            >>> mbr.groups.fetch_all()
            {123: <Group>, 321: <Group>, ...}

        """
        if 'member_id' not in self.member:
            raise ex.NoMemberIdError()
        group = emma.model.group
        path = '/members/%s/groups' % self.member['member_id']
        if not self._dict:
            self._dict = dict(
                (x['member_group_id'], group.Group(self.member.account, x))
                    for x in self.member.account.adapter.paginated_get(path))
        return self._dict