Skip to content

Commit 15b45f0

Browse files
authored
csharp: Mark BaseUrl as deprecated in favor of ServerUrl on SvixOptions (#1917)
2 parents d980a74 + 8fa7d72 commit 15b45f0

File tree

5 files changed

+36
-14
lines changed

5 files changed

+36
-14
lines changed

ChangeLog.md

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* Libs/Python: Bring back the (deprecated) sync `dashboard_access` method, which was accidentally
55
removed in v1.64.1
66
* Libs/Csharp: The `options` argument to the `SvixClient` initializer is now optional.
7+
* Libs/Csharp: The `SvixOptions.BaseUrl` field is deprecated in favor of `SvixOptions.ServerUrl`
78

89
## Version 1.64.1
910
* Libs/JavaScript: Add `HTTPValidationError`, `HttpErrorOut`, `ValidationError` and `ApiException` to the top level exports.

csharp/Svix/SvixClient.cs

+4-2
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,14 @@ public SvixClient(
8181
)
8282
{
8383
Logger = logger;
84+
var opts = options ?? new SvixOptions(Utils.DefaultServerUrlFromToken(token));
8485
SvixHttpClient =
8586
svixHttpClient
8687
?? new SvixHttpClient(
8788
token,
88-
options ?? new SvixOptions(Utils.DefaultServerUrlFromToken(token)),
89-
$"svix-libs/{Version.version}/csharp"
89+
opts.RetryScheduleMilliseconds,
90+
$"svix-libs/{Version.version}/csharp",
91+
opts.ServerUrl ?? Utils.DEFAULT_SERVER_URL
9092
);
9193
}
9294
}

csharp/Svix/SvixHttpClient.cs

+14-7
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
1-
using System.Net;
1+
using System.Collections.Generic;
2+
using System.Net;
23
using System.Net.Http.Headers;
34
using System.Text;
45
using Newtonsoft.Json;
56

67
namespace Svix
78
{
8-
public class SvixHttpClient(string token, SvixOptions options, string userAgent)
9+
public class SvixHttpClient(
10+
string token,
11+
List<int> retryScheduleMilliseconds,
12+
string userAgent,
13+
string serverUrl
14+
)
915
{
10-
readonly SvixOptions _options = options;
11-
readonly HttpClient _httpClient = new();
16+
private readonly List<int> retryScheduleMilliseconds = retryScheduleMilliseconds;
17+
private readonly string serverUrl = serverUrl;
18+
private readonly HttpClient _httpClient = new();
1219
private readonly string _token = token;
1320
private readonly JsonSerializerSettings patchJsonOptions = new();
1421
private readonly JsonSerializerSettings JsonOptions = new()
@@ -63,13 +70,13 @@ public async Task<ApiResponse<T>> SendRequestAsync<T>(
6370
content
6471
);
6572
var response = await _httpClient.SendAsync(request, cancellationToken);
66-
for (var index = 0; index < _options.RetryScheduleMilliseconds.Count; index++)
73+
for (var index = 0; index < retryScheduleMilliseconds.Count; index++)
6774
{
6875
if ((int)response.StatusCode < 500)
6976
{
7077
break;
7178
}
72-
Thread.Sleep(_options.RetryScheduleMilliseconds[index]);
79+
Thread.Sleep(retryScheduleMilliseconds[index]);
7380
HttpRequestMessage retryRequest = BuildRequest(
7481
method,
7582
path,
@@ -131,7 +138,7 @@ HttpRequestMessage BuildRequest(
131138
object? content = null
132139
)
133140
{
134-
var url = _options.BaseUrl;
141+
var url = serverUrl;
135142

136143
// Apply path parameters if provided
137144
if (pathParams != null)

csharp/Svix/SvixOptions.cs

+14-4
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,26 @@ namespace Svix
22
{
33
public class SvixOptions
44
{
5-
public string BaseUrl { get; }
5+
[Obsolete("BaseUrl is deprecated, please use ServerUrl instead.")]
6+
public string? BaseUrl
7+
{
8+
get => ServerUrl;
9+
}
10+
public string? ServerUrl { get; }
611
public List<int> RetryScheduleMilliseconds { get; } = [50, 100, 200];
712
public int TimeoutMilliseconds { get; } = 15000;
813

14+
/// <param name="serverUrl">The server URL to connect to.</param>
15+
/// <param name="baseUrl">[Deprecated] Please use serverUrl parameter instead.</param>
16+
#pragma warning disable CS0618
917
public SvixOptions(
10-
string baseUrl,
18+
string? serverUrl = null,
1119
int timeoutMilliseconds = 15000,
12-
List<int>? retryScheduleMilliseconds = null
20+
List<int>? retryScheduleMilliseconds = null,
21+
string? baseUrl = null
1322
)
1423
{
15-
BaseUrl = baseUrl;
24+
ServerUrl = serverUrl ?? baseUrl;
1625
TimeoutMilliseconds = timeoutMilliseconds;
1726
retryScheduleMilliseconds ??= [50, 100, 200];
1827
if (retryScheduleMilliseconds.Count > 5)
@@ -21,5 +30,6 @@ public SvixOptions(
2130
}
2231
RetryScheduleMilliseconds = retryScheduleMilliseconds;
2332
}
33+
#pragma warning restore CS0618
2434
}
2535
}

csharp/Svix/Utils.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,10 @@ internal static string DefaultServerUrlFromToken(string token)
5151
}
5252
else
5353
{
54-
return "https://api.svix.com";
54+
return DEFAULT_SERVER_URL;
5555
}
5656
}
57+
58+
internal static string DEFAULT_SERVER_URL = "https://api.svix.com";
5759
}
5860
}

0 commit comments

Comments
 (0)