Exemplo n.º 1
0
def query_redis(redispy_method, *args, **kwargs):
    status_code = 200
    try:
        try:
            request_json = request.get_json()
        except:
            request_json = None

        scopes = None
        default_scopes = current_app.config.get('DEFAULT_LARK_SCOPES', set())
        scope_getter = current_app.config.get('LARK_SCOPE_GETTER')
        if scope_getter:
            scopes = scope_getter(redispy_method, request_json, request.args, args, kwargs)

        if scopes is None:
            scopes = default_scopes

        data = RedisApiClient.from_request(redispy_method, g.r, request_json, request.args, args, kwargs, scopes)
        resp_envelope = {
            'meta': {
                'status': 'ok',
                'status_code': status_code,
            },
            'data': data,
        }
    except DataError, e:
        status_code = 400
        resp_envelope = {
            'meta': {
                'status': 'error',
                'status_code': status_code,
                'error_message': unicode(e)
            }
        }
Exemplo n.º 2
0
def query_redis(request, *args, **kwargs):
    status_code = 200
    try:
        methods = kwargs.pop('methods', ['GET'])
        redis_method = kwargs.pop('redispy_method')
        if request.method not in methods:
            raise InvalidMethod()

        request_json = None
        if request.method == 'POST':
            try:
                request_json = json.loads(
                    request.body.decode(encoding='UTF-8'))
            except:
                pass

        scopes = None
        default_scopes = getattr(settings, 'DEFAULT_LARK_SCOPES', set())

        scope_getter = getattr(settings, 'LARK_SCOPE_GETTER', None)
        if scope_getter:
            scopes = scope_getter(request, redis_method, request_json,
                                  request.GET, args, kwargs)

        if scopes is None:
            scopes = default_scopes

        data = RedisApiClient.from_request(redis_method, r, request_json,
                                           request.GET, args, kwargs, scopes)
        resp_envelope = {
            'meta': {
                'status': 'ok',
                'status_code': status_code,
            },
            'data': data,
        }
    except DataError, e:
        status_code = 400
        resp_envelope = {
            'meta': {
                'status': 'error',
                'status_code': status_code,
                'error_message': unicode(e)
            }
        }
Exemplo n.º 3
0
def query_redis(request, *args, **kwargs):
    status_code = 200
    try:
        methods = kwargs.pop('methods', ['GET'])
        redis_method = kwargs.pop('redispy_method')
        if request.method not in methods:
            raise InvalidMethod()

        request_json = None
        if request.method == 'POST':
            try:
                request_json = json.loads(request.body.decode(encoding='UTF-8'))
            except:
                pass

        scopes = None
        default_scopes = getattr(settings, 'DEFAULT_LARK_SCOPES', set())

        scope_getter = getattr(settings, 'LARK_SCOPE_GETTER', None)
        if scope_getter:
            scopes = scope_getter(request, redis_method, request_json, request.GET, args, kwargs)

        if scopes is None:
            scopes = default_scopes

        data = RedisApiClient.from_request(redis_method, r, request_json, request.GET, args, kwargs, scopes)
        resp_envelope = {
            'meta': {
                'status': 'ok',
                'status_code': status_code,
            },
            'data': data,
        }
    except DataError, e:
        status_code = 400
        resp_envelope = {
            'meta': {
                'status': 'error',
                'status_code': status_code,
                'error_message': unicode(e)
            }
        }
Exemplo n.º 4
0
def query_redis(redispy_method, *args, **kwargs):
    status_code = 200
    try:
        try:
            request_json = request.get_json()
        except:
            request_json = None

        scopes = None
        default_scopes = current_app.config.get('DEFAULT_LARK_SCOPES', set())
        scope_getter = current_app.config.get('LARK_SCOPE_GETTER')
        if scope_getter:
            scopes = scope_getter(redispy_method, request_json, request.args,
                                  args, kwargs)

        if scopes is None:
            scopes = default_scopes

        data = RedisApiClient.from_request(redispy_method, g.r, request_json,
                                           request.args, args, kwargs, scopes)
        resp_envelope = {
            'meta': {
                'status': 'ok',
                'status_code': status_code,
            },
            'data': data,
        }
    except DataError, e:
        status_code = 400
        resp_envelope = {
            'meta': {
                'status': 'error',
                'status_code': status_code,
                'error_message': unicode(e)
            }
        }