Skip to content

Commit cd4b2b6

Browse files
Updated monitor example
1 parent 1449014 commit cd4b2b6

3 files changed

Lines changed: 82 additions & 74 deletions

File tree

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ const express = require('express')
6767
, eg003click = require('./lib/click/controllers/eg003CreateNewClickwrapVersion')
6868
, eg004click = require('./lib/click/controllers/eg004ListClickwraps')
6969
, eg005click = require('./lib/click/controllers/eg005ClickwrapResponses')
70-
, eg001monitor = require('./lib/monitor/eg001GetMonitoringData')
70+
, eg001monitor = require('./lib/monitor/controllers/eg001GetMonitoringData')
7171
;
7272

7373
const PORT = process.env.PORT || 5000

lib/monitor/eg001GetMonitoringData.js renamed to lib/monitor/controllers/eg001GetMonitoringData.js

Lines changed: 3 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
*/
66

77
const path = require('path')
8-
, request = require('request')
9-
, dsConfig = require('../../config/index.js').config
8+
, getMonitoringData = require('../examples/getMonitoringData')
9+
, dsConfig = require('../../../config/index.js').config
1010
;
1111

1212
const eg001GetMonitoringData = exports
@@ -39,7 +39,7 @@ eg001GetMonitoringData.createController = async(req, res) => {
3939
results = null;
4040

4141
try {
42-
results = await eg001GetMonitoringData.worker(args)
42+
results = await getMonitoringData.getData(args)
4343
} catch (error) {
4444
// we can pull the DocuSign error code and message from the response body
4545
let errorBody = error && error.response && error.response.body
@@ -60,76 +60,6 @@ eg001GetMonitoringData.createController = async(req, res) => {
6060
}
6161
}
6262

63-
/**
64-
* This function does the work of getting the monitoring data
65-
*/
66-
eg001GetMonitoringData.worker = async(args) => {
67-
// Data for this method
68-
// args.requestUrl
69-
// args.accessToken
70-
71-
72-
const requestOptions = {
73-
method: 'GET',
74-
// step 2 start
75-
headers: {
76-
'Authorization': `Bearer ${args.accessToken}`,
77-
'Content-Type': 'application/json'
78-
},
79-
// step 2 end
80-
json: true
81-
};
82-
83-
// step 3 start
84-
const limit = 2;
85-
let cursorValue = '';
86-
let complete = false;
87-
let results = [];
88-
do {
89-
const requestParams = `cursor=${cursorValue}&limit=${limit}`;
90-
91-
let endCursor = '';
92-
let responseResult = null;
93-
94-
await doRequest(args.requestUrl + requestParams, requestOptions).then((body) => {
95-
endCursor = body.endCursor;
96-
responseResult = body;
97-
}).catch((error) => {
98-
throw error;
99-
});
100-
101-
if (endCursor === cursorValue) {
102-
complete = true;
103-
} else {
104-
cursorValue = endCursor;
105-
results.push(responseResult);
106-
}
107-
108-
} while (!complete);
109-
// step 3 end
110-
return results;
111-
}
112-
113-
/**
114-
* Does the request
115-
* @function
116-
* @private
117-
* @param {string} url request url
118-
* @param {Object} options request options
119-
* @returns {Promise} A promise with request results
120-
*/
121-
function doRequest(url, options) {
122-
return new Promise(function (resolve, reject) {
123-
request(url, options, function (error, res, body) {
124-
if (!error) {
125-
resolve(body);
126-
} else {
127-
reject(error);
128-
}
129-
});
130-
});
131-
}
132-
13363
/**
13464
* Form page for this application
13565
*/
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/**
2+
* @file
3+
* Example 001: Getting the monitoring data
4+
* @author DocuSign
5+
*/
6+
7+
const request = require('request')
8+
9+
const getMonitoringData = exports
10+
11+
/**
12+
* This function does the work of getting the monitoring data
13+
*/
14+
getMonitoringData.getData = async(args) => {
15+
// Data for this method
16+
// args.requestUrl
17+
// args.accessToken
18+
19+
const requestOptions = {
20+
method: 'GET',
21+
// step 2 start
22+
headers: {
23+
'Authorization': `Bearer ${args.accessToken}`,
24+
'Content-Type': 'application/json'
25+
},
26+
// step 2 end
27+
json: true
28+
};
29+
30+
// step 3 start
31+
const limit = 2;
32+
let cursorValue = '';
33+
let complete = false;
34+
let results = [];
35+
do {
36+
const requestParams = `cursor=${cursorValue}&limit=${limit}`;
37+
38+
let endCursor = '';
39+
let responseResult = null;
40+
41+
await doRequest(args.requestUrl + requestParams, requestOptions).then((body) => {
42+
endCursor = body.endCursor;
43+
responseResult = body;
44+
}).catch((error) => {
45+
throw error;
46+
});
47+
48+
if (endCursor === cursorValue) {
49+
complete = true;
50+
} else {
51+
cursorValue = endCursor;
52+
results.push(responseResult);
53+
}
54+
55+
} while (!complete);
56+
// step 3 end
57+
return results;
58+
}
59+
60+
/**
61+
* Does the request
62+
* @function
63+
* @private
64+
* @param {string} url request url
65+
* @param {Object} options request options
66+
* @returns {Promise} A promise with request results
67+
*/
68+
function doRequest(url, options) {
69+
return new Promise(function (resolve, reject) {
70+
request(url, options, function (error, res, body) {
71+
if (!error) {
72+
resolve(body);
73+
} else {
74+
reject(error);
75+
}
76+
});
77+
});
78+
}

0 commit comments

Comments
 (0)