Skip to content

Commit

Permalink
Merge pull request #533 from ThisIsBuddyRIch/get-last-event-method
Browse files Browse the repository at this point in the history
add get last event method
  • Loading branch information
ThisIsBuddyRIch authored Aug 16, 2019
2 parents 2c3cdcd + e538e33 commit 3008749
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 14 deletions.
5 changes: 5 additions & 0 deletions src/ComDiadocApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1520,6 +1520,11 @@ public byte[] ParseTitleXml(

#endregion

public BoxEvent GetLastEvent(string token, string boxId)
{
return diadoc.GetLastEvent(token, boxId);
}

public CustomPrintFormDetectionResult DetectCustomPrintForms(
string authToken,
string boxId,
Expand Down
7 changes: 7 additions & 0 deletions src/DiadocApi.Async.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1190,5 +1190,12 @@ public Task<CustomPrintFormDetectionResult> DetectCustomPrintFormsAsync(string a
if (request == null) throw new ArgumentNullException("request");
return diadocHttpApi.DetectCustomPrintFormsAsync(authToken, boxId, request);
}

public Task<BoxEvent> GetLastEventAsync(string authToken, string boxId)
{
if(authToken == null) throw new ArgumentNullException("authToken");
if(boxId == null) throw new ArgumentNullException("boxId");
return diadocHttpApi.GetLastEventAsync(authToken, boxId);
}
}
}
7 changes: 7 additions & 0 deletions src/DiadocApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1266,5 +1266,12 @@ public CustomPrintFormDetectionResult DetectCustomPrintForms(
if (request == null) throw new ArgumentNullException("request");
return diadocHttpApi.DetectCustomPrintForms(authToken, boxId, request);
}

public BoxEvent GetLastEvent(string authToken, string boxId)
{
if(authToken == null) throw new ArgumentNullException("authToken");
if(boxId == null) throw new ArgumentNullException("boxId");
return diadocHttpApi.GetLastEvent(authToken, boxId);
}
}
}
20 changes: 16 additions & 4 deletions src/DiadocHttpApi.Async.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Net;
using System.Threading.Tasks;
using Diadoc.Api.Proto.Events;
using JetBrains.Annotations;
Expand All @@ -22,17 +23,28 @@ protected Task<TResponse> PerformHttpRequestAsync<TRequest, TResponse>([CanBeNul
}

[ItemNotNull]
protected Task<TResponse> PerformHttpRequestAsync<TResponse>([CanBeNull] string token, [NotNull] string method, [NotNull] string queryString, [CanBeNull] byte[] requestBody = null)
protected Task<TResponse> PerformHttpRequestAsync<TResponse>(
[CanBeNull] string token,
[NotNull] string method,
[NotNull] string queryString,
[CanBeNull] byte[] requestBody = null,
params HttpStatusCode[] allowStatusCodes)
where TResponse: class
{
return PerformHttpRequestAsync(token, method, queryString, requestBody, Deserialize<TResponse>);
return PerformHttpRequestAsync(token, method, queryString, requestBody, Deserialize<TResponse>, allowStatusCodes);
}

[ItemNotNull]
protected async Task<TResponse> PerformHttpRequestAsync<TResponse>([CanBeNull] string token, [NotNull] string method, [NotNull] string queryString, [CanBeNull] byte[] requestBody, [NotNull] Func<byte[], TResponse> convertResponse)
protected async Task<TResponse> PerformHttpRequestAsync<TResponse>(
[CanBeNull] string token,
[NotNull] string method,
[NotNull] string queryString,
[CanBeNull] byte[] requestBody,
[NotNull] Func<byte[], TResponse> convertResponse,
params HttpStatusCode[] allowStatusCodes)
{
var request = BuildHttpRequest(token, method, queryString, requestBody);
var response = await HttpClient.PerformHttpRequestAsync(request).ConfigureAwait(false);
var response = await HttpClient.PerformHttpRequestAsync(request, allowStatusCodes).ConfigureAwait(false);
return DeserializeResponse(request, response, convertResponse);
}

Expand Down
9 changes: 8 additions & 1 deletion src/DiadocHttpApi.Events.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Diadoc.Api.Http;
using System.Net;
using Diadoc.Api.Http;
using Diadoc.Api.Proto.Events;

namespace Diadoc.Api
Expand Down Expand Up @@ -95,5 +96,11 @@ public PrepareDocumentsToSignResponse PrepareDocumentsToSign(string authToken, P
var queryString = "/PrepareDocumentsToSign" + (excludeContent ? "?excludeContent" : "");
return PerformHttpRequest<PrepareDocumentsToSignRequest, PrepareDocumentsToSignResponse>(authToken, queryString, request);
}

public BoxEvent GetLastEvent(string authToken, string boxId)
{
var queryString = BuildQueryStringWithBoxId("GetLastEvent", boxId);
return PerformHttpRequest<BoxEvent>(authToken,"GET", queryString, allowedStatusCodes: HttpStatusCode.NoContent);
}
}
}
11 changes: 10 additions & 1 deletion src/DiadocHttpApi.EventsAsync.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System.Threading.Tasks;
using System.Net;
using System.Threading.Tasks;
using Diadoc.Api.Http;
using Diadoc.Api.Proto.Events;
using JetBrains.Annotations;

namespace Diadoc.Api
{
Expand Down Expand Up @@ -108,5 +110,12 @@ public Task<PrepareDocumentsToSignResponse> PrepareDocumentsToSignAsync(string a
var queryString = "/PrepareDocumentsToSign" + (excludeContent ? "?excludeContent" : "");
return PerformHttpRequestAsync<PrepareDocumentsToSignRequest, PrepareDocumentsToSignResponse>(authToken, queryString, request);
}

[NotNull]
public Task<BoxEvent> GetLastEventAsync([NotNull] string authToken, [NotNull] string boxId)
{
var queryString = BuildQueryStringWithBoxId("GetLastEvent", boxId);
return PerformHttpRequestAsync<BoxEvent>(authToken,"GET", queryString, allowStatusCodes: HttpStatusCode.NoContent);
}
}
}
25 changes: 17 additions & 8 deletions src/DiadocHttpApi.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Net;
using System.Text;
using Diadoc.Api.Cryptography;
using Diadoc.Api.Http;
Expand Down Expand Up @@ -52,20 +53,28 @@ protected TResponse PerformHttpRequest<TRequest, TResponse>([CanBeNull] string t
}

[NotNull]
protected TResponse PerformHttpRequest<TResponse>([CanBeNull] string token, [NotNull] string method,
[NotNull] string queryString, [CanBeNull] byte[] requestBody = null)
where TResponse : class
protected TResponse PerformHttpRequest<TResponse>(
[CanBeNull] string token,
[NotNull] string method,
[NotNull] string queryString,
[CanBeNull] byte[] requestBody = null,
params HttpStatusCode[] allowedStatusCodes)
where TResponse: class
{
return PerformHttpRequest(token, method, queryString, requestBody, Deserialize<TResponse>);
return PerformHttpRequest(token, method, queryString, requestBody, Deserialize<TResponse>, allowedStatusCodes);
}

[NotNull]
protected TResponse PerformHttpRequest<TResponse>([CanBeNull] string token, [NotNull] string method,
[NotNull] string queryString, [CanBeNull] byte[] requestBody,
[NotNull] Func<byte[], TResponse> convertResponse)
protected TResponse PerformHttpRequest<TResponse>(
[CanBeNull] string token,
[NotNull] string method,
[NotNull] string queryString,
[CanBeNull] byte[] requestBody,
[NotNull] Func<byte[], TResponse> convertResponse,
params HttpStatusCode[] allowedStatusCodes)
{
var request = BuildHttpRequest(token, method, queryString, requestBody);
var response = HttpClient.PerformHttpRequest(request);
var response = HttpClient.PerformHttpRequest(request, allowedStatusCodes);
return DeserializeResponse(request, response, convertResponse);
}

Expand Down
3 changes: 3 additions & 0 deletions src/IDiadocApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,8 @@ byte[] ParseTitleXml(
RegistrationResponse Register(string authToken, RegistrationRequest registrationRequest);
void RegisterConfirm(string authToken, RegistrationConfirmRequest registrationConfirmRequest);
CustomPrintFormDetectionResult DetectCustomPrintForms(string authToken, string boxId, CustomPrintFormDetectionRequest request);
BoxEvent GetLastEvent(string authToken, string boxId);

#if !NET35

Task<string> AuthenticateAsync(string login, string password, string key = null, string id = null);
Expand Down Expand Up @@ -428,6 +430,7 @@ Task<AutosignReceiptsResult> WaitAutosignReceiptsResultAsync(string authToken, s
Task<RegistrationResponse> RegisterAsync(string authToken, RegistrationRequest registrationRequest);
Task RegisterConfirmAsync(string authToken, RegistrationConfirmRequest registrationConfirmRequest);
Task<CustomPrintFormDetectionResult> DetectCustomPrintFormsAsync(string authToken, string boxId, CustomPrintFormDetectionRequest request);
Task<BoxEvent> GetLastEventAsync(string authToken, string boxId);
#endif
}
}

0 comments on commit 3008749

Please sign in to comment.