diff options
Diffstat (limited to 'pysite/views')
| -rw-r--r-- | pysite/views/api/bot/hiphopify.py | 4 | ||||
| -rw-r--r-- | pysite/views/api/bot/snake_cog/__init__.py | 0 | ||||
| -rw-r--r-- | pysite/views/api/bot/snake_cog/snake_facts.py | 28 | ||||
| -rw-r--r-- | pysite/views/api/bot/snake_cog/snake_idioms.py | 28 | ||||
| -rw-r--r-- | pysite/views/api/bot/snake_cog/snake_names.py | 48 | ||||
| -rw-r--r-- | pysite/views/api/bot/snake_cog/snake_quiz.py | 28 | ||||
| -rw-r--r-- | pysite/views/api/bot/snake_cog/special_snakes.py | 28 | ||||
| -rw-r--r-- | pysite/views/api/bot/tags.py | 4 | ||||
| -rw-r--r-- | pysite/views/api/bot/user.py | 4 | 
9 files changed, 166 insertions, 6 deletions
| diff --git a/pysite/views/api/bot/hiphopify.py b/pysite/views/api/bot/hiphopify.py index bb85d5b5..50a811c6 100644 --- a/pysite/views/api/bot/hiphopify.py +++ b/pysite/views/api/bot/hiphopify.py @@ -34,8 +34,8 @@ DELETE_SCHEMA = Schema([  class HiphopifyView(APIView, DBMixin): -    path = "/hiphopify" -    name = "hiphopify" +    path = "/bot/hiphopify" +    name = "bot.hiphopify"      prison_table = "hiphopify"      name_table = "hiphopify_namelist" diff --git a/pysite/views/api/bot/snake_cog/__init__.py b/pysite/views/api/bot/snake_cog/__init__.py new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/pysite/views/api/bot/snake_cog/__init__.py diff --git a/pysite/views/api/bot/snake_cog/snake_facts.py b/pysite/views/api/bot/snake_cog/snake_facts.py new file mode 100644 index 00000000..4e8c8a5d --- /dev/null +++ b/pysite/views/api/bot/snake_cog/snake_facts.py @@ -0,0 +1,28 @@ +import logging + +from flask import jsonify + +from pysite.base_route import APIView +from pysite.decorators import api_key +from pysite.mixins import DBMixin + +log = logging.getLogger(__name__) + + +class SnakeFactsView(APIView, DBMixin): +    path = "/bot/snake_facts" +    name = "bot.snake_facts" +    table = "snake_facts" + +    @api_key +    def get(self): +        """ +        Returns a random fact from the snake_facts table. + +        API key must be provided as header. +        """ + +        log.trace("Fetching a random fact from the snake_facts database") +        question = self.db.sample(self.table, 1)[0]["fact"] + +        return jsonify(question) diff --git a/pysite/views/api/bot/snake_cog/snake_idioms.py b/pysite/views/api/bot/snake_cog/snake_idioms.py new file mode 100644 index 00000000..9d879871 --- /dev/null +++ b/pysite/views/api/bot/snake_cog/snake_idioms.py @@ -0,0 +1,28 @@ +import logging + +from flask import jsonify + +from pysite.base_route import APIView +from pysite.decorators import api_key +from pysite.mixins import DBMixin + +log = logging.getLogger(__name__) + + +class SnakeIdiomView(APIView, DBMixin): +    path = "/bot/snake_idioms" +    name = "bot.snake_idioms" +    table = "snake_idioms" + +    @api_key +    def get(self): +        """ +        Returns a random idiom from the snake_idioms table. + +        API key must be provided as header. +        """ + +        log.trace("Fetching a random idiom from the snake_idioms database") +        question = self.db.sample(self.table, 1)[0]["idiom"] + +        return jsonify(question) diff --git a/pysite/views/api/bot/snake_cog/snake_names.py b/pysite/views/api/bot/snake_cog/snake_names.py new file mode 100644 index 00000000..d9e0c6b8 --- /dev/null +++ b/pysite/views/api/bot/snake_cog/snake_names.py @@ -0,0 +1,48 @@ +import logging + +from flask import jsonify +from schema import Optional, Schema + + +from pysite.base_route import APIView +from pysite.constants import ValidationTypes +from pysite.decorators import api_key, api_params +from pysite.mixins import DBMixin + +log = logging.getLogger(__name__) + +GET_SCHEMA = Schema([ +    { +        Optional("get_all"): str +    } +]) + + +class SnakeNamesView(APIView, DBMixin): +    path = "/bot/snake_names" +    name = "bot.snake_names" +    table = "snake_names" + +    @api_key +    @api_params(schema=GET_SCHEMA, validation_type=ValidationTypes.params) +    def get(self, params=None): +        """ +        Returns all snake names random name from the snake_names table. + +        API key must be provided as header. +        """ + +        get_all = None + +        if params: +            get_all = params[0].get("get_all") + +        if get_all: +            log.trace("Returning all snake names from the snake_names table") +            snake_names = self.db.get_all(self.table) + +        else: +            log.trace("Fetching a single random snake name from the snake_names table") +            snake_names = self.db.sample(self.table, 1)[0] + +        return jsonify(snake_names) diff --git a/pysite/views/api/bot/snake_cog/snake_quiz.py b/pysite/views/api/bot/snake_cog/snake_quiz.py new file mode 100644 index 00000000..359077d7 --- /dev/null +++ b/pysite/views/api/bot/snake_cog/snake_quiz.py @@ -0,0 +1,28 @@ +import logging + +from flask import jsonify + +from pysite.base_route import APIView +from pysite.decorators import api_key +from pysite.mixins import DBMixin + +log = logging.getLogger(__name__) + + +class SnakeQuizView(APIView, DBMixin): +    path = "/bot/snake_quiz" +    name = "bot.snake_quiz" +    table = "snake_quiz" + +    @api_key +    def get(self): +        """ +        Returns a random question from the snake_quiz table. + +        API key must be provided as header. +        """ + +        log.trace("Fetching a random question from the snake_quiz database") +        question = self.db.sample(self.table, 1)[0] + +        return jsonify(question) diff --git a/pysite/views/api/bot/snake_cog/special_snakes.py b/pysite/views/api/bot/snake_cog/special_snakes.py new file mode 100644 index 00000000..294c16c9 --- /dev/null +++ b/pysite/views/api/bot/snake_cog/special_snakes.py @@ -0,0 +1,28 @@ +import logging + +from flask import jsonify + +from pysite.base_route import APIView +from pysite.decorators import api_key +from pysite.mixins import DBMixin + +log = logging.getLogger(__name__) + + +class SpecialSnakesView(APIView, DBMixin): +    path = "/bot/special_snakes" +    name = "bot.special_snakes" +    table = "special_snakes" + +    @api_key +    def get(self): +        """ +        Returns all special snake objects from the database + +        API key must be provided as header. +        """ + +        log.trace("Returning all special snakes in the database") +        snake_names = self.db.get_all(self.table) + +        return jsonify(snake_names) diff --git a/pysite/views/api/bot/tags.py b/pysite/views/api/bot/tags.py index c901347e..7fdaee3c 100644 --- a/pysite/views/api/bot/tags.py +++ b/pysite/views/api/bot/tags.py @@ -27,8 +27,8 @@ DELETE_SCHEMA = Schema([  class TagsView(APIView, DBMixin): -    path = "/tags" -    name = "api.bot.tags" +    path = "/bot/tags" +    name = "bot.tags"      table_name = "tags"      @api_key diff --git a/pysite/views/api/bot/user.py b/pysite/views/api/bot/user.py index cd66f3e8..a353ccfe 100644 --- a/pysite/views/api/bot/user.py +++ b/pysite/views/api/bot/user.py @@ -28,8 +28,8 @@ DELETE_SCHEMA = Schema([  class UserView(APIView, DBMixin): -    path = "/user" -    name = "api.bot.user" +    path = "/bot/users" +    name = "bot.users"      table_name = "users"      oauth_table_name = "oauth_data"      participants_table = "code_jam_participants" | 
