Exemple #1
0
    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

        and (where ``topic_name`` is passed):
        https://cloud.google.com/pubsub/reference/rest/v1/projects.topics.subscriptions/list

        :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:`gcloud.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
Exemple #2
0
    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:`gcloud.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
Exemple #3
0
def list_subscriptions(page_size=None, page_token=None, topic_name=None,
                       project=None, connection=None):
    """List subscriptions for a given project.

    See:
    https://cloud.google.com/pubsub/reference/rest/v1beta2/projects/topics/list

    and (where ``topic_name`` is passed):
    https://cloud.google.com/pubsub/reference/rest/v1beta2/projects/topics/subscriptions/list

    :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.

    :type topic_name: string
    :param topic_name: limit results to subscriptions bound to the given topic.

    :type project: string
    :param project: project ID to query.  If not passed, defaults to the
                    project ID inferred from the environment.

    :type connection: :class:`gcloud.pubsub.connection.Connection`
    :param connection: connection to use for the query.  If not passed,
                       defaults to the connection inferred from the
                       environment.

    :rtype: tuple, (list, str)
    :returns: list of :class:`gcloud.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``).
    """
    if project is None:
        project = get_default_project()

    connection = _require_connection(connection)

    params = {}

    if page_size is not None:
        params['pageSize'] = page_size

    if page_token is not None:
        params['pageToken'] = page_token

    if topic_name is None:
        path = '/projects/%s/subscriptions' % project
    else:
        path = '/projects/%s/topics/%s/subscriptions' % (project, topic_name)

    resp = connection.api_request(method='GET', path=path, query_params=params)
    topics = {}
    subscriptions = [Subscription.from_api_repr(resource, topics=topics)
                     for resource in resp['subscriptions']]
    return subscriptions, resp.get('nextPageToken')
Exemple #4
0
    def list_subscriptions(self, page_size=None, page_token=None, topic_name=None):
        """List subscriptions for the project associated with this client.

        See:
        https://cloud.google.com/pubsub/reference/rest/v1/projects.topics/list

        and (where ``topic_name`` is passed):
        https://cloud.google.com/pubsub/reference/rest/v1/projects.topics.subscriptions/list

        :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.

        :type topic_name: string
        :param topic_name: limit results to subscriptions bound to the given
                           topic.

        :rtype: tuple, (list, str)
        :returns: list of :class:`gcloud.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``).
        """
        params = {}

        if page_size is not None:
            params["pageSize"] = page_size

        if page_token is not None:
            params["pageToken"] = page_token

        if topic_name is None:
            path = "/projects/%s/subscriptions" % (self.project,)
        else:
            path = "/projects/%s/topics/%s/subscriptions" % (self.project, topic_name)

        resp = self.connection.api_request(method="GET", path=path, query_params=params)

        topics = {}
        subscriptions = []
        for resource in resp["subscriptions"]:
            if isinstance(resource, dict) and "topic" in resource and len(resource["topic"].split("/")) == 4:
                subscriptions.append(Subscription.from_api_repr(resource, self, topics=topics))
            elif topic_name and len(resource.split("/")) == 4:
                subscription_name = resource.split("/")[3]
                subscriptions.append(Subscription(name=subscription_name, topic=self.topic(topic_name)))
        return subscriptions, resp.get("nextPageToken")
Exemple #5
0
    def list_subscriptions(self, page_size=None, page_token=None,
                           topic_name=None):
        """List subscriptions for the project associated with this client.

        See:
        https://cloud.google.com/pubsub/reference/rest/v1/projects.topics/list

        and (where ``topic_name`` is passed):
        https://cloud.google.com/pubsub/reference/rest/v1/projects.topics.subscriptions/list

        :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.

        :type topic_name: string
        :param topic_name: limit results to subscriptions bound to the given
                           topic.

        :rtype: tuple, (list, str)
        :returns: list of :class:`gcloud.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``).
        """
        params = {}

        if page_size is not None:
            params['pageSize'] = page_size

        if page_token is not None:
            params['pageToken'] = page_token

        if topic_name is None:
            path = '/projects/%s/subscriptions' % (self.project,)
        else:
            path = '/projects/%s/topics/%s/subscriptions' % (self.project,
                                                             topic_name)

        resp = self.connection.api_request(method='GET', path=path,
                                           query_params=params)
        topics = {}
        subscriptions = [Subscription.from_api_repr(resource, self,
                                                    topics=topics)
                         for resource in resp.get('subscriptions', ())]
        return subscriptions, resp.get('nextPageToken')