Exemplo n.º 1
0
    def post(self):
        message = self.request.body
        client = pubsub_utils.get_client()

        topic_name = pubsub_utils.get_full_topic_name()
        body = {
            'messages': [{
                'data': base64.b64encode(message.encode('utf-8'))
            }]
        }
        client.projects().topics().publish(
                topic=topic_name, body=body).execute()
        self.response.write(body)
 def post(self):
     """Publishes the message via the Pub/Sub API."""
     client = pubsub_utils.get_client()
     message = self.request.get('message')
     if message:
         topic_name = pubsub_utils.get_full_topic_name()
         body = {
             'messages': [{
                 'data': base64.b64encode(message.encode('utf-8'))
             }]
         }
         client.projects().topics().publish(topic=topic_name,
                                            body=body).execute()
     self.response.status = 204
Exemplo n.º 3
0
 def post(self):
     """Publishes the message via the Pub/Sub API."""
     client = pubsub_utils.get_client()
     message = self.request.get('message')
     if message:
         topic_name = pubsub_utils.get_full_topic_name()
         body = {
             'topic': topic_name,
             'messages': [{
                 'data': base64.b64encode(message.encode('utf-8'))
             }]
         }
         client.topics().publishBatch(body=body).execute()
     self.response.status = 204
Exemplo n.º 4
0
    def post(self):
        """Publishes the message via the Pub/Sub API."""
        self.response.headers['Access-Control-Allow-Origin'] = '*'
        client = pubsub_utils.get_client()
        message = self.request.get('message')
        full_message = {
            'message_data': message,
            'created': int(time.time())
        }
        user_id = self.request.get('user_id')
        if user_id and UserHandler.users.get(user_id) is not None:
            full_message['user'] = UserHandler.users.get(user_id).__dict__

        if full_message:
            topic_name = pubsub_utils.get_full_topic_name()
            body = {
                'messages': [{
                    'data': base64.b64encode(json.dumps(full_message).encode('utf-8'))
                }]
            }
            client.projects().topics().publish(
                topic=topic_name, body=body).execute()
        self.response.status = 204
 def __init__(self, request=None, response=None):
     """Calls the constructor of the super and does the local setup."""
     super(InitHandler, self).__init__(request, response)
     self.client = pubsub_utils.get_client()
     self._setup_topic()
     self._setup_subscription()
Exemplo n.º 6
0
 def __init__(self, request=None, response=None):
     """Calls the constructor of the super and does the local setup."""
     super(InitHandler, self).__init__(request, response)
     self.client = pubsub_utils.get_client()
     self._setup_topic()
     self._setup_subscription()