Skip to content

Commit

Permalink
lastModified return value added to IPassKitService.GetPassAsync.
Browse files Browse the repository at this point in the history
  • Loading branch information
justdmitry committed Oct 7, 2019
1 parent 112f37e commit 607795a
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
8 changes: 4 additions & 4 deletions PassKitHelper.Tests/PassKitMiddlewareTests_Passes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -122,7 +122,7 @@ public async Task ServiceIsCalled_WithIfModifiedSince()

passkitServiceMock
.Setup(x => x.GetPassAsync(passType, passSerial, authToken, It.IsAny<DateTimeOffset?>()))
.ReturnsAsync((304, null))
.ReturnsAsync((304, null, null))
.Callback<string, string, string, DateTimeOffset?>((x, y, z, d) => { actualDt = dt; })
.Verifiable();

Expand All @@ -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);
Expand All @@ -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<Exception>(() => middleware.InvokeAsync(httpContext));
Expand Down
4 changes: 2 additions & 2 deletions PassKitHelper/IPassKitService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@ public interface IPassKitService
/// <param name="authorizationToken">Pass’s authorization token as specified in the pass.</param>
/// <param name="ifModifiedSince">Return HTTP status code 304 if the pass has not changed.</param>
/// <returns>
/// 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 <see cref="ifModifiedSince"/> - return HTTP status code 304 (and null as pass data).
/// Otherwise, returns the appropriate standard HTTP status (and null as pass data).
/// </returns>
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);

/// <summary>
/// Logging Errors. Log messages contain a description of the error in a human-readable format.
Expand Down
4 changes: 2 additions & 2 deletions PassKitHelper/PassKitHelper.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
<RepositoryType>git</RepositoryType>
<PackageProjectUrl>https://github.com/justdmitry/PassKitHelper</PackageProjectUrl>
<RepositoryUrl>https://github.com/justdmitry/PassKitHelper.git</RepositoryUrl>
<Version>1.0.1</Version>
<Version>2.0.0</Version>
<Description>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!</Description>
<PackageTags>apple passkit passbook pass webservice</PackageTags>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageReleaseNotes>New: `PassKitMiddleware` and `IPassKitService` to easily build your webservice to comminucate with Apple server.</PackageReleaseNotes>
<PackageReleaseNotes>Breaking change: `lastModified` return value added to `IPassKitService.GetPassAsync`.</PackageReleaseNotes>
</PropertyGroup>

<ItemGroup>
Expand Down
8 changes: 7 additions & 1 deletion PassKitHelper/PassKitMiddleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ public async Task InvokePassesAsync(HttpContext context, PathString passesRemain
}

var service = context.RequestServices.GetRequiredService<IPassKitService>();
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)
{
Expand All @@ -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);
}
Expand Down

0 comments on commit 607795a

Please sign in to comment.