Skip to content

Commit 03fb886

Browse files
Added Monitor API, and Get monitor data example
1 parent 8a1cb34 commit 03fb886

17 files changed

Lines changed: 361 additions & 6 deletions

File tree

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,12 @@ This example demonstrates how to use DocuSign Click to get a list of clickwraps
190190
[Source.](./app/click/examples/eg006_list_clickwraps/controller.py)
191191
1. **Get clickwrap responses.**
192192
This example demonstrates how to use DocuSign Click to get user responses to your clickwrap agreements.
193-
[Source.](./app/click/examples/eg007_clickwrap_responses/controller.py)
193+
[Source.](./app/click/examples/eg007_clickwrap_responses/controller.py)
194+
195+
## Monitor API
196+
1. **Get monitor data.**
197+
[Source.](./app/monitor/examples/eg001_get_monitoring_data/controller.py)
198+
This example demonstrates how to get and display all of your organization’s monitoring data
194199

195200
## Included OAuth grant types:
196201

app/__init__.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,17 @@
99
from .ds_config import EXAMPLES_API_TYPE
1010
from .rooms import examples as rooms_examples
1111
from .click import examples as click_examples
12+
from .monitor import examples as monitor_examples
1213
from .views import core
1314

1415
session_path = "/tmp/python_recipe_sessions"
1516

1617
if EXAMPLES_API_TYPE["Rooms"]:
17-
app = Flask(__name__, template_folder='rooms/templates')
18+
app = Flask(__name__, template_folder="rooms/templates")
1819
elif EXAMPLES_API_TYPE["Click"]:
19-
app = Flask(__name__, template_folder='click/templates')
20+
app = Flask(__name__, template_folder="click/templates")
21+
elif EXAMPLES_API_TYPE["Monitor"]:
22+
app = Flask(__name__, template_folder="monitor/templates")
2023
else:
2124
app = Flask(__name__)
2225
app.config.from_pyfile("config.py")
@@ -47,6 +50,9 @@
4750
app.register_blueprint(rooms_examples.eg008)
4851
app.register_blueprint(rooms_examples.eg009)
4952

53+
elif EXAMPLES_API_TYPE["Monitor"]:
54+
app.register_blueprint(monitor_examples.eg001)
55+
5056
elif EXAMPLES_API_TYPE["Click"]:
5157
app.register_blueprint(click_examples.eg001)
5258
app.register_blueprint(click_examples.eg002)

app/docusign/views.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,11 @@ def ds_must_authenticate():
8080
if DS_CONFIG["quickstart"] == "true" and EXAMPLES_API_TYPE['ESignature']:
8181
session["auth_type"] = "code_grant"
8282
return redirect(url_for("ds.ds_login"))
83+
84+
elif EXAMPLES_API_TYPE["Monitor"]:
85+
session["auth_type"] = "jwt"
86+
return redirect(url_for("ds.ds_login"))
87+
8388
else:
8489
return render_template("must_authenticate.html", title="Must authenticate")
8590

app/error_handlers.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66
def process_error(err):
77
error_body_json = err and hasattr(err, "body") and err.body
88
# we can pull the DocuSign error code and message from the response body
9-
error_body = json.loads(error_body_json)
9+
try:
10+
error_body = json.loads(error_body_json)
11+
except json.decoder.JSONDecodeError:
12+
error_body = {}
1013
error_code = error_body and "errorCode" in error_body and error_body["errorCode"]
1114
error_message = error_body and "message" in error_body and error_body["message"]
1215

app/monitor/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from .examples import eg001

app/monitor/examples/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from .eg001_get_monitoring_data import eg001
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from .views import eg001
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
from docusign_monitor import DataSetApi
2+
from flask import session, json
3+
4+
from app.monitor.utils import create_monitor_api_client
5+
6+
7+
class Eg001Controller:
8+
@staticmethod
9+
def get_args():
10+
"""Get required session and request arguments"""
11+
return {
12+
"account_id": session["ds_account_id"], # Represents your {ACCOUNT_ID}
13+
"access_token": session["ds_access_token"], # Represents your {ACCESS_TOKEN}
14+
}
15+
16+
@staticmethod
17+
def worker(args):
18+
"""
19+
1. Create an API client with headers
20+
2. Get your monitor data via SDK
21+
3. Use while loop for collecting rest records
22+
"""
23+
24+
# Step 1. Create an API client with headers
25+
api_client = create_monitor_api_client(
26+
access_token=args["access_token"]
27+
)
28+
29+
# Step 1 end
30+
31+
# Step 2. Get your monitor data
32+
dataset_api = DataSetApi(api_client=api_client)
33+
response = dataset_api.get_stream_for_dataset(
34+
data_set_name="monitor",
35+
version="2.0",
36+
_preload_content=False,
37+
)
38+
response = json.loads(response.data)
39+
40+
# Step 2 end
41+
42+
# Step 3. Use while loop for collecting rest records
43+
44+
result = response["data"]
45+
cursor = response["endCursor"]
46+
47+
# If the endCursor from the response is the same as the one
48+
# that you already have,
49+
# it means that you have reached the end of the records
50+
51+
while True:
52+
response = dataset_api.get_stream_for_dataset(
53+
data_set_name="monitor",
54+
version="2.0",
55+
_preload_content=False,
56+
cursor=cursor
57+
)
58+
59+
response = json.loads(response.data)
60+
61+
if response["endCursor"] == cursor:
62+
break
63+
64+
result.extend(response["data"])
65+
cursor = response["endCursor"]
66+
67+
# Step 3 end
68+
69+
return result
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
"""Example 001: Get monitoring data. """
2+
3+
import json
4+
5+
from docusign_rooms.client.api_exception import ApiException
6+
from flask import Blueprint, render_template, current_app
7+
8+
from app.docusign import authenticate
9+
from app.error_handlers import process_error
10+
from .controller import Eg001Controller
11+
12+
eg = "eg001" # Reference (and URL) for this example
13+
eg001 = Blueprint(eg, __name__)
14+
15+
16+
@eg001.route("/eg001", methods=["GET"])
17+
@authenticate(eg=eg)
18+
def get_view():
19+
"""
20+
1. Get required arguments
21+
2. Call the worker method
22+
3. Render the response
23+
"""
24+
25+
# 1. Get required arguments
26+
args = Eg001Controller.get_args()
27+
try:
28+
# 2. Call the worker method to get your monitor data
29+
results = Eg001Controller.worker(args)
30+
current_app.logger.info(f"""Got your monitor data""")
31+
except ApiException as err:
32+
return process_error(err)
33+
34+
# 3. Render the response
35+
return render_template(
36+
"example_done.html",
37+
title="Get monitoring data",
38+
h1="Get monitoring data",
39+
json=json.dumps(json.dumps(results, default=str))
40+
)

app/monitor/templates/404.html

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<!-- extend base layout -->
2+
{% extends "base.html" %}
3+
4+
{% block content %}
5+
<h1>File Not Found</h1>
6+
<p><a href="{{ url_for('core.index') }}">Continue</a></p>
7+
{% endblock %}

0 commit comments

Comments
 (0)