mirror of
https://github.com/LukeHagar/plexcsharp.git
synced 2025-12-06 12:37:46 +00:00
migrated to v15
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
namespace PlexAPI
|
||||
{
|
||||
using Newtonsoft.Json;
|
||||
using PlexAPI.Models.Components;
|
||||
using PlexAPI.Models.Requests;
|
||||
using PlexAPI.Utils;
|
||||
using System.Net.Http.Headers;
|
||||
@@ -90,7 +91,7 @@ namespace PlexAPI
|
||||
///
|
||||
/// </remarks>
|
||||
/// </summary>
|
||||
Task<GetResizedPhotoResponse> GetResizedPhotoAsync(GetResizedPhotoRequest? request = null);
|
||||
Task<GetResizedPhotoResponse> GetResizedPhotoAsync(GetResizedPhotoRequest request);
|
||||
|
||||
/// <summary>
|
||||
/// Get Server List
|
||||
@@ -113,404 +114,449 @@ namespace PlexAPI
|
||||
{
|
||||
public SDKConfig SDKConfiguration { get; private set; }
|
||||
private const string _language = "csharp";
|
||||
private const string _sdkVersion = "0.1.5";
|
||||
private const string _sdkGenVersion = "2.237.3";
|
||||
private const string _sdkVersion = "0.2.1";
|
||||
private const string _sdkGenVersion = "2.281.2";
|
||||
private const string _openapiDocVersion = "0.0.3";
|
||||
private const string _userAgent = "speakeasy-sdk/csharp 0.1.5 2.237.3 0.0.3 Plex-API";
|
||||
private const string _userAgent = "speakeasy-sdk/csharp 0.2.1 2.281.2 0.0.3 Plex-API";
|
||||
private string _serverUrl = "";
|
||||
private ISpeakeasyHttpClient _defaultClient;
|
||||
private ISpeakeasyHttpClient _securityClient;
|
||||
private Func<Security>? _securitySource;
|
||||
|
||||
public Server(ISpeakeasyHttpClient defaultClient, ISpeakeasyHttpClient securityClient, string serverUrl, SDKConfig config)
|
||||
public Server(ISpeakeasyHttpClient defaultClient, Func<Security>? securitySource, string serverUrl, SDKConfig config)
|
||||
{
|
||||
_defaultClient = defaultClient;
|
||||
_securityClient = securityClient;
|
||||
_securitySource = securitySource;
|
||||
_serverUrl = serverUrl;
|
||||
SDKConfiguration = config;
|
||||
}
|
||||
|
||||
|
||||
public async Task<GetServerCapabilitiesResponse> GetServerCapabilitiesAsync()
|
||||
{
|
||||
string baseUrl = this.SDKConfiguration.GetTemplatedServerDetails();
|
||||
|
||||
var urlString = baseUrl + "/";
|
||||
|
||||
|
||||
var httpRequest = new HttpRequestMessage(HttpMethod.Get, urlString);
|
||||
httpRequest.Headers.Add("user-agent", _userAgent);
|
||||
|
||||
|
||||
var client = _securityClient;
|
||||
|
||||
|
||||
var client = _defaultClient;
|
||||
if (_securitySource != null)
|
||||
{
|
||||
client = SecuritySerializer.Apply(_defaultClient, _securitySource);
|
||||
}
|
||||
|
||||
var httpResponse = await client.SendAsync(httpRequest);
|
||||
|
||||
var contentType = httpResponse.Content.Headers.ContentType?.MediaType;
|
||||
|
||||
|
||||
var response = new GetServerCapabilitiesResponse
|
||||
{
|
||||
StatusCode = (int)httpResponse.StatusCode,
|
||||
ContentType = contentType,
|
||||
RawResponse = httpResponse
|
||||
};
|
||||
|
||||
|
||||
if((response.StatusCode == 200))
|
||||
{
|
||||
if(Utilities.IsContentTypeMatch("application/json",response.ContentType))
|
||||
{
|
||||
response.TwoHundredApplicationJsonObject = JsonConvert.DeserializeObject<GetServerCapabilitiesResponseBody>(await httpResponse.Content.ReadAsStringAsync(), new JsonSerializerSettings(){ NullValueHandling = NullValueHandling.Ignore, Converters = new JsonConverter[] { new FlexibleObjectDeserializer(), new EnumSerializer() }});
|
||||
}
|
||||
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
if((response.StatusCode == 400))
|
||||
{
|
||||
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
if((response.StatusCode == 401))
|
||||
{
|
||||
if(Utilities.IsContentTypeMatch("application/json",response.ContentType))
|
||||
{
|
||||
response.FourHundredAndOneApplicationJsonObject = JsonConvert.DeserializeObject<GetServerCapabilitiesServerResponseBody>(await httpResponse.Content.ReadAsStringAsync(), new JsonSerializerSettings(){ NullValueHandling = NullValueHandling.Ignore, Converters = new JsonConverter[] { new FlexibleObjectDeserializer(), new EnumSerializer() }});
|
||||
}
|
||||
|
||||
|
||||
return response;
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public async Task<GetServerPreferencesResponse> GetServerPreferencesAsync()
|
||||
{
|
||||
string baseUrl = this.SDKConfiguration.GetTemplatedServerDetails();
|
||||
|
||||
var urlString = baseUrl + "/:/prefs";
|
||||
|
||||
|
||||
var httpRequest = new HttpRequestMessage(HttpMethod.Get, urlString);
|
||||
httpRequest.Headers.Add("user-agent", _userAgent);
|
||||
|
||||
|
||||
var client = _securityClient;
|
||||
|
||||
|
||||
var client = _defaultClient;
|
||||
if (_securitySource != null)
|
||||
{
|
||||
client = SecuritySerializer.Apply(_defaultClient, _securitySource);
|
||||
}
|
||||
|
||||
var httpResponse = await client.SendAsync(httpRequest);
|
||||
|
||||
var contentType = httpResponse.Content.Headers.ContentType?.MediaType;
|
||||
|
||||
|
||||
var response = new GetServerPreferencesResponse
|
||||
{
|
||||
StatusCode = (int)httpResponse.StatusCode,
|
||||
ContentType = contentType,
|
||||
RawResponse = httpResponse
|
||||
};
|
||||
|
||||
|
||||
if((response.StatusCode == 200))
|
||||
{
|
||||
if(Utilities.IsContentTypeMatch("application/json",response.ContentType))
|
||||
{
|
||||
response.TwoHundredApplicationJsonObject = JsonConvert.DeserializeObject<GetServerPreferencesResponseBody>(await httpResponse.Content.ReadAsStringAsync(), new JsonSerializerSettings(){ NullValueHandling = NullValueHandling.Ignore, Converters = new JsonConverter[] { new FlexibleObjectDeserializer(), new EnumSerializer() }});
|
||||
}
|
||||
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
if((response.StatusCode == 400))
|
||||
{
|
||||
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
if((response.StatusCode == 401))
|
||||
{
|
||||
if(Utilities.IsContentTypeMatch("application/json",response.ContentType))
|
||||
{
|
||||
response.FourHundredAndOneApplicationJsonObject = JsonConvert.DeserializeObject<GetServerPreferencesServerResponseBody>(await httpResponse.Content.ReadAsStringAsync(), new JsonSerializerSettings(){ NullValueHandling = NullValueHandling.Ignore, Converters = new JsonConverter[] { new FlexibleObjectDeserializer(), new EnumSerializer() }});
|
||||
}
|
||||
|
||||
|
||||
return response;
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public async Task<GetAvailableClientsResponse> GetAvailableClientsAsync()
|
||||
{
|
||||
string baseUrl = this.SDKConfiguration.GetTemplatedServerDetails();
|
||||
|
||||
var urlString = baseUrl + "/clients";
|
||||
|
||||
|
||||
var httpRequest = new HttpRequestMessage(HttpMethod.Get, urlString);
|
||||
httpRequest.Headers.Add("user-agent", _userAgent);
|
||||
|
||||
|
||||
var client = _securityClient;
|
||||
|
||||
|
||||
var client = _defaultClient;
|
||||
if (_securitySource != null)
|
||||
{
|
||||
client = SecuritySerializer.Apply(_defaultClient, _securitySource);
|
||||
}
|
||||
|
||||
var httpResponse = await client.SendAsync(httpRequest);
|
||||
|
||||
var contentType = httpResponse.Content.Headers.ContentType?.MediaType;
|
||||
|
||||
|
||||
var response = new GetAvailableClientsResponse
|
||||
{
|
||||
StatusCode = (int)httpResponse.StatusCode,
|
||||
ContentType = contentType,
|
||||
RawResponse = httpResponse
|
||||
};
|
||||
|
||||
|
||||
if((response.StatusCode == 200))
|
||||
{
|
||||
if(Utilities.IsContentTypeMatch("application/json",response.ContentType))
|
||||
{
|
||||
response.TwoHundredApplicationJsonObject = JsonConvert.DeserializeObject<GetAvailableClientsResponseBody>(await httpResponse.Content.ReadAsStringAsync(), new JsonSerializerSettings(){ NullValueHandling = NullValueHandling.Ignore, Converters = new JsonConverter[] { new FlexibleObjectDeserializer(), new EnumSerializer() }});
|
||||
}
|
||||
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
if((response.StatusCode == 400))
|
||||
{
|
||||
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
if((response.StatusCode == 401))
|
||||
{
|
||||
if(Utilities.IsContentTypeMatch("application/json",response.ContentType))
|
||||
{
|
||||
response.FourHundredAndOneApplicationJsonObject = JsonConvert.DeserializeObject<GetAvailableClientsServerResponseBody>(await httpResponse.Content.ReadAsStringAsync(), new JsonSerializerSettings(){ NullValueHandling = NullValueHandling.Ignore, Converters = new JsonConverter[] { new FlexibleObjectDeserializer(), new EnumSerializer() }});
|
||||
}
|
||||
|
||||
|
||||
return response;
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public async Task<GetDevicesResponse> GetDevicesAsync()
|
||||
{
|
||||
string baseUrl = this.SDKConfiguration.GetTemplatedServerDetails();
|
||||
|
||||
var urlString = baseUrl + "/devices";
|
||||
|
||||
|
||||
var httpRequest = new HttpRequestMessage(HttpMethod.Get, urlString);
|
||||
httpRequest.Headers.Add("user-agent", _userAgent);
|
||||
|
||||
|
||||
var client = _securityClient;
|
||||
|
||||
|
||||
var client = _defaultClient;
|
||||
if (_securitySource != null)
|
||||
{
|
||||
client = SecuritySerializer.Apply(_defaultClient, _securitySource);
|
||||
}
|
||||
|
||||
var httpResponse = await client.SendAsync(httpRequest);
|
||||
|
||||
var contentType = httpResponse.Content.Headers.ContentType?.MediaType;
|
||||
|
||||
|
||||
var response = new GetDevicesResponse
|
||||
{
|
||||
StatusCode = (int)httpResponse.StatusCode,
|
||||
ContentType = contentType,
|
||||
RawResponse = httpResponse
|
||||
};
|
||||
|
||||
|
||||
if((response.StatusCode == 200))
|
||||
{
|
||||
if(Utilities.IsContentTypeMatch("application/json",response.ContentType))
|
||||
{
|
||||
response.TwoHundredApplicationJsonObject = JsonConvert.DeserializeObject<GetDevicesResponseBody>(await httpResponse.Content.ReadAsStringAsync(), new JsonSerializerSettings(){ NullValueHandling = NullValueHandling.Ignore, Converters = new JsonConverter[] { new FlexibleObjectDeserializer(), new EnumSerializer() }});
|
||||
}
|
||||
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
if((response.StatusCode == 400))
|
||||
{
|
||||
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
if((response.StatusCode == 401))
|
||||
{
|
||||
if(Utilities.IsContentTypeMatch("application/json",response.ContentType))
|
||||
{
|
||||
response.FourHundredAndOneApplicationJsonObject = JsonConvert.DeserializeObject<GetDevicesServerResponseBody>(await httpResponse.Content.ReadAsStringAsync(), new JsonSerializerSettings(){ NullValueHandling = NullValueHandling.Ignore, Converters = new JsonConverter[] { new FlexibleObjectDeserializer(), new EnumSerializer() }});
|
||||
}
|
||||
|
||||
|
||||
return response;
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public async Task<GetServerIdentityResponse> GetServerIdentityAsync()
|
||||
{
|
||||
string baseUrl = this.SDKConfiguration.GetTemplatedServerDetails();
|
||||
|
||||
var urlString = baseUrl + "/identity";
|
||||
|
||||
|
||||
var httpRequest = new HttpRequestMessage(HttpMethod.Get, urlString);
|
||||
httpRequest.Headers.Add("user-agent", _userAgent);
|
||||
|
||||
|
||||
var client = _securityClient;
|
||||
|
||||
|
||||
var client = _defaultClient;
|
||||
if (_securitySource != null)
|
||||
{
|
||||
client = SecuritySerializer.Apply(_defaultClient, _securitySource);
|
||||
}
|
||||
|
||||
var httpResponse = await client.SendAsync(httpRequest);
|
||||
|
||||
var contentType = httpResponse.Content.Headers.ContentType?.MediaType;
|
||||
|
||||
|
||||
var response = new GetServerIdentityResponse
|
||||
{
|
||||
StatusCode = (int)httpResponse.StatusCode,
|
||||
ContentType = contentType,
|
||||
RawResponse = httpResponse
|
||||
};
|
||||
|
||||
|
||||
if((response.StatusCode == 200))
|
||||
{
|
||||
if(Utilities.IsContentTypeMatch("application/json",response.ContentType))
|
||||
{
|
||||
response.TwoHundredApplicationJsonObject = JsonConvert.DeserializeObject<GetServerIdentityResponseBody>(await httpResponse.Content.ReadAsStringAsync(), new JsonSerializerSettings(){ NullValueHandling = NullValueHandling.Ignore, Converters = new JsonConverter[] { new FlexibleObjectDeserializer(), new EnumSerializer() }});
|
||||
}
|
||||
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
if((response.StatusCode == 400))
|
||||
{
|
||||
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
if((response.StatusCode == 401))
|
||||
{
|
||||
if(Utilities.IsContentTypeMatch("application/json",response.ContentType))
|
||||
{
|
||||
response.FourHundredAndOneApplicationJsonObject = JsonConvert.DeserializeObject<GetServerIdentityServerResponseBody>(await httpResponse.Content.ReadAsStringAsync(), new JsonSerializerSettings(){ NullValueHandling = NullValueHandling.Ignore, Converters = new JsonConverter[] { new FlexibleObjectDeserializer(), new EnumSerializer() }});
|
||||
}
|
||||
|
||||
|
||||
return response;
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public async Task<GetMyPlexAccountResponse> GetMyPlexAccountAsync()
|
||||
{
|
||||
string baseUrl = this.SDKConfiguration.GetTemplatedServerDetails();
|
||||
|
||||
var urlString = baseUrl + "/myplex/account";
|
||||
|
||||
|
||||
var httpRequest = new HttpRequestMessage(HttpMethod.Get, urlString);
|
||||
httpRequest.Headers.Add("user-agent", _userAgent);
|
||||
|
||||
|
||||
var client = _securityClient;
|
||||
|
||||
|
||||
var client = _defaultClient;
|
||||
if (_securitySource != null)
|
||||
{
|
||||
client = SecuritySerializer.Apply(_defaultClient, _securitySource);
|
||||
}
|
||||
|
||||
var httpResponse = await client.SendAsync(httpRequest);
|
||||
|
||||
var contentType = httpResponse.Content.Headers.ContentType?.MediaType;
|
||||
|
||||
|
||||
var response = new GetMyPlexAccountResponse
|
||||
{
|
||||
StatusCode = (int)httpResponse.StatusCode,
|
||||
ContentType = contentType,
|
||||
RawResponse = httpResponse
|
||||
};
|
||||
|
||||
|
||||
if((response.StatusCode == 200))
|
||||
{
|
||||
if(Utilities.IsContentTypeMatch("application/json",response.ContentType))
|
||||
{
|
||||
response.TwoHundredApplicationJsonObject = JsonConvert.DeserializeObject<GetMyPlexAccountResponseBody>(await httpResponse.Content.ReadAsStringAsync(), new JsonSerializerSettings(){ NullValueHandling = NullValueHandling.Ignore, Converters = new JsonConverter[] { new FlexibleObjectDeserializer(), new EnumSerializer() }});
|
||||
}
|
||||
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
if((response.StatusCode == 400))
|
||||
{
|
||||
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
if((response.StatusCode == 401))
|
||||
{
|
||||
if(Utilities.IsContentTypeMatch("application/json",response.ContentType))
|
||||
{
|
||||
response.FourHundredAndOneApplicationJsonObject = JsonConvert.DeserializeObject<GetMyPlexAccountServerResponseBody>(await httpResponse.Content.ReadAsStringAsync(), new JsonSerializerSettings(){ NullValueHandling = NullValueHandling.Ignore, Converters = new JsonConverter[] { new FlexibleObjectDeserializer(), new EnumSerializer() }});
|
||||
}
|
||||
|
||||
|
||||
return response;
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
|
||||
public async Task<GetResizedPhotoResponse> GetResizedPhotoAsync(GetResizedPhotoRequest? request = null)
|
||||
|
||||
public async Task<GetResizedPhotoResponse> GetResizedPhotoAsync(GetResizedPhotoRequest request)
|
||||
{
|
||||
string baseUrl = this.SDKConfiguration.GetTemplatedServerDetails();
|
||||
var urlString = URLBuilder.Build(baseUrl, "/photo/:/transcode", request);
|
||||
|
||||
|
||||
var httpRequest = new HttpRequestMessage(HttpMethod.Get, urlString);
|
||||
httpRequest.Headers.Add("user-agent", _userAgent);
|
||||
|
||||
|
||||
var client = _securityClient;
|
||||
|
||||
|
||||
var client = _defaultClient;
|
||||
if (_securitySource != null)
|
||||
{
|
||||
client = SecuritySerializer.Apply(_defaultClient, _securitySource);
|
||||
}
|
||||
|
||||
var httpResponse = await client.SendAsync(httpRequest);
|
||||
|
||||
var contentType = httpResponse.Content.Headers.ContentType?.MediaType;
|
||||
|
||||
|
||||
var response = new GetResizedPhotoResponse
|
||||
{
|
||||
StatusCode = (int)httpResponse.StatusCode,
|
||||
ContentType = contentType,
|
||||
RawResponse = httpResponse
|
||||
};
|
||||
|
||||
|
||||
if((response.StatusCode == 200) || (response.StatusCode == 400))
|
||||
{
|
||||
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
if((response.StatusCode == 401))
|
||||
{
|
||||
if(Utilities.IsContentTypeMatch("application/json",response.ContentType))
|
||||
{
|
||||
response.Object = JsonConvert.DeserializeObject<GetResizedPhotoResponseBody>(await httpResponse.Content.ReadAsStringAsync(), new JsonSerializerSettings(){ NullValueHandling = NullValueHandling.Ignore, Converters = new JsonConverter[] { new FlexibleObjectDeserializer(), new EnumSerializer() }});
|
||||
}
|
||||
|
||||
|
||||
return response;
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public async Task<GetServerListResponse> GetServerListAsync()
|
||||
{
|
||||
string baseUrl = this.SDKConfiguration.GetTemplatedServerDetails();
|
||||
|
||||
var urlString = baseUrl + "/servers";
|
||||
|
||||
|
||||
var httpRequest = new HttpRequestMessage(HttpMethod.Get, urlString);
|
||||
httpRequest.Headers.Add("user-agent", _userAgent);
|
||||
|
||||
|
||||
var client = _securityClient;
|
||||
|
||||
|
||||
var client = _defaultClient;
|
||||
if (_securitySource != null)
|
||||
{
|
||||
client = SecuritySerializer.Apply(_defaultClient, _securitySource);
|
||||
}
|
||||
|
||||
var httpResponse = await client.SendAsync(httpRequest);
|
||||
|
||||
var contentType = httpResponse.Content.Headers.ContentType?.MediaType;
|
||||
|
||||
|
||||
var response = new GetServerListResponse
|
||||
{
|
||||
StatusCode = (int)httpResponse.StatusCode,
|
||||
ContentType = contentType,
|
||||
RawResponse = httpResponse
|
||||
};
|
||||
|
||||
|
||||
if((response.StatusCode == 200))
|
||||
{
|
||||
if(Utilities.IsContentTypeMatch("application/json",response.ContentType))
|
||||
{
|
||||
response.TwoHundredApplicationJsonObject = JsonConvert.DeserializeObject<GetServerListResponseBody>(await httpResponse.Content.ReadAsStringAsync(), new JsonSerializerSettings(){ NullValueHandling = NullValueHandling.Ignore, Converters = new JsonConverter[] { new FlexibleObjectDeserializer(), new EnumSerializer() }});
|
||||
}
|
||||
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
if((response.StatusCode == 400))
|
||||
{
|
||||
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
if((response.StatusCode == 401))
|
||||
{
|
||||
if(Utilities.IsContentTypeMatch("application/json",response.ContentType))
|
||||
{
|
||||
response.FourHundredAndOneApplicationJsonObject = JsonConvert.DeserializeObject<GetServerListServerResponseBody>(await httpResponse.Content.ReadAsStringAsync(), new JsonSerializerSettings(){ NullValueHandling = NullValueHandling.Ignore, Converters = new JsonConverter[] { new FlexibleObjectDeserializer(), new EnumSerializer() }});
|
||||
}
|
||||
|
||||
|
||||
return response;
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user