Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions AccessGridTest/ConsoleServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@
}
""";

string capturedBody = null;

Check warning on line 267 in AccessGridTest/ConsoleServiceTests.cs

View workflow job for this annotation

GitHub Actions / test (8.0.x)

Converting null literal or possible null value to non-nullable type.
_mockHttpClient
.Setup(x => x.SendAsync(It.IsAny<HttpRequestMessage>()))
.Returns<HttpRequestMessage>(async req =>
Expand Down Expand Up @@ -300,6 +300,32 @@

#endregion

#region PublishTemplateAsync

[Test]
public async Task PublishTemplateAsync_PostsToPublishEndpointAndReturnsStatus()
{
var json = """
{
"id": "tmpl-123",
"status": "in-review"
}
""";
StubHttpResponse(json);

var result = await _client.Console.PublishTemplateAsync("tmpl-123");

Assert.That(result.Id, Is.EqualTo("tmpl-123"));
Assert.That(result.Status, Is.EqualTo("in-review"));

_mockHttpClient.Verify(x => x.SendAsync(It.Is<HttpRequestMessage>(req =>
req.Method == HttpMethod.Post &&
req.RequestUri!.ToString().Contains("/v1/console/card-templates/tmpl-123/publish")
)), Times.Once);
}

#endregion

#region UpdateTemplateAsync

[Test]
Expand Down Expand Up @@ -349,7 +375,7 @@
{
var json = """{ "id": "tmpl-123", "name": "Test" }""";

string capturedBody = null;

Check warning on line 378 in AccessGridTest/ConsoleServiceTests.cs

View workflow job for this annotation

GitHub Actions / test (8.0.x)

Converting null literal or possible null value to non-nullable type.
_mockHttpClient
.Setup(x => x.SendAsync(It.IsAny<HttpRequestMessage>()))
.Returns<HttpRequestMessage>(async req =>
Expand Down
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,27 @@ public async Task ReadTemplateAsync()
}
```

### Publishing a Card Template

```csharp
using AccessGrid;
using System;
using System.Threading.Tasks;

public async Task PublishTemplateAsync()
{
var accountId = Environment.GetEnvironmentVariable("ACCOUNT_ID");
var secretKey = Environment.GetEnvironmentVariable("SECRET_KEY");

using var client = new AccessGridClient(accountId, secretKey);

var result = await client.Console.PublishTemplateAsync("0xd3adb00b5");

Console.WriteLine($"Template ID: {result.Id}");
Console.WriteLine($"Status: {result.Status}");
}
```

### Reading Event Logs

```csharp
Expand Down Expand Up @@ -1069,6 +1090,7 @@ public class AccessCardsApiTests
| POST /v1/console/card-templates | `Console.CreateTemplateAsync()` | Y |
| PUT /v1/console/card-templates/{id} | `Console.UpdateTemplateAsync()` | Y |
| GET /v1/console/card-templates/{id} | `Console.ReadTemplateAsync()` | Y |
| POST /v1/console/card-templates/{id}/publish | `Console.PublishTemplateAsync()` | Y |
| GET /v1/console/card-templates/{id}/logs | `Console.EventLogAsync()` | Y |
| GET /v1/console/card-template-pairs | `Console.ListPassTemplatePairsAsync()` | Y |
| POST /v1/console/card-template-pairs | `Console.CreatePassTemplatePairAsync()` | Y |
Expand Down
11 changes: 11 additions & 0 deletions src/AccessGrid/ConsoleService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,17 @@ public async Task<Template> ReadTemplateAsync(string templateId)
return response;
}

/// <summary>
/// Publishes a card template (enterprise only)
/// </summary>
/// <param name="templateId">Unique identifier for the card template to publish</param>
/// <returns>Template id and resulting status</returns>
public async Task<PublishTemplateResponse> PublishTemplateAsync(string templateId)
{
var response = await _apiService.PostAsync<PublishTemplateResponse>($"/v1/console/card-templates/{templateId}/publish", null);
return response;
}

/// <summary>
/// Gets event logs for a card template (enterprise only)
/// </summary>
Expand Down
12 changes: 12 additions & 0 deletions src/AccessGrid/Models.cs
Original file line number Diff line number Diff line change
Expand Up @@ -806,6 +806,18 @@ public class LedgerItemsResponse
public PaginationInfo Pagination { get; set; }
}

/// <summary>
/// Response from publishing a card template
/// </summary>
public class PublishTemplateResponse
{
[JsonPropertyName("id")]
public string Id { get; set; }

[JsonPropertyName("status")]
public string Status { get; set; }
}

/// <summary>
/// iOS In-App Provisioning preflight response
/// </summary>
Expand Down
Loading