//------------------------------------------------------------------------------ // // This code was generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. // // Changes to this file may cause incorrect behavior and will be lost when // the code is regenerated. // //------------------------------------------------------------------------------ #nullable enable namespace PlexAPI { using Newtonsoft.Json; using PlexAPI.Models.Requests; using PlexAPI.Utils; using System.Net.Http.Headers; using System.Net.Http; using System.Threading.Tasks; using System; /// /// Butler is the task manager of the Plex Media Server Ecosystem.
/// /// /// /// ///
public interface IButler { /// /// Get Butler tasks /// /// /// Returns a list of butler tasks /// /// Task GetButlerTasksAsync(); /// /// Start all Butler tasks /// /// /// This endpoint will attempt to start all Butler tasks that are enabled in the settings. Butler tasks normally run automatically during a time window configured on the server's Settings page but can be manually started using this endpoint. Tasks will run with the following criteria:
/// 1. Any tasks not scheduled to run on the current day will be skipped.
/// 2. If a task is configured to run at a random time during the configured window and we are outside that window, the task will start immediately.
/// 3. If a task is configured to run at a random time during the configured window and we are within that window, the task will be scheduled at a random time within the window.
/// 4. If we are outside the configured window, the task will start immediately.
/// ///
///
Task StartAllTasksAsync(); /// /// Stop all Butler tasks /// /// /// This endpoint will stop all currently running tasks and remove any scheduled tasks from the queue.
/// ///
///
Task StopAllTasksAsync(); /// /// Start a single Butler task /// /// /// This endpoint will attempt to start a single Butler task that is enabled in the settings. Butler tasks normally run automatically during a time window configured on the server's Settings page but can be manually started using this endpoint. Tasks will run with the following criteria:
/// 1. Any tasks not scheduled to run on the current day will be skipped.
/// 2. If a task is configured to run at a random time during the configured window and we are outside that window, the task will start immediately.
/// 3. If a task is configured to run at a random time during the configured window and we are within that window, the task will be scheduled at a random time within the window.
/// 4. If we are outside the configured window, the task will start immediately.
/// ///
///
Task StartTaskAsync(TaskName taskName); /// /// Stop a single Butler task /// /// /// This endpoint will stop a currently running task by name, or remove it from the list of scheduled tasks if it exists. See the section above for a list of task names for this endpoint.
/// ///
///
Task StopTaskAsync(PathParamTaskName taskName); } /// /// Butler is the task manager of the Plex Media Server Ecosystem.
/// /// /// /// ///
public class Butler: IButler { public SDKConfig SDKConfiguration { get; private set; } private const string _language = "csharp"; private const string _sdkVersion = "0.1.0"; private const string _sdkGenVersion = "2.225.2"; private const string _openapiDocVersion = "0.0.3"; private const string _userAgent = "speakeasy-sdk/csharp 0.1.0 2.225.2 0.0.3 Plex-API"; private string _serverUrl = ""; private ISpeakeasyHttpClient _defaultClient; private ISpeakeasyHttpClient _securityClient; public Butler(ISpeakeasyHttpClient defaultClient, ISpeakeasyHttpClient securityClient, string serverUrl, SDKConfig config) { _defaultClient = defaultClient; _securityClient = securityClient; _serverUrl = serverUrl; SDKConfiguration = config; } public async Task GetButlerTasksAsync() { string baseUrl = this.SDKConfiguration.GetTemplatedServerDetails(); var urlString = baseUrl + "/butler"; var httpRequest = new HttpRequestMessage(HttpMethod.Get, urlString); httpRequest.Headers.Add("user-agent", _userAgent); var client = _securityClient; var httpResponse = await client.SendAsync(httpRequest); var contentType = httpResponse.Content.Headers.ContentType?.MediaType; var response = new GetButlerTasksResponse { StatusCode = (int)httpResponse.StatusCode, ContentType = contentType, RawResponse = httpResponse }; if((response.StatusCode == 200)) { if(Utilities.IsContentTypeMatch("application/json",response.ContentType)) { response.TwoHundredApplicationJsonObject = JsonConvert.DeserializeObject(await httpResponse.Content.ReadAsStringAsync(), new JsonSerializerSettings(){ NullValueHandling = NullValueHandling.Ignore, Converters = new JsonConverter[] { new FlexibleObjectDeserializer(), new EnumSerializer() }}); } return response; } if((response.StatusCode == 400)) { return response; } if((response.StatusCode == 401)) { if(Utilities.IsContentTypeMatch("application/json",response.ContentType)) { response.FourHundredAndOneApplicationJsonObject = JsonConvert.DeserializeObject(await httpResponse.Content.ReadAsStringAsync(), new JsonSerializerSettings(){ NullValueHandling = NullValueHandling.Ignore, Converters = new JsonConverter[] { new FlexibleObjectDeserializer(), new EnumSerializer() }}); } return response; } return response; } public async Task StartAllTasksAsync() { string baseUrl = this.SDKConfiguration.GetTemplatedServerDetails(); var urlString = baseUrl + "/butler"; var httpRequest = new HttpRequestMessage(HttpMethod.Post, urlString); httpRequest.Headers.Add("user-agent", _userAgent); var client = _securityClient; var httpResponse = await client.SendAsync(httpRequest); var contentType = httpResponse.Content.Headers.ContentType?.MediaType; var response = new StartAllTasksResponse { StatusCode = (int)httpResponse.StatusCode, ContentType = contentType, RawResponse = httpResponse }; if((response.StatusCode == 200) || (response.StatusCode == 400)) { return response; } if((response.StatusCode == 401)) { if(Utilities.IsContentTypeMatch("application/json",response.ContentType)) { response.Object = JsonConvert.DeserializeObject(await httpResponse.Content.ReadAsStringAsync(), new JsonSerializerSettings(){ NullValueHandling = NullValueHandling.Ignore, Converters = new JsonConverter[] { new FlexibleObjectDeserializer(), new EnumSerializer() }}); } return response; } return response; } public async Task StopAllTasksAsync() { string baseUrl = this.SDKConfiguration.GetTemplatedServerDetails(); var urlString = baseUrl + "/butler"; var httpRequest = new HttpRequestMessage(HttpMethod.Delete, urlString); httpRequest.Headers.Add("user-agent", _userAgent); var client = _securityClient; var httpResponse = await client.SendAsync(httpRequest); var contentType = httpResponse.Content.Headers.ContentType?.MediaType; var response = new StopAllTasksResponse { StatusCode = (int)httpResponse.StatusCode, ContentType = contentType, RawResponse = httpResponse }; if((response.StatusCode == 200) || (response.StatusCode == 400)) { return response; } if((response.StatusCode == 401)) { if(Utilities.IsContentTypeMatch("application/json",response.ContentType)) { response.Object = JsonConvert.DeserializeObject(await httpResponse.Content.ReadAsStringAsync(), new JsonSerializerSettings(){ NullValueHandling = NullValueHandling.Ignore, Converters = new JsonConverter[] { new FlexibleObjectDeserializer(), new EnumSerializer() }}); } return response; } return response; } public async Task StartTaskAsync(TaskName taskName) { var request = new StartTaskRequest() { TaskName = taskName, }; string baseUrl = this.SDKConfiguration.GetTemplatedServerDetails(); var urlString = URLBuilder.Build(baseUrl, "/butler/{taskName}", request); var httpRequest = new HttpRequestMessage(HttpMethod.Post, urlString); httpRequest.Headers.Add("user-agent", _userAgent); var client = _securityClient; var httpResponse = await client.SendAsync(httpRequest); var contentType = httpResponse.Content.Headers.ContentType?.MediaType; var response = new StartTaskResponse { StatusCode = (int)httpResponse.StatusCode, ContentType = contentType, RawResponse = httpResponse }; if((response.StatusCode == 200) || (response.StatusCode == 202) || (response.StatusCode == 400)) { return response; } if((response.StatusCode == 401)) { if(Utilities.IsContentTypeMatch("application/json",response.ContentType)) { response.Object = JsonConvert.DeserializeObject(await httpResponse.Content.ReadAsStringAsync(), new JsonSerializerSettings(){ NullValueHandling = NullValueHandling.Ignore, Converters = new JsonConverter[] { new FlexibleObjectDeserializer(), new EnumSerializer() }}); } return response; } return response; } public async Task StopTaskAsync(PathParamTaskName taskName) { var request = new StopTaskRequest() { TaskName = taskName, }; string baseUrl = this.SDKConfiguration.GetTemplatedServerDetails(); var urlString = URLBuilder.Build(baseUrl, "/butler/{taskName}", request); var httpRequest = new HttpRequestMessage(HttpMethod.Delete, urlString); httpRequest.Headers.Add("user-agent", _userAgent); var client = _securityClient; var httpResponse = await client.SendAsync(httpRequest); var contentType = httpResponse.Content.Headers.ContentType?.MediaType; var response = new StopTaskResponse { StatusCode = (int)httpResponse.StatusCode, ContentType = contentType, RawResponse = httpResponse }; if((response.StatusCode == 200) || (response.StatusCode == 400) || (response.StatusCode == 404)) { return response; } if((response.StatusCode == 401)) { if(Utilities.IsContentTypeMatch("application/json",response.ContentType)) { response.Object = JsonConvert.DeserializeObject(await httpResponse.Content.ReadAsStringAsync(), new JsonSerializerSettings(){ NullValueHandling = NullValueHandling.Ignore, Converters = new JsonConverter[] { new FlexibleObjectDeserializer(), new EnumSerializer() }}); } return response; } return response; } } }