瀏覽代碼

Also use JSON in feedback request; update docs.

scossu 1 年之前
父節點
當前提交
235100f043
共有 2 個文件被更改,包括 31 次插入13 次删除
  1. 23 0
      doc/rest_api.md
  2. 8 13
      scriptshifter/rest_api.py

+ 23 - 0
doc/rest_api.md

@@ -69,6 +69,10 @@ Transliterate an input string into a given language.
 
 
 ### POST body
 ### POST body
 
 
+MIME type: `application/json`
+
+Content: JSON object with the following keys:
+
 - `lang`: Language code as given by the `/languages` endpoint. 
 - `lang`: Language code as given by the `/languages` endpoint. 
 - `text`: Input text to be transliterated.
 - `text`: Input text to be transliterated.
 - `capitalize`: One of `first` (capitalize the first letter of the input),
 - `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
 string; and `warnings` containing a list of warnings. Characters not found in
 the mapping are copied verbatim in the transliterated string (see
 the mapping are copied verbatim in the transliterated string (see
 "Configuration files" section for more information).
 "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.

+ 8 - 13
scriptshifter/rest_api.py

@@ -131,14 +131,9 @@ def feedback():
     """
     """
     Allows users to provide feedback to improve a specific result.
     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 = EmailMessage()
     msg["subject"] = "Scriptshifter feedback report"
     msg["subject"] = "Scriptshifter feedback report"
@@ -148,16 +143,16 @@ def feedback():
         msg["cc"] = contact
         msg["cc"] = contact
     msg.set_content(f"""
     msg.set_content(f"""
         *Scriptshifter feedback report from {contact or 'anonymous'}*\n\n
         *Scriptshifter feedback report from {contact or 'anonymous'}*\n\n
-        *Language:* {lang}\n
+        *Language:* {request.json['lang']}\n
         *Direction:* {
         *Direction:* {
                     'Roman to Script' if t_dir == 'r2s'
                     'Roman to Script' if t_dir == 'r2s'
                     else 'Script to Roman'}\n
                     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
         *Applied options:* {dumps(options)}\n
         *Notes:*\n
         *Notes:*\n
-        {notes}""")
+        {request.json['notes']}""")
 
 
     # TODO This uses a test SMTP server:
     # TODO This uses a test SMTP server:
     # python -m smtpd -n -c DebuggingServer localhost:1025
     # python -m smtpd -n -c DebuggingServer localhost:1025