-
Notifications
You must be signed in to change notification settings - Fork 2
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
🌿 Fern Regeneration -- August 26, 2024 #47
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using System.Runtime.Serialization; | ||
|
||
namespace AssemblyAI.Core; | ||
|
||
internal static class Extensions | ||
{ | ||
public static string Stringify(this Enum value) | ||
{ | ||
var field = value.GetType().GetField(value.ToString()); | ||
var attribute = (EnumMemberAttribute) | ||
Attribute.GetCustomAttribute(field, typeof(EnumMemberAttribute)); | ||
return attribute?.Value ?? value.ToString(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using OneOf; | ||
|
||
namespace AssemblyAI.Core; | ||
|
||
internal sealed class HeaderValue(OneOf<string, Func<string>> value) | ||
: OneOfBase<string, Func<string>>(value) | ||
{ | ||
public static implicit operator HeaderValue(string value) | ||
{ | ||
return new HeaderValue(value); | ||
} | ||
|
||
public static implicit operator HeaderValue(Func<string> value) | ||
{ | ||
return new HeaderValue(value); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
namespace AssemblyAI.Core; | ||
|
||
internal sealed class Headers : Dictionary<string, HeaderValue> | ||
{ | ||
public Headers() { } | ||
|
||
public Headers(Dictionary<string, string> value) | ||
{ | ||
foreach (var kvp in value) | ||
{ | ||
this[kvp.Key] = new HeaderValue(kvp.Value); | ||
} | ||
} | ||
|
||
public Headers(IEnumerable<KeyValuePair<string, HeaderValue>> value) | ||
: base(value.ToDictionary(e => e.Key, e => e.Value)) { } | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,35 @@ | ||
using System; | ||
using System.Net.Http; | ||
// ReSharper disable PartialTypeWithSinglePart | ||
// ReSharper disable AutoPropertyCanBeMadeGetOnly.Global | ||
// ReSharper disable CheckNamespace | ||
using AssemblyAI.Core; | ||
|
||
#nullable enable | ||
|
||
namespace AssemblyAI; | ||
|
||
public partial class ClientOptions | ||
{ | ||
/// <summary> | ||
/// The AssemblyAI API key | ||
/// </summary> | ||
public required string ApiKey { get; set; } | ||
|
||
/// <summary> | ||
/// The Base URL for the API. | ||
/// </summary> | ||
public string BaseUrl { get; set; } = AssemblyAIClientEnvironment.Default; | ||
public string BaseUrl { get; init; } = AssemblyAIClientEnvironment.Default; | ||
|
||
/// <summary> | ||
/// The AssemblyAI user agent | ||
/// The http client used to make requests. | ||
/// </summary> | ||
public UserAgent UserAgent { get; set; } = new(); | ||
public HttpClient HttpClient { get; init; } = new HttpClient(); | ||
|
||
/// <summary> | ||
/// The http client used to make requests. | ||
/// </summary> | ||
public HttpClient? HttpClient { get; set; } | ||
public int MaxRetries { get; init; } = 2; | ||
|
||
/// <summary> | ||
/// The http client used to make requests. | ||
/// The timeout for the request. | ||
/// </summary> | ||
public int MaxRetries { get; set; } = 2; | ||
public TimeSpan Timeout { get; init; } = TimeSpan.FromSeconds(30); | ||
|
||
/// <summary> | ||
/// The timeout for the request. | ||
/// The http headers sent with the request. | ||
/// </summary> | ||
public TimeSpan Timeout { get; set; } = TimeSpan.FromSeconds(30); | ||
internal Headers Headers { get; init; } = new(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
using System.Net.Http; | ||
using System.Text.Json; | ||
using System.Threading; | ||
using AssemblyAI; | ||
using AssemblyAI.Core; | ||
|
||
|
@@ -19,7 +20,11 @@ internal FilesClient(RawClient client) | |
/// <summary> | ||
/// Upload a media file to AssemblyAI's servers. | ||
/// </summary> | ||
public async Task<UploadedFile> UploadAsync(Stream request, RequestOptions? options = null) | ||
public async Task<UploadedFile> UploadAsync( | ||
Stream request, | ||
RequestOptions? options = null, | ||
CancellationToken cancellationToken = default | ||
) | ||
{ | ||
var response = await _client.MakeRequestAsync( | ||
new RawClient.StreamApiRequest | ||
|
@@ -28,8 +33,9 @@ public async Task<UploadedFile> UploadAsync(Stream request, RequestOptions? opti | |
Method = HttpMethod.Post, | ||
Path = "v2/upload", | ||
Body = request, | ||
Options = options | ||
} | ||
Options = options, | ||
}, | ||
cancellationToken | ||
); | ||
var responseBody = await response.Raw.Content.ReadAsStringAsync(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Anything that's async usually There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You'll need to use conditional compilation tho: #if NET6_0_OR_GREATER
var responseBody = await response.Raw.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false);
#else
var responseBody = await response.Raw.Content.ReadAsStringAsync().ConfigureAwait(false);
#endif |
||
if (response.StatusCode is >= 200 and < 400) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doc comment is incorrect.