From 5af7ff9c52ad7dd3bcc7c8756d589cc02d8190a0 Mon Sep 17 00:00:00 2001 From: Volodymyr Lisovskyi Date: Thu, 1 Aug 2024 16:00:16 +0200 Subject: [PATCH 1/8] feat: add available numbers method to ISinchNumbers --- src/Sinch/Numbers/Available.cs | 14 ++++++--- src/Sinch/Numbers/Numbers.cs | 52 +++++++++++++++++++++++++++++++++- 2 files changed, 61 insertions(+), 5 deletions(-) diff --git a/src/Sinch/Numbers/Available.cs b/src/Sinch/Numbers/Available.cs index 1996531..42702c2 100644 --- a/src/Sinch/Numbers/Available.cs +++ b/src/Sinch/Numbers/Available.cs @@ -16,7 +16,7 @@ public interface ISinchNumbersAvailable { /// /// Search for and activate an available Sinch virtual number all in one API call. - /// Currently the rentAny operation works only for US 10DLC numbers + /// Currently, the rentAny operation works only for US 10DLC numbers /// /// /// @@ -26,11 +26,11 @@ Task RentAny(RentAnyNumberRequest request, /// /// Activate a virtual number to use with SMS products, Voice products, or both.

- /// You'll use SmsConfiguration to setup your number for SMS and VoiceConfiguration for Voice. - /// To setup for both, add both objects.

+ /// You'll use SmsConfiguration to set up your number for SMS and VoiceConfiguration for Voice. + /// To set up for both, add both objects.

/// Note: You cannot add both objects if you only need to configure one object. /// For example, if you only need to configure smsConfiguration for SMS messaging, - /// do not add the voiceConfiguration object or it will result in an error. + /// do not add the voiceConfiguration object, or it will result in an error. ///
/// Output only. The phone number in E.164 format with leading +. /// @@ -83,6 +83,7 @@ public AvailableNumbers(string projectId, Uri baseAddress, } /// + [Obsolete($"This method is obsolete, use {nameof(ISinchNumbers)}.{nameof(Numbers.RentAny)} instead.")] public Task RentAny(RentAnyNumberRequest request, CancellationToken cancellationToken = default) { @@ -95,6 +96,7 @@ public Task RentAny(RentAnyNumberRequest request, } /// + [Obsolete($"This method is obsolete, use {nameof(ISinchNumbers)}.{nameof(Numbers.Rent)} instead.")] public Task Rent(string phoneNumber, RentActiveNumberRequest request, CancellationToken cancellationToken = default) { @@ -104,6 +106,8 @@ public Task Rent(string phoneNumber, RentActiveNumberRequest reque } /// + [Obsolete( + $"This method is obsolete, use {nameof(ISinchNumbers)}.{nameof(Numbers.SearchForAvailableNumbers)} instead.")] public Task List(ListAvailableNumbersRequest request, CancellationToken cancellationToken = default) { @@ -115,6 +119,8 @@ public Task List(ListAvailableNumbersRequest reque } /// + [Obsolete( + $"This method is obsolete, use {nameof(ISinchNumbers)}.{nameof(Numbers.CheckAvailability)} instead.")] public async Task CheckAvailability(string phoneNumber, CancellationToken cancellationToken = default) { diff --git a/src/Sinch/Numbers/Numbers.cs b/src/Sinch/Numbers/Numbers.cs index 4d201d9..838d162 100644 --- a/src/Sinch/Numbers/Numbers.cs +++ b/src/Sinch/Numbers/Numbers.cs @@ -1,6 +1,13 @@ using System; +using System.Threading; +using System.Threading.Tasks; using Sinch.Core; using Sinch.Logger; +using Sinch.Numbers.Active; +using Sinch.Numbers.Available; +using Sinch.Numbers.Available.List; +using Sinch.Numbers.Available.Rent; +using Sinch.Numbers.Available.RentAny; namespace Sinch.Numbers { @@ -11,7 +18,7 @@ namespace Sinch.Numbers public interface ISinchNumbers { /// - /// You can use the Available Regions API to list all of the regions that have numbers assigned to a project. + /// You can use the Available Regions API to list all the regions that have numbers assigned to a project. /// public ISinchNumbersRegions Regions { get; } @@ -25,6 +32,22 @@ public interface ISinchNumbers /// release numbers from projects, or list all numbers assigned to a project. /// public ISinchNumbersActive Active { get; } + + /// + Task RentAny(RentAnyNumberRequest request, + CancellationToken cancellationToken = default); + + /// + Task Rent(string phoneNumber, + RentActiveNumberRequest request, CancellationToken cancellationToken = default); + + /// + Task SearchForAvailableNumbers( + ListAvailableNumbersRequest request, CancellationToken cancellationToken = default); + + /// + Task CheckAvailability(string phoneNumber, + CancellationToken cancellationToken = default); } public sealed class Numbers : ISinchNumbers @@ -45,5 +68,32 @@ internal Numbers(string projectId, Uri baseAddress, public ISinchNumbersActive Active { get; } public ISinchNumbersAvailable Available { get; } + + /// + public Task RentAny(RentAnyNumberRequest request, CancellationToken cancellationToken = default) + { + return Available.RentAny(request, cancellationToken); + } + + /// + public Task Rent(string phoneNumber, RentActiveNumberRequest request, + CancellationToken cancellationToken = default) + { + return Available.Rent(phoneNumber, request, cancellationToken); + } + + /// + public Task SearchForAvailableNumbers(ListAvailableNumbersRequest request, + CancellationToken cancellationToken = default) + { + return Available.List(request, cancellationToken); + } + + /// + public Task CheckAvailability(string phoneNumber, + CancellationToken cancellationToken = default) + { + return Available.CheckAvailability(phoneNumber, cancellationToken); + } } } From 686a5e199dcdbe97a4f50adc82aa0cf3ae9e5b5f Mon Sep 17 00:00:00 2001 From: Volodymyr Lisovskyi Date: Thu, 1 Aug 2024 16:10:42 +0200 Subject: [PATCH 2/8] feat: add active numbers method to ISinchNumbers --- src/Sinch/Numbers/Active.cs | 19 +++++++++-- src/Sinch/Numbers/Available.cs | 12 +++---- src/Sinch/Numbers/Numbers.cs | 60 ++++++++++++++++++++++++++++++++++ 3 files changed, 82 insertions(+), 9 deletions(-) diff --git a/src/Sinch/Numbers/Active.cs b/src/Sinch/Numbers/Active.cs index 852aa4b..96c68f7 100644 --- a/src/Sinch/Numbers/Active.cs +++ b/src/Sinch/Numbers/Active.cs @@ -25,6 +25,8 @@ public interface ISinchNumbersActive /// /// /// + [Obsolete( + $"This method is obsolete, use {nameof(ISinchNumbers)}.{nameof(Numbers.List)} instead.")] Task List(ListActiveNumbersRequest request, CancellationToken cancellationToken = default); @@ -37,7 +39,7 @@ Task List(ListActiveNumbersRequest request, /// scheduled provisioning status. You can also update the type of number, currency type and amount. Note: You cannot /// add both objects if you only need to update one object. For example, if you only need to reconfigure /// smsConfiguration for SMS messaging, - /// do not add the voiceConfiguration object or it will result in an error. + /// do not add the voiceConfiguration object, or it will result in an error. /// /// /// Output only. The phone number in @@ -46,6 +48,8 @@ Task List(ListActiveNumbersRequest request, /// A request object /// /// + [Obsolete( + $"This method is obsolete, use {nameof(ISinchNumbers)}.{nameof(Numbers.Update)} instead.")] Task Update(string phoneNumber, UpdateActiveNumberRequest request, CancellationToken cancellationToken = default); @@ -55,6 +59,8 @@ Task Update(string phoneNumber, /// Number to get info about /// /// + [Obsolete( + $"This method is obsolete, use {nameof(ISinchNumbers)}.{nameof(Numbers.Get)} instead.")] Task Get(string phoneNumber, CancellationToken cancellationToken = default); @@ -68,9 +74,13 @@ Task Get(string phoneNumber, /// /// /// + [Obsolete( + $"This method is obsolete, use {nameof(ISinchNumbers)}.{nameof(Numbers.Release)} instead.")] Task Release( string phoneNumber, CancellationToken cancellationToken = default); + [Obsolete( + $"This method is obsolete, use {nameof(ISinchNumbers)}.{nameof(Numbers.ListAuto)} instead.")] IAsyncEnumerable ListAuto(ListActiveNumbersRequest request, CancellationToken cancellationToken = default); } @@ -91,7 +101,9 @@ public ActiveNumbers(string projectId, Uri baseAddress, _http = http; } - public Task List(ListActiveNumbersRequest request, CancellationToken cancellationToken = default) + + public Task List(ListActiveNumbersRequest request, + CancellationToken cancellationToken = default) { _logger?.LogDebug("Fetching active numbers {request}", request); var uri = new Uri(_baseAddress, $"v1/projects/{_projectId}/activeNumbers?{request.GetQueryString()}"); @@ -122,7 +134,8 @@ public Task Update(string phoneNumber, UpdateActiveNumberRequest r _logger?.LogDebug("Updating a {number}", phoneNumber); var uri = new Uri(_baseAddress, $"v1/projects/{_projectId}/activeNumbers/{phoneNumber}"); - return _http.Send(uri, HttpMethod.Patch, request, cancellationToken); + return _http.Send(uri, HttpMethod.Patch, request, + cancellationToken); } /// diff --git a/src/Sinch/Numbers/Available.cs b/src/Sinch/Numbers/Available.cs index 42702c2..39d5097 100644 --- a/src/Sinch/Numbers/Available.cs +++ b/src/Sinch/Numbers/Available.cs @@ -21,6 +21,7 @@ public interface ISinchNumbersAvailable /// /// /// + [Obsolete($"This method is obsolete, use {nameof(ISinchNumbers)}.{nameof(Numbers.RentAny)} instead.")] Task RentAny(RentAnyNumberRequest request, CancellationToken cancellationToken = default); @@ -36,6 +37,7 @@ Task RentAny(RentAnyNumberRequest request, /// /// /// + [Obsolete($"This method is obsolete, use {nameof(ISinchNumbers)}.{nameof(Numbers.Rent)} instead.")] Task Rent(string phoneNumber, RentActiveNumberRequest request, CancellationToken cancellationToken = default); @@ -49,6 +51,8 @@ Task Rent(string phoneNumber, /// /// /// + [Obsolete( + $"This method is obsolete, use {nameof(ISinchNumbers)}.{nameof(Numbers.SearchForAvailableNumbers)} instead.")] Task List( ListAvailableNumbersRequest request, CancellationToken cancellationToken = default); @@ -62,6 +66,8 @@ Task List( /// /// /// + [Obsolete( + $"This method is obsolete, use {nameof(ISinchNumbers)}.{nameof(Numbers.CheckAvailability)} instead.")] Task CheckAvailability(string phoneNumber, CancellationToken cancellationToken = default); } @@ -83,7 +89,6 @@ public AvailableNumbers(string projectId, Uri baseAddress, } /// - [Obsolete($"This method is obsolete, use {nameof(ISinchNumbers)}.{nameof(Numbers.RentAny)} instead.")] public Task RentAny(RentAnyNumberRequest request, CancellationToken cancellationToken = default) { @@ -96,7 +101,6 @@ public Task RentAny(RentAnyNumberRequest request, } /// - [Obsolete($"This method is obsolete, use {nameof(ISinchNumbers)}.{nameof(Numbers.Rent)} instead.")] public Task Rent(string phoneNumber, RentActiveNumberRequest request, CancellationToken cancellationToken = default) { @@ -106,8 +110,6 @@ public Task Rent(string phoneNumber, RentActiveNumberRequest reque } /// - [Obsolete( - $"This method is obsolete, use {nameof(ISinchNumbers)}.{nameof(Numbers.SearchForAvailableNumbers)} instead.")] public Task List(ListAvailableNumbersRequest request, CancellationToken cancellationToken = default) { @@ -119,8 +121,6 @@ public Task List(ListAvailableNumbersRequest reque } /// - [Obsolete( - $"This method is obsolete, use {nameof(ISinchNumbers)}.{nameof(Numbers.CheckAvailability)} instead.")] public async Task CheckAvailability(string phoneNumber, CancellationToken cancellationToken = default) { diff --git a/src/Sinch/Numbers/Numbers.cs b/src/Sinch/Numbers/Numbers.cs index 838d162..ee7859f 100644 --- a/src/Sinch/Numbers/Numbers.cs +++ b/src/Sinch/Numbers/Numbers.cs @@ -1,9 +1,12 @@ using System; +using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; using Sinch.Core; using Sinch.Logger; using Sinch.Numbers.Active; +using Sinch.Numbers.Active.List; +using Sinch.Numbers.Active.Update; using Sinch.Numbers.Available; using Sinch.Numbers.Available.List; using Sinch.Numbers.Available.Rent; @@ -48,6 +51,26 @@ Task SearchForAvailableNumbers( /// Task CheckAvailability(string phoneNumber, CancellationToken cancellationToken = default); + + /// + Task Release( + string phoneNumber, CancellationToken cancellationToken = default); + + /// + Task Get(string phoneNumber, + CancellationToken cancellationToken = default); + + /// + Task Update(string phoneNumber, + UpdateActiveNumberRequest request, CancellationToken cancellationToken = default); + + /// + Task List(ListActiveNumbersRequest request, + CancellationToken cancellationToken = default); + + /// + IAsyncEnumerable ListAuto(ListActiveNumbersRequest request, + CancellationToken cancellationToken = default); } public sealed class Numbers : ISinchNumbers @@ -69,6 +92,9 @@ internal Numbers(string projectId, Uri baseAddress, public ISinchNumbersAvailable Available { get; } + // disabling obsolete usage as in next major version, active and available interfaces will remain, + // but visibility changed to internal, and public interface will be available only through this methods +#pragma warning disable CS0618 // Type or member is obsolete /// public Task RentAny(RentAnyNumberRequest request, CancellationToken cancellationToken = default) { @@ -95,5 +121,39 @@ public Task CheckAvailability(string phoneNumber, { return Available.CheckAvailability(phoneNumber, cancellationToken); } + + /// + public Task Release(string phoneNumber, CancellationToken cancellationToken = default) + { + return Active.Release(phoneNumber, cancellationToken); + } + + /// + public Task Get(string phoneNumber, CancellationToken cancellationToken = default) + { + return Active.Get(phoneNumber, cancellationToken); + } + + /// + public Task Update(string phoneNumber, UpdateActiveNumberRequest request, + CancellationToken cancellationToken = default) + { + return Active.Update(phoneNumber, request, cancellationToken); + } + + /// + public Task List(ListActiveNumbersRequest request, + CancellationToken cancellationToken = default) + { + return Active.List(request, cancellationToken); + } + + /// + public IAsyncEnumerable ListAuto(ListActiveNumbersRequest request, + CancellationToken cancellationToken = default) + { + return Active.ListAuto(request, cancellationToken); + } +#pragma warning restore CS0618 // Type or member is obsolete } } From 30a887fbea504b32dd6a3bda1692fec704ea162d Mon Sep 17 00:00:00 2001 From: Volodymyr Lisovskyi Date: Fri, 2 Aug 2024 12:59:53 +0200 Subject: [PATCH 3/8] feat: point test to not deprecated method --- tests/Sinch.Tests/e2e/NumbersTests.cs | 75 ++++++++++++++------------- 1 file changed, 40 insertions(+), 35 deletions(-) diff --git a/tests/Sinch.Tests/e2e/NumbersTests.cs b/tests/Sinch.Tests/e2e/NumbersTests.cs index e55c78e..3959ca2 100644 --- a/tests/Sinch.Tests/e2e/NumbersTests.cs +++ b/tests/Sinch.Tests/e2e/NumbersTests.cs @@ -14,7 +14,8 @@ public class NumbersTests : TestBase [Fact] public async Task ListRegions() { - var response = await SinchClientMockStudio.Numbers.Regions.List(new List() { Types.Local, Types.Mobile }); + var response = + await SinchClientMockStudio.Numbers.Regions.List(new List() { Types.Local, Types.Mobile }); response = response.ToList(); response.Should().HaveCount(18); var brRegion = response.First(x => x.RegionCode == "CL"); @@ -25,7 +26,7 @@ public async Task ListRegions() [Fact] public async Task Rent() { - var response = await SinchClientMockStudio.Numbers.Available.Rent("+447520652221", new RentActiveNumberRequest() + var response = await SinchClientMockStudio.Numbers.Rent("+447520652221", new RentActiveNumberRequest() { SmsConfiguration = null, VoiceConfiguration = null, @@ -37,43 +38,46 @@ public async Task Rent() [Fact] public async Task ListAvailableWithPattern() { - var response = await SinchClientMockStudio.Numbers.Available.List(new Sinch.Numbers.Available.List.ListAvailableNumbersRequest - { - RegionCode = "US", - Type = Types.Local, - NumberPattern = new NumberPattern + var response = await SinchClientMockStudio.Numbers.SearchForAvailableNumbers( + new Sinch.Numbers.Available.List.ListAvailableNumbersRequest { - Pattern = "122", - SearchPattern = SearchPattern.End - } - }); + RegionCode = "US", + Type = Types.Local, + NumberPattern = new NumberPattern + { + Pattern = "122", + SearchPattern = SearchPattern.End + } + }); response.AvailableNumbers.Should().HaveCount(5); } [Fact] public async Task ListAvailableWithCapabilities() { - var response = await SinchClientMockStudio.Numbers.Available.List(new Sinch.Numbers.Available.List.ListAvailableNumbersRequest - { - RegionCode = "US", - Type = Types.Local, - Capabilities = new List() + var response = await SinchClientMockStudio.Numbers.SearchForAvailableNumbers( + new Sinch.Numbers.Available.List.ListAvailableNumbersRequest { - Product.Voice - } - }); + RegionCode = "US", + Type = Types.Local, + Capabilities = new List() + { + Product.Voice + } + }); response.AvailableNumbers.Should().HaveCount(5); } [Fact] public async Task ListActiveWithPageSize() { - var response = await SinchClientMockStudio.Numbers.Active.List(new Sinch.Numbers.Active.List.ListActiveNumbersRequest - { - RegionCode = "GB", - Type = Types.Mobile, - PageSize = 1 - }); + var response = await SinchClientMockStudio.Numbers.List( + new Sinch.Numbers.Active.List.ListActiveNumbersRequest + { + RegionCode = "GB", + Type = Types.Mobile, + PageSize = 1 + }); response.TotalSize.Should().Be(6); response.ActiveNumbers.Should().HaveCount(1); } @@ -81,14 +85,15 @@ public async Task ListActiveWithPageSize() [Fact] public async Task ListActiveWithPageToken() { - var response = await SinchClientMockStudio.Numbers.Active.List(new Sinch.Numbers.Active.List.ListActiveNumbersRequest - { - RegionCode = "GB", - Type = Types.Mobile, - PageSize = 1, - PageToken = - "CgtwaG9uZU51bWJlchJoCjl0eXBlLmdvb2dsZWFwaXMuY29tL3NpbmNoLnVuaWZpZWRudW1iZXIudjEuTnVtYmVyUGFnZU1hcmsSKwoaMDFnZTI0Z3JwejFjcXcyN2c4MnBoZnEzN3oSDSs0NDc1MjA2NTI2NDI=", - }); + var response = await SinchClientMockStudio.Numbers.List( + new Sinch.Numbers.Active.List.ListActiveNumbersRequest + { + RegionCode = "GB", + Type = Types.Mobile, + PageSize = 1, + PageToken = + "CgtwaG9uZU51bWJlchJoCjl0eXBlLmdvb2dsZWFwaXMuY29tL3NpbmNoLnVuaWZpZWRudW1iZXIudjEuTnVtYmVyUGFnZU1hcmsSKwoaMDFnZTI0Z3JwejFjcXcyN2c4MnBoZnEzN3oSDSs0NDc1MjA2NTI2NDI=", + }); response.TotalSize.Should().Be(6); response.ActiveNumbers.Should().HaveCount(1); response.NextPageToken.Should().BeEmpty(); @@ -97,14 +102,14 @@ public async Task ListActiveWithPageToken() [Fact] public async Task GetActive() { - var response = await SinchClientMockStudio.Numbers.Active.Get("+447520650626"); + var response = await SinchClientMockStudio.Numbers.Get("+447520650626"); response.ExpireAt.Should().Be(8.October(2022).At(7, 52, 49, 454)); } [Fact] public async Task Release() { - var response = await SinchClientMockStudio.Numbers.Active.Release("+447520650626"); + var response = await SinchClientMockStudio.Numbers.Release("+447520650626"); response.PhoneNumber.Should().Be("+447520650626"); } } From df0dc0c819b182a612f692f4d7260deefa799730 Mon Sep 17 00:00:00 2001 From: Volodymyr Lisovskyi Date: Tue, 13 Aug 2024 11:43:32 +0200 Subject: [PATCH 4/8] chore: point to actual methods --- tests/Sinch.Tests/Numbers/ActiveNumberTests.cs | 12 ++++++------ tests/Sinch.Tests/Numbers/AvailableNumbersTests.cs | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/tests/Sinch.Tests/Numbers/ActiveNumberTests.cs b/tests/Sinch.Tests/Numbers/ActiveNumberTests.cs index 5cbdc0f..28504ca 100644 --- a/tests/Sinch.Tests/Numbers/ActiveNumberTests.cs +++ b/tests/Sinch.Tests/Numbers/ActiveNumberTests.cs @@ -24,7 +24,7 @@ public async Task Get() .WithHeaders("Authorization", $"Bearer {Token}") .Respond(HttpStatusCode.OK, JsonContent.Create(TestData.ActiveNumber)); - var response = await Numbers.Active.Get("+12025550134"); + var response = await Numbers.Get("+12025550134"); response.Should().NotBeNull(); response.PhoneNumber.Should().Be("+12025550134"); @@ -47,7 +47,7 @@ public async Task List() totalSize = 5 })); - var response = await Numbers.Active.List(new ListActiveNumbersRequest + var response = await Numbers.List(new ListActiveNumbersRequest { RegionCode = "US", Type = Types.Mobile, @@ -96,7 +96,7 @@ public async Task ListWithFullParams() Capability = new List { Product.Sms, Product.Voice }, NumberPattern = new NumberPattern { Pattern = "2020", SearchPattern = SearchPattern.Contain } }; - var response = await Numbers.Active.List(request); + var response = await Numbers.List(request); response.Should().NotBeNull(); response.ActiveNumbers.Should().HaveCount(1); @@ -113,7 +113,7 @@ public async Task Release() .WithHeaders("Authorization", $"Bearer {Token}") .Respond(HttpStatusCode.OK, JsonContent.Create(TestData.ActiveNumber)); - var response = await Numbers.Active.Release("+12025550134"); + var response = await Numbers.Release("+12025550134"); response.Should().NotBeNull(); response.PhoneNumber.Should().Be("+12025550134"); @@ -130,7 +130,7 @@ public async Task Update() .Respond(HttpStatusCode.OK, JsonContent.Create(TestData.ActiveNumber)); - var response = await Numbers.Active.Update("+12025550134", new Sinch.Numbers.Active.Update.UpdateActiveNumberRequest + var response = await Numbers.Update("+12025550134", new Sinch.Numbers.Active.Update.UpdateActiveNumberRequest { DisplayName = "Name", SmsConfiguration = new SmsConfiguration @@ -184,7 +184,7 @@ public async Task ListAuto() })); - var res = Numbers.Active.ListAuto(new ListActiveNumbersRequest + var res = Numbers.ListAuto(new ListActiveNumbersRequest { RegionCode = "US", Type = Types.Mobile, diff --git a/tests/Sinch.Tests/Numbers/AvailableNumbersTests.cs b/tests/Sinch.Tests/Numbers/AvailableNumbersTests.cs index e60c631..0830787 100644 --- a/tests/Sinch.Tests/Numbers/AvailableNumbersTests.cs +++ b/tests/Sinch.Tests/Numbers/AvailableNumbersTests.cs @@ -39,7 +39,7 @@ public async Task Rent() } }; - var response = await Numbers.Available.Rent("+12025550134", request); + var response = await Numbers.Rent("+12025550134", request); response.Should().NotBeNull(); response.PhoneNumber.Should().Be("+12025550134"); } @@ -70,7 +70,7 @@ public async Task RentAny() CampaignId = "campaign_id" } }; - var response = await Numbers.Available.RentAny(request); + var response = await Numbers.RentAny(request); response.Should().NotBeNull(); response.PhoneNumber.Should().Be("+12025550134"); @@ -92,7 +92,7 @@ public async Task Search() availableNumbers = new[] { TestData.AvailableNumber } })); - var response = await Numbers.Available.List( + var response = await Numbers.SearchForAvailableNumbers( new Sinch.Numbers.Available.List.ListAvailableNumbersRequest { RegionCode = "US", @@ -107,7 +107,7 @@ public async Task Search() }); response.Should().NotBeNull(); - response.AvailableNumbers.Count().Should().Be(1); + response.AvailableNumbers!.Count().Should().Be(1); } [Fact] @@ -119,7 +119,7 @@ public async Task CheckAvailability() .WithHeaders("Authorization", $"Bearer {Token}") .Respond(HttpStatusCode.OK, JsonContent.Create(TestData.AvailableNumber)); - var response = await Numbers.Available.CheckAvailability("+12025550134"); + var response = await Numbers.CheckAvailability("+12025550134"); response.Should().NotBeNull(); response.PhoneNumber.Should().Be("+12025550134"); @@ -152,7 +152,7 @@ public async Task AvailableError() } })); - Func> response = () => Numbers.Available.CheckAvailability("+12025550"); + Func> response = () => Numbers.CheckAvailability("+12025550"); var exception = await response.Should().ThrowAsync(); var node = exception.And.Details!.First(); From 255ac3cba636a8fcb66ff1a34f206870e53db6af Mon Sep 17 00:00:00 2001 From: Volodymyr Lisovskyi Date: Tue, 13 Aug 2024 11:45:11 +0200 Subject: [PATCH 5/8] chore: point to actual in example --- examples/Console/ListActiveNumbers.cs | 2 +- examples/Console/RentAndConfigureNumbers.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/Console/ListActiveNumbers.cs b/examples/Console/ListActiveNumbers.cs index b942ef3..7a8eebd 100644 --- a/examples/Console/ListActiveNumbers.cs +++ b/examples/Console/ListActiveNumbers.cs @@ -12,7 +12,7 @@ public async Task Example() Environment.GetEnvironmentVariable("SINCH_KEY_ID")!, Environment.GetEnvironmentVariable("SINCH_KEY_SECRET")! ); - ListActiveNumbersResponse response = await sinch.Numbers.Active.List(new ListActiveNumbersRequest + ListActiveNumbersResponse response = await sinch.Numbers.List(new ListActiveNumbersRequest { RegionCode = "US", Type = Types.Mobile diff --git a/examples/Console/RentAndConfigureNumbers.cs b/examples/Console/RentAndConfigureNumbers.cs index c446b86..a90109b 100644 --- a/examples/Console/RentAndConfigureNumbers.cs +++ b/examples/Console/RentAndConfigureNumbers.cs @@ -10,7 +10,7 @@ public class RentAndConfigureNumbers public static async Task Example() { var sinchClient = new SinchClient("PROJECT_ID", "KEY_ID", "KEY_SECRET"); - var response = await sinchClient.Numbers.Available.Rent("+4811111111", new RentActiveNumberRequest() + var response = await sinchClient.Numbers.Rent("+4811111111", new RentActiveNumberRequest() { SmsConfiguration = new SmsConfiguration { From 5b16f239bc6978d0284e69a54c18e9e0d3a90b3c Mon Sep 17 00:00:00 2001 From: Volodymyr Lisovskyi Date: Tue, 13 Aug 2024 11:45:34 +0200 Subject: [PATCH 6/8] chore: cleanup using and mark null pass as intentional --- src/Sinch/Core/Http.cs | 2 +- src/Sinch/SMS/Inbounds/BinaryInbound.cs | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Sinch/Core/Http.cs b/src/Sinch/Core/Http.cs index da5a36b..09f3c15 100644 --- a/src/Sinch/Core/Http.cs +++ b/src/Sinch/Core/Http.cs @@ -86,7 +86,7 @@ public Http(ISinchAuth auth, HttpClient httpClient, ILoggerAdapter? logge public Task Send(Uri uri, HttpMethod httpMethod, CancellationToken cancellationToken = default, Dictionary>? headers = null) { - return Send(uri, httpMethod, null, cancellationToken, headers); + return Send(uri, httpMethod, null!, cancellationToken, headers); } public async Task Send(Uri uri, HttpMethod httpMethod, TRequest request, diff --git a/src/Sinch/SMS/Inbounds/BinaryInbound.cs b/src/Sinch/SMS/Inbounds/BinaryInbound.cs index ba36caf..9da4d69 100644 --- a/src/Sinch/SMS/Inbounds/BinaryInbound.cs +++ b/src/Sinch/SMS/Inbounds/BinaryInbound.cs @@ -1,5 +1,4 @@ using System; -using System.Text.Json.Serialization; namespace Sinch.SMS.Inbounds { From 43053e321b8099ecae2a23b92bbd7e0116c4b3cc Mon Sep 17 00:00:00 2001 From: Volodymyr Lisovskyi Date: Tue, 13 Aug 2024 11:50:03 +0200 Subject: [PATCH 7/8] chore: throw exception if URI is null in AplicationSignedAuth --- src/Sinch/Core/Http.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Sinch/Core/Http.cs b/src/Sinch/Core/Http.cs index 09f3c15..f487ede 100644 --- a/src/Sinch/Core/Http.cs +++ b/src/Sinch/Core/Http.cs @@ -205,6 +205,11 @@ private static void AddOrOverrideHeaders(HttpRequestMessage msg, bytes = await msg.Content.ReadAsByteArrayAsync(cancellationToken); } + if (msg.RequestUri is null) + { + throw new NullReferenceException("HttpRequestMessage request uri is null"); + } + token = appSignAuth.GetSignedAuth( bytes, msg.Method.ToString().ToUpperInvariant(), msg.RequestUri.PathAndQuery, From 8da1e13880e14371338a2f5afb7ac8c741aa437b Mon Sep 17 00:00:00 2001 From: Volodymyr Lisovskyi Date: Mon, 19 Aug 2024 18:18:20 +0200 Subject: [PATCH 8/8] chore: add obsolete for Active and Available tags --- src/Sinch/Numbers/Numbers.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Sinch/Numbers/Numbers.cs b/src/Sinch/Numbers/Numbers.cs index ee7859f..821fd86 100644 --- a/src/Sinch/Numbers/Numbers.cs +++ b/src/Sinch/Numbers/Numbers.cs @@ -28,12 +28,14 @@ public interface ISinchNumbers /// /// You can use the Available Number API to search for available numbers or activate an available number. /// + [Obsolete($"This property is obsolete, use methods of this ({nameof(ISinchNumbers)}) interface instead.")] public ISinchNumbersAvailable Available { get; } /// /// You can use the Active Number API to manage numbers you own. Assign numbers to projects, /// release numbers from projects, or list all numbers assigned to a project. /// + [Obsolete($"This property is obsolete, use methods of this ({nameof(ISinchNumbers)}) interface instead.")] public ISinchNumbersActive Active { get; } ///