diff --git a/src/ComDiadocApi.cs b/src/ComDiadocApi.cs index f98cc2a0..be32df72 100644 --- a/src/ComDiadocApi.cs +++ b/src/ComDiadocApi.cs @@ -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, diff --git a/src/DiadocApi.Async.cs b/src/DiadocApi.Async.cs index 59d1a901..230a4b34 100644 --- a/src/DiadocApi.Async.cs +++ b/src/DiadocApi.Async.cs @@ -1190,5 +1190,12 @@ public Task DetectCustomPrintFormsAsync(string a if (request == null) throw new ArgumentNullException("request"); return diadocHttpApi.DetectCustomPrintFormsAsync(authToken, boxId, request); } + + public Task GetLastEventAsync(string authToken, string boxId) + { + if(authToken == null) throw new ArgumentNullException("authToken"); + if(boxId == null) throw new ArgumentNullException("boxId"); + return diadocHttpApi.GetLastEventAsync(authToken, boxId); + } } } \ No newline at end of file diff --git a/src/DiadocApi.cs b/src/DiadocApi.cs index b3003ea6..b12a85dc 100644 --- a/src/DiadocApi.cs +++ b/src/DiadocApi.cs @@ -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); + } } } \ No newline at end of file diff --git a/src/DiadocHttpApi.Async.cs b/src/DiadocHttpApi.Async.cs index e932f7af..90fc23e9 100644 --- a/src/DiadocHttpApi.Async.cs +++ b/src/DiadocHttpApi.Async.cs @@ -1,4 +1,5 @@ using System; +using System.Net; using System.Threading.Tasks; using Diadoc.Api.Proto.Events; using JetBrains.Annotations; @@ -22,17 +23,28 @@ protected Task PerformHttpRequestAsync([CanBeNul } [ItemNotNull] - protected Task PerformHttpRequestAsync([CanBeNull] string token, [NotNull] string method, [NotNull] string queryString, [CanBeNull] byte[] requestBody = null) + protected Task PerformHttpRequestAsync( + [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); + return PerformHttpRequestAsync(token, method, queryString, requestBody, Deserialize, allowStatusCodes); } [ItemNotNull] - protected async Task PerformHttpRequestAsync([CanBeNull] string token, [NotNull] string method, [NotNull] string queryString, [CanBeNull] byte[] requestBody, [NotNull] Func convertResponse) + protected async Task PerformHttpRequestAsync( + [CanBeNull] string token, + [NotNull] string method, + [NotNull] string queryString, + [CanBeNull] byte[] requestBody, + [NotNull] Func 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); } diff --git a/src/DiadocHttpApi.Events.cs b/src/DiadocHttpApi.Events.cs index ab9bc91f..2fe385e7 100644 --- a/src/DiadocHttpApi.Events.cs +++ b/src/DiadocHttpApi.Events.cs @@ -1,4 +1,5 @@ -using Diadoc.Api.Http; +using System.Net; +using Diadoc.Api.Http; using Diadoc.Api.Proto.Events; namespace Diadoc.Api @@ -95,5 +96,11 @@ public PrepareDocumentsToSignResponse PrepareDocumentsToSign(string authToken, P var queryString = "/PrepareDocumentsToSign" + (excludeContent ? "?excludeContent" : ""); return PerformHttpRequest(authToken, queryString, request); } + + public BoxEvent GetLastEvent(string authToken, string boxId) + { + var queryString = BuildQueryStringWithBoxId("GetLastEvent", boxId); + return PerformHttpRequest(authToken,"GET", queryString, allowedStatusCodes: HttpStatusCode.NoContent); + } } } diff --git a/src/DiadocHttpApi.EventsAsync.cs b/src/DiadocHttpApi.EventsAsync.cs index edfb10ae..2205d18f 100644 --- a/src/DiadocHttpApi.EventsAsync.cs +++ b/src/DiadocHttpApi.EventsAsync.cs @@ -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 { @@ -108,5 +110,12 @@ public Task PrepareDocumentsToSignAsync(string a var queryString = "/PrepareDocumentsToSign" + (excludeContent ? "?excludeContent" : ""); return PerformHttpRequestAsync(authToken, queryString, request); } + + [NotNull] + public Task GetLastEventAsync([NotNull] string authToken, [NotNull] string boxId) + { + var queryString = BuildQueryStringWithBoxId("GetLastEvent", boxId); + return PerformHttpRequestAsync(authToken,"GET", queryString, allowStatusCodes: HttpStatusCode.NoContent); + } } } diff --git a/src/DiadocHttpApi.cs b/src/DiadocHttpApi.cs index 758988a1..d05e5b07 100644 --- a/src/DiadocHttpApi.cs +++ b/src/DiadocHttpApi.cs @@ -1,4 +1,5 @@ using System; +using System.Net; using System.Text; using Diadoc.Api.Cryptography; using Diadoc.Api.Http; @@ -52,20 +53,28 @@ protected TResponse PerformHttpRequest([CanBeNull] string t } [NotNull] - protected TResponse PerformHttpRequest([CanBeNull] string token, [NotNull] string method, - [NotNull] string queryString, [CanBeNull] byte[] requestBody = null) - where TResponse : class + protected TResponse PerformHttpRequest( + [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); + return PerformHttpRequest(token, method, queryString, requestBody, Deserialize, allowedStatusCodes); } [NotNull] - protected TResponse PerformHttpRequest([CanBeNull] string token, [NotNull] string method, - [NotNull] string queryString, [CanBeNull] byte[] requestBody, - [NotNull] Func convertResponse) + protected TResponse PerformHttpRequest( + [CanBeNull] string token, + [NotNull] string method, + [NotNull] string queryString, + [CanBeNull] byte[] requestBody, + [NotNull] Func 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); } diff --git a/src/IDiadocApi.cs b/src/IDiadocApi.cs index cc23bd04..8b2d7216 100644 --- a/src/IDiadocApi.cs +++ b/src/IDiadocApi.cs @@ -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 AuthenticateAsync(string login, string password, string key = null, string id = null); @@ -428,6 +430,7 @@ Task WaitAutosignReceiptsResultAsync(string authToken, s Task RegisterAsync(string authToken, RegistrationRequest registrationRequest); Task RegisterConfirmAsync(string authToken, RegistrationConfirmRequest registrationConfirmRequest); Task DetectCustomPrintFormsAsync(string authToken, string boxId, CustomPrintFormDetectionRequest request); + Task GetLastEventAsync(string authToken, string boxId); #endif } } \ No newline at end of file