Skip to content

Latest commit

 

History

History
106 lines (76 loc) · 3.11 KB

File metadata and controls

106 lines (76 loc) · 3.11 KB

GitHub codecov NuGet NuGet

Zammad.Client.SystemTextJson

A hard fork of Zammad.Client with support for System.Text.Json instead of Newtonsoft.Json.

This library provides a .NET client for interacting with the Zammad helpdesk system API.

Installation

dotnet add package Zammad.Client.SystemTextJson

Usage

Basic example:

var httpClient = new HttpClient();
var client = new ZammadClient(
    httpClient,
    Options.Create(new ZammadOptions
    {
        BaseUrl = new Uri("https://zammad.example.com/"),
        Token = "your_token_here",
    })
);

var user = await client.GetUserMeAsync();
Console.WriteLine($"Signed in as {user.FirstName} {user.LastName} ({user.Email})");

Dependency Injection

Install the extensions package:

dotnet add package Zammad.Client.SystemTextJson.Extensions

Configure the client:

builder.Services.AddZammadClient(options =>
{
    options.BaseUrl = new Uri("https://zammad.example.com/");
    options.Token = "your_token_here";
});

Alternatively, use a configuration section:

builder.Services.AddZammadClient(builder.Configuration.GetSection("Zammad"));

Then inject the client:

public class MyService(IZammadClient client)
{
    public async Task DoSomething()
     {
         var user = await client.GetUserMeAsync();
         Console.WriteLine($"Signed in as {user.FirstName} {user.LastName} ({user.Email})");
     }
}

HttpClient Customization

The AddZammadClient method returns an IHttpClientBuilder, allowing further customization of the underlying HttpClient. For example, to add a resilience handler:

dotnet add package Microsoft.Extensions.Http.Resilience
builder.Services.AddZammadClient(builder.Configuration.GetSection("Zammad"))
    .AddStandardResilienceHandler();

This configuration will automatically handle transient errors, making your application more robust.

Contributing

Pull requests are welcome. Please use Conventional Commits to keep commit messages consistent.

Please consider adding tests for any new features or bug fixes.

Acknowledgements

License

Distributed under the Apache License 2.0. See LICENSE for more information.