from flask import Flask, abort, jsonify, request

from config import SECRET_KEY
from store import redis


app = Flask(__name__)


@app.errorhandler(401)
def unauthorized(e):
    return jsonify(message=str(e)), 401


@app.before_request
def authenticate():
    if 'CAAS-Auth-Token' not in request.headers:
        abort(401)

    if request.headers['CAAS-Auth-Token'] != SECRET_KEY:
        abort(401)


@app.route('/<label>', methods=['GET'])
def get(label):
    counter = redis.get(label)

    if counter is None:
        counter = redis.incr(label)

    return jsonify(counter=int(counter))


@app.route('/<label>', methods=['PUT'])
def incr(label):
    counter = redis.incr(label)
    return jsonify(counter=counter)


@app.route('/<label>/<int:counter>', methods=['POST'])
def set(label, counter):
    redis.set(label, counter)
    return jsonify(counter=counter)


@app.route('/<label>', methods=['DELETE'])
def reset(label):
    counter = redis.delete(label)
    return jsonify(counter=1)


if __name__ == '__main__':
    app.run()

@@ -460,475 +460,1339 @@
     
-counter = redis.get(label)%0A%0A    if counter is None:%0A        counter = redis.incr(label)%0A%0A    return jsonify(counter=int(counter))%0A%0A%0A@app.route('/%3Clabel%3E', methods=%5B'PUT'%5D)%0Adef incr(label):%0A    counter = redis.incr(label)%0A    return jsonify(counter=counter)%0A%0A%0A@app.route('/%3Clabel%3E/%3Cint:counter%3E', methods=%5B'POST'%5D)%0Adef set(label, counter):%0A    redis.set(label, counter)%0A    return jsonify(counter=counter)%0A%0A%0A@app.route('/%3Clabel%3E', methods=%5B'DELETE'%5D)%0Adef reset(label):
+%22%22%22%0A    @api %7Bget%7D /:label Get counter value%0A    @apiName GetCounter%0A    @apiGroup Counter%0A%0A    @apiParam %7BString%7D label Counter label.%0A%0A    @apiSuccess %7BNumber%7D counter Current value.%0A    %22%22%22%0A    counter = redis.get(label)%0A%0A    if counter is None:%0A        counter = redis.incr(label)%0A%0A    return jsonify(counter=int(counter))%0A%0A%0A@app.route('/%3Clabel%3E', methods=%5B'PUT'%5D)%0Adef incr(label):%0A    %22%22%22%0A    @api %7Bput%7D /:label Increment counter%0A    @apiName IncrementCounter%0A    @apiGroup Counter%0A%0A    @apiParam %7BString%7D label Counter label.%0A%0A    @apiSuccess %7BNumber%7D counter Current value.%0A    %22%22%22%0A    counter = redis.incr(label)%0A    return jsonify(counter=counter)%0A%0A%0A@app.route('/%3Clabel%3E/%3Cint:counter%3E', methods=%5B'POST'%5D)%0Adef set(label, counter):%0A    %22%22%22%0A    @api %7Bpost%7D /:label/:counter Directly set counter value%0A    @apiName SetCounter%0A    @apiGroup Counter%0A%0A    @apiParam %7BString%7D label Counter label.%0A    @apiParam %7BNumber%7D counter New counter value.%0A%0A    @apiSuccess %7BNumber%7D counter Current value.%0A    %22%22%22%0A    redis.set(label, counter)%0A    return jsonify(counter=counter)%0A%0A%0A@app.route('/%3Clabel%3E', methods=%5B'DELETE'%5D)%0Adef reset(label):%0A    %22%22%22%0A    @api %7Bdelete%7D /:label Reset counter%0A    @apiName ResetCounter%0A    @apiGroup Counter%0A%0A    @apiParam %7BString%7D label Counter label.%0A%0A    @apiSuccess %7BNumber%7D counter Initial value.%0A    %22%22%22
 %0A   

Add apidoc