spacepaste

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
class ChannelComms(webapp2.RequestHandler):
    @dopamine_api_handler
    def post(self):
        if 'device_id' in self.data:
            token_value = self.data['tokenValue']
        else:
            logging.warn("Channel Comms: No token present")
            return ('err_token_not_found', {
                'tokenValue': "undefined"
            })

        try:
            token = ndb.Key(urlsafe=token_value).get()
        except:
            logging.warn("Bad token_value, exception raised by .get()")
            logging.info("Token Value: [{}]".format(token_value))
            token = None

        if not token:
            logging.warn("Channel Comms: No token found")
            return ('err_token_not_found', {
                'tokenValue': token_value
            })
            
        ret = updatestream.channel_comms(
            token=token,
            message_type=self.data['type'],
            message_data=self.data.get('mData', None)
        )

        return {
            'updates': ret
        }