Beispiel #1
0
    def force_split_test_winner(self, winner_id):
        """
        Declare the winner of a split test manually. In the event that the test
        duration has not elapsed, the current stats for each test will be frozen
        and the content defined in the user declared winner will sent to the
        remaining members for the mailing. Please note, any messages that are
        pending for each of the test variations will receive the content
        assigned to them when the test was initially constructed.

        :param winner_id: The identifier for the winner
        :type winner_id: :class:`int`
        :rtype: :class:`None`

        Usage::

            >>> from emma.model.account import Account
            >>> acct = Account(1234, "08192a3b4c5d6e7f", "f7e6d5c4b3a29180")
            >>> mlng = acct.mailings[123]
            >>> mlng.winner(12)
            None
        """
        if 'mailing_id' not in self._dict:
            raise ex.NoMailingIdError()

        path = "/mailings/%s/winner/%s" % (self._dict['mailing_id'], winner_id)

        self.account.adapter.post(path)
Beispiel #2
0
    def update_status(self, status):
        """
        Update status of a current mailing.

        :param status: The new mailing status
        :type status: :class:`str`
        :rtype: :class:`None`

        Usage::

            >>> from emma.model.account import Account
            >>> from emma.enumerations import MailingStatus
            >>> acct = Account(1234, "08192a3b4c5d6e7f", "f7e6d5c4b3a29180")
            >>> mlng = acct.mailings[123]
            >>> mlng.update_statues(MailingStatus.Canceled)
            None
            >>> mlng.update_statues(MailingStatus.Ready)
            <MailingStatusUpdateError>
        """
        if 'mailing_id' not in self._dict:
            raise ex.NoMailingIdError()

        path = "/mailings/%s" % self._dict['mailing_id']
        data = {'status': {
            MailingStatus.Canceled: "canceled",
            MailingStatus.Paused: "paused",
            MailingStatus.Ready: "ready"
        }[status]}
        self._dict['status'] = self.account.adapter.put(path, data)
Beispiel #3
0
    def send_additional(self,
                        recipient_emails=None,
                        sender=None,
                        heads_up_emails=None,
                        recipient_groups=None,
                        recipient_searches=None):
        """
        Send a prior mailing to additional recipients. A new mailing will be
        created that inherits its content from the original.

        :param recipient_emails: The additional emails to which this mailing shall be sent
        :type recipient_emails: :class:`list` of :class:`str`
        :rtype: :class:`int`

        Usage::

            >>> from emma.model.account import Account
            >>> acct = Account(1234, "08192a3b4c5d6e7f", "f7e6d5c4b3a29180")
            >>> mlng = acct.mailings[123]
            >>> mlng.send_additional(["*****@*****.**"])
            124
        """
        if 'mailing_id' not in self._dict:
            raise ex.NoMailingIdError()

        path = "/mailings/%s" % self._dict['mailing_id']
        data = dict(
            x for x in {
                'recipient_emails': recipient_emails,
                'sender': sender,
                'heads_up_emails': heads_up_emails,
                'recipient_groups': recipient_groups,
                'recipient_searches': recipient_searches
            }.items() if x[1] is not None)

        if not data:
            return None

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

        if result:
            return result['mailing_id']
Beispiel #4
0
    def get_heads_up_emails(self):
        """
        Get heads up email address(es) related to a mailing.

        :rtype: :class:`list` of :class:`str`

        Usage::

            >>> from emma.model.account import Account
            >>> acct = Account(1234, "08192a3b4c5d6e7f", "f7e6d5c4b3a29180")
            >>> mlng = acct.mailings[123]
            >>> mlng.get_heads_up_emails()
            ["*****@*****.**", "*****@*****.**"]
        """
        if 'mailing_id' not in self._dict:
            raise ex.NoMailingIdError()

        path = "/mailings/%s/headsup" % self._dict['mailing_id']

        return self.account.adapter.get(path)
Beispiel #5
0
    def cancel(self):
        """
        Cancels a mailing that has a current status of pending or paused.

        :rtype: :class:`None`

        Usage::

            >>> from emma.model.account import Account
            >>> acct = Account(1234, "08192a3b4c5d6e7f", "f7e6d5c4b3a29180")
            >>> mlng = acct.mailings[123]
            >>> mlng.cancel()
            None
        """
        if 'mailing_id' not in self._dict:
            raise ex.NoMailingIdError()

        path = "/mailings/cancel/%s" % self._dict['mailing_id']
        if not self.account.adapter.delete(path):
            raise ex.MailingCancelError()
Beispiel #6
0
    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']
Beispiel #7
0
    def archive(self):
        """
        Sets archived timestamp for a mailing.

        :rtype: :class:`None`

        Usage::

            >>> from emma.model.account import Account
            >>> acct = Account(1234, "08192a3b4c5d6e7f", "f7e6d5c4b3a29180")
            >>> mlng = acct.mailings[123]
            >>> mlng.archive()
            None
        """
        if 'mailing_id' not in self._dict:
            raise ex.NoMailingIdError()
        if self.is_archived():
            return None

        path = "/mailings/%s" % self._dict['mailing_id']
        if not self.account.adapter.delete(path):
            raise ex.MailingArchiveError()

        self._dict['archived_ts'] = datetime.now()
Beispiel #8
0
    def find_one_by_member_id(self, member_id, message_type=None):
        """
        Lazy-loads a single :class:`Message` by Member ID

        :param member_id: The member identifier
        :type member_id: :class:`int`
        :param message_type: The portion of the message to retrieve
        :type message_type: :class:`str`
        :rtype: :class:`dict` or :class:`None`

        Usage::

            >>> from emma.model.account import Account
            >>> acct = Account(1234, "08192a3b4c5d6e7f", "f7e6d5c4b3a29180")
            >>> mlng = acct.mailings[123]
            >>> mlng.messages(12)
            {'plaintext': ..., 'subject': ..., 'html_body': ...}
            >>> from emma.enumerations import PersonalizedMessageType as pmt
            >>> mlng.messages(12, type=pmt.Html)
            {'html_body': ...}
        """
        if 'mailing_id' not in self.mailing:
            raise ex.NoMailingIdError()

        member_id = int(member_id)
        path = "/mailings/%s/messages/%s" % (
            self.mailing['mailing_id'], member_id)
        params = {'type': message_type} if message_type else {}
        if member_id not in self._dict:
            message = emma.model.message
            raw = self.mailing.account.adapter.get(path, params)
            if raw:
                self._dict[member_id] = message.Message(
                    self.mailing, member_id, raw)

        return (member_id in self._dict) and self._dict[member_id] or None
Beispiel #9
0
    def fetch_all(self):
        """
        Lazy-loads the full set of :class:`Search` objects

        :rtype: :class:`dict` of :class:`Search` objects

        Usage::

            >>> from emma.model.account import Account
            >>> acct = Account(1234, "08192a3b4c5d6e7f", "f7e6d5c4b3a29180")
            >>> mlng = acct.mailings[123]
            >>> mlng.searches.fetch_all()
            {123: <Search>, 321: <Search>, ...}

        """
        if 'mailing_id' not in self.mailing:
            raise ex.NoMailingIdError()
        search = emma.model.search
        path = '/mailings/%s/searches' % self.mailing['mailing_id']
        if not self._dict:
            self._dict = dict(
                (x['search_id'], search.Search(self.mailing.account, x))
                    for x in self.mailing.account.adapter.paginated_get(path))
        return self._dict