示例#1
0
    def get(self):
        auth_util.get_bot(flask.request)

        sub_events_query = ds_util.client.query(kind='SubscriptionEvent')
        for sub_event in sub_events_query.fetch():
            task_util.process_event(sub_event.key)
        return responses.OK
示例#2
0
    def get(self):
        auth_util.get_bot(flask.request)
        redirect_uri = config.frontend_url + '/services/strava/echo'

        client = stravalib.client.Client()
        url = client.authorization_url(
            client_id=config.strava_creds['client_id'],
            redirect_uri=redirect_uri,
            approval_prompt='force',
            scope=['activity:read_all', 'profile:read_all'],
        )
        return {'auth_url': url}
示例#3
0
    def post(self):
        auth_util.get_bot(flask.request)

        key = ds_util.key_from_path(api.payload.get('path'))
        if key is None or ds_util.client.get(key) is None:
            logging.debug('No entity with key: %s', key)
            return key
        children_query = ds_util.client.query(ancestor=key)
        children_query.keys_only()
        ds_util.client.delete_multi(child.key
                                    for child in children_query.fetch())

        return key
示例#4
0
    def post(self, name):
        bot = auth_util.get_bot(flask.request)

        service = Service.get(name, parent=bot.key)
        Service.clear_credentials(service)
        ds_util.client.put(service)
        return WrapEntity(service)
示例#5
0
    def post(self, name):
        bot = auth_util.get_bot(flask.request)

        force = api.payload.get('force', False)
        service = Service.get(name, parent=bot.key)
        task_util.sync_service(service, force=force)
        return WrapEntity(service)
示例#6
0
 def get(self):
     bot = auth_util.get_bot(flask.request)
     service = Service.get('slack', parent=bot.key)
     query = ds_util.client.query(kind='SlackWorkspace',
                                  ancestor=service.key)
     workspaces = [e for e in query.fetch()]
     return {'service': WrapEntity(service), 'workspaces': workspaces}
示例#7
0
    def get(self, club_id):
        bot = auth_util.get_bot(flask.request)

        service = Service.get('strava', parent=bot.key)
        club = StravaClubWorker(club_id, service).sync_club()

        return WrapEntity(club)
示例#8
0
    def get(self):
        bot = auth_util.get_bot(flask.request)

        service = Service.get('strava', parent=bot.key)
        club_query = ds_util.client.query(kind='Club', ancestor=service.key)

        return [WrapEntity(club) for club in club_query.fetch()]
示例#9
0
    def get(self, club_id):
        bot = auth_util.get_bot(flask.request)

        service = Service.get('strava', parent=bot.key)
        club = Club.get(club_id, parent=service.key)
        if club is not None:
            ds_util.client.delete(club.key)

        return None
示例#10
0
    def post(self):
        auth_util.get_bot(flask.request)

        callbackurl = flask.request.form.get('callbackurl', None)
        logging.info('Unsubscribing: %s', callbackurl)

        if callbackurl is None or 'withings' not in callbackurl:
            return responses.BAD_REQUEST

        services_query = ds_util.client.query(kind='Service')
        services_query.add_filter('sync_enabled', '=', True)
        services = [
            service for service in services_query.fetch()
            if service.key.name == 'withings'
            and service.get('credentials') is not None
        ]

        for service in services:
            logging.info('Unsubscribing: %s from %s', callbackurl, service.key)
            client = withings_create_client(service)
            results = []
            try:
                result = client.unsubscribe(callbackurl)
                logging.info('Unsubscribed %s from %s (%s)', callbackurl,
                             service.key, result)
                results.append({
                    'callbackurl': callbackurl,
                    'result': str(result),
                    'service': str(service.key),
                })
            except Exception as e:
                logging.exception('Unable to unsubscribe %s from %s',
                                  callbackurl, service.key)
                results.append({
                    'callbackurl': callbackurl,
                    'error': str(e),
                    'service': str(service.key),
                })
        return results
示例#11
0
    def get(self):
        bot = auth_util.get_bot(flask.request)

        user_entities = [bot]
        user_entities += ds_util.client.query(kind='User').fetch()
        users = []
        for user_entity in user_entities:
            users.append({
                'user':
                WrapEntity(user_entity),
                'google':
                Service.get('google', parent=user_entity.key),
                'strava':
                Service.get('strava', parent=user_entity.key),
                'withings':
                Service.get('withings', parent=user_entity.key),
                'fitbit':
                Service.get('fitbit', parent=user_entity.key),
            })

        return users
示例#12
0
    def get(self, name):
        bot = auth_util.get_bot(flask.request)

        service = Service.get(name, parent=bot.key)
        task_util.sync_service(service, force=True)
        return responses.OK
示例#13
0
    def get(self, name):
        bot = auth_util.get_bot(flask.request)

        service = Service.get(name, parent=bot.key)
        return WrapEntity(service)