Skip to content

Commit a8ee698

Browse files
committed
Make 'Connection.topic_publish' return a bare list of message IDs.
1 parent 9adf05b commit a8ee698

File tree

4 files changed

+19
-20
lines changed

4 files changed

+19
-20
lines changed

gcloud/pubsub/connection.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -216,14 +216,13 @@ def topic_publish(self, topic_path, messages):
216216
:type messages: list of dict
217217
:param messages: messages to be published.
218218
219-
:rtype: dict
220-
:returns: resource returned from the API: a mapping with key,
221-
``messageIds``, whose values is a list of opaque IDs for
222-
published messages.
219+
:rtype: list of string
220+
:returns: list of opaque IDs for published messages.
223221
"""
224222
data = {'messages': messages}
225-
return self.api_request(
223+
response = self.api_request(
226224
method='POST', path='/%s:publish' % (topic_path,), data=data)
225+
return response['messageIds']
227226

228227
def topic_list_subscriptions(self, topic_path, page_size=None,
229228
page_token=None):
@@ -467,7 +466,7 @@ def subscription_modify_ack_deadline(self, subscription_path, ack_ids,
467466
"""API call: acknowledge retrieved messages for the subscription.
468467
469468
See:
470-
https://cloud.google.com/pubsub/reference/rest/v1/projects.subscriptions/modifyPushConfig
469+
https://cloud.google.com/pubsub/reference/rest/v1/projects.subscriptions/modifyAckDeadline
471470
472471
:type subscription_path: string
473472
:param subscription_path: the fully-qualfied path of the new

gcloud/pubsub/test_connection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ def test_topic_publish(self):
334334

335335
resource = conn.topic_publish(self.TOPIC_PATH, [MESSAGE])
336336

337-
self.assertEqual(resource, RETURNED)
337+
self.assertEqual(resource, [MSGID])
338338
self.assertEqual(http._called_with['method'], 'POST')
339339
self._verify_uri(http._called_with['uri'],
340340
'%s:publish' % (self.TOPIC_PATH,))

gcloud/pubsub/test_topic.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ def test_publish_single_bytes_wo_attrs_w_bound_client(self):
138138
MSGID = 'DEADBEEF'
139139
MESSAGE = {'data': B64, 'attributes': {}}
140140
conn = _Connection()
141-
conn._topic_publish_response = {'messageIds': [MSGID]}
141+
conn._topic_publish_response = [MSGID]
142142
client = _Client(project=self.PROJECT, connection=conn)
143143
topic = self._makeOne(self.TOPIC_NAME, client=client)
144144

@@ -169,7 +169,7 @@ def _utcnow():
169169
conn1 = _Connection()
170170
client1 = _Client(project=self.PROJECT, connection=conn1)
171171
conn2 = _Connection()
172-
conn2._topic_publish_response = {'messageIds': [MSGID]}
172+
conn2._topic_publish_response = [MSGID]
173173
client2 = _Client(project=self.PROJECT, connection=conn2)
174174

175175
topic = self._makeOne(self.TOPIC_NAME, client=client1,
@@ -191,7 +191,7 @@ def test_publish_single_bytes_w_add_timestamp_w_ts_in_attrs(self):
191191
MESSAGE = {'data': B64,
192192
'attributes': {'timestamp': OVERRIDE}}
193193
conn = _Connection()
194-
conn._topic_publish_response = {'messageIds': [MSGID]}
194+
conn._topic_publish_response = [MSGID]
195195
client = _Client(project=self.PROJECT, connection=conn)
196196
topic = self._makeOne(self.TOPIC_NAME, client=client,
197197
timestamp_messages=True)
@@ -210,7 +210,7 @@ def test_publish_single_w_attrs(self):
210210
MESSAGE = {'data': B64,
211211
'attributes': {'attr1': 'value1', 'attr2': 'value2'}}
212212
conn = _Connection()
213-
conn._topic_publish_response = {'messageIds': [MSGID]}
213+
conn._topic_publish_response = [MSGID]
214214
client = _Client(project=self.PROJECT, connection=conn)
215215
topic = self._makeOne(self.TOPIC_NAME, client=client)
216216

@@ -233,7 +233,7 @@ def test_publish_multiple_w_bound_client(self):
233233
MESSAGE2 = {'data': B64_2.decode('ascii'),
234234
'attributes': {'attr1': 'value1', 'attr2': 'value2'}}
235235
conn = _Connection()
236-
conn._topic_publish_response = {'messageIds': [MSGID1, MSGID2]}
236+
conn._topic_publish_response = [MSGID1, MSGID2]
237237
client = _Client(project=self.PROJECT, connection=conn)
238238
topic = self._makeOne(self.TOPIC_NAME, client=client)
239239

@@ -263,7 +263,7 @@ def test_publish_multiple_w_alternate_client(self):
263263
conn1 = _Connection()
264264
client1 = _Client(project=self.PROJECT, connection=conn1)
265265
conn2 = _Connection()
266-
conn2._topic_publish_response = {'messageIds': [MSGID1, MSGID2]}
266+
conn2._topic_publish_response = [MSGID1, MSGID2]
267267
client2 = _Client(project=self.PROJECT, connection=conn2)
268268
topic = self._makeOne(self.TOPIC_NAME, client=client1)
269269

@@ -627,7 +627,7 @@ def test_commit_w_bound_client(self):
627627
MESSAGE2 = {'data': B64_2.decode('ascii'),
628628
'attributes': {'attr1': 'value1', 'attr2': 'value2'}}
629629
conn = _Connection()
630-
conn._topic_publish_response = {'messageIds': [MSGID1, MSGID2]}
630+
conn._topic_publish_response = [MSGID1, MSGID2]
631631
client = _Client(project='PROJECT', connection=conn)
632632
topic = _Topic()
633633
batch = self._makeOne(topic, client=client)
@@ -657,7 +657,7 @@ def test_commit_w_alternate_client(self):
657657
conn1 = _Connection()
658658
client1 = _Client(project='PROJECT', connection=conn1)
659659
conn2 = _Connection()
660-
conn2._topic_publish_response = {'messageIds': [MSGID1, MSGID2]}
660+
conn2._topic_publish_response = [MSGID1, MSGID2]
661661
client2 = _Client(project='PROJECT', connection=conn2)
662662
topic = _Topic()
663663
batch = self._makeOne(topic, client=client1)
@@ -686,7 +686,7 @@ def test_context_mgr_success(self):
686686
MESSAGE2 = {'data': B64_2.decode('ascii'),
687687
'attributes': {'attr1': 'value1', 'attr2': 'value2'}}
688688
conn = _Connection()
689-
conn._topic_publish_response = {'messageIds': [MSGID1, MSGID2]}
689+
conn._topic_publish_response = [MSGID1, MSGID2]
690690
client = _Client(project='PROJECT', connection=conn)
691691
topic = _Topic()
692692
batch = self._makeOne(topic, client=client)

gcloud/pubsub/topic.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,9 @@ def publish(self, message, client=None, **attrs):
191191
self._timestamp_message(attrs)
192192
message_b = base64.b64encode(message).decode('ascii')
193193
message_data = {'data': message_b, 'attributes': attrs}
194-
response = client.connection.topic_publish(
194+
message_ids = client.connection.topic_publish(
195195
self.full_name, [message_data])
196-
return response['messageIds'][0]
196+
return message_ids[0]
197197

198198
def batch(self, client=None):
199199
"""Return a batch to use as a context manager.
@@ -355,7 +355,7 @@ def commit(self, client=None):
355355
"""
356356
if client is None:
357357
client = self.client
358-
response = client.connection.topic_publish(
358+
message_ids = client.connection.topic_publish(
359359
self.topic.full_name, self.messages[:])
360-
self.message_ids.extend(response['messageIds'])
360+
self.message_ids.extend(message_ids)
361361
del self.messages[:]

0 commit comments

Comments
 (0)