Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Analyze Unit Tests and Fix Analyze Func Names #224

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
426 changes: 426 additions & 0 deletions Deepgram.Tests/UnitTests/ClientTests/AnalyzeClientTests.cs

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Deepgram.Tests/UnitTests/ClientTests/LiveClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Deepgram.Models.Authenticate.v1;

namespace Deepgram.Tests.UnitTests.ClientTests;

public class LiveClientTests
{
DeepgramClientOptions _options;
Expand Down
6 changes: 1 addition & 5 deletions Deepgram.Tests/UnitTests/ClientTests/ManageClientTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -22,10 +22,6 @@ public void Setup()
}

#region Projects




[Test]
public async Task GetProjects_Should_Call_GetAsync_Returning_ProjectsResponse()
davidvonthenen marked this conversation as resolved.
Show resolved Hide resolved
{
Expand Down
4 changes: 1 addition & 3 deletions Deepgram.Tests/UnitTests/ClientTests/OnPremClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Deepgram.Models.Authenticate.v1;

namespace Deepgram.Tests.UnitTests.ClientTests;

public class OnPremClientTests
{
DeepgramClientOptions _options;
Expand All @@ -21,9 +22,6 @@ public void Setup()
_apiKey = new Faker().Random.Guid().ToString();
}




[Test]
public async Task ListCredentials_Should_Call_GetAsync_Returning_CredentialsResponse()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Deepgram.Models.Authenticate.v1;

namespace Deepgram.Tests.UnitTests.ClientTests;

public class PrerecordedClientTests
{
DeepgramClientOptions _options;
Expand Down
46 changes: 23 additions & 23 deletions Deepgram/AnalyzeClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,33 +12,33 @@ namespace Deepgram;
/// </summary>
/// <param name="apiKey">Required DeepgramApiKey</param>
/// <param name="deepgramClientOptions"><see cref="DeepgramClientOptions"/> for HttpClient Configuration</param>
public class ReadClient(string apiKey, DeepgramClientOptions? deepgramClientOptions = null)
public class AnalyzeClient(string apiKey, DeepgramClientOptions? deepgramClientOptions = null)
: AbstractRestClient(apiKey, deepgramClientOptions)
{
#region NoneCallBacks
/// <summary>
/// Transcribe a file by providing a url
/// Analyze a file by providing a url
/// </summary>
/// <param name="source">Url to the file that is to be transcribed <see cref="UrlSource"></param>
/// <param name="source">Url to the file that is to be analyzed <see cref="UrlSource"></param>
/// <param name="analyzeSchema">Options for the transcription <see cref="AnalyzeSchema"/></param>
/// <returns><see cref="SyncResponse"/></returns>
public async Task<SyncResponse> TranscribeUrl(UrlSource source, AnalyzeSchema? analyzeSchema, CancellationToken cancellationToken = default)
public async Task<SyncResponse> AnalyzeUrl(UrlSource source, AnalyzeSchema? analyzeSchema, CancellationToken cancellationToken = default)
{
VerifyNoCallBack(nameof(TranscribeUrl), analyzeSchema);
VerifyNoCallBack(nameof(AnalyzeUrl), analyzeSchema);
var stringedOptions = QueryParameterUtil.GetParameters(analyzeSchema);
return await PostAsync<SyncResponse>(
$"{UriSegments.ANALYZE}?{stringedOptions}",
RequestContentUtil.CreatePayload(source), cancellationToken);
}
/// <summary>
/// Transcribes a file using the provided byte array
/// Analyzes a file using the provided byte array
/// </summary>
/// <param name="source">file is the form of a byte[]</param>
/// <param name="analyzeSchema">Options for the transcription <see cref="AnalyzeSchema"/></param>
/// <returns><see cref="SyncResponse"/></returns>
public async Task<SyncResponse> TranscribeFile(byte[] source, AnalyzeSchema? analyzeSchema, CancellationToken cancellationToken = default)
public async Task<SyncResponse> 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);
Expand All @@ -48,14 +48,14 @@ public async Task<SyncResponse> TranscribeFile(byte[] source, AnalyzeSchema? ana
}

/// <summary>
/// Transcribes a file using the provided stream
/// Analyzes a file using the provided stream
/// </summary>
/// <param name="source">file is the form of a stream <see cref="Stream"/></param>
/// <param name="analyzeSchema">Options for the transcription <see cref="AnalyzeSchema"/></param>
/// <returns><see cref="SyncResponse"/></returns>
public async Task<SyncResponse> TranscribeFile(Stream source, AnalyzeSchema? analyzeSchema, CancellationToken cancellationToken = default)
public async Task<SyncResponse> AnalyzeFile(Stream source, AnalyzeSchema? analyzeSchema, CancellationToken cancellationToken = default)
{
VerifyNoCallBack(nameof(TranscribeFile), analyzeSchema);
VerifyNoCallBack(nameof(AnalyzeFile), analyzeSchema);
var stringedOptions = QueryParameterUtil.GetParameters(analyzeSchema);
return await PostAsync<SyncResponse>(
$"{UriSegments.ANALYZE}?{stringedOptions}",
Expand All @@ -66,15 +66,15 @@ public async Task<SyncResponse> TranscribeFile(Stream source, AnalyzeSchema? ana

#region CallBack Methods
/// <summary>
/// Transcribes a file using the provided byte array and providing a CallBack
/// Analyzes a file using the provided byte array and providing a CallBack
/// </summary>
/// <param name="source">file is the form of a byte[]</param>
/// <param name="callBack">CallBack url</param>
/// <param name="analyzeSchema">Options for the transcription<see cref="AnalyzeSchema"></param>
/// <returns><see cref="AsyncResponse"/></returns>
public async Task<AsyncResponse> TranscribeFileCallBack(byte[] source, string? callBack, AnalyzeSchema? analyzeSchema, CancellationToken cancellationToken = default)
public async Task<AsyncResponse> 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;
Expand All @@ -87,15 +87,15 @@ public async Task<AsyncResponse> TranscribeFileCallBack(byte[] source, string? c
}

/// <summary>
/// Transcribes a file using the provided stream and providing a CallBack
/// Analyzes a file using the provided stream and providing a CallBack
/// </summary>
/// <param name="source">file is the form of a stream <see cref="Stream"></param>
/// <param name="callBack">CallBack url</param>
/// <param name="analyzeSchema">Options for the transcription<see cref="AnalyzeSchema"></param>
/// <returns><see cref="AsyncResponse"/></returns>
public async Task<AsyncResponse> TranscribeFileCallBack(Stream source, string? callBack, AnalyzeSchema? analyzeSchema, CancellationToken cancellationToken = default)
public async Task<AsyncResponse> 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);
Expand All @@ -105,15 +105,15 @@ public async Task<AsyncResponse> TranscribeFileCallBack(Stream source, string? c
}

/// <summary>
/// Transcribe a file by providing a url and a CallBack
/// Analyze a file by providing a url and a CallBack
/// </summary>
/// <param name="source">Url to the file that is to be transcribed <see cref="UrlSource"/></param>
/// <param name="source">Url to the file that is to be analyzed <see cref="UrlSource"/></param>
/// <param name="callBack">CallBack url</param>
/// <param name="analyzeSchema">Options for the transcription<see cref="AnalyzeSchema"></param>
/// <returns><see cref="AsyncResponse"/></returns>
public async Task<AsyncResponse> TranscribeUrlCallBack(UrlSource source, string? callBack, AnalyzeSchema? analyzeSchema, CancellationToken cancellationToken = default)
public async Task<AsyncResponse> 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;
Expand All @@ -128,15 +128,15 @@ public async Task<AsyncResponse> 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)
{

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;
}
Expand Down
Loading