From 76c7020d798b33d21b151eb41f5672153c9469bc Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Wed, 19 Aug 2020 02:31:34 +0200 Subject: [PATCH] Update to 5.11.0 --- examplepack/stars/api_example.py | 56 +++++++++++++++++++++++++------- pyproject.toml | 5 ++- 2 files changed, 46 insertions(+), 15 deletions(-) diff --git a/examplepack/stars/api_example.py b/examplepack/stars/api_example.py index 66c6e835..13f8f5fe 100644 --- a/examplepack/stars/api_example.py +++ b/examplepack/stars/api_example.py @@ -15,25 +15,37 @@ class EchoStar(rca.ApiStar): NOTE: This method can only be used by Royalnet Admins. """ - # The HTTP methods that can be used with this ApiStar. - methods = ["GET", "POST"] - # You can disambiguate between methods using the `data.method` variable. - # The HTTP path this ApiStar should bind to. path = "/api/example/echo/v1" # Does this method require any auth? # Only for documentation purposes, it doesn't do any check on it's own. - requires_auth = True + auth = { + "get": True, + "post": False, + "put": False, + "delete": False, + } # To authenticate an user through their token, use the `await data.user()` method. # If the user isn't logged in, the method authomatically returns 403 Forbidden, unless `rcae.ForbiddenError` # is caught. # A dict of paramenters accepted by this method, with a description of their purpose. parameters = { - "echo": "What should the method return? " - "(Optional: if nothing is passed, the ApiStar will return the username of the caller.)", - "error": "Should the method return a sample error?" + "get": { + "echo": "What should the method return? " + "(Optional: if nothing is passed, the ApiStar will return the username of the caller.)", + "error": "Should the method return a sample error?" + }, + "post": { + + }, + "put": { + + }, + "delete": { + + }, } # You can access parameters by using `data` as a dict with the parameter name as key. # If a missing parameter is accessed, a `rcae.MissingParameterError` will be raised, which will lead to a @@ -42,9 +54,14 @@ class EchoStar(rca.ApiStar): # The autodoc categories this ApiStar should fall in. tags = ["example"] - # The actual method called when the ApiStar received a HTTP request. - # It must return a JSON-compatible object, such as a str, a int, a float, a list, a dict or None. - async def api(self, data: rca.ApiData) -> ru.JSON: + # The methods called when the ApiStar received a HTTP request. + # They must return a JSON-compatible object, such as a str, a int, a float, a list, a dict or None. + # They also must be wrapped with the @rca.magic decorator. + # You are free to not add them if you don't want the methods to be available + + # Called on a GET request + @rca.magic + async def get(self, data: rca.ApiData) -> ru.JSON: # If "true" is passed as the "error" parameter in the query string... if data["error"] == "true": @@ -67,4 +84,19 @@ class EchoStar(rca.ApiStar): echo = user.username # Return a 200 OK successful response containing the value of the echo variable and the HTTP method used - return {"echo": echo, "method_used": data.method} + return {"echo": echo, "method_used": "GET"} + + # Called on a POST request + @rca.magic + async def post(self, data: rca.ApiData) -> ru.JSON: + return "This is a response to a POST." + + # Called on a PUT request + @rca.magic + async def put(self, data: rca.ApiData) -> ru.JSON: + return data + + # Called on a DELETE request + @rca.magic + async def post(self, data: rca.ApiData) -> ru.JSON: + return None diff --git a/pyproject.toml b/pyproject.toml index c9a76d70..7a7c4ab9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -14,7 +14,7 @@ # TODO: Set this to the GitHub page of your pack (or another website) homepage = "https://github.com/your-username/" # TODO: Set this to a link to the Pack documentation (if there's any) - documentation = "https://gh.steffo.eu/royalpack/" + documentation = "https://gh.steffo.eu/royalnet-pack-template/" # TODO: Pick some classifiers to include your Pack in: https://pypi.org/classifiers/ classifiers = [ "Development Status :: 3 - Alpha", @@ -29,13 +29,12 @@ python = "^3.8" [tool.poetry.dependencies.royalnet] - version = "~5.10.3" + version = "~5.11.0" # TODO: select the Royalnet modules required by your pack extras = [ "telegram", "discord", "alchemy_easy", - "bard", "constellation", "sentry", "herald",