|
| 1 | +"""Example 002: Post web query. """ |
| 2 | + |
| 3 | +import json |
| 4 | +from os import path |
| 5 | +from datetime import date, timedelta |
| 6 | + |
| 7 | +from docusign_monitor.client.api_exception import ApiException |
| 8 | +from flask import Blueprint, render_template, current_app |
| 9 | + |
| 10 | +from app.docusign import authenticate |
| 11 | +from app.error_handlers import process_error |
| 12 | +from ..examples.eg002_post_web_query import Eg002PostWebQueryController |
| 13 | +from ...ds_config import DS_CONFIG |
| 14 | + |
| 15 | +eg = "eg002" # Reference (and URL) for this example |
| 16 | +eg002 = Blueprint(eg, __name__) |
| 17 | + |
| 18 | +@eg002.route(f"/{eg}", methods=["POST"]) |
| 19 | +@authenticate(eg=eg) |
| 20 | +def get_monitoring_data(): |
| 21 | + """ |
| 22 | + 1. Get required arguments |
| 23 | + 2. Call the worker method |
| 24 | + 3. Render the response |
| 25 | + """ |
| 26 | + |
| 27 | + # 1. Get required arguments |
| 28 | + args = Eg002PostWebQueryController.get_args() |
| 29 | + try: |
| 30 | + # 2. Call the worker method |
| 31 | + results = Eg002PostWebQueryController.worker(args) |
| 32 | + current_app.logger.info(f"""Got your monitor data""") |
| 33 | + except ApiException as err: |
| 34 | + return process_error(err) |
| 35 | + |
| 36 | + return render_template( |
| 37 | + "example_done.html", |
| 38 | + title="Query monitoring data with filters", |
| 39 | + h1="Query monitoring data with filters", |
| 40 | + message="Results from DataSet:postWebQuery method:", |
| 41 | + json=json.dumps(json.dumps(results.to_dict())) |
| 42 | + ) |
| 43 | + |
| 44 | +@eg002.route(f"/{eg}", methods=["GET"]) |
| 45 | +@authenticate(eg=eg) |
| 46 | +def get_view(): |
| 47 | + """ Responds with the form for the example""" |
| 48 | + |
| 49 | + current_date = date.today() |
| 50 | + start_date = date.today() - timedelta(10) |
| 51 | + |
| 52 | + return render_template( |
| 53 | + f"{eg}_post_web_query.html", |
| 54 | + title="Get monitoring data", |
| 55 | + source_file=f"{eg}_post_web_query.py", |
| 56 | + source_url=DS_CONFIG["monitor_github_url"] + f"{eg}_post_web_query.py", |
| 57 | + documentation=DS_CONFIG["documentation"] + eg, |
| 58 | + start_date=start_date, |
| 59 | + end_date=current_date |
| 60 | + ) |
| 61 | + |
0 commit comments