mirror of
https://github.com/LukeHagar/plexcsharp.git
synced 2025-12-10 12:37:45 +00:00
Regenerated SDK with small changes
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// This code was generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT.
|
||||
@@ -17,80 +16,66 @@ namespace PlexAPI.Utils
|
||||
|
||||
public interface ISpeakeasyHttpClient
|
||||
{
|
||||
void AddHeader(string key, string value);
|
||||
void AddQueryParam(string key, string value);
|
||||
Task<HttpResponseMessage> SendAsync(HttpRequestMessage message);
|
||||
/// <summary>
|
||||
/// Sends an HTTP request asynchronously.
|
||||
/// </summary>
|
||||
/// <param name="request">The HTTP request message to send.</param>
|
||||
/// <returns>The value of the TResult parameter contains the HTTP response message.</returns>
|
||||
Task<HttpResponseMessage> SendAsync(HttpRequestMessage request);
|
||||
|
||||
/// <summary>
|
||||
/// Clones an HTTP request asynchronously.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This method is used in the context of Retries. It creates a new HttpRequestMessage instance
|
||||
/// as a deep copy of the original request, including its method, URI, content, headers and options.
|
||||
/// </remarks>
|
||||
/// <param name="request">The HTTP request message to clone.</param>
|
||||
/// <returns>The value of the TResult parameter contains the cloned HTTP request message.</returns>
|
||||
Task<HttpRequestMessage> CloneAsync(HttpRequestMessage request);
|
||||
}
|
||||
|
||||
public class SpeakeasyHttpClient : ISpeakeasyHttpClient
|
||||
{
|
||||
private ISpeakeasyHttpClient? client;
|
||||
protected readonly HttpClient httpClient;
|
||||
|
||||
private Dictionary<string, List<string>> headers { get; } =
|
||||
new Dictionary<string, List<string>>();
|
||||
|
||||
private Dictionary<string, List<string>> queryParams { get; } =
|
||||
new Dictionary<string, List<string>>();
|
||||
|
||||
internal SpeakeasyHttpClient(ISpeakeasyHttpClient? client = null)
|
||||
public SpeakeasyHttpClient()
|
||||
{
|
||||
this.client = client;
|
||||
httpClient = new System.Net.Http.HttpClient();
|
||||
}
|
||||
|
||||
public void AddHeader(string key, string value)
|
||||
public virtual async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request)
|
||||
{
|
||||
if (headers.ContainsKey(key))
|
||||
{
|
||||
headers[key].Add(value);
|
||||
}
|
||||
else
|
||||
{
|
||||
headers.Add(key, new List<string> { value });
|
||||
}
|
||||
return await httpClient.SendAsync(request);
|
||||
}
|
||||
|
||||
public void AddQueryParam(string key, string value)
|
||||
public virtual async Task<HttpRequestMessage> CloneAsync(HttpRequestMessage request)
|
||||
{
|
||||
if (queryParams.ContainsKey(key))
|
||||
{
|
||||
queryParams[key].Add(value);
|
||||
}
|
||||
else
|
||||
{
|
||||
queryParams.Add(key, new List<string> { value });
|
||||
}
|
||||
}
|
||||
HttpRequestMessage clone = new HttpRequestMessage(request.Method, request.RequestUri);
|
||||
|
||||
public async Task<HttpResponseMessage> SendAsync(HttpRequestMessage message)
|
||||
{
|
||||
foreach(var hh in headers)
|
||||
if (request.Content != null)
|
||||
{
|
||||
foreach(var hv in hh.Value)
|
||||
clone.Content = new ByteArrayContent(await request.Content.ReadAsByteArrayAsync());
|
||||
if (request.Content.Headers != null)
|
||||
{
|
||||
message.Headers.Add(hh.Key, hv);
|
||||
foreach (var h in request.Content.Headers)
|
||||
{
|
||||
clone.Content.Headers.Add(h.Key, h.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*var qp = URLBuilder.SerializeQueryParams(queryParams);
|
||||
|
||||
if (qp != "")
|
||||
foreach (KeyValuePair<string, IEnumerable<string>> header in request.Headers)
|
||||
{
|
||||
if (message.uri.Query == "")
|
||||
{
|
||||
message.url += "?" + qp;
|
||||
}
|
||||
else
|
||||
{
|
||||
message.url += "&" + qp;
|
||||
}
|
||||
}*/
|
||||
|
||||
if (client != null)
|
||||
{
|
||||
return await client.SendAsync(message);
|
||||
clone.Headers.TryAddWithoutValidation(header.Key, header.Value);
|
||||
}
|
||||
|
||||
return await new HttpClient().SendAsync(message);
|
||||
foreach (KeyValuePair<string, object?> prop in request.Options)
|
||||
{
|
||||
clone.Options.TryAdd(prop.Key, prop.Value);
|
||||
}
|
||||
|
||||
return clone;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user