From 607795a20259aee233d621b8ffee412222d94873 Mon Sep 17 00:00:00 2001 From: Dmitry Popov Date: Mon, 7 Oct 2019 18:50:17 +0300 Subject: [PATCH] `lastModified` return value added to `IPassKitService.GetPassAsync`. --- PassKitHelper.Tests/PassKitMiddlewareTests_Passes.cs | 8 ++++---- PassKitHelper/IPassKitService.cs | 4 ++-- PassKitHelper/PassKitHelper.csproj | 4 ++-- PassKitHelper/PassKitMiddleware.cs | 8 +++++++- 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/PassKitHelper.Tests/PassKitMiddlewareTests_Passes.cs b/PassKitHelper.Tests/PassKitMiddlewareTests_Passes.cs index eb71ec5..8abc6b0 100644 --- a/PassKitHelper.Tests/PassKitMiddlewareTests_Passes.cs +++ b/PassKitHelper.Tests/PassKitMiddlewareTests_Passes.cs @@ -94,7 +94,7 @@ public async Task ServiceIsCalled() passkitServiceMock .Setup(x => x.GetPassAsync(passType, passSerial, authToken, null)) - .ReturnsAsync((200, obj)) + .ReturnsAsync((200, obj, DateTimeOffset.Now)) .Verifiable(); await middleware.InvokeAsync(httpContext); @@ -122,7 +122,7 @@ public async Task ServiceIsCalled_WithIfModifiedSince() passkitServiceMock .Setup(x => x.GetPassAsync(passType, passSerial, authToken, It.IsAny())) - .ReturnsAsync((304, null)) + .ReturnsAsync((304, null, null)) .Callback((x, y, z, d) => { actualDt = dt; }) .Verifiable(); @@ -140,7 +140,7 @@ public async Task ServiceIsCalled_Non200Result() { passkitServiceMock .Setup(x => x.GetPassAsync(passType, passSerial, authToken, null)) - .ReturnsAsync((304, null)) + .ReturnsAsync((304, null, null)) .Verifiable(); await middleware.InvokeAsync(httpContext); @@ -154,7 +154,7 @@ public async Task ExceptionThrownOnWrongServiceResult() { passkitServiceMock .Setup(x => x.GetPassAsync(passType, passSerial, authToken, null)) - .ReturnsAsync((200, null)) + .ReturnsAsync((200, null, null)) .Verifiable(); await Assert.ThrowsAsync(() => middleware.InvokeAsync(httpContext)); diff --git a/PassKitHelper/IPassKitService.cs b/PassKitHelper/IPassKitService.cs index db5b83f..63c9054 100644 --- a/PassKitHelper/IPassKitService.cs +++ b/PassKitHelper/IPassKitService.cs @@ -63,12 +63,12 @@ public interface IPassKitService /// Pass’s authorization token as specified in the pass. /// Return HTTP status code 304 if the pass has not changed. /// - /// If request is authorized, returns HTTP status 200 with a payload of the pass data (signed and built pass package). + /// If request is authorized, returns HTTP status 200 with a payload of the pass data (signed and built pass package, timestamp of last change). /// If the request is not authorized, returns HTTP status 401 (and null as pass data). /// If no data has changed since - return HTTP status code 304 (and null as pass data). /// Otherwise, returns the appropriate standard HTTP status (and null as pass data). /// - Task<(int statusCode, MemoryStream? passData)> GetPassAsync(string passTypeIdentifier, string serialNumber, string authorizationToken, DateTimeOffset? ifModifiedSince); + Task<(int statusCode, MemoryStream? passData, DateTimeOffset? lastModified)> GetPassAsync(string passTypeIdentifier, string serialNumber, string authorizationToken, DateTimeOffset? ifModifiedSince); /// /// Logging Errors. Log messages contain a description of the error in a human-readable format. diff --git a/PassKitHelper/PassKitHelper.csproj b/PassKitHelper/PassKitHelper.csproj index a31b314..0ea0423 100644 --- a/PassKitHelper/PassKitHelper.csproj +++ b/PassKitHelper/PassKitHelper.csproj @@ -12,11 +12,11 @@ git https://github.com/justdmitry/PassKitHelper https://github.com/justdmitry/PassKitHelper.git - 1.0.1 + 2.0.0 Helper library for all your Apple PassKit (Apple Wallet, Apple Passbook) needs: create passes, sign pass packages, receive webhooks into your aspnetcore app. Apple Developer Account required! apple passkit passbook pass webservice true - New: `PassKitMiddleware` and `IPassKitService` to easily build your webservice to comminucate with Apple server. + Breaking change: `lastModified` return value added to `IPassKitService.GetPassAsync`. diff --git a/PassKitHelper/PassKitMiddleware.cs b/PassKitHelper/PassKitMiddleware.cs index 821dce1..b2a0b5d 100644 --- a/PassKitHelper/PassKitMiddleware.cs +++ b/PassKitHelper/PassKitMiddleware.cs @@ -229,7 +229,7 @@ public async Task InvokePassesAsync(HttpContext context, PathString passesRemain } var service = context.RequestServices.GetRequiredService(); - var (status, pass) = await service.GetPassAsync(passTypeIdentifier, serialNumber, authorizationToken, ifModifiedSince); + var (status, pass, lastModified) = await service.GetPassAsync(passTypeIdentifier, serialNumber, authorizationToken, ifModifiedSince); if (status == StatusCodes.Status200OK) { @@ -238,6 +238,12 @@ public async Task InvokePassesAsync(HttpContext context, PathString passesRemain throw new Exception("GetPassAsync() must return non-null 'pass' when 'status' == 200"); } + if (!lastModified.HasValue) + { + throw new Exception("GetPassAsync() must return non-null 'lastModified' when 'status' == 200"); + } + + context.Response.Headers["Last-Modified"] = lastModified.Value.ToString("r"); context.Response.ContentType = PassPackageBuilder.PkpassMimeContentType; await pass.CopyToAsync(context.Response.Body); }