Skip to content
This repository has been archived by the owner on Aug 11, 2022. It is now read-only.

Commit

Permalink
Handle both url and id resources at the same endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
ms-christensen committed Aug 11, 2019
1 parent 5db29aa commit 88180d9
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions service.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,26 @@ def handle_job(resource_id: str, resource_type: str) -> dict:
@app.route("/api/v1/resource")
def process_resource():
resource_id = request.args.get("id")
resource_type = "scta"
if not resource_id:
resource_url = request.args.get("url")
if not resource_id and not resource_url:
error_message = {
"error": "The parameter 'id' is requied. It must container an SCTA resource id, e.g. scta.info/resource/lectio1"
"error": "One of the parameters 'id' and 'url' must be given. 'id' must container an SCTA resource id, e.g. scta.info/resource/lectio1. 'url' must contain an http reference to an XML file, e.g. https://raw.githubusercontent.com/scta-texts/da-49/master/da-49-l1q1/da-49-l1q1.xml"
}
return jsonify(error_message)
elif resource_id and resource_url:
error_message = {
"error": "One of the parameters 'id' and 'url' must be given, but not both."
}
return jsonify(error_message)

if resource_id:
resource_value = resource_id
resource_type = "scta"
else:
resource_value = resource_url
resource_type = "url"

response = handle_job(resource_id, resource_type)
response = handle_job(resource_value, resource_type)

return jsonify(response)

Expand Down

0 comments on commit 88180d9

Please sign in to comment.