Innovian.Telnyx.Storage
2023.11.14.15
See the version list below for details.
dotnet add package Innovian.Telnyx.Storage --version 2023.11.14.15
NuGet\Install-Package Innovian.Telnyx.Storage -Version 2023.11.14.15
<PackageReference Include="Innovian.Telnyx.Storage" Version="2023.11.14.15" />
paket add Innovian.Telnyx.Storage --version 2023.11.14.15
#r "nuget: Innovian.Telnyx.Storage, 2023.11.14.15"
// Install Innovian.Telnyx.Storage as a Cake Addin #addin nuget:?package=Innovian.Telnyx.Storage&version=2023.11.14.15 // Install Innovian.Telnyx.Storage as a Cake Tool #tool nuget:?package=Innovian.Telnyx.Storage&version=2023.11.14.15
Innovian.Telnyx.Storage
This is an unofficial .NET library for the Telnyx Storage API, targeting .NET 7 built by Innovian.
Note that Telnyx is making significant changes to their API in an ongoing basis and they don't yet support API versioning, so while this pipeline performs an E2E test daily so I can get a heads up of anything that isn't working suddenly, it's possible that Telnyx may break this implementation from time to time. Keep this in mind before using this in a production environment.
Installation
Using the .NET Core CLI tools:
dotnet add package Innovian.Telnyx.Storage
Using the NuGet CLI:
nuget install Innovian.Telnyx.Storage
Using the Package Manager Console:
Install-Package Innovian.Telnyx.Storage
From within Visual Studio:
- Open the Solution Explorer.
- Right-click on a project within your solution.
- Click on "Manage NuGet Packages...".
- Click on the "Browse" tab and search for "Innovian.Telnyx.Storage".
- Click on the Innovian.Telnyx.Storage package, select the appropriate version in the right-tab and click Install.
Usage
Authentication
The Telnyx API authenticates requests using the API key generated from within your Telnyx account. When logged into Telnyx, click on "Account Settings" in the left-nav to expand it, then select "Keys & Credentials" from the list that appears. You'll be looking at a page title "API Keys". Either use an existing and active API key by clicking the "copy" button to the right of any of the keys listed in the table or click the green button labeled "Create API Key" in the top right of the page, then click Create and Copy to generate and copy the newly created API key to your clipboard. This API key typically starts with "KEY..."
Any of these keys can be used with this library or the official Telnyx libraries for the other functionality without restriction.
Dependency Injection Registration
Dependency injection using top-level statements:
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddTelnyxClient(opt =>
{
opt.TelnyxApiKey = "KEY..."; //Insert the Telnyx API key here
});
//...
var app = builder.Build();
//...
app.Run();
Dependency injection via Startup.cs
registration:
//Startup.cs
public void ConfigureServices(IServiceCollection services)
{
services.AddTelnyxClient(opt =>
{
opt.TelnyxApiKey = "KEY..."; //Insert the Telnyx API key here
});
}
Manual DI registration (used if you need access to the service provider context to obtain the API key):
// Assumes use of Startup.cs wherein `services` is an `IServiceCollection`.
// If using top-level statements, replace `services` with `builder.Services`
services.AddHttpClient(); //Mandatory so IHttpClientFactory is registered - handled for you in the above extension registrations
services.AddSingleton(c => {
var apiKey = ""; //Retrieve this from somewhere
var httpFactory = c.GetRequiredService<IHttpClientFactory>();
return new TelnyxStorageService(httpFactory, apiKey);
});
You can register this library via Autofac as well by installing the Autofac.Extensions.DependencyInjection package to your project first, then using the following snippet:
public static class CompositionRoot
{
public static IContainer Builder()
{
var builder = new ContainerBuilder();
//...
var services = new ServiceCollection();
services.AddTelnyxClient(opt => {
opt.TelnyxApiKey = ""; //Retrieve this from somewhere
});
builder.Populate(services);
return builder.Build();
}
}
Finally, this library also supports delegate factories in case you want to register with Autofac and need to acquire the API key at a later point. This example uses the Autofac.Extensions.DependencyInjection package to simplify registering the IHttpClientFactory
.
//CompositionRoot.cs
public class MyExample
{
var builder = new ContainerBuilder();
//Register the TelnyxStorageService
builder.RegisterType<TelnyxStorageService>();
//Register the IHttpClientFactory
var services = new ServiceCollection();
services.AddHttpClient();
builder.Populate(services);
using var container = builder.Build();
//Create a local scope and retrieve the factory from the Autofac container
using var scope = container.BeginLifetimeScope();
var createStorageClient = scope.Resolve<TelnyxStorageService.Factory>();
//Autofac automatically injects the IHttpClientFactory for us, we just need to pass in the API key
var telnyxApiKey = ""; //Retrieve this from somewhere
var telnyxClient = createStorageClient(telnyxApiKey); //Returns an ITelnyxStorageService ready to use
}
Example usage
To use the service, inject the ITelnyxStorageService
interface into the constructor of the type you're using it in as in the following:
public class MyClass
{
private readonly ITelnyxStorageService _storageService;
public MyClass (ITelnyxStorageService storageService)
{
_storageService = storageService;
}
public async Task DoSoemthingAsync()
{
//Do something...
}
}
Here's an example showing injection into another class after it's been registered via Autofac's delegate factory approach:
public class MyOtherClass
{
private readonly ITelenyxStorageService _telnyxClient;
public MyOtherClass(TelnyxStorageService.Factory telnyxFactory)
{
var telnyxApiKey = ""; //Retrieve this from somewhere
_telnyxClient = telnyxFactory(telnyxApiKey);
}
public async Task DoSomethingAsync()
{
//Do something...
}
}
Running unit tests
The unit tests most run through one integrated test which iterates through all the functionality in the library. It requires an active API key to run through the tests and will briefly incur charges (though it's likely to fit well within the free usage threshold). Your API key will need to be stored in an environment variable named "TelnyxApiKey" for the test runner to pick it up. In order for the tests to pass, the bucket name must not be in use. The tests use a GUID as part of the name generation, so this generally shouldn't be a problem, but heads up nonetheless. Assuming the test runs to completion successfully, it will create a new bucket, do some uploads, delete these uploads and delete the new bucket. Should it fail, you may need to delete a bucket in your account whose name will start with "integration-testing-" and 8 random hexadecimal characters.
Contributing
Contributions are welcome. Please read our contributing guide to learn more about filing issues and submitting PRs.
License
Innovian.Telnyx.Storage is licensed for use under the Apache 2.0 license.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | 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. |
-
net7.0
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 7.0.0)
- Microsoft.Extensions.Http (>= 7.0.0)
- Microsoft.Extensions.Options (>= 7.0.1)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 7.0.0)
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 |
---|---|---|
2023.11.30.1 | 239 | 11/30/2023 |
2023.11.14.15 | 137 | 11/14/2023 |
2023.11.14.13 | 110 | 11/14/2023 |
2023.11.14.12 | 116 | 11/14/2023 |
2023.11.14.11 | 125 | 11/14/2023 |
2023.11.14.7 | 119 | 11/14/2023 |
2023.11.14.6 | 113 | 11/14/2023 |
2023.10.3.1 | 139 | 10/3/2023 |
2023.9.29.12 | 150 | 9/29/2023 |
2023.9.29.11 | 148 | 9/29/2023 |
2023.9.29.10 | 142 | 9/29/2023 |
2023.9.29.9 | 127 | 9/29/2023 |