def _item_to_sub_for_client(iterator, sub_pb, topics): """Convert a subscription protobuf to the native object. .. note:: This method does not have the correct signature to be used as the ``item_to_value`` argument to :class:`~google.cloud.iterator.Iterator`. It is intended to be patched with a mutable topics argument that can be updated on subsequent calls. For an example, see how the method is used above in :meth:`_SubscriberAPI.list_subscriptions`. :type iterator: :class:`~google.cloud.iterator.Iterator` :param iterator: The iterator that is currently in use. :type sub_pb: :class:`.pubsub_pb2.Subscription` :param sub_pb: A subscription returned from the API. :type topics: dict :param topics: A dictionary of topics to be used (and modified) as new subscriptions are created bound to topics. :rtype: :class:`~google.cloud.pubsub.subscription.Subscription` :returns: The next subscription in the page. """ resource = MessageToDict(sub_pb) return Subscription.from_api_repr( resource, iterator.client, topics=topics)
def _item_to_sub_for_client(iterator, resource, topics): """Convert a subscription to the native object. .. note:: This method does not have the correct signature to be used as the ``item_to_value`` argument to :class:`~google.cloud.iterator.Iterator`. It is intended to be patched with a mutable topics argument that can be updated on subsequent calls. For an example, see how the method is used above in :meth:`_SubscriberAPI.list_subscriptions`. :type iterator: :class:`~google.cloud.iterator.Iterator` :param iterator: The iterator that is currently in use. :type resource: dict :param resource: A subscription returned from the API. :type topics: dict :param topics: A dictionary of topics to be used (and modified) as new subscriptions are created bound to topics. :rtype: :class:`~google.cloud.pubsub.subscription.Subscription` :returns: The next subscription in the page. """ return Subscription.from_api_repr(resource, iterator.client, topics=topics)
def list_subscriptions(self, page_size=None, page_token=None): """List subscriptions for the project associated with this client. See: https://cloud.google.com/pubsub/reference/rest/v1/projects.topics/list Example: .. literalinclude:: pubsub_snippets.py :start-after: [START client_list_subscriptions] :end-before: [END client_list_subscriptions] :type page_size: int :param page_size: maximum number of topics to return, If not passed, defaults to a value set by the API. :type page_token: string :param page_token: opaque marker for the next "page" of topics. If not passed, the API will return the first page of topics. :rtype: tuple, (list, str) :returns: list of :class:`~.pubsub.subscription.Subscription`, plus a "next page token" string: if not None, indicates that more topics can be retrieved with another call (pass that value as ``page_token``). """ api = self.subscriber_api resources, next_token = api.list_subscriptions( self.project, page_size, page_token) topics = {} subscriptions = [Subscription.from_api_repr(resource, self, topics=topics) for resource in resources] return subscriptions, next_token