1
1
using System ;
2
2
using System . Collections . Generic ;
3
- using System . IO ;
4
- using System . Net ;
5
- using Microsoft . AspNetCore . Mvc ;
6
- using Newtonsoft . Json . Linq ;
3
+ using DocuSign . Monitor . Api ;
4
+ using DocuSign . Monitor . Client ;
5
+ using static DocuSign . Monitor . Api . DataSetApi ;
7
6
8
7
namespace DocuSign . CodeExamples . Monitor . Examples
9
8
{
@@ -17,40 +16,36 @@ public class GetMonitoringDataFunc
17
16
/// <returns>The list of JObjects, containing data from monitor</returns>
18
17
public virtual IEnumerable < Object > Invoke ( string accessToken , string requestPath )
19
18
{
19
+ ApiClient apiClient = new ApiClient ( ApiClient . Demo_REST_BasePath ) ;
20
+
20
21
// Construct API headers
21
22
// step 2 start
22
- WebHeaderCollection headers = new WebHeaderCollection ( ) ;
23
- headers . Add ( "Authorization" , String . Format ( "Bearer {0}" , accessToken ) ) ;
24
- headers . Add ( "Content-Type" , "application/json" ) ;
23
+ apiClient . SetBasePath ( ApiClient . Demo_REST_BasePath ) ;
24
+ apiClient . Configuration . DefaultHeader . Add ( "Authorization" , String . Format ( "Bearer {0}" , accessToken ) ) ;
25
+ apiClient . Configuration . DefaultHeader . Add ( "Content-Type" , "application/json" ) ;
25
26
// step 2 end
26
27
27
28
// Declare variables
28
29
// step 3 start
29
30
bool complete = false ;
30
31
string cursorValue = "" ;
31
32
int limit = 2 ; // Amount of records you want to read in one request
32
- List < JObject > functionResult = new List < JObject > ( ) ;
33
+ List < object > functionResult = new List < object > ( ) ;
34
+
35
+ DataSetApi dataSetApi = new DataSetApi ( apiClient ) ;
36
+ GetStreamOptions options = new GetStreamOptions ( ) ;
37
+
38
+ options . limit = limit ;
33
39
34
40
// Get monitoring data
35
41
do
36
42
{
37
- var cursorValueFormatted = ( ! string . IsNullOrEmpty ( cursorValue ) ) ? $ "={ cursorValue } " : cursorValue ;
38
-
39
- // Add cursor value and amount of records to read to the request
40
- var requestParameters = String . Format ( "stream?cursor{0}&limit={1}" ,
41
- cursorValueFormatted , limit ) ;
42
-
43
- WebRequest request = WebRequest . Create ( requestPath + requestParameters ) ;
44
- request . Headers = headers ;
45
-
46
- Stream requestStream = request . GetResponse ( ) . GetResponseStream ( ) ;
47
- StreamReader requestStreamReader = new StreamReader ( requestStream ) ;
43
+ if ( ! string . IsNullOrEmpty ( cursorValue ) )
44
+ options . cursor = cursorValue ;
48
45
49
- string result = requestStreamReader . ReadToEnd ( ) ;
46
+ var cursoredResult = dataSetApi . GetStreamWithHttpInfo ( "2.0" , "monitor" , options ) ;
50
47
51
- // Parse result to JSON format
52
- JObject resultJson = JObject . Parse ( result ) ;
53
- string endCursor = resultJson . GetValue ( "endCursor" ) . ToString ( ) ;
48
+ string endCursor = cursoredResult . Data . EndCursor ;
54
49
55
50
// If the endCursor from the response is the same as the one that you already have,
56
51
// it means that you have reached the end of the records
@@ -61,7 +56,7 @@ public virtual IEnumerable<Object> Invoke(string accessToken, string requestPath
61
56
else
62
57
{
63
58
cursorValue = endCursor ;
64
- functionResult . Add ( resultJson ) ;
59
+ functionResult . AddRange ( cursoredResult . Data . Data ) ;
65
60
}
66
61
}
67
62
while ( ! complete ) ;
0 commit comments