示例#1
0
def sync(request_json):
    app = db.get_app_from_key(request_json['_app_key'])
    if not app:
        data = {'app_key': request_json['_app_key']}
        return utils.jsonrpc_error(request_json, 8, data)

    app_version = db.get_app_version_for_bundle_version(app['id'],
        request_json['_bundle_version'])

    # If the app is over the limit and they're not a first-time customer, then
    # we return an error instead of the updated file list.
    if request_json['_app_version'] != '-1' and not app['enabled']:
        return utils.jsonrpc_error(request_json, 15, {})

    device = db.get_device_for_udid_and_app(request_json['_udid'], app['id'])

    return utils.jsonrpc_response(request_json, {
        'files': _get_file_list(app, app_version),
        'conf': _get_conf(app, app_version, device),
    })
示例#2
0
def sync(request_json):
    app = db.get_app_from_key(request_json['_app_key'])
    if not app:
        data = {'app_key': request_json['_app_key']}
        return utils.jsonrpc_error(request_json, 8, data)

    app_version = db.get_app_version_for_bundle_version(
        app['id'], request_json['_bundle_version'])

    # If the app is over the limit and they're not a first-time customer, then
    # we return an error instead of the updated file list.
    if request_json['_app_version'] != '-1' and not app['enabled']:
        return utils.jsonrpc_error(request_json, 15, {})

    device = db.get_device_for_udid_and_app(request_json['_udid'], app['id'])

    return utils.jsonrpc_response(
        request_json, {
            'files': _get_file_list(app, app_version),
            'conf': _get_conf(app, app_version, device),
        })
示例#3
0
def get_file(request_json, filename=None):
    app = db.get_app_from_key(request_json['_app_key'])
    if not app:
        data = {'app_key': request_json['_app_key']}
        return utils.jsonrpc_error(request_json, 8, data)

    conn = S3Connection(settings.AWS_ACCESS_KEY, settings.AWS_ACCESS_SECRET)
    bucket = conn.get_bucket(settings.AWS_BUCKET_NAME, validate=False)
    key = Key(bucket, '%s/%s/files/%s' % (
        app['slug'],
        request_json['_app_version'],
        filename,
    ))
    if key is None:
        return utils.jsonrpc_error(request_json, 4, {'filename': filename},
            code=404)
    if request_json['_platform'] == 'Android':
        return utils.jsonrpc_response(request_json,
            {'url': key.generate_url(120)})
    else:
        return utils.redirect(key.generate_url(120))
示例#4
0
def device_authenticate(request_json, device_id=None, app_key=None):
    app = db.get_app_from_key(app_key)

    if app:
        device = db.get_device_for_udid_and_app(device_id, app['id'])
    else:
        device = None

    data = {}
    if device:
        data['user'] = {
            'user_id': device['user_id'],
            'username': device['username'],
            'email': device['email'],
        }
    if app:
        data['app'] = {
            'app_id': app['id'],
            'slug': app['slug'],
            'name': app['name'],
        }
    return utils.jsonrpc_response(request_json, data)
示例#5
0
def device_authenticate(request_json, device_id=None, app_key=None):
    app = db.get_app_from_key(app_key)

    if app:
        device = db.get_device_for_udid_and_app(device_id, app['id'])
    else:
        device = None

    data = {}
    if device:
        data['user'] = {
            'user_id': device['user_id'],
            'username': device['username'],
            'email': device['email'],
        }
    if app:
        data['app'] = {
            'app_id': app['id'],
            'slug': app['slug'],
            'name': app['name'],
        }
    return utils.jsonrpc_response(request_json, data)
示例#6
0
文件: ab.py 项目: zhoufan2013/clutch
def get_ab_metadata(request_json, guid):
    app = db.get_app_from_key(request_json['_app_key'])
    if app is None:
        data = {'app_key': request_json['_app_key']}
        return utils.jsonrpc_error(request_json, 8, data)

    experiments = dict(((e['id'], e)
        for e in db.get_experiments_for_app(app['id'])))
    variations = db.get_variations_for_app(app['id'])

    metadata = {}
    for variation in variations:
        experiment = experiments[variation['experiment_id']]
        metadata.setdefault(experiment['slug'], {})
        metadata[experiment['slug']].setdefault('weights', [])
        metadata[experiment['slug']]['weights'].append(variation['weight'])
        if experiment['has_data']:
            metadata[experiment['slug']].setdefault('data', [])
            metadata[experiment['slug']]['data'].append(
                simplejson.loads(variation['data']))

    return utils.jsonrpc_response(request_json, {'metadata': metadata})
示例#7
0
def get_file(request_json, filename=None):
    app = db.get_app_from_key(request_json['_app_key'])
    if not app:
        data = {'app_key': request_json['_app_key']}
        return utils.jsonrpc_error(request_json, 8, data)

    conn = S3Connection(settings.AWS_ACCESS_KEY, settings.AWS_ACCESS_SECRET)
    bucket = conn.get_bucket(settings.AWS_BUCKET_NAME, validate=False)
    key = Key(
        bucket, '%s/%s/files/%s' % (
            app['slug'],
            request_json['_app_version'],
            filename,
        ))
    if key is None:
        return utils.jsonrpc_error(request_json,
                                   4, {'filename': filename},
                                   code=404)
    if request_json['_platform'] == 'Android':
        return utils.jsonrpc_response(request_json,
                                      {'url': key.generate_url(120)})
    else:
        return utils.redirect(key.generate_url(120))