From 9fb16ecf1a611a8ef0bee2f0fc18922fdfa656cc Mon Sep 17 00:00:00 2001 From: Auston Bunsen Date: Mon, 30 Mar 2026 22:03:35 -0400 Subject: [PATCH] Flatten CreateTemplateRequest params to match API Replace nested Design/SupportInfo objects with flat fields (background_color, label_color, support_url, etc.) matching the API's template_params. Add Metadata field. Update README example and bump version to 1.3.0. --- AccessGridTest/AccessGridTest.csproj | 2 +- AccessGridTest/ConsoleServiceTests.cs | 66 ++++++++++++++++++++++++++- README.md | 30 ++++++------ src/AccessGrid.csproj | 2 +- src/AccessGrid/AccessGridClient.cs | 2 +- src/AccessGrid/Models.cs | 54 +++++++++++++++++++--- 6 files changed, 128 insertions(+), 28 deletions(-) diff --git a/AccessGridTest/AccessGridTest.csproj b/AccessGridTest/AccessGridTest.csproj index b61ae27..e959efc 100644 --- a/AccessGridTest/AccessGridTest.csproj +++ b/AccessGridTest/AccessGridTest.csproj @@ -1,6 +1,6 @@ - net8.0 + net10.0 enable enable false diff --git a/AccessGridTest/ConsoleServiceTests.cs b/AccessGridTest/ConsoleServiceTests.cs index be667cc..59ffa50 100644 --- a/AccessGridTest/ConsoleServiceTests.cs +++ b/AccessGridTest/ConsoleServiceTests.cs @@ -165,7 +165,8 @@ public async Task CreateTemplateAsync_ShouldPostAndReturnTemplate() "protocol": "desfire", "created_at": "2025-03-01T00:00:00Z", "issued_keys_count": 0, - "active_keys_count": 0 + "active_keys_count": 0, + "metadata": { "version": "2.1" } } """; StubHttpResponse(json); @@ -178,7 +179,20 @@ public async Task CreateTemplateAsync_ShouldPostAndReturnTemplate() Protocol = Protocol.DESFire, AllowOnMultipleDevices = true, WatchCount = 2, - IPhoneCount = 3 + IPhoneCount = 3, + BackgroundColor = "#FFFFFF", + LabelColor = "#000000", + LabelSecondaryColor = "#333333", + SupportUrl = "https://help.yourcompany.com", + SupportPhoneNumber = "+1-555-123-4567", + SupportEmail = "support@yourcompany.com", + PrivacyPolicyUrl = "https://yourcompany.com/privacy", + TermsAndConditionsUrl = "https://yourcompany.com/terms", + Metadata = new Dictionary + { + ["version"] = "2.1", + ["approval_status"] = "approved" + } }; var result = await _client.Console.CreateTemplateAsync(request); @@ -196,6 +210,54 @@ public async Task CreateTemplateAsync_ShouldPostAndReturnTemplate() )), Times.Once); } + [Test] + public async Task CreateTemplateAsync_SendsFlatDesignAndSupportParams() + { + var json = """ + { + "id": "tmpl-flat", + "name": "Flat Params Template", + "platform": "apple", + "use_case": "employee_badge", + "protocol": "desfire", + "metadata": { "version": "2.1" } + } + """; + + string capturedBody = null; + _mockHttpClient + .Setup(x => x.SendAsync(It.IsAny())) + .Returns(async req => + { + if (req.Content != null) + capturedBody = await req.Content.ReadAsStringAsync(); + return new HttpResponseMessage(HttpStatusCode.OK) + { + Content = new StringContent(json, Encoding.UTF8, "application/json") + }; + }); + + var request = new CreateTemplateRequest + { + Name = "Flat Params Template", + Platform = Platform.Apple, + UseCase = "employee_badge", + Protocol = Protocol.DESFire, + BackgroundColor = "#FFFFFF", + SupportUrl = "https://help.yourcompany.com", + Metadata = new Dictionary { ["version"] = "2.1" } + }; + + await _client.Console.CreateTemplateAsync(request); + + Assert.That(capturedBody, Is.Not.Null); + // Flat params should appear at root level, not nested under design/support_info + Assert.That(capturedBody, Does.Contain("background_color")); + Assert.That(capturedBody, Does.Contain("support_url")); + Assert.That(capturedBody, Does.Not.Contain("\"design\"")); + Assert.That(capturedBody, Does.Not.Contain("\"support_info\"")); + } + #endregion #region UpdateTemplateAsync diff --git a/README.md b/README.md index 6a7d1f8..9841a94 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ Official C# SDK for interacting with the AccessGrid API. ## Installation ``` -Install-Package accessgrid -Version 1.2.2 +Install-Package accessgrid -Version 1.3.0 ``` ## Authentication @@ -232,29 +232,25 @@ public async Task CreateTemplateAsync() var template = await client.Console.CreateTemplateAsync(new CreateTemplateRequest { - Name = "Employee NFC key", + Name = "Employee Access Pass", Platform = "apple", UseCase = "employee_badge", Protocol = "desfire", AllowOnMultipleDevices = true, WatchCount = 2, IPhoneCount = 3, - Design = new TemplateDesign + BackgroundColor = "#FFFFFF", + LabelColor = "#000000", + LabelSecondaryColor = "#333333", + SupportUrl = "https://help.yourcompany.com", + SupportPhoneNumber = "+1-555-123-4567", + SupportEmail = "support@yourcompany.com", + PrivacyPolicyUrl = "https://yourcompany.com/privacy", + TermsAndConditionsUrl = "https://yourcompany.com/terms", + Metadata = new Dictionary { - BackgroundColor = "#FFFFFF", - LabelColor = "#000000", - LabelSecondaryColor = "#333333", - BackgroundImage = "[image_in_base64_encoded_format]", - LogoImage = "[image_in_base64_encoded_format]", - IconImage = "[image_in_base64_encoded_format]" - }, - SupportInfo = new SupportInfo - { - SupportUrl = "https://help.yourcompany.com", - SupportPhoneNumber = "+1-555-123-4567", - SupportEmail = "support@yourcompany.com", - PrivacyPolicyUrl = "https://yourcompany.com/privacy", - TermsAndConditionsUrl = "https://yourcompany.com/terms" + ["version"] = "2.1", + ["approval_status"] = "approved" } }); diff --git a/src/AccessGrid.csproj b/src/AccessGrid.csproj index 27b2d5f..0673fbd 100644 --- a/src/AccessGrid.csproj +++ b/src/AccessGrid.csproj @@ -4,7 +4,7 @@ netstandard2.0 8.0 accessgrid - 1.2.2 + 1.3.0 AccessGrid AccessGrid Official C# SDK for the AccessGrid API diff --git a/src/AccessGrid/AccessGridClient.cs b/src/AccessGrid/AccessGridClient.cs index 6d06a8d..9e38899 100644 --- a/src/AccessGrid/AccessGridClient.cs +++ b/src/AccessGrid/AccessGridClient.cs @@ -19,7 +19,7 @@ public class AccessGridClient : IAccessGridClient, IApiService private readonly string _accountId; private readonly string _secretKey; private readonly JsonSerializerOptions _jsonOptions; - private const string Version = "1.0.0"; + private const string Version = "1.3.0"; /// /// Service for managing access cards diff --git a/src/AccessGrid/Models.cs b/src/AccessGrid/Models.cs index 7565ca8..82a7356 100644 --- a/src/AccessGrid/Models.cs +++ b/src/AccessGrid/Models.cs @@ -396,16 +396,58 @@ public class CreateTemplateRequest public int? IPhoneCount { get; set; } /// - /// Object representing card template design + /// Must be a 6 character hexadecimal value for the background color, i.e. #FFFFFF /// - [JsonPropertyName("design")] - public TemplateDesign Design { get; set; } + [JsonPropertyName("background_color")] + public string BackgroundColor { get; set; } /// - /// Information for users that shows up on the back of the NFC key + /// Must be a 6 character hexadecimal value for the label color, i.e. #000000 /// - [JsonPropertyName("support_info")] - public SupportInfo SupportInfo { get; set; } + [JsonPropertyName("label_color")] + public string LabelColor { get; set; } + + /// + /// Must be a 6 character hexadecimal value for the secondary label color, i.e. #333333 + /// + [JsonPropertyName("label_secondary_color")] + public string LabelSecondaryColor { get; set; } + + /// + /// Shows on the back of the issued NFC key + /// + [JsonPropertyName("support_url")] + public string SupportUrl { get; set; } + + /// + /// Shows on the back of the issued NFC key + /// + [JsonPropertyName("support_phone_number")] + public string SupportPhoneNumber { get; set; } + + /// + /// Shows on the back of the issued NFC key + /// + [JsonPropertyName("support_email")] + public string SupportEmail { get; set; } + + /// + /// Shows on the back of the issued NFC key + /// + [JsonPropertyName("privacy_policy_url")] + public string PrivacyPolicyUrl { get; set; } + + /// + /// Shows on the back of the issued NFC key + /// + [JsonPropertyName("terms_and_conditions_url")] + public string TermsAndConditionsUrl { get; set; } + + /// + /// Optional metadata key-value pairs + /// + [JsonPropertyName("metadata")] + public Dictionary Metadata { get; set; } } public class UpdateTemplateRequest