From 235100f043fcdaada0b87d048d95e52adee58c7e Mon Sep 17 00:00:00 2001 From: scossu Date: Wed, 8 May 2024 07:41:01 -0400 Subject: [PATCH] Also use JSON in feedback request; update docs. --- doc/rest_api.md | 23 +++++++++++++++++++++++ scriptshifter/rest_api.py | 21 ++++++++------------- 2 files changed, 31 insertions(+), 13 deletions(-) diff --git a/doc/rest_api.md b/doc/rest_api.md index 34c9f2b..b4712c3 100644 --- a/doc/rest_api.md +++ b/doc/rest_api.md @@ -69,6 +69,10 @@ Transliterate an input string into a given language. ### POST body +MIME type: `application/json` + +Content: JSON object with the following keys: + - `lang`: Language code as given by the `/languages` endpoint. - `text`: Input text to be transliterated. - `capitalize`: One of `first` (capitalize the first letter of the input), @@ -92,3 +96,22 @@ Content: JSON object containing two keys: `ouput` containing the transliterated string; and `warnings` containing a list of warnings. Characters not found in the mapping are copied verbatim in the transliterated string (see "Configuration files" section for more information). + +## `POST /feedback` + +Send a feedback form about a transliteration result. + +### POST body + +MIME type: `application/json` + +Content: JSON object with the following keys: + + `lang`: language of the transliteration. Mandatory. + `src`: source text. Mandatory. + `t_dir`: transliteration direction. If omitted, it defaults to `s2r`. + `result`: result of the transliteration. Mandatory. + `expected`: expected result. Mandatory. + `options`: options passed to the request, if any. + `notes`: optional user notes. + `contact`: contact email for feedback. Optional. diff --git a/scriptshifter/rest_api.py b/scriptshifter/rest_api.py index e9ba013..e544c59 100644 --- a/scriptshifter/rest_api.py +++ b/scriptshifter/rest_api.py @@ -131,14 +131,9 @@ def feedback(): """ Allows users to provide feedback to improve a specific result. """ - lang = request.form["lang"] - src = request.form["src"] - t_dir = request.form.get("t_dir", "s2r") - result = request.form["result"] - expected = request.form["expected"] - options = request.form.get("options", {}) - notes = request.form.get("notes") - contact = request.form.get("contact") + t_dir = request.json.get("t_dir", "s2r") + options = request.json.get("options", {}) + contact = request.json.get("contact") msg = EmailMessage() msg["subject"] = "Scriptshifter feedback report" @@ -148,16 +143,16 @@ def feedback(): msg["cc"] = contact msg.set_content(f""" *Scriptshifter feedback report from {contact or 'anonymous'}*\n\n - *Language:* {lang}\n + *Language:* {request.json['lang']}\n *Direction:* { 'Roman to Script' if t_dir == 'r2s' else 'Script to Roman'}\n - *Source:* {src}\n - *Result:* {result}\n - *Expected result:* {expected}\n + *Source:* {request.json['src']}\n + *Result:* {request.json['result']}\n + *Expected result:* {request.json['expected']}\n *Applied options:* {dumps(options)}\n *Notes:*\n - {notes}""") + {request.json['notes']}""") # TODO This uses a test SMTP server: # python -m smtpd -n -c DebuggingServer localhost:1025