Exemple #1
0
    def find_one_by_webhook_id(self, webhook_id):
        """
        Lazy-loads a single :class:`WebHook` by ID

        :param webhook_id: The webhook identifier
        :type webhook_id: :class:`int`
        :rtype: :class:`Field` or :class:`None`

        Usage::

            >>> from emma.model.account import Account
            >>> acct = Account(1234, "08192a3b4c5d6e7f", "f7e6d5c4b3a29180")
            >>> acct.webhooks.find_one_by_webhook_id(0) # does not exist
            raises <KeyError>
            >>> acct.webhooks.find_one_by_webhook_id(123)
            <WebHook>
            >>> acct.webhooks[123]
            <WebHook>
        """
        webhook_id = int(webhook_id)
        path = '/webhooks/%s' % webhook_id
        if webhook_id not in self._dict:
            webhook = emma.model.webhook
            raw = self.account.adapter.get(path)
            if raw:
                self._dict[webhook_id] = webhook.WebHook(self.account, raw)

        return (webhook_id in self._dict) and self._dict[webhook_id] or None
Exemple #2
0
    def fetch_all(self):
        """
        Lazy-loads the full set of :class:`WebHook` objects

        :rtype: :class:`dict` of :class:`WebHook` objects

        Usage::

            >>> from emma.model.account import Account
            >>> acct = Account(1234, "08192a3b4c5d6e7f", "f7e6d5c4b3a29180")
            >>> acct.webhooks.fetch_all()
            {123: <WebHook>, 321: <WebHook>, ...}
        """
        webhook = emma.model.webhook
        path = '/webhooks'
        if not self._dict:
            self._dict = dict(
                (x['webhook_id'], webhook.WebHook(self.account, x))
                for x in self.account.adapter.paginated_get(path))
        return self._dict