Skip to content

YuHima03/dotnet-traq

Repository files navigation

dotnet-traq

.NET client library for the traQ API.

The source code is generated from the OpenAPI Spec for the traQ API by Microsoft Kiota.

How to Use

Use in Generic Host

An extension method for the IServiceCollection type can be used.

In the sample code below, an instance of the TraqApiClient class configured by environment variables (TRAQ_BASE_ADDRESS and TRAQ_ACCESS_TOKEN) is added to the service collection.

var host = Host.CreateDefaultApplication(args)
    .ConfigureServices((ctx, services) =>
    {
        services.AddTraqApiClient(options =>
        {
            var conf = ctx.Configuration;
            options.BaseAddress = conf["TRAQ_BASE_ADDRESS"];
            options.BearerAuthToken = conf["TRAQ_ACCESS_TOKEN"];
        });
    })
    .Build();

host.Run();

You can also separate configurator from the AddTraqApiClient method by using parameterless method. In the following code, the added TraqApiClient automatically use configured TraqApiClientOptions.

var host = Host.CreateDefaultApplication(args)
    .ConfigureServices((ctx, services) =>
    {
        services.Configure<TraqApiClientOptions>(ctx.Configuration);
        services.AddTraqApiClient();
    })
    .Build();

host.Run();

Configure Options

The TraqApiClientOptions class is used to configure the TraqApiClient instance.

You must fill the BaseAddress property to access the traQ API.

You can also set the BearerAuthToken, CookieAuthToken, and AuthMethodPreference properties to configure authentication.

Create API Client Manually

The CreateFromOptions method in the TraqApiClientHelper class is useful to create a new instance of the TraqApiClient class with specified options.

TraqApiClientOptions options = new()
{
    BaseAddress = "Base address of the traQ API",
    BearerAuthToken = "Bearer authentication token"
}
var client = TraqApiClientHelper.CreateFromOptions(options);

The TraqApiClient class implements Microsoft.Kiota.Abstractions.BaseRequestBuilder so that you can manually manage methods to access the traQ API.

For more information, please check Kiota Official Documentation.

Source Generation

Docker and Task are required for source generation.

To generate API client for certain version of traQ, set it to the TRAQ_TAG_NAME variable and run task gen or task generate-client.

The following command generates API client for traQ v3.27.0.

TRAQ_TAG_NAME="v3.27.0" task gen

About

Third party .NET client library for the traQ API.

Topics

Resources

License

Stars

Watchers

Forks

Contributors 2

  •  
  •  

Languages