//------------------------------------------------------------------------------ // // 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. // //------------------------------------------------------------------------------ #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.Retries; using LukeHagar.PlexAPI.SDK.Utils; using Newtonsoft.Json; using System.Collections.Generic; using System.Net.Http.Headers; using System.Net.Http; using System.Threading.Tasks; using System; /// /// Operations against the Plex Media Server System.
/// /// /// /// ///
public interface IServer { /// /// Get Server Capabilities /// /// /// Get Server Capabilities /// /// Task GetServerCapabilitiesAsync(RetryConfig? retryConfig = null); /// /// Get Server Preferences /// /// /// Get Server Preferences /// /// Task GetServerPreferencesAsync(RetryConfig? retryConfig = null); /// /// Get Available Clients /// /// /// Get Available Clients /// /// Task GetAvailableClientsAsync(RetryConfig? retryConfig = null); /// /// Get Devices /// /// /// Get Devices /// /// Task GetDevicesAsync(RetryConfig? retryConfig = null); /// /// Get Server Identity /// /// /// This request is useful to determine if the server is online or offline /// /// Task GetServerIdentityAsync(RetryConfig? retryConfig = null); /// /// Get MyPlex Account /// /// /// Returns MyPlex Account Information /// /// Task GetMyPlexAccountAsync(RetryConfig? retryConfig = null); /// /// Get a Resized Photo /// /// /// Plex's Photo transcoder is used throughout the service to serve images at specified sizes.
/// ///
///
Task GetResizedPhotoAsync(GetResizedPhotoRequest request, RetryConfig? retryConfig = null); /// /// Get Media Providers /// /// /// Retrieves media providers and their features from the Plex server. /// /// Task GetMediaProvidersAsync(string xPlexToken, RetryConfig? retryConfig = null); /// /// Get Server List /// /// /// Get Server List /// /// Task GetServerListAsync(RetryConfig? retryConfig = null); } /// /// Operations against the Plex Media Server System.
/// /// /// /// ///
public class Server: IServer { public SDKConfig SDKConfiguration { get; private set; } private const string _language = "csharp"; private const string _sdkVersion = "0.9.1"; private const string _sdkGenVersion = "2.429.0"; private const string _openapiDocVersion = "0.0.3"; private const string _userAgent = "speakeasy-sdk/csharp 0.9.1 2.429.0 0.0.3 LukeHagar.PlexAPI.SDK"; private string _serverUrl = ""; private ISpeakeasyHttpClient _client; private Func? _securitySource; public Server(ISpeakeasyHttpClient client, Func? securitySource, string serverUrl, SDKConfig config) { _client = client; _securitySource = securitySource; _serverUrl = serverUrl; SDKConfiguration = config; } public async Task GetServerCapabilitiesAsync(RetryConfig? retryConfig = null) { string baseUrl = this.SDKConfiguration.GetTemplatedServerUrl(); var urlString = baseUrl + "/"; var httpRequest = new HttpRequestMessage(HttpMethod.Get, urlString); httpRequest.Headers.Add("user-agent", _userAgent); if (_securitySource != null) { httpRequest = new SecurityMetadata(_securitySource).Apply(httpRequest); } var hookCtx = new HookContext("getServerCapabilities", null, _securitySource); httpRequest = await this.SDKConfiguration.Hooks.BeforeRequestAsync(new BeforeRequestContext(hookCtx), httpRequest); if (retryConfig == null) { if (this.SDKConfiguration.RetryConfig != null) { retryConfig = this.SDKConfiguration.RetryConfig; } else { var backoff = new BackoffStrategy( initialIntervalMs: 500L, maxIntervalMs: 60000L, maxElapsedTimeMs: 3600000L, exponent: 1.5 ); retryConfig = new RetryConfig( strategy: RetryConfig.RetryStrategy.BACKOFF, backoff: backoff, retryConnectionErrors: true ); } } List statusCodes = new List { "5XX", }; Func> retrySend = async () => { var _httpRequest = await _client.CloneAsync(httpRequest); return await _client.SendAsync(_httpRequest); }; var retries = new LukeHagar.PlexAPI.SDK.Utils.Retries.Retries(retrySend, retryConfig, statusCodes); HttpResponseMessage httpResponse; try { httpResponse = await retries.Run(); 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 obj = ResponseBodyDeserializer.Deserialize(await httpResponse.Content.ReadAsStringAsync(), NullValueHandling.Ignore); var response = new GetServerCapabilitiesResponse() { StatusCode = responseStatusCode, ContentType = contentType, RawResponse = httpResponse }; response.Object = obj; return response; } throw new Models.Errors.SDKException("Unknown content type received", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); } else if(responseStatusCode == 400) { if(Utilities.IsContentTypeMatch("application/json", contentType)) { var obj = ResponseBodyDeserializer.Deserialize(await httpResponse.Content.ReadAsStringAsync(), NullValueHandling.Ignore); obj!.RawResponse = httpResponse; throw obj!; } throw new Models.Errors.SDKException("Unknown content type received", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); } else if(responseStatusCode == 401) { if(Utilities.IsContentTypeMatch("application/json", contentType)) { var obj = ResponseBodyDeserializer.Deserialize(await httpResponse.Content.ReadAsStringAsync(), NullValueHandling.Ignore); obj!.RawResponse = httpResponse; throw obj!; } throw new Models.Errors.SDKException("Unknown content type received", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); } else if(responseStatusCode >= 400 && responseStatusCode < 500 || responseStatusCode >= 500 && responseStatusCode < 600) { throw new Models.Errors.SDKException("API error occurred", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); } throw new Models.Errors.SDKException("Unknown status code received", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); } public async Task GetServerPreferencesAsync(RetryConfig? retryConfig = null) { string baseUrl = this.SDKConfiguration.GetTemplatedServerUrl(); var urlString = baseUrl + "/:/prefs"; var httpRequest = new HttpRequestMessage(HttpMethod.Get, urlString); httpRequest.Headers.Add("user-agent", _userAgent); if (_securitySource != null) { httpRequest = new SecurityMetadata(_securitySource).Apply(httpRequest); } var hookCtx = new HookContext("getServerPreferences", null, _securitySource); httpRequest = await this.SDKConfiguration.Hooks.BeforeRequestAsync(new BeforeRequestContext(hookCtx), httpRequest); if (retryConfig == null) { if (this.SDKConfiguration.RetryConfig != null) { retryConfig = this.SDKConfiguration.RetryConfig; } else { var backoff = new BackoffStrategy( initialIntervalMs: 500L, maxIntervalMs: 60000L, maxElapsedTimeMs: 3600000L, exponent: 1.5 ); retryConfig = new RetryConfig( strategy: RetryConfig.RetryStrategy.BACKOFF, backoff: backoff, retryConnectionErrors: true ); } } List statusCodes = new List { "5XX", }; Func> retrySend = async () => { var _httpRequest = await _client.CloneAsync(httpRequest); return await _client.SendAsync(_httpRequest); }; var retries = new LukeHagar.PlexAPI.SDK.Utils.Retries.Retries(retrySend, retryConfig, statusCodes); HttpResponseMessage httpResponse; try { httpResponse = await retries.Run(); 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 obj = ResponseBodyDeserializer.Deserialize(await httpResponse.Content.ReadAsStringAsync(), NullValueHandling.Ignore); var response = new GetServerPreferencesResponse() { StatusCode = responseStatusCode, ContentType = contentType, RawResponse = httpResponse }; response.Object = obj; return response; } throw new Models.Errors.SDKException("Unknown content type received", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); } else if(responseStatusCode == 400) { if(Utilities.IsContentTypeMatch("application/json", contentType)) { var obj = ResponseBodyDeserializer.Deserialize(await httpResponse.Content.ReadAsStringAsync(), NullValueHandling.Ignore); obj!.RawResponse = httpResponse; throw obj!; } throw new Models.Errors.SDKException("Unknown content type received", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); } else if(responseStatusCode == 401) { if(Utilities.IsContentTypeMatch("application/json", contentType)) { var obj = ResponseBodyDeserializer.Deserialize(await httpResponse.Content.ReadAsStringAsync(), NullValueHandling.Ignore); obj!.RawResponse = httpResponse; throw obj!; } throw new Models.Errors.SDKException("Unknown content type received", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); } else if(responseStatusCode >= 400 && responseStatusCode < 500 || responseStatusCode >= 500 && responseStatusCode < 600) { throw new Models.Errors.SDKException("API error occurred", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); } throw new Models.Errors.SDKException("Unknown status code received", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); } public async Task GetAvailableClientsAsync(RetryConfig? retryConfig = null) { string baseUrl = this.SDKConfiguration.GetTemplatedServerUrl(); var urlString = baseUrl + "/clients"; var httpRequest = new HttpRequestMessage(HttpMethod.Get, urlString); httpRequest.Headers.Add("user-agent", _userAgent); if (_securitySource != null) { httpRequest = new SecurityMetadata(_securitySource).Apply(httpRequest); } var hookCtx = new HookContext("getAvailableClients", null, _securitySource); httpRequest = await this.SDKConfiguration.Hooks.BeforeRequestAsync(new BeforeRequestContext(hookCtx), httpRequest); if (retryConfig == null) { if (this.SDKConfiguration.RetryConfig != null) { retryConfig = this.SDKConfiguration.RetryConfig; } else { var backoff = new BackoffStrategy( initialIntervalMs: 500L, maxIntervalMs: 60000L, maxElapsedTimeMs: 3600000L, exponent: 1.5 ); retryConfig = new RetryConfig( strategy: RetryConfig.RetryStrategy.BACKOFF, backoff: backoff, retryConnectionErrors: true ); } } List statusCodes = new List { "5XX", }; Func> retrySend = async () => { var _httpRequest = await _client.CloneAsync(httpRequest); return await _client.SendAsync(_httpRequest); }; var retries = new LukeHagar.PlexAPI.SDK.Utils.Retries.Retries(retrySend, retryConfig, statusCodes); HttpResponseMessage httpResponse; try { httpResponse = await retries.Run(); 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 obj = ResponseBodyDeserializer.Deserialize(await httpResponse.Content.ReadAsStringAsync(), NullValueHandling.Ignore); var response = new GetAvailableClientsResponse() { StatusCode = responseStatusCode, ContentType = contentType, RawResponse = httpResponse }; response.Object = obj; return response; } throw new Models.Errors.SDKException("Unknown content type received", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); } else if(responseStatusCode == 400) { if(Utilities.IsContentTypeMatch("application/json", contentType)) { var obj = ResponseBodyDeserializer.Deserialize(await httpResponse.Content.ReadAsStringAsync(), NullValueHandling.Ignore); obj!.RawResponse = httpResponse; throw obj!; } throw new Models.Errors.SDKException("Unknown content type received", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); } else if(responseStatusCode == 401) { if(Utilities.IsContentTypeMatch("application/json", contentType)) { var obj = ResponseBodyDeserializer.Deserialize(await httpResponse.Content.ReadAsStringAsync(), NullValueHandling.Ignore); obj!.RawResponse = httpResponse; throw obj!; } throw new Models.Errors.SDKException("Unknown content type received", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); } else if(responseStatusCode >= 400 && responseStatusCode < 500 || responseStatusCode >= 500 && responseStatusCode < 600) { throw new Models.Errors.SDKException("API error occurred", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); } throw new Models.Errors.SDKException("Unknown status code received", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); } public async Task GetDevicesAsync(RetryConfig? retryConfig = null) { string baseUrl = this.SDKConfiguration.GetTemplatedServerUrl(); var urlString = baseUrl + "/devices"; var httpRequest = new HttpRequestMessage(HttpMethod.Get, urlString); httpRequest.Headers.Add("user-agent", _userAgent); if (_securitySource != null) { httpRequest = new SecurityMetadata(_securitySource).Apply(httpRequest); } var hookCtx = new HookContext("getDevices", null, _securitySource); httpRequest = await this.SDKConfiguration.Hooks.BeforeRequestAsync(new BeforeRequestContext(hookCtx), httpRequest); if (retryConfig == null) { if (this.SDKConfiguration.RetryConfig != null) { retryConfig = this.SDKConfiguration.RetryConfig; } else { var backoff = new BackoffStrategy( initialIntervalMs: 500L, maxIntervalMs: 60000L, maxElapsedTimeMs: 3600000L, exponent: 1.5 ); retryConfig = new RetryConfig( strategy: RetryConfig.RetryStrategy.BACKOFF, backoff: backoff, retryConnectionErrors: true ); } } List statusCodes = new List { "5XX", }; Func> retrySend = async () => { var _httpRequest = await _client.CloneAsync(httpRequest); return await _client.SendAsync(_httpRequest); }; var retries = new LukeHagar.PlexAPI.SDK.Utils.Retries.Retries(retrySend, retryConfig, statusCodes); HttpResponseMessage httpResponse; try { httpResponse = await retries.Run(); 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 obj = ResponseBodyDeserializer.Deserialize(await httpResponse.Content.ReadAsStringAsync(), NullValueHandling.Ignore); var response = new GetDevicesResponse() { StatusCode = responseStatusCode, ContentType = contentType, RawResponse = httpResponse }; response.Object = obj; return response; } throw new Models.Errors.SDKException("Unknown content type received", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); } else if(responseStatusCode == 400) { if(Utilities.IsContentTypeMatch("application/json", contentType)) { var obj = ResponseBodyDeserializer.Deserialize(await httpResponse.Content.ReadAsStringAsync(), NullValueHandling.Ignore); obj!.RawResponse = httpResponse; throw obj!; } throw new Models.Errors.SDKException("Unknown content type received", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); } else if(responseStatusCode == 401) { if(Utilities.IsContentTypeMatch("application/json", contentType)) { var obj = ResponseBodyDeserializer.Deserialize(await httpResponse.Content.ReadAsStringAsync(), NullValueHandling.Ignore); obj!.RawResponse = httpResponse; throw obj!; } throw new Models.Errors.SDKException("Unknown content type received", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); } else if(responseStatusCode >= 400 && responseStatusCode < 500 || responseStatusCode >= 500 && responseStatusCode < 600) { throw new Models.Errors.SDKException("API error occurred", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); } throw new Models.Errors.SDKException("Unknown status code received", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); } public async Task GetServerIdentityAsync(RetryConfig? retryConfig = null) { string baseUrl = this.SDKConfiguration.GetTemplatedServerUrl(); var urlString = baseUrl + "/identity"; var httpRequest = new HttpRequestMessage(HttpMethod.Get, urlString); httpRequest.Headers.Add("user-agent", _userAgent); var hookCtx = new HookContext("get-server-identity", null, null); httpRequest = await this.SDKConfiguration.Hooks.BeforeRequestAsync(new BeforeRequestContext(hookCtx), httpRequest); if (retryConfig == null) { if (this.SDKConfiguration.RetryConfig != null) { retryConfig = this.SDKConfiguration.RetryConfig; } else { var backoff = new BackoffStrategy( initialIntervalMs: 500L, maxIntervalMs: 60000L, maxElapsedTimeMs: 3600000L, exponent: 1.5 ); retryConfig = new RetryConfig( strategy: RetryConfig.RetryStrategy.BACKOFF, backoff: backoff, retryConnectionErrors: true ); } } List statusCodes = new List { "5XX", }; Func> retrySend = async () => { var _httpRequest = await _client.CloneAsync(httpRequest); return await _client.SendAsync(_httpRequest); }; var retries = new LukeHagar.PlexAPI.SDK.Utils.Retries.Retries(retrySend, retryConfig, statusCodes); HttpResponseMessage httpResponse; try { httpResponse = await retries.Run(); int _statusCode = (int)httpResponse.StatusCode; if (_statusCode == 408 || _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 obj = ResponseBodyDeserializer.Deserialize(await httpResponse.Content.ReadAsStringAsync(), NullValueHandling.Ignore); var response = new GetServerIdentityResponse() { StatusCode = responseStatusCode, ContentType = contentType, RawResponse = httpResponse }; response.Object = obj; return response; } throw new Models.Errors.SDKException("Unknown content type received", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); } else if(responseStatusCode == 408) { if(Utilities.IsContentTypeMatch("application/json", contentType)) { var obj = ResponseBodyDeserializer.Deserialize(await httpResponse.Content.ReadAsStringAsync(), NullValueHandling.Ignore); obj!.RawResponse = httpResponse; throw obj!; } throw new Models.Errors.SDKException("Unknown content type received", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); } else if(responseStatusCode >= 400 && responseStatusCode < 500 || responseStatusCode >= 500 && responseStatusCode < 600) { throw new Models.Errors.SDKException("API error occurred", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); } throw new Models.Errors.SDKException("Unknown status code received", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); } public async Task GetMyPlexAccountAsync(RetryConfig? retryConfig = null) { string baseUrl = this.SDKConfiguration.GetTemplatedServerUrl(); var urlString = baseUrl + "/myplex/account"; var httpRequest = new HttpRequestMessage(HttpMethod.Get, urlString); httpRequest.Headers.Add("user-agent", _userAgent); if (_securitySource != null) { httpRequest = new SecurityMetadata(_securitySource).Apply(httpRequest); } var hookCtx = new HookContext("getMyPlexAccount", null, _securitySource); httpRequest = await this.SDKConfiguration.Hooks.BeforeRequestAsync(new BeforeRequestContext(hookCtx), httpRequest); if (retryConfig == null) { if (this.SDKConfiguration.RetryConfig != null) { retryConfig = this.SDKConfiguration.RetryConfig; } else { var backoff = new BackoffStrategy( initialIntervalMs: 500L, maxIntervalMs: 60000L, maxElapsedTimeMs: 3600000L, exponent: 1.5 ); retryConfig = new RetryConfig( strategy: RetryConfig.RetryStrategy.BACKOFF, backoff: backoff, retryConnectionErrors: true ); } } List statusCodes = new List { "5XX", }; Func> retrySend = async () => { var _httpRequest = await _client.CloneAsync(httpRequest); return await _client.SendAsync(_httpRequest); }; var retries = new LukeHagar.PlexAPI.SDK.Utils.Retries.Retries(retrySend, retryConfig, statusCodes); HttpResponseMessage httpResponse; try { httpResponse = await retries.Run(); 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 obj = ResponseBodyDeserializer.Deserialize(await httpResponse.Content.ReadAsStringAsync(), NullValueHandling.Ignore); var response = new GetMyPlexAccountResponse() { StatusCode = responseStatusCode, ContentType = contentType, RawResponse = httpResponse }; response.Object = obj; return response; } throw new Models.Errors.SDKException("Unknown content type received", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); } else if(responseStatusCode == 400) { if(Utilities.IsContentTypeMatch("application/json", contentType)) { var obj = ResponseBodyDeserializer.Deserialize(await httpResponse.Content.ReadAsStringAsync(), NullValueHandling.Ignore); obj!.RawResponse = httpResponse; throw obj!; } throw new Models.Errors.SDKException("Unknown content type received", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); } else if(responseStatusCode == 401) { if(Utilities.IsContentTypeMatch("application/json", contentType)) { var obj = ResponseBodyDeserializer.Deserialize(await httpResponse.Content.ReadAsStringAsync(), NullValueHandling.Ignore); obj!.RawResponse = httpResponse; throw obj!; } throw new Models.Errors.SDKException("Unknown content type received", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); } else if(responseStatusCode >= 400 && responseStatusCode < 500 || responseStatusCode >= 500 && responseStatusCode < 600) { throw new Models.Errors.SDKException("API error occurred", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); } throw new Models.Errors.SDKException("Unknown status code received", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); } public async Task GetResizedPhotoAsync(GetResizedPhotoRequest request, RetryConfig? retryConfig = null) { string baseUrl = this.SDKConfiguration.GetTemplatedServerUrl(); var urlString = URLBuilder.Build(baseUrl, "/photo/:/transcode", request); var httpRequest = new HttpRequestMessage(HttpMethod.Get, urlString); httpRequest.Headers.Add("user-agent", _userAgent); if (_securitySource != null) { httpRequest = new SecurityMetadata(_securitySource).Apply(httpRequest); } var hookCtx = new HookContext("getResizedPhoto", null, _securitySource); httpRequest = await this.SDKConfiguration.Hooks.BeforeRequestAsync(new BeforeRequestContext(hookCtx), httpRequest); if (retryConfig == null) { if (this.SDKConfiguration.RetryConfig != null) { retryConfig = this.SDKConfiguration.RetryConfig; } else { var backoff = new BackoffStrategy( initialIntervalMs: 500L, maxIntervalMs: 60000L, maxElapsedTimeMs: 3600000L, exponent: 1.5 ); retryConfig = new RetryConfig( strategy: RetryConfig.RetryStrategy.BACKOFF, backoff: backoff, retryConnectionErrors: true ); } } List statusCodes = new List { "5XX", }; Func> retrySend = async () => { var _httpRequest = await _client.CloneAsync(httpRequest); return await _client.SendAsync(_httpRequest); }; var retries = new LukeHagar.PlexAPI.SDK.Utils.Retries.Retries(retrySend, retryConfig, statusCodes); HttpResponseMessage httpResponse; try { httpResponse = await retries.Run(); 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) { return new GetResizedPhotoResponse() { StatusCode = responseStatusCode, ContentType = contentType, RawResponse = httpResponse }; } else if(responseStatusCode == 400) { if(Utilities.IsContentTypeMatch("application/json", contentType)) { var obj = ResponseBodyDeserializer.Deserialize(await httpResponse.Content.ReadAsStringAsync(), NullValueHandling.Ignore); obj!.RawResponse = httpResponse; throw obj!; } throw new Models.Errors.SDKException("Unknown content type received", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); } else if(responseStatusCode == 401) { if(Utilities.IsContentTypeMatch("application/json", contentType)) { var obj = ResponseBodyDeserializer.Deserialize(await httpResponse.Content.ReadAsStringAsync(), NullValueHandling.Ignore); obj!.RawResponse = httpResponse; throw obj!; } throw new Models.Errors.SDKException("Unknown content type received", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); } else if(responseStatusCode >= 400 && responseStatusCode < 500 || responseStatusCode >= 500 && responseStatusCode < 600) { throw new Models.Errors.SDKException("API error occurred", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); } throw new Models.Errors.SDKException("Unknown status code received", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); } public async Task GetMediaProvidersAsync(string xPlexToken, RetryConfig? retryConfig = null) { var request = new GetMediaProvidersRequest() { XPlexToken = xPlexToken, }; string baseUrl = this.SDKConfiguration.GetTemplatedServerUrl(); var urlString = baseUrl + "/media/providers"; var httpRequest = new HttpRequestMessage(HttpMethod.Get, urlString); httpRequest.Headers.Add("user-agent", _userAgent); HeaderSerializer.PopulateHeaders(ref httpRequest, request); if (_securitySource != null) { httpRequest = new SecurityMetadata(_securitySource).Apply(httpRequest); } var hookCtx = new HookContext("get-media-providers", null, _securitySource); httpRequest = await this.SDKConfiguration.Hooks.BeforeRequestAsync(new BeforeRequestContext(hookCtx), httpRequest); if (retryConfig == null) { if (this.SDKConfiguration.RetryConfig != null) { retryConfig = this.SDKConfiguration.RetryConfig; } else { var backoff = new BackoffStrategy( initialIntervalMs: 500L, maxIntervalMs: 60000L, maxElapsedTimeMs: 3600000L, exponent: 1.5 ); retryConfig = new RetryConfig( strategy: RetryConfig.RetryStrategy.BACKOFF, backoff: backoff, retryConnectionErrors: true ); } } List statusCodes = new List { "5XX", }; Func> retrySend = async () => { var _httpRequest = await _client.CloneAsync(httpRequest); return await _client.SendAsync(_httpRequest); }; var retries = new LukeHagar.PlexAPI.SDK.Utils.Retries.Retries(retrySend, retryConfig, statusCodes); HttpResponseMessage httpResponse; try { httpResponse = await retries.Run(); 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 obj = ResponseBodyDeserializer.Deserialize(await httpResponse.Content.ReadAsStringAsync(), NullValueHandling.Ignore); var response = new GetMediaProvidersResponse() { StatusCode = responseStatusCode, ContentType = contentType, RawResponse = httpResponse }; response.Object = obj; return response; } throw new Models.Errors.SDKException("Unknown content type received", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); } else if(responseStatusCode == 400) { if(Utilities.IsContentTypeMatch("application/json", contentType)) { var obj = ResponseBodyDeserializer.Deserialize(await httpResponse.Content.ReadAsStringAsync(), NullValueHandling.Ignore); obj!.RawResponse = httpResponse; throw obj!; } throw new Models.Errors.SDKException("Unknown content type received", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); } else if(responseStatusCode == 401) { if(Utilities.IsContentTypeMatch("application/json", contentType)) { var obj = ResponseBodyDeserializer.Deserialize(await httpResponse.Content.ReadAsStringAsync(), NullValueHandling.Ignore); obj!.RawResponse = httpResponse; throw obj!; } throw new Models.Errors.SDKException("Unknown content type received", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); } else if(responseStatusCode >= 400 && responseStatusCode < 500 || responseStatusCode >= 500 && responseStatusCode < 600) { throw new Models.Errors.SDKException("API error occurred", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); } throw new Models.Errors.SDKException("Unknown status code received", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); } public async Task GetServerListAsync(RetryConfig? retryConfig = null) { string baseUrl = this.SDKConfiguration.GetTemplatedServerUrl(); var urlString = baseUrl + "/servers"; var httpRequest = new HttpRequestMessage(HttpMethod.Get, urlString); httpRequest.Headers.Add("user-agent", _userAgent); if (_securitySource != null) { httpRequest = new SecurityMetadata(_securitySource).Apply(httpRequest); } var hookCtx = new HookContext("getServerList", null, _securitySource); httpRequest = await this.SDKConfiguration.Hooks.BeforeRequestAsync(new BeforeRequestContext(hookCtx), httpRequest); if (retryConfig == null) { if (this.SDKConfiguration.RetryConfig != null) { retryConfig = this.SDKConfiguration.RetryConfig; } else { var backoff = new BackoffStrategy( initialIntervalMs: 500L, maxIntervalMs: 60000L, maxElapsedTimeMs: 3600000L, exponent: 1.5 ); retryConfig = new RetryConfig( strategy: RetryConfig.RetryStrategy.BACKOFF, backoff: backoff, retryConnectionErrors: true ); } } List statusCodes = new List { "5XX", }; Func> retrySend = async () => { var _httpRequest = await _client.CloneAsync(httpRequest); return await _client.SendAsync(_httpRequest); }; var retries = new LukeHagar.PlexAPI.SDK.Utils.Retries.Retries(retrySend, retryConfig, statusCodes); HttpResponseMessage httpResponse; try { httpResponse = await retries.Run(); 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 obj = ResponseBodyDeserializer.Deserialize(await httpResponse.Content.ReadAsStringAsync(), NullValueHandling.Ignore); var response = new GetServerListResponse() { StatusCode = responseStatusCode, ContentType = contentType, RawResponse = httpResponse }; response.Object = obj; return response; } throw new Models.Errors.SDKException("Unknown content type received", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); } else if(responseStatusCode == 400) { if(Utilities.IsContentTypeMatch("application/json", contentType)) { var obj = ResponseBodyDeserializer.Deserialize(await httpResponse.Content.ReadAsStringAsync(), NullValueHandling.Ignore); obj!.RawResponse = httpResponse; throw obj!; } throw new Models.Errors.SDKException("Unknown content type received", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); } else if(responseStatusCode == 401) { if(Utilities.IsContentTypeMatch("application/json", contentType)) { var obj = ResponseBodyDeserializer.Deserialize(await httpResponse.Content.ReadAsStringAsync(), NullValueHandling.Ignore); obj!.RawResponse = httpResponse; throw obj!; } throw new Models.Errors.SDKException("Unknown content type received", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); } else if(responseStatusCode >= 400 && responseStatusCode < 500 || responseStatusCode >= 500 && responseStatusCode < 600) { throw new Models.Errors.SDKException("API error occurred", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); } throw new Models.Errors.SDKException("Unknown status code received", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); } } }