| OLD | NEW |
| (Empty) | |
| 1 # Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. |
| 4 |
| 5 import base64 |
| 6 |
| 7 import httplib2 |
| 8 from googleapiclient import discovery |
| 9 from oauth2client import client as oauth2client |
| 10 |
| 11 |
| 12 PUBSUB_SCOPES = [ |
| 13 'https://www.googleapis.com/auth/pubsub', |
| 14 ] |
| 15 |
| 16 |
| 17 def CreatePubSubClient(): # pragma: no cover. |
| 18 credentials = oauth2client.GoogleCredentials.get_application_default() |
| 19 if credentials.create_scoped_required(): |
| 20 credentials = credentials.create_scoped(PUBSUB_SCOPES) |
| 21 http = httplib2.Http() |
| 22 credentials.authorize(http) |
| 23 return discovery.build('pubsub', 'v1', http=http) |
| 24 |
| 25 |
| 26 def PublishMessagesToTopic(messages_data, topic): # pragma: no cover. |
| 27 messages = [] |
| 28 for message_data in messages_data: |
| 29 messages.append({'data': base64.b64encode(message_data)}) |
| 30 return CreatePubSubClient().projects().topics().publish( |
| 31 topic=topic, body={'messages': messages}).execute() |
| OLD | NEW |