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
2 changes: 1 addition & 1 deletion AccessGridTest/AccessGridTest.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
Expand Down
111 changes: 108 additions & 3 deletions AccessGridTest/ConsoleServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,8 @@
"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);
Expand All @@ -178,7 +179,20 @@
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<string, object>
{
["version"] = "2.1",
["approval_status"] = "approved"
}
};

var result = await _client.Console.CreateTemplateAsync(request);
Expand All @@ -196,6 +210,54 @@
)), 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;

Check warning on line 227 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 =>
{
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<string, object> { ["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
Expand All @@ -220,7 +282,15 @@
Name = "Updated Badge",
AllowOnMultipleDevices = false,
WatchCount = 1,
IPhoneCount = 2
IPhoneCount = 2,
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"
};

var result = await _client.Console.UpdateTemplateAsync(request);
Expand All @@ -234,6 +304,41 @@
)), Times.Once);
}

[Test]
public async Task UpdateTemplateAsync_SendsFlatDesignAndSupportParams()
{
var json = """{ "id": "tmpl-123", "name": "Test" }""";

string capturedBody = null;

Check warning on line 312 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 =>
{
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 UpdateTemplateRequest
{
CardTemplateId = "tmpl-123",
Name = "Test",
BackgroundColor = "#FFFFFF",
SupportUrl = "https://help.yourcompany.com"
};

await _client.Console.UpdateTemplateAsync(request);

Assert.That(capturedBody, Is.Not.Null);
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 ReadTemplateAsync
Expand Down
48 changes: 22 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<string, object>
{
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"
}
});

Expand All @@ -280,18 +276,18 @@ public async Task UpdateTemplateAsync()
new UpdateTemplateRequest
{
CardTemplateId = "0xd3adb00b5",
Name = "Updated Employee NFC key",
Name = "Updated Employee Access Pass",
AllowOnMultipleDevices = true,
WatchCount = 2,
IPhoneCount = 3,
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"
}
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"
}
);

Expand Down
2 changes: 1 addition & 1 deletion src/AccessGrid.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFramework>netstandard2.0</TargetFramework>
<LangVersion>8.0</LangVersion>
<PackageId>accessgrid</PackageId>
<Version>1.2.2</Version>
<Version>1.3.0</Version>
<Authors>AccessGrid</Authors>
<Company>AccessGrid</Company>
<Description>Official C# SDK for the AccessGrid API</Description>
Expand Down
2 changes: 1 addition & 1 deletion src/AccessGrid/AccessGridClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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";

/// <summary>
/// Service for managing access cards
Expand Down
102 changes: 93 additions & 9 deletions src/AccessGrid/Models.cs
Original file line number Diff line number Diff line change
Expand Up @@ -396,16 +396,58 @@ public class CreateTemplateRequest
public int? IPhoneCount { get; set; }

/// <summary>
/// Object representing card template design
/// Must be a 6 character hexadecimal value for the background color, i.e. #FFFFFF
/// </summary>
[JsonPropertyName("design")]
public TemplateDesign Design { get; set; }
[JsonPropertyName("background_color")]
public string BackgroundColor { get; set; }

/// <summary>
/// Must be a 6 character hexadecimal value for the label color, i.e. #000000
/// </summary>
[JsonPropertyName("label_color")]
public string LabelColor { get; set; }

/// <summary>
/// Must be a 6 character hexadecimal value for the secondary label color, i.e. #333333
/// </summary>
[JsonPropertyName("label_secondary_color")]
public string LabelSecondaryColor { get; set; }

/// <summary>
/// Information for users that shows up on the back of the NFC key
/// Shows on the back of the issued NFC key
/// </summary>
[JsonPropertyName("support_info")]
public SupportInfo SupportInfo { get; set; }
[JsonPropertyName("support_url")]
public string SupportUrl { get; set; }

/// <summary>
/// Shows on the back of the issued NFC key
/// </summary>
[JsonPropertyName("support_phone_number")]
public string SupportPhoneNumber { get; set; }

/// <summary>
/// Shows on the back of the issued NFC key
/// </summary>
[JsonPropertyName("support_email")]
public string SupportEmail { get; set; }

/// <summary>
/// Shows on the back of the issued NFC key
/// </summary>
[JsonPropertyName("privacy_policy_url")]
public string PrivacyPolicyUrl { get; set; }

/// <summary>
/// Shows on the back of the issued NFC key
/// </summary>
[JsonPropertyName("terms_and_conditions_url")]
public string TermsAndConditionsUrl { get; set; }

/// <summary>
/// Optional metadata key-value pairs
/// </summary>
[JsonPropertyName("metadata")]
public Dictionary<string, object> Metadata { get; set; }
}

public class UpdateTemplateRequest
Expand Down Expand Up @@ -441,10 +483,52 @@ public class UpdateTemplateRequest
public int? IPhoneCount { get; set; }

/// <summary>
/// Information for users that shows up on the back of the NFC key
/// Must be a 6 character hexadecimal value for the background color, i.e. #FFFFFF
/// </summary>
[JsonPropertyName("background_color")]
public string BackgroundColor { get; set; }

/// <summary>
/// Must be a 6 character hexadecimal value for the label color, i.e. #000000
/// </summary>
[JsonPropertyName("label_color")]
public string LabelColor { get; set; }

/// <summary>
/// Must be a 6 character hexadecimal value for the secondary label color, i.e. #333333
/// </summary>
[JsonPropertyName("support_info")]
public SupportInfo SupportInfo { get; set; }
[JsonPropertyName("label_secondary_color")]
public string LabelSecondaryColor { get; set; }

/// <summary>
/// Shows on the back of the issued NFC key
/// </summary>
[JsonPropertyName("support_url")]
public string SupportUrl { get; set; }

/// <summary>
/// Shows on the back of the issued NFC key
/// </summary>
[JsonPropertyName("support_phone_number")]
public string SupportPhoneNumber { get; set; }

/// <summary>
/// Shows on the back of the issued NFC key
/// </summary>
[JsonPropertyName("support_email")]
public string SupportEmail { get; set; }

/// <summary>
/// Shows on the back of the issued NFC key
/// </summary>
[JsonPropertyName("privacy_policy_url")]
public string PrivacyPolicyUrl { get; set; }

/// <summary>
/// Shows on the back of the issued NFC key
/// </summary>
[JsonPropertyName("terms_and_conditions_url")]
public string TermsAndConditionsUrl { get; set; }
}

public class EventLogFilters
Expand Down
Loading