コード例 #1
0
def get_employees():
    # Get URL parameters
    limit, offset, expand = get_list_url_parameters()

    # Request Data from API
    payload = {'limit': limit, 'offset': offset}
    response = requests.get(current_app.config.get('EMPLOYEE_API'),
                            params=payload)
    data = response.json()

    # Expand the data
    if expand:
        data = expand_data(data, expand)

    # Return response
    return jsonify(data)
コード例 #2
0
def get_offices():
    # Get URL parameters
    limit, offset, expand = get_list_url_parameters()

    # Get Data
    with open(current_app.config.get('OFFICES_JSON')) as json_file:
        office_data = json.load(json_file)

    # Filter data
    data = [e for e in office_data if e.get('id') > offset][:limit]

    # Expand data
    ALLOWED_EXPANSIONS = []
    if expand:
        data = expand_data(data, expand, ALLOWED_EXPANSIONS)

    return jsonify(data)
コード例 #3
0
def get_departments():
    # Get URL parameters
    limit, offset, expand = get_list_url_parameters()

    # Get Data
    with open(current_app.config.get('DEPARTMENTS_JSON')) as json_file:
        department_data = json.load(json_file)

    # Filter data
    data = [e for e in department_data if e.get('id') > offset][:limit]

    # Expand data
    ALLOWED_EXPANSIONS = ['superdepartment']
    if expand:
        data = expand_data(data, expand, ALLOWED_EXPANSIONS)

    return jsonify(data)
コード例 #4
0
def get_employee(id):
    # Get URL parameter
    expand = request.args.getlist('expand')

    # Request Data from API
    payload = {'id': id}
    response = requests.get(current_app.config.get('EMPLOYEE_API'),
                            params=payload)
    data = response.json()
    if len(data) == 0:
        abort(404, description='No employee found with the provided id')

    # Expand the data
    if expand:
        data = expand_data(data, expand)

    # Return response
    return jsonify(data.pop())
コード例 #5
0
def get_office(id):
    # Get URL parameters
    expand = request.args.getlist('expand')

    # Get Data
    with open(current_app.config.get('OFFICES_JSON')) as json_file:
        office_data = json.load(json_file)

    # Filter data
    data = [e for e in office_data if e.get('id') == id]
    if len(data) == 0:
        abort(404, description='Id provided is invalid')

    # Expand data
    ALLOWED_EXPANSIONS = []
    if expand:
        data = expand_data(data, expand, ALLOWED_EXPANSIONS)

    return jsonify(data.pop())