Skip to content

Commit

Permalink
Also use JSON in feedback request; update docs.
Browse files Browse the repository at this point in the history
  • Loading branch information
scossu committed May 8, 2024
1 parent d833c60 commit 235100f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 13 deletions.
23 changes: 23 additions & 0 deletions doc/rest_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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.
21 changes: 8 additions & 13 deletions scriptshifter/rest_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down

0 comments on commit 235100f

Please sign in to comment.