Skip to content

Commit

Permalink
Revert "chore: add linking in README.md (#54)"
Browse files Browse the repository at this point in the history
This reverts commit 4f30a74.
  • Loading branch information
Dovchik authored Apr 17, 2024
1 parent 4f30a74 commit 11612d0
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 88 deletions.
80 changes: 73 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,35 @@ Once the SDK is installed, you must start by initializing the main client class.

To initialize communication with the Sinch servers, credentials obtained from the Sinch dashboard must be provided to the main client class of this SDK. It's highly recommended to not hardcode these credentials and to load them from environment variables instead or any key-secret storage (for example, [app-secrets](https://learn.microsoft.com/en-us/aspnet/core/security/app-secrets?view=aspnetcore-7.0)).

https://github.com/sinch/sinch-sdk-dotnet/blob/9f69eb2c5da48d5678d0f28ec4c039dd816f36d7/examples/Console/Program.cs#L8-L10
```csharp
using Sinch;

var sinch = new SinchClient(configuration["Sinch:KeyId"], configuration["Sinch:KeySecret"], configuration["Sinch:ProjectId"]);
```

With ASP.NET dependency injection:

https://github.com/sinch/sinch-sdk-dotnet/blob/9f69eb2c5da48d5678d0f28ec4c039dd816f36d7/examples/WebApi/Program.cs#L17-L25
```csharp
// SinchClient is thread safe so it's okay to add it as a singleton
builder.Services.AddSingleton<ISinch>(x => new SinchClient(
builder.Configuration["Sinch:KeyId"],
builder.Configuration["Sinch:KeySecret"],
builder.Configuration["Sinch:ProjectId"]));
```

To configure Conversation or Sms hosting regions, and any other additional parameters, use [`SinchOptions`](https://github.com/sinch/sinch-sdk-dotnet/blob/main/src/Sinch/SinchOptions.cs):

https://github.com/sinch/sinch-sdk-dotnet/blob/4ca70fc3df975f213c822a66a0e6775d3ddee23d/examples/Console/UsingSinchOptions.cs#L9-L16
```csharp
var sinch = new SinchClient(
configuration["Sinch:KeyId"],
configuration["Sinch:KeySecret"],
configuration["Sinch:ProjectId"],
options =>
{
options.SmsHostingRegion = Sinch.SMS.SmsHostingRegion.Eu;
options.ConversationRegion = Sinch.Conversation.ConversationRegion.Eu;
});
```

## Supported Sinch Products

Expand All @@ -60,20 +80,66 @@ Sinch client provides access to the following Sinch products:
- additional products coming soon!

Usage example of the `numbers` product, assuming `sinch` is a type of `ISinchClient`:

https://github.com/sinch/sinch-sdk-dotnet/blob/63752849bb3277b464754f8ad9544cfae2d51d35/examples/Console/ListActiveNumbers.cs#L15-L19
```csharp
using Sinch.Numbers.Active.List;

ListActiveNumbersResponse response = await sinch.Numbers.Active.List(new ListActiveNumbersRequest
{
RegionCode = "US",
Type = Types.Mobile
});
```

## Logging, HttpClient, and additional options

To configure a logger, provide your own `HttpClient`, or any additional options utilize `SinchOptions` action within the constructor:

https://github.com/sinch/sinch-sdk-dotnet/blob/9f69eb2c5da48d5678d0f28ec4c039dd816f36d7/examples/WebApi/Program.cs#L17-L25
```csharp
using Sinch;
using Sinch.SMS;

var sinch = new SinchClient(
configuration["Sinch:KeyId"],
configuration["Sinch:KeySecret"],
configuration["Sinch:ProjectId"],
options =>
{
// provide any logger factory which satisfies Microsoft.Extensions.Logging.ILoggerFactory
options.LoggerFactory = LoggerFactory.Create(config => {
// add log output to console
config.AddConsole();
});
// Provide your http client here
options.HttpClient = new HttpClient();
// Set a hosting region for Sms
options.SmsHostingRegion = SmsHostingRegion.Eu;
});
```

## Handling exceptions

For an unsuccessful API calls `SinchApiException` will be thrown:

https://github.com/sinch/sinch-sdk-dotnet/blob/3ad0f84dc19968d1d708fab59fd84e134c76f066/examples/Console/HandlingExceptions.cs#L19-L35
```csharp
using Sinch;
using Sinch.SMS.Batches.Send;

try {
var batch = await sinch.Sms.Batches.Send(new SendBatchRequest
{
Body = "Hello, World!",
DeliveryReport = DeliveryReport.None,
To = new List<string>()
{
123456789
}
});
}
catch(SinchApiException e)
{
logger.LogError("Api Exception. Status: {status}. Detailed message: {message}", e.Status, e.DetailedMessage);
}
```

## Sample apps

Expand Down
38 changes: 0 additions & 38 deletions examples/Console/HandlingExceptions.cs

This file was deleted.

21 changes: 0 additions & 21 deletions examples/Console/ListActiveNumbers.cs

This file was deleted.

7 changes: 3 additions & 4 deletions examples/Console/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
// Assume .env file is present in your output directory
Env.Load();

var sinch = new SinchClient(Environment.GetEnvironmentVariable("SINCH_PROJECT_ID")!,
Environment.GetEnvironmentVariable("SINCH_KEY_ID")!,
Environment.GetEnvironmentVariable("SINCH_KEY_SECRET")!
);
var sinch = new SinchClient(Environment.GetEnvironmentVariable("SINCH_KEY_ID")!,
Environment.GetEnvironmentVariable("SINCH_KEY_SECRET")!,
Environment.GetEnvironmentVariable("SINCH_PROJECT_ID")!);

_ = sinch.Verification(Environment.GetEnvironmentVariable("SINCH_APP_KEY")!,
Environment.GetEnvironmentVariable("SINCH_APP_SECRET")!);
Expand Down
18 changes: 0 additions & 18 deletions examples/Console/UsingSinchOptions.cs

This file was deleted.

0 comments on commit 11612d0

Please sign in to comment.