File: api.py

package info (click to toggle)
buildbot 4.3.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 21,080 kB
  • sloc: python: 174,183; sh: 1,204; makefile: 332; javascript: 119; xml: 16
file content (26 lines) | stat: -rw-r--r-- 754 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import json

from klein import Klein
from twisted.internet import defer


class Api:
    app = Klein()
    pizzaIngredients = {
        'margherita': ['tomato', 'ham', 'cheese'],
        'regina': ['tomato', 'ham', 'cheese', 'mushrooms'],
    }

    def __init__(self, ep):
        self.ep = ep

    @app.route("/getIngredients", methods=['GET'])
    def getIngredients(self, request):
        pizzaArgument = request.args.get('pizza')
        if pizzaArgument is None:
            return defer.succeed(json.dumps("invalid request"))
        pizza = pizzaArgument[0].lower()
        res = self.pizzaIngredients.get(
            pizza, [f"only {self.pizzaIngredients.keys()} are supported for now"]
        )
        return defer.succeed(json.dumps(res))