Skip to content

Commit

Permalink
Factor out handling of paging options.
Browse files Browse the repository at this point in the history
Addresses:
#1855 (comment).
  • Loading branch information
tseaver committed Jun 13, 2016
1 parent 2cd1ae5 commit eec245d
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions gcloud/pubsub/_gax.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@
from gcloud._helpers import _to_bytes


def _build_paging_options(page_token=None):
"""Helper for :meth:'_PublisherAPI.list_topics' et aliae."""
if page_token is None:
page_token = INITIAL_PAGE
options = {'page_token': page_token}
return CallOptions(**options)


class _PublisherAPI(object):
"""Helper mapping publisher-related APIs.
Expand Down Expand Up @@ -58,10 +66,7 @@ def list_topics(self, project, page_token=None):
more topics can be retrieved with another call (pass that
value as ``page_token``).
"""
if page_token is None:
page_token = INITIAL_PAGE
options = {'page_token': page_token}
options = CallOptions(**options)
options = _build_paging_options(page_token)
path = 'projects/%s' % (project,)
response = self._gax_api.list_topics(path, options)
topics = [{'name': topic_pb.name} for topic_pb in response.topics]
Expand Down Expand Up @@ -182,10 +187,7 @@ def topic_list_subscriptions(self, topic_path, page_token=None):
:raises: :exc:`gcloud.exceptions.NotFound` if the topic does not
exist
"""
if page_token is None:
page_token = INITIAL_PAGE
options = {'page_token': page_token}
options = CallOptions(**options)
options = _build_paging_options(page_token)
try:
response = self._gax_api.list_topic_subscriptions(
topic_path, options)
Expand Down Expand Up @@ -227,10 +229,7 @@ def list_subscriptions(self, project, page_token=None):
more topics can be retrieved with another call (pass that
value as ``page_token``).
"""
if page_token is None:
page_token = INITIAL_PAGE
options = {'page_token': page_token}
options = CallOptions(**options)
options = _build_paging_options(page_token)
path = 'projects/%s' % (project,)
response = self._gax_api.list_subscriptions(path, options)
subscriptions = [_subscription_pb_to_mapping(sub_pb)
Expand Down

0 comments on commit eec245d

Please sign in to comment.