Skip to content

Commit

Permalink
Merge pull request #1700 from tseaver/851-1696-pubsub-connection_maps…
Browse files Browse the repository at this point in the history
…_api

Add methods to connection mapping API requests
  • Loading branch information
tseaver committed Apr 22, 2016
2 parents eb21b2e + a8ee698 commit 18c92fe
Show file tree
Hide file tree
Showing 9 changed files with 1,770 additions and 870 deletions.
37 changes: 10 additions & 27 deletions gcloud/pubsub/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,20 +65,12 @@ def list_topics(self, page_size=None, page_token=None):
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

path = '/projects/%s/topics' % (self.project,)
resp = self.connection.api_request(method='GET', path=path,
query_params=params)
conn = self.connection
resources, next_token = conn.list_topics(
self.project, page_size, page_token)
topics = [Topic.from_api_repr(resource, self)
for resource in resp.get('topics', ())]
return topics, resp.get('nextPageToken')
for resource in resources]
return topics, next_token

def list_subscriptions(self, page_size=None, page_token=None):
"""List subscriptions for the project associated with this client.
Expand All @@ -104,23 +96,14 @@ def list_subscriptions(self, page_size=None, page_token=None):
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

path = '/projects/%s/subscriptions' % (self.project,)

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

def topic(self, name, timestamp_messages=False):
"""Creates a topic bound to the current client.
Expand Down
Loading

0 comments on commit 18c92fe

Please sign in to comment.