11using System ;
22using 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 ;
76
87namespace DocuSign . CodeExamples . Monitor . Examples
98{
@@ -17,40 +16,36 @@ public class GetMonitoringDataFunc
1716 /// <returns>The list of JObjects, containing data from monitor</returns>
1817 public virtual IEnumerable < Object > Invoke ( string accessToken , string requestPath )
1918 {
19+ ApiClient apiClient = new ApiClient ( ApiClient . Demo_REST_BasePath ) ;
20+
2021 // Construct API headers
2122 // 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" ) ;
2526 // step 2 end
2627
2728 // Declare variables
2829 // step 3 start
2930 bool complete = false ;
3031 string cursorValue = "" ;
3132 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 ;
3339
3440 // Get monitoring data
3541 do
3642 {
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 ;
4845
49- string result = requestStreamReader . ReadToEnd ( ) ;
46+ var cursoredResult = dataSetApi . GetStreamWithHttpInfo ( "2.0" , "monitor" , options ) ;
5047
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 ;
5449
5550 // If the endCursor from the response is the same as the one that you already have,
5651 // it means that you have reached the end of the records
@@ -61,7 +56,7 @@ public virtual IEnumerable<Object> Invoke(string accessToken, string requestPath
6156 else
6257 {
6358 cursorValue = endCursor ;
64- functionResult . Add ( resultJson ) ;
59+ functionResult . AddRange ( cursoredResult . Data . Data ) ;
6560 }
6661 }
6762 while ( ! complete ) ;
0 commit comments