OnCourse.Kami
2.0.0
dotnet add package OnCourse.Kami --version 2.0.0
NuGet\Install-Package OnCourse.Kami -Version 2.0.0
<PackageReference Include="OnCourse.Kami" Version="2.0.0" />
paket add OnCourse.Kami --version 2.0.0
#r "nuget: OnCourse.Kami, 2.0.0"
// Install OnCourse.Kami as a Cake Addin #addin nuget:?package=OnCourse.Kami&version=2.0.0 // Install OnCourse.Kami as a Cake Tool #tool nuget:?package=OnCourse.Kami&version=2.0.0
OnCourse.Kami
OnCourse.Kami is a .NET SDK library used to communicate with the Kami API
✔ Features
Kami API library helps to generate requests for the following services:
- Embedding
- Uploads
- Documents
- View Sessions
- Exporting
⭐ Installation
This project is a class library built for compatibility all the back to .NET Standard 2.0.
To install the OnCourse.Kami NuGet package, run the following command via the dotnet CLI
dotnet add package OnCourse.Kami
Or run the following command in the Package Manager Console of Visual Studio
PM> Install-Package OnCourse.Kami
📕 General Usage
Initialization
To use Kami, import the namespace and include the .AddKami() method when initializing the host builder (typically found in the Program.cs file)
using Kami;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddKamiClient(builder.Configuration);
...
var app = builder.Build();
Fault Handling / Resilience
By default, the client will be configured to retry a call up to three times with increasing waits between (1s, 5s, 10s). If after the third call the service still returns an error then the call will be considered failed. You can override this policy during the UseKami method by passing in a policy as the second parameter. It is recommended to use Polly, a 3rd-party library, that has a lot of options for creating policies
builder.Services.AddKamiClient(builder.Configuration, (p => p.WaitAndRetryAsync(new[]
{
TimeSpan.FromSeconds(1),
TimeSpan.FromSeconds(5),
TimeSpan.FromSeconds(10)
}));
Configuration
Additional configuration can be done in the appSettings.config file within the "Kami" section. The default settings are shown here and can be overridden if needed:
{
"Kami": {
"Token": "Token #####################",
"BaseAddress": "https://api.notablepdf.com/",
"AllowedExtensions": [
"doc",
"docx",
"ppt",
"pptx",
"xls",
"xlsx",
"pdf",
"odt",
"odp",
"ods",
"txt",
"rtf",
"gdoc",
"gsheet",
"jpg",
"jpeg",
"gif",
"png",
"tif",
"tiff"
]
}
}
🚀 Example
After initializing with the UseKami() method above, the client will be registered in the DI system. You can inject the client in the constructor of any class that needs to use it.
public class TestClass
{
private readonly IKamiClient kamiClient
public TestClass(IKamiClient kamiClient)
{
this.kamiClient = kamiClient;
}
public async Task<KamiUploadResult> UploadDocument(int fileId)
{
var (bytes, mimeType, fileName) = await this.GetFile(fileId);
return await this.kamiClient.UploadFile(bytes, mimeType, fileName);
}
public async Task<KamiDeleteResult> DeleteDocument(string kamiDocumentId)
{
await this.kamiClient.DeleteFile(kamiDocumentId);
}
public async Task<KamiCreateViewSessionResult> CreateViewSession(string kamiDocumentId)
{
var (username, userId) = await this.GetUser();
// optional settings
var expiresAt = DateTime.Now.AddDays(7);
var viewerOptions = new KamiViewerOptions();
// var mobileViewerOptions = KamiViewerOptions.Mobile;
var editable = true;
return await this.kamiClient.CreateViewSession(kamiDocumentId, username, userId, expiresAt, viewerOptions, editable);
}
public async Task<KamiDocumentExportResult> ExportDocument(kamiDocumentId)
{
// export type is optional, defaults to "inline". See Kami API documentation site for more options and what they do
var exportType = "inline";
return await this.kamiClient.ExportFile(kamiDocumentId, exportType);
}
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. |
-
net6.0
- Ardalis.GuardClauses (>= 4.0.1)
- Microsoft.Extensions.Configuration (>= 7.0.0)
- Microsoft.Extensions.DependencyInjection (>= 7.0.0)
- Microsoft.Extensions.Http (>= 7.0.0)
- Microsoft.Extensions.Http.Polly (>= 7.0.5)
- Microsoft.Extensions.Options (>= 7.0.1)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 7.0.0)
- Newtonsoft.Json (>= 13.0.3)
-
net7.0
- Ardalis.GuardClauses (>= 4.0.1)
- Microsoft.Extensions.Configuration (>= 7.0.0)
- Microsoft.Extensions.DependencyInjection (>= 7.0.0)
- Microsoft.Extensions.Http (>= 7.0.0)
- Microsoft.Extensions.Http.Polly (>= 7.0.5)
- Microsoft.Extensions.Options (>= 7.0.1)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 7.0.0)
- Newtonsoft.Json (>= 13.0.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
2.0.0 | 197 | 5/8/2023 |