Exemplo n.º 1
0
def collections_endpoint(url):
    """ Resource endpoint handler

    :param url: the url that led here

    .. versionchanged:: 0.0.7
       Using 'utils.request_method' helper function now.

    .. versionchanged:: 0.0.6
       Support for HEAD requests

    .. versionchanged:: 0.0.2
        Support for DELETE resource method.
    """

    resource = config.RESOURCES[url]
    response = None
    method = request_method()
    if method in ('GET', 'HEAD'):
        response = get(resource)
    elif method == 'POST':
        response = post(resource)
    elif method == 'DELETE':
        response = delete_resource(resource)
    elif method == 'OPTIONS':
        send_response(resource, response)
    else:
        abort(405)
    return send_response(resource, response)
Exemplo n.º 2
0
def item_endpoint(url, **lookup):
    """ Item endpoint handler

    :param url: the url that led here
    :param lookup: the query

    .. versionchanged:: 0.0.7
       Using 'utils.request_method' helper function now.

    .. versionchanged:: 0.0.6
       Support for HEAD requests
    """
    resource = config.RESOURCES[url]
    response = None
    method = request_method()
    if method in ('GET', 'HEAD'):
        response = getitem(resource, **lookup)
    elif method == 'PATCH':
        response = patch(resource, **lookup)
    elif method == 'DELETE':
        response = delete(resource, **lookup)
    elif method == 'OPTIONS':
        send_response(resource, response)
    else:
        abort(405)
    return send_response(resource, response)
Exemplo n.º 3
0
def item_endpoint(url, **lookup):
    """ Item endpoint handler

    :param url: the url that led here
    :param lookup: the query

    .. versionchanged:: 0.0.7
       Using 'utils.request_method' helper function now.

    .. versionchanged:: 0.0.6
       Support for HEAD requests
    """
    resource = config.RESOURCES[url]
    response = None
    method = request_method()
    if method in ('GET', 'HEAD'):
        response = getitem(resource, **lookup)
    elif method == 'PATCH':
        response = patch(resource, **lookup)
    elif method == 'DELETE':
        response = delete(resource, **lookup)
    elif method == 'OPTIONS':
        send_response(resource, response)
    else:
        abort(405)
    return send_response(resource, response)
Exemplo n.º 4
0
def collections_endpoint(url):
    """ Resource endpoint handler

    :param url: the url that led here

    .. versionchanged:: 0.0.7
       Using 'utils.request_method' helper function now.

    .. versionchanged:: 0.0.6
       Support for HEAD requests

    .. versionchanged:: 0.0.2
        Support for DELETE resource method.
    """

    resource = config.RESOURCES[url]
    response = None
    method = request_method()
    if method in ('GET', 'HEAD'):
        response = get(resource)
    elif method == 'POST':
        response = post(resource)
    elif method == 'DELETE':
        response = delete_resource(resource)
    elif method == 'OPTIONS':
        send_response(resource, response)
    else:
        abort(405)
    return send_response(resource, response)
Exemplo n.º 5
0
def home_endpoint():
    """ Home/API entry point. Will provide links to each available resource
    """
    response = {}
    links = []
    for resource in config.DOMAIN.keys():
        links.append({'href': '%s' % resource_uri(resource),
                      'title': '%s' % config.URLS[resource]})
    response['_links'] = {'child': links}
    return send_response(None, (response,))
Exemplo n.º 6
0
def home_endpoint():
    """ Home/API entry point. Will provide links to each available resource
    """
    response = dict()
    links = list()
    for resource in config.DOMAIN.keys():
        links.append("<link rel='child' title='%s' href='%s' />" %
                     (config.URLS[resource], resource_uri(resource)))
    response['links'] = links
    return send_response(None, response)
Exemplo n.º 7
0
def home_endpoint():
    """ Home/API entry point. Will provide links to each available resource
    """
    response = {}
    links = []
    for resource in config.DOMAIN.keys():
        links.append({
            'href': '%s' % resource_uri(resource),
            'title': '%s' % config.URLS[resource]
        })
    response['_links'] = {'child': links}
    return send_response(None, (response, ))
Exemplo n.º 8
0
def collections_endpoint(url):
    """ Resource endpoint handler

    :param url: the url that led here

    .. versionadded:: 0.0.2
        Support for DELETE resource method.
    """

    resource = config.RESOURCES[url]
    response = None
    if request.method == 'GET':
        response = get(resource)
    elif request.method == 'POST':
        response = post(resource)
    elif request.method == 'DELETE':
        response = delete_resource(resource)
    return send_response(resource, response)
Exemplo n.º 9
0
def collections_endpoint(url):
    """ Resource endpoint handler

    :param url: the url that led here

    .. versionadded:: 0.0.2
        Support for DELETE resource method.
    """

    resource = config.RESOURCES[url]
    response = None
    if request.method == 'GET':
        response = get(resource)
    elif request.method == 'POST':
        response = post(resource)
    elif request.method == 'DELETE':
        response = delete_resource(resource)
    return send_response(resource, response)
Exemplo n.º 10
0
def item_endpoint(url, **lookup):
    """ Item endpoint handler

    :param url: the url that led here
    :param lookup: the query
    """
    resource = config.RESOURCES[url]
    response = None
    if request.method == 'GET':
        response = getitem(resource, **lookup)
    elif request.method == 'PATCH' or (
            request.method == 'POST'
            and request.headers.get('X-HTTP-Method-Override')):
        response = patch(resource, **lookup)
    elif request.method == 'DELETE':
        response = delete(resource, **lookup)
    elif request.method == 'POST':
        # We are supporting PATCH via POST with X-HTTP-Method-Override (see
        # above), therefore we must explicitly handle this case.
        abort(405)
    return send_response(resource, response)
Exemplo n.º 11
0
def item_endpoint(url, **lookup):
    """ Item endpoint handler

    :param url: the url that led here
    :param lookup: the query
    """
    resource = config.RESOURCES[url]
    response = None
    if request.method == 'GET':
        response = getitem(resource, **lookup)
    elif request.method == 'PATCH' or (request.method == 'POST' and
                                       request.headers.get(
                                           'X-HTTP-Method-Override')):
        response = patch(resource, **lookup)
    elif request.method == 'DELETE':
        response = delete(resource, **lookup)
    elif request.method == 'POST':
        # We are supporting PATCH via POST with X-HTTP-Method-Override (see
        # above), therefore we must explicitly handle this case.
        abort(405)
    return send_response(resource, response)