diff --git a/Deepgram.Tests/UnitTests/ClientTests/AnalyzeClientTests.cs b/Deepgram.Tests/UnitTests/ClientTests/AnalyzeClientTests.cs new file mode 100644 index 00000000..3737b744 --- /dev/null +++ b/Deepgram.Tests/UnitTests/ClientTests/AnalyzeClientTests.cs @@ -0,0 +1,426 @@ +// Copyright 2021-2024 Deepgram .NET SDK contributors. All Rights Reserved. +// Use of this source code is governed by a MIT license that can be found in the LICENSE file. +// SPDX-License-Identifier: MIT + +using Deepgram.Encapsulations; +using Deepgram.Models.Analyze.v1; +using Deepgram.Models.Authenticate.v1; + +namespace Deepgram.Tests.UnitTests.ClientTests; + +public class AnalyzeClientTests +{ + DeepgramClientOptions _options; + string _apiKey; + + [SetUp] + public void Setup() + { + _options = new DeepgramClientOptions(); + _apiKey = new Faker().Random.Guid().ToString(); + } + + [Test] + public async Task AnalyzeUrl_Should_Call_PostAsync_Returning_SyncResponse() + { + //Arrange + var expectedResponse = new AutoFaker().Generate(); + var analyzeSchema = new AutoFaker().Generate(); + analyzeSchema.CallBack = null; + var stringedOptions = QueryParameterUtil.GetParameters(analyzeSchema); + var source = new AutoFaker().Generate(); + var httpClient = MockHttpClient.CreateHttpClientWithResult(expectedResponse); + + var analyzeClient = Substitute.For(_apiKey, _options); + analyzeClient._httpClientWrapper = new HttpClientWrapper(httpClient); + + analyzeClient.When(x => x.PostAsync(Arg.Any(), Arg.Any())).DoNotCallBase(); + analyzeClient.PostAsync($"{UriSegments.ANALYZE}?{stringedOptions}", Arg.Any()).Returns(expectedResponse); + + // Act + var result = await analyzeClient.AnalyzeUrl(source, analyzeSchema); + + // Assert + await analyzeClient.Received().PostAsync($"{UriSegments.ANALYZE}?{stringedOptions}", Arg.Any()); + + using (new AssertionScope()) + { + result.Should().NotBeNull(); + result.Should().BeAssignableTo(); + result.Should().BeEquivalentTo(expectedResponse); + } + } + + [Test] + public async Task AnalyzeUrl_Should_Throw_ArgumentException_If_CallBack_Not_Null() + { + //Arrange + var expectedResponse = new AutoFaker().Generate(); + var analyzeSchema = new AutoFaker().Generate(); + var stringedOptions = QueryParameterUtil.GetParameters(analyzeSchema); + var source = new AutoFaker().Generate(); + var httpClient = MockHttpClient.CreateHttpClientWithResult(expectedResponse); + + var analyzeClient = Substitute.For(_apiKey, _options); + analyzeClient._httpClientWrapper = new HttpClientWrapper(httpClient); + analyzeClient.When(x => x.PostAsync(Arg.Any(), Arg.Any())).DoNotCallBase(); + analyzeClient.PostAsync($"{UriSegments.ANALYZE}?{stringedOptions}", Arg.Any()).Returns(expectedResponse); + + // Act and Assert + await analyzeClient.Invoking(y => y.AnalyzeUrl(source, analyzeSchema)) + .Should().ThrowAsync(); + + await analyzeClient.DidNotReceive().PostAsync($"{UriSegments.ANALYZE}?{stringedOptions}", Arg.Any()); + } + + [Test] + public async Task AnalyzeUrlCallBack_Should_Call_PostAsync_Returning_SyncResponse_With_CallBack_Parameter() + { + //Arrange + var expectedResponse = new AutoFaker().Generate(); + var source = new AutoFaker().Generate(); + var analyzeSchema = new AutoFaker().Generate(); + // analyzeSchema is not null here as we first need to get the querystring with the callBack included + var stringedQuery = QueryParameterUtil.GetParameters(analyzeSchema); + var httpClient = MockHttpClient.CreateHttpClientWithResult(expectedResponse); + + var analyzeClient = Substitute.For(_apiKey, _options); + analyzeClient._httpClientWrapper = new HttpClientWrapper(httpClient); + analyzeClient.When(x => x.PostAsync(Arg.Any(), Arg.Any())).DoNotCallBase(); + analyzeClient.PostAsync($"{UriSegments.ANALYZE}?{stringedQuery}", Arg.Any()).Returns(expectedResponse); + var callBackParameter = analyzeSchema.CallBack; + //before we act to test this call with the callBack parameter and not the callBack property we need to null the callBack property + analyzeSchema.CallBack = null; + + + // Act + var result = await analyzeClient.AnalyzeUrlCallBack(source, callBackParameter, analyzeSchema); + + // Assert + await analyzeClient.Received().PostAsync($"{UriSegments.ANALYZE}?{stringedQuery}", Arg.Any()); + using (new AssertionScope()) + { + result.Should().NotBeNull(); + result.Should().BeAssignableTo(); + result.Should().BeEquivalentTo(expectedResponse); + } + } + + [Test] + public async Task AnalyzeUrlCallBack_Should_Call_PostAsync_Returning_SyncResponse_With_CallBack_Property() + { + //Arrange + var expectedResponse = new AutoFaker().Generate(); + var source = new AutoFaker().Generate(); + var analyzeSchema = new AutoFaker().Generate(); + var stringedQuery = QueryParameterUtil.GetParameters(analyzeSchema); + var httpClient = MockHttpClient.CreateHttpClientWithResult(expectedResponse); + + var analyzeClient = Substitute.For(_apiKey, _options); + analyzeClient._httpClientWrapper = new HttpClientWrapper(httpClient); + analyzeClient.When(x => x.PostAsync(Arg.Any(), Arg.Any())).DoNotCallBase(); + analyzeClient.PostAsync($"{UriSegments.ANALYZE}?{stringedQuery}", Arg.Any()).Returns(expectedResponse); + + // Act + var result = await analyzeClient.AnalyzeUrlCallBack(source, null, analyzeSchema); + + // Assert + await analyzeClient.Received().PostAsync($"{UriSegments.ANALYZE}?{stringedQuery}", Arg.Any()); + using (new AssertionScope()) + { + result.Should().NotBeNull(); + result.Should().BeAssignableTo(); + result.Should().BeEquivalentTo(expectedResponse); + } + } + + [Test] + public async Task AnalyzeUrlCallBack_Should_Throw_ArgumentException_With_CallBack_Property_And_CallBack_Parameter_Set() + { + //Arrange + var expectedResponse = new AutoFaker().Generate(); + var source = new AutoFaker().Generate(); + var analyzeSchema = new AutoFaker().Generate(); + var stringedQuery = QueryParameterUtil.GetParameters(analyzeSchema); + + var httpClient = MockHttpClient.CreateHttpClientWithResult(expectedResponse); + var analyzeClient = Substitute.For(_apiKey, _options); + analyzeClient._httpClientWrapper = new HttpClientWrapper(httpClient); + analyzeClient.When(x => x.PostAsync(Arg.Any(), Arg.Any())).DoNotCallBase(); + analyzeClient.PostAsync($"{UriSegments.ANALYZE}?{stringedQuery}", Arg.Any()).Returns(expectedResponse); + var callBackParameter = analyzeSchema.CallBack; + + // Act Assert + await analyzeClient.Invoking(y => y.AnalyzeUrlCallBack(source, callBackParameter, analyzeSchema)) + .Should().ThrowAsync(); + + await analyzeClient.DidNotReceive().PostAsync($"{UriSegments.ANALYZE}?{stringedQuery}", Arg.Any()); + } + + [Test] + public async Task AnalyzeUrlCallBack_Should_Throw_ArgumentException_With_No_CallBack_Set() + { + //Arrange + var expectedResponse = new AutoFaker().Generate(); + var source = new AutoFaker().Generate(); + var analyzeSchema = new AutoFaker().Generate(); + analyzeSchema.CallBack = null; + var stringedQuery = QueryParameterUtil.GetParameters(analyzeSchema); + + var httpClient = MockHttpClient.CreateHttpClientWithResult(expectedResponse); + var analyzeClient = Substitute.For(_apiKey, _options); + analyzeClient._httpClientWrapper = new HttpClientWrapper(httpClient); + analyzeClient.When(x => x.PostAsync(Arg.Any(), Arg.Any())).DoNotCallBase(); + analyzeClient.PostAsync($"{UriSegments.ANALYZE}?{stringedQuery}", Arg.Any()).Returns(expectedResponse); + + + // Act Assert + await analyzeClient.Invoking(y => y.AnalyzeUrlCallBack(source, null, analyzeSchema)) + .Should().ThrowAsync(); + + await analyzeClient.DidNotReceive().PostAsync($"{UriSegments.ANALYZE}?{stringedQuery}", Arg.Any()); + } + + [Test] + public async Task AnalyzeFile_With_Stream_Should_Call_PostAsync_Returning_SyncResponse() + { + //Arrange + var expectedResponse = new AutoFaker().Generate(); + var analyzeSchema = new AutoFaker().Generate(); + analyzeSchema.CallBack = null; + var stringedOptions = QueryParameterUtil.GetParameters(analyzeSchema); + var source = GetFakeStream(GetFakeByteArray()); + var httpClient = MockHttpClient.CreateHttpClientWithResult(expectedResponse); + + var analyzeClient = Substitute.For(_apiKey, _options); + analyzeClient._httpClientWrapper = new HttpClientWrapper(httpClient); + analyzeClient.When(x => x.PostAsync(Arg.Any(), Arg.Any())).DoNotCallBase(); + analyzeClient.PostAsync($"{UriSegments.ANALYZE}?{stringedOptions}", Arg.Any()).Returns(expectedResponse); + + // Act + var result = await analyzeClient.AnalyzeFile(source, analyzeSchema); + + // Assert + await analyzeClient.Received().PostAsync($"{UriSegments.ANALYZE}?{stringedOptions}", Arg.Any()); + using (new AssertionScope()) + { + result.Should().NotBeNull(); + result.Should().BeAssignableTo(); + result.Should().BeEquivalentTo(expectedResponse); + } + } + + [Test] + public async Task AnalyzeFile_With_Bytes_Should_Call_PostAsync_Returning_SyncResponse() + { + //Arrange + var expectedResponse = new AutoFaker().Generate(); + var analyzeSchema = new AutoFaker().Generate(); + analyzeSchema.CallBack = null; + var stringedOptions = QueryParameterUtil.GetParameters(analyzeSchema); + var source = GetFakeByteArray(); + var httpClient = MockHttpClient.CreateHttpClientWithResult(expectedResponse); + + var analyzeClient = Substitute.For(_apiKey, _options); + analyzeClient._httpClientWrapper = new HttpClientWrapper(httpClient); + analyzeClient.When(x => x.PostAsync(Arg.Any(), Arg.Any())).DoNotCallBase(); + analyzeClient.PostAsync($"{UriSegments.ANALYZE}?{stringedOptions}", Arg.Any()).Returns(expectedResponse); + + // Act + var result = await analyzeClient.AnalyzeFile(source, analyzeSchema); + + // Assert + await analyzeClient.Received().PostAsync($"{UriSegments.ANALYZE}?{stringedOptions}", Arg.Any()); + using (new AssertionScope()) + { + result.Should().NotBeNull(); + result.Should().BeAssignableTo(); + result.Should().BeEquivalentTo(expectedResponse); + } + } + + [Test] + public async Task AnalyzeFileCallBack_With_Stream_With_CallBack_Property_Should_Call_PostAsync_Returning_SyncResponse() + { + //Arrange + var expectedResponse = new AutoFaker().Generate(); + var analyzeSchema = new AutoFaker().Generate(); + var stringedOptions = QueryParameterUtil.GetParameters(analyzeSchema); + var source = GetFakeStream(GetFakeByteArray()); + var httpClient = MockHttpClient.CreateHttpClientWithResult(expectedResponse); + + var analyzeClient = Substitute.For(_apiKey, _options); + analyzeClient._httpClientWrapper = new HttpClientWrapper(httpClient); + analyzeClient.When(x => x.PostAsync(Arg.Any(), Arg.Any())).DoNotCallBase(); + analyzeClient.PostAsync($"{UriSegments.ANALYZE}?{stringedOptions}", Arg.Any()).Returns(expectedResponse); + + // Act + var result = await analyzeClient.AnalyzeFileCallBack(source, null, analyzeSchema); + + // Assert + await analyzeClient.Received().PostAsync($"{UriSegments.ANALYZE}?{stringedOptions}", Arg.Any()); + using (new AssertionScope()) + { + result.Should().NotBeNull(); + result.Should().BeAssignableTo(); + result.Should().BeEquivalentTo(expectedResponse); + } + } + + [Test] + public async Task AnalyzeFileCallBack_With_Bytes_With_CallBack_Property_Should_Call_PostAsync_Returning_SyncResponse() + { + //Arrange + var expectedResponse = new AutoFaker().Generate(); + var analyzeSchema = new AutoFaker().Generate(); + var stringedOptions = QueryParameterUtil.GetParameters(analyzeSchema); + var source = GetFakeByteArray(); + var httpClient = MockHttpClient.CreateHttpClientWithResult(expectedResponse); + + var analyzeClient = Substitute.For(_apiKey, _options); + analyzeClient._httpClientWrapper = new HttpClientWrapper(httpClient); + analyzeClient.When(x => x.PostAsync(Arg.Any(), Arg.Any())).DoNotCallBase(); + analyzeClient.PostAsync($"{UriSegments.ANALYZE}?{stringedOptions}", Arg.Any()).Returns(expectedResponse); + + // Act + var result = await analyzeClient.AnalyzeFileCallBack(source, null, analyzeSchema); + + // Assert + await analyzeClient.Received().PostAsync($"{UriSegments.ANALYZE}?{stringedOptions}", Arg.Any()); + + using (new AssertionScope()) + { + result.Should().NotBeNull(); + result.Should().BeAssignableTo(); + result.Should().BeEquivalentTo(expectedResponse); + } + } + + [Test] + public async Task AnalyzeFileCallBack_With_Stream_With_CallBack_Parameter_Should_Call_PostAsync_Returning_SyncResponse() + { + //Arrange + var expectedResponse = new AutoFaker().Generate(); + var analyzeSchema = new AutoFaker().Generate(); + // analyzeSchema is not null here as we first need to get the querystring with the callBack included + var stringedOptions = QueryParameterUtil.GetParameters(analyzeSchema); + var source = GetFakeStream(GetFakeByteArray()); + var httpClient = MockHttpClient.CreateHttpClientWithResult(expectedResponse); + + var analyzeClient = Substitute.For(_apiKey, _options); + analyzeClient._httpClientWrapper = new HttpClientWrapper(httpClient); + analyzeClient.When(x => x.PostAsync(Arg.Any(), Arg.Any())).DoNotCallBase(); + analyzeClient.PostAsync($"{UriSegments.ANALYZE}?{stringedOptions}", Arg.Any()).Returns(expectedResponse); + + var callBack = analyzeSchema.CallBack; + + //before we act to test this call with the callBack parameter and not the callBack property we need to null the callBack property + analyzeSchema.CallBack = null; + + // Act + var result = await analyzeClient.AnalyzeFileCallBack(source, callBack, analyzeSchema); + + // Assert + await analyzeClient.Received().PostAsync($"{UriSegments.ANALYZE}?{stringedOptions}", Arg.Any()); + using (new AssertionScope()) + { + result.Should().NotBeNull(); + result.Should().BeAssignableTo(); + result.Should().BeEquivalentTo(expectedResponse); + } + } + + [Test] + public async Task AnalyzeFileCallBack_With_Bytes_With_CallBack_Parameter_Should_Call_PostAsync_Returning_SyncResponse() + { + //Arrange + var expectedResponse = new AutoFaker().Generate(); + var analyzeSchema = new AutoFaker().Generate(); + // analyzeSchema is not null here as we first need to get the querystring with the callBack included + var stringedOptions = QueryParameterUtil.GetParameters(analyzeSchema); + var source = GetFakeByteArray(); + + var httpClient = MockHttpClient.CreateHttpClientWithResult(expectedResponse); + var analyzeClient = Substitute.For(_apiKey, _options); + analyzeClient._httpClientWrapper = new HttpClientWrapper(httpClient); + analyzeClient.When(x => x.PostAsync(Arg.Any(), Arg.Any())).DoNotCallBase(); + analyzeClient.PostAsync($"{UriSegments.ANALYZE}?{stringedOptions}", Arg.Any()).Returns(expectedResponse); + + var callBack = analyzeSchema.CallBack; + + //before we act to test this call with the callBack parameter and not the callBack property we need to null the callBack property + analyzeSchema.CallBack = null; + + // Act + var result = await analyzeClient.AnalyzeFileCallBack(source, callBack, analyzeSchema); + + // Assert + await analyzeClient.Received().PostAsync($"{UriSegments.ANALYZE}?{stringedOptions}", Arg.Any()); + using (new AssertionScope()) + { + result.Should().NotBeNull(); + result.Should().BeAssignableTo(); + result.Should().BeEquivalentTo(expectedResponse); + } + } + + [Test] + public async Task AnalyzeFileCallBack_With_Stream_Throw_ArgumentException_With_CallBack_Property_And_CallBack_Parameter_Set() + { + //Arrange + var expectedResponse = new AutoFaker().Generate(); + var analyzeSchema = new AutoFaker().Generate(); + var stringedOptions = QueryParameterUtil.GetParameters(analyzeSchema); + var source = GetFakeStream(GetFakeByteArray()); + var httpClient = MockHttpClient.CreateHttpClientWithResult(expectedResponse); + + var analyzeClient = Substitute.For(_apiKey, _options); + analyzeClient._httpClientWrapper = new HttpClientWrapper(httpClient); + analyzeClient.When(x => x.PostAsync(Arg.Any(), Arg.Any())).DoNotCallBase(); + analyzeClient.PostAsync($"{UriSegments.ANALYZE}?{stringedOptions}", Arg.Any()).Returns(expectedResponse); + var callBack = analyzeSchema.CallBack; + + + // Act Assert + await analyzeClient.Invoking(y => y.AnalyzeFileCallBack(source, callBack, analyzeSchema)) + .Should().ThrowAsync(); + + await analyzeClient.DidNotReceive().PostAsync($"{UriSegments.ANALYZE}?{stringedOptions}", Arg.Any()); + + + } + + [Test] + public async Task AnalyzeFileCallBack_With_Bytes_Should_Throw_ArgumentException_With_No_CallBack_Set() + { + //Arrange + var expectedResponse = new AutoFaker().Generate(); + var analyzeSchema = new AutoFaker().Generate(); + // analyzeSchema is not null here as we first need to get the querystring with the callBack included + var stringedOptions = QueryParameterUtil.GetParameters(analyzeSchema); + var source = GetFakeByteArray(); + + var httpClient = MockHttpClient.CreateHttpClientWithResult(expectedResponse); + var analyzeClient = Substitute.For(_apiKey, _options); + analyzeClient._httpClientWrapper = new HttpClientWrapper(httpClient); + analyzeClient.When(x => x.PostAsync(Arg.Any(), Arg.Any())).DoNotCallBase(); + analyzeClient.PostAsync($"{UriSegments.ANALYZE}?{stringedOptions}", Arg.Any()).Returns(expectedResponse); + analyzeSchema.CallBack = null; + + // Act Assert + await analyzeClient.Invoking(y => y.AnalyzeFileCallBack(source, null, analyzeSchema)) + .Should().ThrowAsync(); + + await analyzeClient.DidNotReceive().PostAsync($"{UriSegments.ANALYZE}?{stringedOptions}", Arg.Any()); + } + + private static Stream GetFakeStream(byte[] source) + { + var stream = new MemoryStream(); + stream.Write(source, 0, source.Length); + return stream; + } + + private static byte[] GetFakeByteArray() => new Faker().Random.Bytes(10); + +} diff --git a/Deepgram.Tests/UnitTests/ClientTests/LiveClientTests.cs b/Deepgram.Tests/UnitTests/ClientTests/LiveClientTests.cs index cf1d1160..3040a0e2 100644 --- a/Deepgram.Tests/UnitTests/ClientTests/LiveClientTests.cs +++ b/Deepgram.Tests/UnitTests/ClientTests/LiveClientTests.cs @@ -8,6 +8,7 @@ using Deepgram.Models.Authenticate.v1; namespace Deepgram.Tests.UnitTests.ClientTests; + public class LiveClientTests { DeepgramClientOptions _options; diff --git a/Deepgram.Tests/UnitTests/ClientTests/ManageClientTest.cs b/Deepgram.Tests/UnitTests/ClientTests/ManageClientTest.cs index 9675a166..46d811e5 100644 --- a/Deepgram.Tests/UnitTests/ClientTests/ManageClientTest.cs +++ b/Deepgram.Tests/UnitTests/ClientTests/ManageClientTest.cs @@ -3,11 +3,11 @@ // SPDX-License-Identifier: MIT using Deepgram.Encapsulations; -using Deepgram.Models.Manage; using Deepgram.Models.Manage.v1; using Deepgram.Models.Authenticate.v1; namespace Deepgram.Tests.UnitTests.ClientTests; + public class ManageClientTest { DeepgramClientOptions _options; @@ -22,10 +22,6 @@ public void Setup() } #region Projects - - - - [Test] public async Task GetProjects_Should_Call_GetAsync_Returning_ProjectsResponse() { diff --git a/Deepgram.Tests/UnitTests/ClientTests/OnPremClientTests.cs b/Deepgram.Tests/UnitTests/ClientTests/OnPremClientTests.cs index 784bcc61..7991191d 100644 --- a/Deepgram.Tests/UnitTests/ClientTests/OnPremClientTests.cs +++ b/Deepgram.Tests/UnitTests/ClientTests/OnPremClientTests.cs @@ -8,6 +8,7 @@ using Deepgram.Models.Authenticate.v1; namespace Deepgram.Tests.UnitTests.ClientTests; + public class OnPremClientTests { DeepgramClientOptions _options; @@ -21,9 +22,6 @@ public void Setup() _apiKey = new Faker().Random.Guid().ToString(); } - - - [Test] public async Task ListCredentials_Should_Call_GetAsync_Returning_CredentialsResponse() { diff --git a/Deepgram.Tests/UnitTests/ClientTests/PrerecordedClientTests.cs b/Deepgram.Tests/UnitTests/ClientTests/PrerecordedClientTests.cs index 08be0496..6f539db2 100644 --- a/Deepgram.Tests/UnitTests/ClientTests/PrerecordedClientTests.cs +++ b/Deepgram.Tests/UnitTests/ClientTests/PrerecordedClientTests.cs @@ -7,6 +7,7 @@ using Deepgram.Models.Authenticate.v1; namespace Deepgram.Tests.UnitTests.ClientTests; + public class PrerecordedClientTests { DeepgramClientOptions _options; diff --git a/Deepgram/AnalyzeClient.cs b/Deepgram/AnalyzeClient.cs index dd94b1fe..ba113897 100644 --- a/Deepgram/AnalyzeClient.cs +++ b/Deepgram/AnalyzeClient.cs @@ -12,33 +12,33 @@ namespace Deepgram; /// /// Required DeepgramApiKey /// for HttpClient Configuration -public class ReadClient(string apiKey, DeepgramClientOptions? deepgramClientOptions = null) +public class AnalyzeClient(string apiKey, DeepgramClientOptions? deepgramClientOptions = null) : AbstractRestClient(apiKey, deepgramClientOptions) { #region NoneCallBacks /// - /// Transcribe a file by providing a url + /// Analyze a file by providing a url /// - /// Url to the file that is to be transcribed + /// Url to the file that is to be analyzed /// Options for the transcription /// - public async Task TranscribeUrl(UrlSource source, AnalyzeSchema? analyzeSchema, CancellationToken cancellationToken = default) + public async Task AnalyzeUrl(UrlSource source, AnalyzeSchema? analyzeSchema, CancellationToken cancellationToken = default) { - VerifyNoCallBack(nameof(TranscribeUrl), analyzeSchema); + VerifyNoCallBack(nameof(AnalyzeUrl), analyzeSchema); var stringedOptions = QueryParameterUtil.GetParameters(analyzeSchema); return await PostAsync( $"{UriSegments.ANALYZE}?{stringedOptions}", RequestContentUtil.CreatePayload(source), cancellationToken); } /// - /// Transcribes a file using the provided byte array + /// Analyzes a file using the provided byte array /// /// file is the form of a byte[] /// Options for the transcription /// - public async Task TranscribeFile(byte[] source, AnalyzeSchema? analyzeSchema, CancellationToken cancellationToken = default) + public async Task AnalyzeFile(byte[] source, AnalyzeSchema? analyzeSchema, CancellationToken cancellationToken = default) { - VerifyNoCallBack(nameof(TranscribeFile), analyzeSchema); + VerifyNoCallBack(nameof(AnalyzeFile), analyzeSchema); var stringedOptions = QueryParameterUtil.GetParameters(analyzeSchema); var stream = new MemoryStream(); stream.Write(source, 0, source.Length); @@ -48,14 +48,14 @@ public async Task TranscribeFile(byte[] source, AnalyzeSchema? ana } /// - /// Transcribes a file using the provided stream + /// Analyzes a file using the provided stream /// /// file is the form of a stream /// Options for the transcription /// - public async Task TranscribeFile(Stream source, AnalyzeSchema? analyzeSchema, CancellationToken cancellationToken = default) + public async Task AnalyzeFile(Stream source, AnalyzeSchema? analyzeSchema, CancellationToken cancellationToken = default) { - VerifyNoCallBack(nameof(TranscribeFile), analyzeSchema); + VerifyNoCallBack(nameof(AnalyzeFile), analyzeSchema); var stringedOptions = QueryParameterUtil.GetParameters(analyzeSchema); return await PostAsync( $"{UriSegments.ANALYZE}?{stringedOptions}", @@ -66,15 +66,15 @@ public async Task TranscribeFile(Stream source, AnalyzeSchema? ana #region CallBack Methods /// - /// Transcribes a file using the provided byte array and providing a CallBack + /// Analyzes a file using the provided byte array and providing a CallBack /// /// file is the form of a byte[] /// CallBack url /// Options for the transcription /// - public async Task TranscribeFileCallBack(byte[] source, string? callBack, AnalyzeSchema? analyzeSchema, CancellationToken cancellationToken = default) + public async Task AnalyzeFileCallBack(byte[] source, string? callBack, AnalyzeSchema? analyzeSchema, CancellationToken cancellationToken = default) { - VerifyOneCallBackSet(nameof(TranscribeFileCallBack), callBack, analyzeSchema); + VerifyOneCallBackSet(nameof(AnalyzeFileCallBack), callBack, analyzeSchema); if (callBack != null) analyzeSchema.CallBack = callBack; @@ -87,15 +87,15 @@ public async Task TranscribeFileCallBack(byte[] source, string? c } /// - /// Transcribes a file using the provided stream and providing a CallBack + /// Analyzes a file using the provided stream and providing a CallBack /// /// file is the form of a stream /// CallBack url /// Options for the transcription /// - public async Task TranscribeFileCallBack(Stream source, string? callBack, AnalyzeSchema? analyzeSchema, CancellationToken cancellationToken = default) + public async Task AnalyzeFileCallBack(Stream source, string? callBack, AnalyzeSchema? analyzeSchema, CancellationToken cancellationToken = default) { - VerifyOneCallBackSet(nameof(TranscribeFileCallBack), callBack, analyzeSchema); + VerifyOneCallBackSet(nameof(AnalyzeFileCallBack), callBack, analyzeSchema); if (callBack != null) analyzeSchema.CallBack = callBack; var stringedOptions = QueryParameterUtil.GetParameters(analyzeSchema); @@ -105,15 +105,15 @@ public async Task TranscribeFileCallBack(Stream source, string? c } /// - /// Transcribe a file by providing a url and a CallBack + /// Analyze a file by providing a url and a CallBack /// - /// Url to the file that is to be transcribed + /// Url to the file that is to be analyzed /// CallBack url /// Options for the transcription /// - public async Task TranscribeUrlCallBack(UrlSource source, string? callBack, AnalyzeSchema? analyzeSchema, CancellationToken cancellationToken = default) + public async Task AnalyzeUrlCallBack(UrlSource source, string? callBack, AnalyzeSchema? analyzeSchema, CancellationToken cancellationToken = default) { - VerifyOneCallBackSet(nameof(TranscribeUrlCallBack), callBack, analyzeSchema); + VerifyOneCallBackSet(nameof(AnalyzeUrlCallBack), callBack, analyzeSchema); if (callBack != null) analyzeSchema.CallBack = callBack; @@ -128,7 +128,7 @@ public async Task TranscribeUrlCallBack(UrlSource source, string? private void VerifyNoCallBack(string method, AnalyzeSchema? analyzeSchema) { if (analyzeSchema != null && analyzeSchema.CallBack != null) - throw new ArgumentException($"CallBack cannot be provided as schema option to a synchronous transcription when calling {method}. Use {nameof(TranscribeFileCallBack)} or {nameof(TranscribeUrlCallBack)}"); + throw new ArgumentException($"CallBack cannot be provided as schema option to a synchronous transcription when calling {method}. Use {nameof(AnalyzeFileCallBack)} or {nameof(AnalyzeUrlCallBack)}"); } private void VerifyOneCallBackSet(string callingMethod, string? callBack, AnalyzeSchema? analyzeSchema) @@ -136,7 +136,7 @@ private void VerifyOneCallBackSet(string callingMethod, string? callBack, Analyz if (analyzeSchema.CallBack == null && callBack == null) { //check if no CallBack set in either callBack parameter or AnalyzeSchema - var ex = new ArgumentException($"Either provide a CallBack url or set AnalyzeSchema.CallBack. If no CallBack needed either {nameof(TranscribeUrl)} or {nameof(TranscribeFile)}"); + var ex = new ArgumentException($"Either provide a CallBack url or set AnalyzeSchema.CallBack. If no CallBack needed either {nameof(AnalyzeUrl)} or {nameof(AnalyzeFile)}"); Log.Exception(_logger, $"While calling {callingMethod} no callback set", ex); throw ex; }