Files
plexcsharp/LukeHagar/PlexAPI/SDK/Plex.cs

1073 lines
50 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>
/// API Calls that perform operations directly against https://Plex.tv<br/>
///
/// <remarks>
///
/// </remarks>
/// </summary>
public interface IPlex
{
/// <summary>
/// Get Companions Data
///
/// <remarks>
/// Get Companions Data
/// </remarks>
/// </summary>
Task<GetCompanionsDataResponse> GetCompanionsDataAsync(string? serverUrl = null);
/// <summary>
/// Get list of friends of the user logged in
///
/// <remarks>
/// Get friends of provided auth token.
/// </remarks>
/// </summary>
Task<GetUserFriendsResponse> GetUserFriendsAsync(string? serverUrl = null);
/// <summary>
/// Get Geo Data
///
/// <remarks>
/// Returns the geolocation and locale data of the caller
/// </remarks>
/// </summary>
Task<GetGeoDataResponse> GetGeoDataAsync(string? serverUrl = null);
/// <summary>
/// Get Plex Home Data
///
/// <remarks>
/// Retrieves the home data for the authenticated user, including details like home ID, name, guest access information, and subscription status.
/// </remarks>
/// </summary>
Task<GetHomeDataResponse> GetHomeDataAsync();
/// <summary>
/// Get Server Resources
///
/// <remarks>
/// Get Plex server access tokens and server connections
/// </remarks>
/// </summary>
Task<GetServerResourcesResponse> GetServerResourcesAsync(string clientID, IncludeHttps? includeHttps = LukeHagar.PlexAPI.SDK.Models.Requests.IncludeHttps.Disable, IncludeRelay? includeRelay = LukeHagar.PlexAPI.SDK.Models.Requests.IncludeRelay.Disable, IncludeIPv6? includeIPv6 = LukeHagar.PlexAPI.SDK.Models.Requests.IncludeIPv6.Disable, string? serverUrl = null);
/// <summary>
/// Get a Pin
///
/// <remarks>
/// Retrieve a Pin ID from Plex.tv to use for authentication flows
/// </remarks>
/// </summary>
Task<GetPinResponse> GetPinAsync(GetPinRequest request, string? serverUrl = null);
/// <summary>
/// Get Access Token by PinId
///
/// <remarks>
/// Retrieve an Access Token from Plex.tv after the Pin has been authenticated
/// </remarks>
/// </summary>
Task<GetTokenByPinIdResponse> GetTokenByPinIdAsync(GetTokenByPinIdRequest request, string? serverUrl = null);
}
/// <summary>
/// API Calls that perform operations directly against https://Plex.tv<br/>
///
/// <remarks>
///
/// </remarks>
/// </summary>
public class Plex: IPlex
{
/// <summary>
/// List of server URLs available for the getCompanionsData operation.
/// </summary>
public static readonly string[] GetCompanionsDataServerList = {
"https://plex.tv/api/v2",
};
/// <summary>
/// List of server URLs available for the getUserFriends operation.
/// </summary>
public static readonly string[] GetUserFriendsServerList = {
"https://plex.tv/api/v2",
};
/// <summary>
/// List of server URLs available for the getGeoData operation.
/// </summary>
public static readonly string[] GetGeoDataServerList = {
"https://plex.tv/api/v2",
};
/// <summary>
/// List of server URLs available for the get-server-resources operation.
/// </summary>
public static readonly string[] GetServerResourcesServerList = {
"https://plex.tv/api/v2",
};
/// <summary>
/// List of server URLs available for the getPin operation.
/// </summary>
public static readonly string[] GetPinServerList = {
"https://plex.tv/api/v2",
};
/// <summary>
/// List of server URLs available for the getTokenByPinId operation.
/// </summary>
public static readonly string[] GetTokenByPinIdServerList = {
"https://plex.tv/api/v2",
};
public SDKConfig SDKConfiguration { get; private set; }
private const string _language = "csharp";
private const string _sdkVersion = "0.17.0";
private const string _sdkGenVersion = "2.698.4";
private const string _openapiDocVersion = "0.0.3";
public Plex(SDKConfig config)
{
SDKConfiguration = config;
}
public async Task<GetCompanionsDataResponse> GetCompanionsDataAsync(string? serverUrl = null)
{
string baseUrl = Utilities.TemplateUrl(GetCompanionsDataServerList[0], new Dictionary<string, string>(){
});
if (serverUrl != null)
{
baseUrl = serverUrl;
}
var urlString = baseUrl + "/companions";
var httpRequest = new HttpRequestMessage(HttpMethod.Get, urlString);
httpRequest.Headers.Add("user-agent", SDKConfiguration.UserAgent);
if (SDKConfiguration.SecuritySource != null)
{
httpRequest = new SecurityMetadata(SDKConfiguration.SecuritySource).Apply(httpRequest);
}
var hookCtx = new HookContext(SDKConfiguration, baseUrl, "getCompanionsData", new List<string> { }, 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 == 401 || _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();
List<ResponseBody> obj;
try
{
obj = ResponseBodyDeserializer.DeserializeNotNull<List<ResponseBody>>(httpResponseBody, NullValueHandling.Ignore);
}
catch (Exception ex)
{
throw new ResponseValidationException("Failed to deserialize response body into List<ResponseBody>.", httpResponse, httpResponseBody, ex);
}
var response = new GetCompanionsDataResponse()
{
StatusCode = responseStatusCode,
ContentType = contentType,
RawResponse = httpResponse
};
response.ResponseBodies = obj;
return response;
}
throw new Models.Errors.SDKException("Unknown content type received", httpResponse, await httpResponse.Content.ReadAsStringAsync());
}
else if(responseStatusCode == 400)
{
if(Utilities.IsContentTypeMatch("application/json", contentType))
{
var httpResponseBody = await httpResponse.Content.ReadAsStringAsync();
GetCompanionsDataBadRequestPayload payload;
try
{
payload = ResponseBodyDeserializer.DeserializeNotNull<GetCompanionsDataBadRequestPayload>(httpResponseBody, NullValueHandling.Ignore);
}
catch (Exception ex)
{
throw new ResponseValidationException("Failed to deserialize response body into GetCompanionsDataBadRequestPayload.", httpResponse, httpResponseBody, ex);
}
payload.RawResponse = httpResponse;
throw new GetCompanionsDataBadRequest(payload, httpResponse, httpResponseBody);
}
throw new Models.Errors.SDKException("Unknown content type received", httpResponse, await httpResponse.Content.ReadAsStringAsync());
}
else if(responseStatusCode == 401)
{
if(Utilities.IsContentTypeMatch("application/json", contentType))
{
var httpResponseBody = await httpResponse.Content.ReadAsStringAsync();
GetCompanionsDataUnauthorizedPayload payload;
try
{
payload = ResponseBodyDeserializer.DeserializeNotNull<GetCompanionsDataUnauthorizedPayload>(httpResponseBody, NullValueHandling.Ignore);
}
catch (Exception ex)
{
throw new ResponseValidationException("Failed to deserialize response body into GetCompanionsDataUnauthorizedPayload.", httpResponse, httpResponseBody, ex);
}
payload.RawResponse = httpResponse;
throw new GetCompanionsDataUnauthorized(payload, httpResponse, httpResponseBody);
}
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<GetUserFriendsResponse> GetUserFriendsAsync(string? serverUrl = null)
{
string baseUrl = Utilities.TemplateUrl(GetUserFriendsServerList[0], new Dictionary<string, string>(){
});
if (serverUrl != null)
{
baseUrl = serverUrl;
}
var urlString = baseUrl + "/friends";
var httpRequest = new HttpRequestMessage(HttpMethod.Get, urlString);
httpRequest.Headers.Add("user-agent", SDKConfiguration.UserAgent);
if (SDKConfiguration.SecuritySource != null)
{
httpRequest = new SecurityMetadata(SDKConfiguration.SecuritySource).Apply(httpRequest);
}
var hookCtx = new HookContext(SDKConfiguration, baseUrl, "getUserFriends", new List<string> { }, 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 == 401 || _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();
List<Friend> obj;
try
{
obj = ResponseBodyDeserializer.DeserializeNotNull<List<Friend>>(httpResponseBody, NullValueHandling.Ignore);
}
catch (Exception ex)
{
throw new ResponseValidationException("Failed to deserialize response body into List<Friend>.", httpResponse, httpResponseBody, ex);
}
var response = new GetUserFriendsResponse()
{
StatusCode = responseStatusCode,
ContentType = contentType,
RawResponse = httpResponse
};
response.Friends = obj;
return response;
}
throw new Models.Errors.SDKException("Unknown content type received", httpResponse, await httpResponse.Content.ReadAsStringAsync());
}
else if(responseStatusCode == 400)
{
if(Utilities.IsContentTypeMatch("application/json", contentType))
{
var httpResponseBody = await httpResponse.Content.ReadAsStringAsync();
GetUserFriendsBadRequestPayload payload;
try
{
payload = ResponseBodyDeserializer.DeserializeNotNull<GetUserFriendsBadRequestPayload>(httpResponseBody, NullValueHandling.Ignore);
}
catch (Exception ex)
{
throw new ResponseValidationException("Failed to deserialize response body into GetUserFriendsBadRequestPayload.", httpResponse, httpResponseBody, ex);
}
payload.RawResponse = httpResponse;
throw new GetUserFriendsBadRequest(payload, httpResponse, httpResponseBody);
}
throw new Models.Errors.SDKException("Unknown content type received", httpResponse, await httpResponse.Content.ReadAsStringAsync());
}
else if(responseStatusCode == 401)
{
if(Utilities.IsContentTypeMatch("application/json", contentType))
{
var httpResponseBody = await httpResponse.Content.ReadAsStringAsync();
GetUserFriendsUnauthorizedPayload payload;
try
{
payload = ResponseBodyDeserializer.DeserializeNotNull<GetUserFriendsUnauthorizedPayload>(httpResponseBody, NullValueHandling.Ignore);
}
catch (Exception ex)
{
throw new ResponseValidationException("Failed to deserialize response body into GetUserFriendsUnauthorizedPayload.", httpResponse, httpResponseBody, ex);
}
payload.RawResponse = httpResponse;
throw new GetUserFriendsUnauthorized(payload, httpResponse, httpResponseBody);
}
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<GetGeoDataResponse> GetGeoDataAsync(string? serverUrl = null)
{
string baseUrl = Utilities.TemplateUrl(GetGeoDataServerList[0], new Dictionary<string, string>(){
});
if (serverUrl != null)
{
baseUrl = serverUrl;
}
var urlString = baseUrl + "/geoip";
var httpRequest = new HttpRequestMessage(HttpMethod.Get, urlString);
httpRequest.Headers.Add("user-agent", SDKConfiguration.UserAgent);
var hookCtx = new HookContext(SDKConfiguration, baseUrl, "getGeoData", new List<string> { }, 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 == 401 || _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();
GetGeoDataGeoData obj;
try
{
obj = ResponseBodyDeserializer.DeserializeNotNull<GetGeoDataGeoData>(httpResponseBody, NullValueHandling.Ignore);
}
catch (Exception ex)
{
throw new ResponseValidationException("Failed to deserialize response body into GetGeoDataGeoData.", httpResponse, httpResponseBody, ex);
}
var response = new GetGeoDataResponse()
{
StatusCode = responseStatusCode,
ContentType = contentType,
RawResponse = httpResponse
};
response.GeoData = obj;
return response;
}
throw new Models.Errors.SDKException("Unknown content type received", httpResponse, await httpResponse.Content.ReadAsStringAsync());
}
else if(responseStatusCode == 400)
{
if(Utilities.IsContentTypeMatch("application/json", contentType))
{
var httpResponseBody = await httpResponse.Content.ReadAsStringAsync();
GetGeoDataBadRequestPayload payload;
try
{
payload = ResponseBodyDeserializer.DeserializeNotNull<GetGeoDataBadRequestPayload>(httpResponseBody, NullValueHandling.Ignore);
}
catch (Exception ex)
{
throw new ResponseValidationException("Failed to deserialize response body into GetGeoDataBadRequestPayload.", httpResponse, httpResponseBody, ex);
}
payload.RawResponse = httpResponse;
throw new GetGeoDataBadRequest(payload, httpResponse, httpResponseBody);
}
throw new Models.Errors.SDKException("Unknown content type received", httpResponse, await httpResponse.Content.ReadAsStringAsync());
}
else if(responseStatusCode == 401)
{
if(Utilities.IsContentTypeMatch("application/json", contentType))
{
var httpResponseBody = await httpResponse.Content.ReadAsStringAsync();
GetGeoDataUnauthorizedPayload payload;
try
{
payload = ResponseBodyDeserializer.DeserializeNotNull<GetGeoDataUnauthorizedPayload>(httpResponseBody, NullValueHandling.Ignore);
}
catch (Exception ex)
{
throw new ResponseValidationException("Failed to deserialize response body into GetGeoDataUnauthorizedPayload.", httpResponse, httpResponseBody, ex);
}
payload.RawResponse = httpResponse;
throw new GetGeoDataUnauthorized(payload, httpResponse, httpResponseBody);
}
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<GetHomeDataResponse> GetHomeDataAsync()
{
string baseUrl = this.SDKConfiguration.GetTemplatedServerUrl();
var urlString = baseUrl + "/home";
var httpRequest = new HttpRequestMessage(HttpMethod.Get, urlString);
httpRequest.Headers.Add("user-agent", SDKConfiguration.UserAgent);
if (SDKConfiguration.SecuritySource != null)
{
httpRequest = new SecurityMetadata(SDKConfiguration.SecuritySource).Apply(httpRequest);
}
var hookCtx = new HookContext(SDKConfiguration, baseUrl, "getHomeData", new List<string> { }, 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 == 401 || _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();
GetHomeDataResponseBody obj;
try
{
obj = ResponseBodyDeserializer.DeserializeNotNull<GetHomeDataResponseBody>(httpResponseBody, NullValueHandling.Ignore);
}
catch (Exception ex)
{
throw new ResponseValidationException("Failed to deserialize response body into GetHomeDataResponseBody.", httpResponse, httpResponseBody, ex);
}
var response = new GetHomeDataResponse()
{
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)
{
if(Utilities.IsContentTypeMatch("application/json", contentType))
{
var httpResponseBody = await httpResponse.Content.ReadAsStringAsync();
GetHomeDataBadRequestPayload payload;
try
{
payload = ResponseBodyDeserializer.DeserializeNotNull<GetHomeDataBadRequestPayload>(httpResponseBody, NullValueHandling.Ignore);
}
catch (Exception ex)
{
throw new ResponseValidationException("Failed to deserialize response body into GetHomeDataBadRequestPayload.", httpResponse, httpResponseBody, ex);
}
payload.RawResponse = httpResponse;
throw new GetHomeDataBadRequest(payload, httpResponse, httpResponseBody);
}
throw new Models.Errors.SDKException("Unknown content type received", httpResponse, await httpResponse.Content.ReadAsStringAsync());
}
else if(responseStatusCode == 401)
{
if(Utilities.IsContentTypeMatch("application/json", contentType))
{
var httpResponseBody = await httpResponse.Content.ReadAsStringAsync();
GetHomeDataUnauthorizedPayload payload;
try
{
payload = ResponseBodyDeserializer.DeserializeNotNull<GetHomeDataUnauthorizedPayload>(httpResponseBody, NullValueHandling.Ignore);
}
catch (Exception ex)
{
throw new ResponseValidationException("Failed to deserialize response body into GetHomeDataUnauthorizedPayload.", httpResponse, httpResponseBody, ex);
}
payload.RawResponse = httpResponse;
throw new GetHomeDataUnauthorized(payload, httpResponse, httpResponseBody);
}
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<GetServerResourcesResponse> GetServerResourcesAsync(string clientID, IncludeHttps? includeHttps = LukeHagar.PlexAPI.SDK.Models.Requests.IncludeHttps.Disable, IncludeRelay? includeRelay = LukeHagar.PlexAPI.SDK.Models.Requests.IncludeRelay.Disable, IncludeIPv6? includeIPv6 = LukeHagar.PlexAPI.SDK.Models.Requests.IncludeIPv6.Disable, string? serverUrl = null)
{
var request = new GetServerResourcesRequest()
{
ClientID = clientID,
IncludeHttps = includeHttps,
IncludeRelay = includeRelay,
IncludeIPv6 = includeIPv6,
};
string baseUrl = Utilities.TemplateUrl(GetServerResourcesServerList[0], new Dictionary<string, string>(){
});
if (serverUrl != null)
{
baseUrl = serverUrl;
}
var urlString = URLBuilder.Build(baseUrl, "/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, "get-server-resources", new List<string> { }, 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 == 401 || _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();
List<PlexDevice> obj;
try
{
obj = ResponseBodyDeserializer.DeserializeNotNull<List<PlexDevice>>(httpResponseBody, NullValueHandling.Ignore);
}
catch (Exception ex)
{
throw new ResponseValidationException("Failed to deserialize response body into List<PlexDevice>.", httpResponse, httpResponseBody, ex);
}
var response = new GetServerResourcesResponse()
{
StatusCode = responseStatusCode,
ContentType = contentType,
RawResponse = httpResponse
};
response.PlexDevices = obj;
return response;
}
throw new Models.Errors.SDKException("Unknown content type received", httpResponse, await httpResponse.Content.ReadAsStringAsync());
}
else if(responseStatusCode == 400)
{
if(Utilities.IsContentTypeMatch("application/json", contentType))
{
var httpResponseBody = await httpResponse.Content.ReadAsStringAsync();
GetServerResourcesBadRequestPayload payload;
try
{
payload = ResponseBodyDeserializer.DeserializeNotNull<GetServerResourcesBadRequestPayload>(httpResponseBody, NullValueHandling.Ignore);
}
catch (Exception ex)
{
throw new ResponseValidationException("Failed to deserialize response body into GetServerResourcesBadRequestPayload.", httpResponse, httpResponseBody, ex);
}
payload.RawResponse = httpResponse;
throw new GetServerResourcesBadRequest(payload, httpResponse, httpResponseBody);
}
throw new Models.Errors.SDKException("Unknown content type received", httpResponse, await httpResponse.Content.ReadAsStringAsync());
}
else if(responseStatusCode == 401)
{
if(Utilities.IsContentTypeMatch("application/json", contentType))
{
var httpResponseBody = await httpResponse.Content.ReadAsStringAsync();
GetServerResourcesUnauthorizedPayload payload;
try
{
payload = ResponseBodyDeserializer.DeserializeNotNull<GetServerResourcesUnauthorizedPayload>(httpResponseBody, NullValueHandling.Ignore);
}
catch (Exception ex)
{
throw new ResponseValidationException("Failed to deserialize response body into GetServerResourcesUnauthorizedPayload.", httpResponse, httpResponseBody, ex);
}
payload.RawResponse = httpResponse;
throw new GetServerResourcesUnauthorized(payload, httpResponse, httpResponseBody);
}
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<GetPinResponse> GetPinAsync(GetPinRequest request, string? serverUrl = null)
{
string baseUrl = Utilities.TemplateUrl(GetPinServerList[0], new Dictionary<string, string>(){
});
if (serverUrl != null)
{
baseUrl = serverUrl;
}
var urlString = URLBuilder.Build(baseUrl, "/pins", request);
var httpRequest = new HttpRequestMessage(HttpMethod.Post, urlString);
httpRequest.Headers.Add("user-agent", SDKConfiguration.UserAgent);
HeaderSerializer.PopulateHeaders(ref httpRequest, request);
var hookCtx = new HookContext(SDKConfiguration, baseUrl, "getPin", new List<string> { }, 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 >= 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 == 201)
{
if(Utilities.IsContentTypeMatch("application/json", contentType))
{
var httpResponseBody = await httpResponse.Content.ReadAsStringAsync();
GetPinAuthPinContainer obj;
try
{
obj = ResponseBodyDeserializer.DeserializeNotNull<GetPinAuthPinContainer>(httpResponseBody, NullValueHandling.Ignore);
}
catch (Exception ex)
{
throw new ResponseValidationException("Failed to deserialize response body into GetPinAuthPinContainer.", httpResponse, httpResponseBody, ex);
}
var response = new GetPinResponse()
{
StatusCode = responseStatusCode,
ContentType = contentType,
RawResponse = httpResponse
};
response.AuthPinContainer = obj;
return response;
}
throw new Models.Errors.SDKException("Unknown content type received", httpResponse, await httpResponse.Content.ReadAsStringAsync());
}
else if(responseStatusCode == 400)
{
if(Utilities.IsContentTypeMatch("application/json", contentType))
{
var httpResponseBody = await httpResponse.Content.ReadAsStringAsync();
GetPinBadRequestPayload payload;
try
{
payload = ResponseBodyDeserializer.DeserializeNotNull<GetPinBadRequestPayload>(httpResponseBody, NullValueHandling.Ignore);
}
catch (Exception ex)
{
throw new ResponseValidationException("Failed to deserialize response body into GetPinBadRequestPayload.", httpResponse, httpResponseBody, ex);
}
payload.RawResponse = httpResponse;
throw new GetPinBadRequest(payload, httpResponse, httpResponseBody);
}
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<GetTokenByPinIdResponse> GetTokenByPinIdAsync(GetTokenByPinIdRequest request, string? serverUrl = null)
{
string baseUrl = Utilities.TemplateUrl(GetTokenByPinIdServerList[0], new Dictionary<string, string>(){
});
if (serverUrl != null)
{
baseUrl = serverUrl;
}
var urlString = URLBuilder.Build(baseUrl, "/pins/{pinID}", request);
var httpRequest = new HttpRequestMessage(HttpMethod.Get, urlString);
httpRequest.Headers.Add("user-agent", SDKConfiguration.UserAgent);
HeaderSerializer.PopulateHeaders(ref httpRequest, request);
var hookCtx = new HookContext(SDKConfiguration, baseUrl, "getTokenByPinId", new List<string> { }, 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 == 404 || _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();
GetTokenByPinIdAuthPinContainer obj;
try
{
obj = ResponseBodyDeserializer.DeserializeNotNull<GetTokenByPinIdAuthPinContainer>(httpResponseBody, NullValueHandling.Ignore);
}
catch (Exception ex)
{
throw new ResponseValidationException("Failed to deserialize response body into GetTokenByPinIdAuthPinContainer.", httpResponse, httpResponseBody, ex);
}
var response = new GetTokenByPinIdResponse()
{
StatusCode = responseStatusCode,
ContentType = contentType,
RawResponse = httpResponse
};
response.AuthPinContainer = obj;
return response;
}
throw new Models.Errors.SDKException("Unknown content type received", httpResponse, await httpResponse.Content.ReadAsStringAsync());
}
else if(responseStatusCode == 400)
{
if(Utilities.IsContentTypeMatch("application/json", contentType))
{
var httpResponseBody = await httpResponse.Content.ReadAsStringAsync();
GetTokenByPinIdBadRequestPayload payload;
try
{
payload = ResponseBodyDeserializer.DeserializeNotNull<GetTokenByPinIdBadRequestPayload>(httpResponseBody, NullValueHandling.Ignore);
}
catch (Exception ex)
{
throw new ResponseValidationException("Failed to deserialize response body into GetTokenByPinIdBadRequestPayload.", httpResponse, httpResponseBody, ex);
}
payload.RawResponse = httpResponse;
throw new GetTokenByPinIdBadRequest(payload, httpResponse, httpResponseBody);
}
throw new Models.Errors.SDKException("Unknown content type received", httpResponse, await httpResponse.Content.ReadAsStringAsync());
}
else if(responseStatusCode == 404)
{
if(Utilities.IsContentTypeMatch("application/json", contentType))
{
var httpResponseBody = await httpResponse.Content.ReadAsStringAsync();
GetTokenByPinIdResponseBodyPayload payload;
try
{
payload = ResponseBodyDeserializer.DeserializeNotNull<GetTokenByPinIdResponseBodyPayload>(httpResponseBody, NullValueHandling.Ignore);
}
catch (Exception ex)
{
throw new ResponseValidationException("Failed to deserialize response body into GetTokenByPinIdResponseBodyPayload.", httpResponse, httpResponseBody, ex);
}
payload.RawResponse = httpResponse;
throw new GetTokenByPinIdResponseBody(payload, httpResponse, httpResponseBody);
}
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());
}
}
}