Beispiel #1
0
 def _parse_raw(self, raw):
     raw.update(str_fields_to_datetime(['deleted_at', 'start_ts'], raw))
     if 'parent_mailing' in raw:
         mailing = emma.model.mailing
         raw['parent_mailing'] = mailing.Mailing(self.account,
                                                 raw['parent_mailing'])
     return raw
Beispiel #2
0
    def find_one_by_mailing_id(self, mailing_id):
        """
        Lazy-loads a single :class:`Mailing` by ID

        :param mailing_id: The mailing identifier
        :type mailing_id: :class:`int` or :class:`str`
        :rtype: :class:`Mailing` or :class:`None`

        Usage::

            >>> from emma.model.account import Account
            >>> acct = Account(1234, "08192a3b4c5d6e7f", "f7e6d5c4b3a29180")
            >>> acct.mailings.find_one_by_mailing_id(0) # does not exist
            raises <KeyError>
            >>> acct.mailings.find_one_by_mailing_id(123)
            <Import>
            >>> acct.mailings[123]
            <Import>
        """
        mailing_id = int(mailing_id)
        path = '/mailings/%s' % mailing_id
        if mailing_id not in self._dict:
            mailing = emma.model.mailing
            raw = self.account.adapter.get(path)
            if raw:
                self._dict[mailing_id] = mailing.Mailing(self.account, raw)

        return (mailing_id in self._dict) and self._dict[mailing_id] or None
Beispiel #3
0
    def fetch_all(self,
                  include_archived=False,
                  mailing_types=None,
                  mailing_statuses=None,
                  is_scheduled=False,
                  with_html_body=False,
                  with_plaintext=False):
        """
        Lazy-loads the full set of :class:`Mailing` objects

        :rtype: :class:`dict` of :class:`Mailing` objects

        Usage::

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

        """
        path = '/mailings'
        params = {}
        if include_archived:
            params['include_archived'] = True
        if mailing_types:
            params['mailing_types'] = mailing_types
        if mailing_statuses:
            params['mailing_statuses'] = mailing_statuses
        if is_scheduled:
            params['is_scheduled'] = True
        if with_html_body:
            params['with_html_body'] = True
        if with_plaintext:
            params['with_plaintext'] = True
        if not self._dict:
            mailing = emma.model.mailing
            self._dict = dict(
                (x['mailing_id'], mailing.Mailing(self.account, x))
                for x in self.account.adapter.paginated_get(path, params))
        return self._dict
Beispiel #4
0
    def fetch_all(self):
        """
        Lazy-loads the full set of :class:`Mailing` objects

        :rtype: :class:`dict` of :class:`Mailing` objects

        Usage::

            >>> from emma.model.account import Account
            >>> acct = Account(1234, "08192a3b4c5d6e7f", "f7e6d5c4b3a29180")
            >>> trggr = acct.triggers[1024]
            >>> trggr.mailings.fetch_all()
            {200: <Mailing>, 201: <Mailing>, ...}
        """
        if not 'trigger_id' in self.trigger:
            raise ex.NoSearchIdError()

        path = '/triggers/%s/mailings' % self.trigger['trigger_id']
        if not self._dict:
            mailing = emma.model.mailing
            self._dict = dict(
                (x['mailing_id'], mailing.Mailing(self.trigger.account, x))
                for x in self.trigger.account.adapter.paginated_get(path))
        return self._dict
Beispiel #5
0
    def fetch_all(self):
        """
        Lazy-loads the full set of :class:`Mailing` objects

        :rtype: :class:`dict` of :class:`Mailing` objects

        Usage::

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

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