mirror of
https://github.com/LukeHagar/plexcsharp.git
synced 2025-12-06 12:37:46 +00:00
481 lines
22 KiB
C#
481 lines
22 KiB
C#
//------------------------------------------------------------------------------
|
|
// <auto-generated>
|
|
// This code was generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
|
|
//
|
|
// Changes to this file may cause incorrect behavior and will be lost when
|
|
// the code is regenerated.
|
|
// </auto-generated>
|
|
//------------------------------------------------------------------------------
|
|
#nullable enable
|
|
namespace LukeHagar.PlexAPI.SDK
|
|
{
|
|
using LukeHagar.PlexAPI.SDK.Hooks;
|
|
using LukeHagar.PlexAPI.SDK.Models.Components;
|
|
using LukeHagar.PlexAPI.SDK.Models.Errors;
|
|
using LukeHagar.PlexAPI.SDK.Models.Requests;
|
|
using LukeHagar.PlexAPI.SDK.Utils;
|
|
using LukeHagar.PlexAPI.SDK.Utils.Retries;
|
|
using Newtonsoft.Json;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Net.Http;
|
|
using System.Net.Http.Headers;
|
|
using System.Threading.Tasks;
|
|
|
|
/// <summary>
|
|
/// General endpoints for basic PMS operation not specific to any media provider
|
|
/// </summary>
|
|
public interface IGeneral
|
|
{
|
|
|
|
/// <summary>
|
|
/// Get PMS info
|
|
///
|
|
/// <remarks>
|
|
/// Information about this PMS setup and configuration
|
|
/// </remarks>
|
|
/// </summary>
|
|
Task<GetServerInfoResponse> GetServerInfoAsync(GetServerInfoRequest? request = null);
|
|
|
|
/// <summary>
|
|
/// Get PMS identity
|
|
///
|
|
/// <remarks>
|
|
/// Get details about this PMS's identity
|
|
/// </remarks>
|
|
/// </summary>
|
|
Task<GetIdentityResponse> GetIdentityAsync();
|
|
|
|
/// <summary>
|
|
/// Get Source Connection Information
|
|
///
|
|
/// <remarks>
|
|
/// If a caller requires connection details and a transient token for a source that is known to the server, for example a cloud media provider or shared PMS, then this endpoint can be called. This endpoint is only accessible with either an admin token or a valid transient token generated from an admin token.
|
|
/// </remarks>
|
|
/// </summary>
|
|
Task<GetSourceConnectionInformationResponse> GetSourceConnectionInformationAsync(GetSourceConnectionInformationRequest request);
|
|
|
|
/// <summary>
|
|
/// Get Transient Tokens
|
|
///
|
|
/// <remarks>
|
|
/// This endpoint provides the caller with a temporary token with the same access level as the caller's token. These tokens are valid for up to 48 hours and are destroyed if the server instance is restarted.<br/>
|
|
/// Note: This endpoint responds to all HTTP verbs but POST in preferred
|
|
/// </remarks>
|
|
/// </summary>
|
|
Task<GetTransientTokenResponse> GetTransientTokenAsync(GetTransientTokenRequest request);
|
|
}
|
|
|
|
/// <summary>
|
|
/// General endpoints for basic PMS operation not specific to any media provider
|
|
/// </summary>
|
|
public class General: IGeneral
|
|
{
|
|
public SDKConfig SDKConfiguration { get; private set; }
|
|
private const string _language = "csharp";
|
|
private const string _sdkVersion = "0.19.0";
|
|
private const string _sdkGenVersion = "2.743.2";
|
|
private const string _openapiDocVersion = "1.1.1";
|
|
|
|
public General(SDKConfig config)
|
|
{
|
|
SDKConfiguration = config;
|
|
}
|
|
|
|
public async Task<GetServerInfoResponse> GetServerInfoAsync(GetServerInfoRequest? request = null)
|
|
{
|
|
request.Accepts ??= SDKConfiguration.Accepts;
|
|
request.ClientIdentifier ??= SDKConfiguration.ClientIdentifier;
|
|
request.Product ??= SDKConfiguration.Product;
|
|
request.Version ??= SDKConfiguration.Version;
|
|
request.Platform ??= SDKConfiguration.Platform;
|
|
request.PlatformVersion ??= SDKConfiguration.PlatformVersion;
|
|
request.Device ??= SDKConfiguration.Device;
|
|
request.Model ??= SDKConfiguration.Model;
|
|
request.DeviceVendor ??= SDKConfiguration.DeviceVendor;
|
|
request.DeviceName ??= SDKConfiguration.DeviceName;
|
|
request.Marketplace ??= SDKConfiguration.Marketplace;
|
|
|
|
string baseUrl = this.SDKConfiguration.GetTemplatedServerUrl();
|
|
|
|
var urlString = baseUrl + "/";
|
|
|
|
var httpRequest = new HttpRequestMessage(HttpMethod.Get, urlString);
|
|
httpRequest.Headers.Add("user-agent", SDKConfiguration.UserAgent);
|
|
HeaderSerializer.PopulateHeaders(ref httpRequest, request);
|
|
|
|
if (SDKConfiguration.SecuritySource != null)
|
|
{
|
|
httpRequest = new SecurityMetadata(SDKConfiguration.SecuritySource).Apply(httpRequest);
|
|
}
|
|
|
|
var hookCtx = new HookContext(SDKConfiguration, baseUrl, "getServerInfo", null, SDKConfiguration.SecuritySource);
|
|
|
|
httpRequest = await this.SDKConfiguration.Hooks.BeforeRequestAsync(new BeforeRequestContext(hookCtx), httpRequest);
|
|
|
|
HttpResponseMessage httpResponse;
|
|
try
|
|
{
|
|
httpResponse = await SDKConfiguration.Client.SendAsync(httpRequest);
|
|
int _statusCode = (int)httpResponse.StatusCode;
|
|
|
|
if (_statusCode >= 400 && _statusCode < 500 || _statusCode >= 500 && _statusCode < 600)
|
|
{
|
|
var _httpResponse = await this.SDKConfiguration.Hooks.AfterErrorAsync(new AfterErrorContext(hookCtx), httpResponse, null);
|
|
if (_httpResponse != null)
|
|
{
|
|
httpResponse = _httpResponse;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception error)
|
|
{
|
|
var _httpResponse = await this.SDKConfiguration.Hooks.AfterErrorAsync(new AfterErrorContext(hookCtx), null, error);
|
|
if (_httpResponse != null)
|
|
{
|
|
httpResponse = _httpResponse;
|
|
}
|
|
else
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
httpResponse = await this.SDKConfiguration.Hooks.AfterSuccessAsync(new AfterSuccessContext(hookCtx), httpResponse);
|
|
|
|
var contentType = httpResponse.Content.Headers.ContentType?.MediaType;
|
|
int responseStatusCode = (int)httpResponse.StatusCode;
|
|
if(responseStatusCode == 200)
|
|
{
|
|
if(Utilities.IsContentTypeMatch("application/json", contentType))
|
|
{
|
|
var httpResponseBody = await httpResponse.Content.ReadAsStringAsync();
|
|
MediaContainerWithDirectory obj;
|
|
try
|
|
{
|
|
obj = ResponseBodyDeserializer.DeserializeNotNull<MediaContainerWithDirectory>(httpResponseBody, NullValueHandling.Include);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw new ResponseValidationException("Failed to deserialize response body into MediaContainerWithDirectory.", httpResponse, httpResponseBody, ex);
|
|
}
|
|
|
|
var response = new GetServerInfoResponse()
|
|
{
|
|
StatusCode = responseStatusCode,
|
|
ContentType = contentType,
|
|
RawResponse = httpResponse
|
|
};
|
|
response.MediaContainerWithDirectory = obj;
|
|
return response;
|
|
}
|
|
|
|
throw new Models.Errors.SDKException("Unknown content type received", httpResponse, await httpResponse.Content.ReadAsStringAsync());
|
|
}
|
|
else if(responseStatusCode >= 400 && responseStatusCode < 500)
|
|
{
|
|
throw new Models.Errors.SDKException("API error occurred", httpResponse, await httpResponse.Content.ReadAsStringAsync());
|
|
}
|
|
else if(responseStatusCode >= 500 && responseStatusCode < 600)
|
|
{
|
|
throw new Models.Errors.SDKException("API error occurred", httpResponse, await httpResponse.Content.ReadAsStringAsync());
|
|
}
|
|
|
|
throw new Models.Errors.SDKException("Unknown status code received", httpResponse, await httpResponse.Content.ReadAsStringAsync());
|
|
}
|
|
|
|
public async Task<GetIdentityResponse> GetIdentityAsync()
|
|
{
|
|
string baseUrl = this.SDKConfiguration.GetTemplatedServerUrl();
|
|
|
|
var urlString = baseUrl + "/identity";
|
|
|
|
var httpRequest = new HttpRequestMessage(HttpMethod.Get, urlString);
|
|
httpRequest.Headers.Add("user-agent", SDKConfiguration.UserAgent);
|
|
|
|
var hookCtx = new HookContext(SDKConfiguration, baseUrl, "getIdentity", null, null);
|
|
|
|
httpRequest = await this.SDKConfiguration.Hooks.BeforeRequestAsync(new BeforeRequestContext(hookCtx), httpRequest);
|
|
|
|
HttpResponseMessage httpResponse;
|
|
try
|
|
{
|
|
httpResponse = await SDKConfiguration.Client.SendAsync(httpRequest);
|
|
int _statusCode = (int)httpResponse.StatusCode;
|
|
|
|
if (_statusCode >= 400 && _statusCode < 500 || _statusCode >= 500 && _statusCode < 600)
|
|
{
|
|
var _httpResponse = await this.SDKConfiguration.Hooks.AfterErrorAsync(new AfterErrorContext(hookCtx), httpResponse, null);
|
|
if (_httpResponse != null)
|
|
{
|
|
httpResponse = _httpResponse;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception error)
|
|
{
|
|
var _httpResponse = await this.SDKConfiguration.Hooks.AfterErrorAsync(new AfterErrorContext(hookCtx), null, error);
|
|
if (_httpResponse != null)
|
|
{
|
|
httpResponse = _httpResponse;
|
|
}
|
|
else
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
httpResponse = await this.SDKConfiguration.Hooks.AfterSuccessAsync(new AfterSuccessContext(hookCtx), httpResponse);
|
|
|
|
var contentType = httpResponse.Content.Headers.ContentType?.MediaType;
|
|
int responseStatusCode = (int)httpResponse.StatusCode;
|
|
if(responseStatusCode == 200)
|
|
{
|
|
if(Utilities.IsContentTypeMatch("application/json", contentType))
|
|
{
|
|
var httpResponseBody = await httpResponse.Content.ReadAsStringAsync();
|
|
GetIdentityResponseBody obj;
|
|
try
|
|
{
|
|
obj = ResponseBodyDeserializer.DeserializeNotNull<GetIdentityResponseBody>(httpResponseBody, NullValueHandling.Ignore);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw new ResponseValidationException("Failed to deserialize response body into GetIdentityResponseBody.", httpResponse, httpResponseBody, ex);
|
|
}
|
|
|
|
var response = new GetIdentityResponse()
|
|
{
|
|
StatusCode = responseStatusCode,
|
|
ContentType = contentType,
|
|
RawResponse = httpResponse
|
|
};
|
|
response.Object = obj;
|
|
return response;
|
|
}
|
|
|
|
throw new Models.Errors.SDKException("Unknown content type received", httpResponse, await httpResponse.Content.ReadAsStringAsync());
|
|
}
|
|
else if(responseStatusCode >= 400 && responseStatusCode < 500)
|
|
{
|
|
throw new Models.Errors.SDKException("API error occurred", httpResponse, await httpResponse.Content.ReadAsStringAsync());
|
|
}
|
|
else if(responseStatusCode >= 500 && responseStatusCode < 600)
|
|
{
|
|
throw new Models.Errors.SDKException("API error occurred", httpResponse, await httpResponse.Content.ReadAsStringAsync());
|
|
}
|
|
|
|
throw new Models.Errors.SDKException("Unknown status code received", httpResponse, await httpResponse.Content.ReadAsStringAsync());
|
|
}
|
|
|
|
public async Task<GetSourceConnectionInformationResponse> GetSourceConnectionInformationAsync(GetSourceConnectionInformationRequest request)
|
|
{
|
|
if (request == null)
|
|
{
|
|
request = new GetSourceConnectionInformationRequest();
|
|
}
|
|
request.Accepts ??= SDKConfiguration.Accepts;
|
|
request.ClientIdentifier ??= SDKConfiguration.ClientIdentifier;
|
|
request.Product ??= SDKConfiguration.Product;
|
|
request.Version ??= SDKConfiguration.Version;
|
|
request.Platform ??= SDKConfiguration.Platform;
|
|
request.PlatformVersion ??= SDKConfiguration.PlatformVersion;
|
|
request.Device ??= SDKConfiguration.Device;
|
|
request.Model ??= SDKConfiguration.Model;
|
|
request.DeviceVendor ??= SDKConfiguration.DeviceVendor;
|
|
request.DeviceName ??= SDKConfiguration.DeviceName;
|
|
request.Marketplace ??= SDKConfiguration.Marketplace;
|
|
|
|
string baseUrl = this.SDKConfiguration.GetTemplatedServerUrl();
|
|
var urlString = URLBuilder.Build(baseUrl, "/security/resources", request);
|
|
|
|
var httpRequest = new HttpRequestMessage(HttpMethod.Get, urlString);
|
|
httpRequest.Headers.Add("user-agent", SDKConfiguration.UserAgent);
|
|
HeaderSerializer.PopulateHeaders(ref httpRequest, request);
|
|
|
|
if (SDKConfiguration.SecuritySource != null)
|
|
{
|
|
httpRequest = new SecurityMetadata(SDKConfiguration.SecuritySource).Apply(httpRequest);
|
|
}
|
|
|
|
var hookCtx = new HookContext(SDKConfiguration, baseUrl, "getSourceConnectionInformation", null, SDKConfiguration.SecuritySource);
|
|
|
|
httpRequest = await this.SDKConfiguration.Hooks.BeforeRequestAsync(new BeforeRequestContext(hookCtx), httpRequest);
|
|
|
|
HttpResponseMessage httpResponse;
|
|
try
|
|
{
|
|
httpResponse = await SDKConfiguration.Client.SendAsync(httpRequest);
|
|
int _statusCode = (int)httpResponse.StatusCode;
|
|
|
|
if (_statusCode == 400 || _statusCode == 403 || _statusCode >= 400 && _statusCode < 500 || _statusCode >= 500 && _statusCode < 600)
|
|
{
|
|
var _httpResponse = await this.SDKConfiguration.Hooks.AfterErrorAsync(new AfterErrorContext(hookCtx), httpResponse, null);
|
|
if (_httpResponse != null)
|
|
{
|
|
httpResponse = _httpResponse;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception error)
|
|
{
|
|
var _httpResponse = await this.SDKConfiguration.Hooks.AfterErrorAsync(new AfterErrorContext(hookCtx), null, error);
|
|
if (_httpResponse != null)
|
|
{
|
|
httpResponse = _httpResponse;
|
|
}
|
|
else
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
httpResponse = await this.SDKConfiguration.Hooks.AfterSuccessAsync(new AfterSuccessContext(hookCtx), httpResponse);
|
|
|
|
var contentType = httpResponse.Content.Headers.ContentType?.MediaType;
|
|
int responseStatusCode = (int)httpResponse.StatusCode;
|
|
if(responseStatusCode == 200)
|
|
{
|
|
if(Utilities.IsContentTypeMatch("application/json", contentType))
|
|
{
|
|
var httpResponseBody = await httpResponse.Content.ReadAsStringAsync();
|
|
GetSourceConnectionInformationResponseBody obj;
|
|
try
|
|
{
|
|
obj = ResponseBodyDeserializer.DeserializeNotNull<GetSourceConnectionInformationResponseBody>(httpResponseBody, NullValueHandling.Ignore);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw new ResponseValidationException("Failed to deserialize response body into GetSourceConnectionInformationResponseBody.", httpResponse, httpResponseBody, ex);
|
|
}
|
|
|
|
var response = new GetSourceConnectionInformationResponse()
|
|
{
|
|
StatusCode = responseStatusCode,
|
|
ContentType = contentType,
|
|
RawResponse = httpResponse
|
|
};
|
|
response.Object = obj;
|
|
return response;
|
|
}
|
|
|
|
throw new Models.Errors.SDKException("Unknown content type received", httpResponse, await httpResponse.Content.ReadAsStringAsync());
|
|
}
|
|
else if(responseStatusCode == 400 || responseStatusCode == 403 || responseStatusCode >= 400 && responseStatusCode < 500)
|
|
{
|
|
throw new Models.Errors.SDKException("API error occurred", httpResponse, await httpResponse.Content.ReadAsStringAsync());
|
|
}
|
|
else if(responseStatusCode >= 500 && responseStatusCode < 600)
|
|
{
|
|
throw new Models.Errors.SDKException("API error occurred", httpResponse, await httpResponse.Content.ReadAsStringAsync());
|
|
}
|
|
|
|
throw new Models.Errors.SDKException("Unknown status code received", httpResponse, await httpResponse.Content.ReadAsStringAsync());
|
|
}
|
|
|
|
public async Task<GetTransientTokenResponse> GetTransientTokenAsync(GetTransientTokenRequest request)
|
|
{
|
|
if (request == null)
|
|
{
|
|
request = new GetTransientTokenRequest();
|
|
}
|
|
request.Accepts ??= SDKConfiguration.Accepts;
|
|
request.ClientIdentifier ??= SDKConfiguration.ClientIdentifier;
|
|
request.Product ??= SDKConfiguration.Product;
|
|
request.Version ??= SDKConfiguration.Version;
|
|
request.Platform ??= SDKConfiguration.Platform;
|
|
request.PlatformVersion ??= SDKConfiguration.PlatformVersion;
|
|
request.Device ??= SDKConfiguration.Device;
|
|
request.Model ??= SDKConfiguration.Model;
|
|
request.DeviceVendor ??= SDKConfiguration.DeviceVendor;
|
|
request.DeviceName ??= SDKConfiguration.DeviceName;
|
|
request.Marketplace ??= SDKConfiguration.Marketplace;
|
|
|
|
string baseUrl = this.SDKConfiguration.GetTemplatedServerUrl();
|
|
var urlString = URLBuilder.Build(baseUrl, "/security/token", request);
|
|
|
|
var httpRequest = new HttpRequestMessage(HttpMethod.Post, urlString);
|
|
httpRequest.Headers.Add("user-agent", SDKConfiguration.UserAgent);
|
|
HeaderSerializer.PopulateHeaders(ref httpRequest, request);
|
|
|
|
if (SDKConfiguration.SecuritySource != null)
|
|
{
|
|
httpRequest = new SecurityMetadata(SDKConfiguration.SecuritySource).Apply(httpRequest);
|
|
}
|
|
|
|
var hookCtx = new HookContext(SDKConfiguration, baseUrl, "getTransientToken", null, SDKConfiguration.SecuritySource);
|
|
|
|
httpRequest = await this.SDKConfiguration.Hooks.BeforeRequestAsync(new BeforeRequestContext(hookCtx), httpRequest);
|
|
|
|
HttpResponseMessage httpResponse;
|
|
try
|
|
{
|
|
httpResponse = await SDKConfiguration.Client.SendAsync(httpRequest);
|
|
int _statusCode = (int)httpResponse.StatusCode;
|
|
|
|
if (_statusCode == 400 || _statusCode == 403 || _statusCode >= 400 && _statusCode < 500 || _statusCode >= 500 && _statusCode < 600)
|
|
{
|
|
var _httpResponse = await this.SDKConfiguration.Hooks.AfterErrorAsync(new AfterErrorContext(hookCtx), httpResponse, null);
|
|
if (_httpResponse != null)
|
|
{
|
|
httpResponse = _httpResponse;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception error)
|
|
{
|
|
var _httpResponse = await this.SDKConfiguration.Hooks.AfterErrorAsync(new AfterErrorContext(hookCtx), null, error);
|
|
if (_httpResponse != null)
|
|
{
|
|
httpResponse = _httpResponse;
|
|
}
|
|
else
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
httpResponse = await this.SDKConfiguration.Hooks.AfterSuccessAsync(new AfterSuccessContext(hookCtx), httpResponse);
|
|
|
|
var contentType = httpResponse.Content.Headers.ContentType?.MediaType;
|
|
int responseStatusCode = (int)httpResponse.StatusCode;
|
|
if(responseStatusCode == 200)
|
|
{
|
|
if(Utilities.IsContentTypeMatch("application/json", contentType))
|
|
{
|
|
var httpResponseBody = await httpResponse.Content.ReadAsStringAsync();
|
|
GetTransientTokenResponseBody obj;
|
|
try
|
|
{
|
|
obj = ResponseBodyDeserializer.DeserializeNotNull<GetTransientTokenResponseBody>(httpResponseBody, NullValueHandling.Ignore);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw new ResponseValidationException("Failed to deserialize response body into GetTransientTokenResponseBody.", httpResponse, httpResponseBody, ex);
|
|
}
|
|
|
|
var response = new GetTransientTokenResponse()
|
|
{
|
|
StatusCode = responseStatusCode,
|
|
ContentType = contentType,
|
|
RawResponse = httpResponse
|
|
};
|
|
response.Object = obj;
|
|
return response;
|
|
}
|
|
|
|
throw new Models.Errors.SDKException("Unknown content type received", httpResponse, await httpResponse.Content.ReadAsStringAsync());
|
|
}
|
|
else if(responseStatusCode == 400 || responseStatusCode == 403 || responseStatusCode >= 400 && responseStatusCode < 500)
|
|
{
|
|
throw new Models.Errors.SDKException("API error occurred", httpResponse, await httpResponse.Content.ReadAsStringAsync());
|
|
}
|
|
else if(responseStatusCode >= 500 && responseStatusCode < 600)
|
|
{
|
|
throw new Models.Errors.SDKException("API error occurred", httpResponse, await httpResponse.Content.ReadAsStringAsync());
|
|
}
|
|
|
|
throw new Models.Errors.SDKException("Unknown status code received", httpResponse, await httpResponse.Content.ReadAsStringAsync());
|
|
}
|
|
}
|
|
} |