//------------------------------------------------------------------------------ // // 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; 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; /// /// Media playlists that can be created and played back /// public interface IPlaylist { /// /// List playlists /// /// /// Gets a list of playlists and playlist folders for a user. General filters are permitted, such as `sort=lastViewedAt:desc`. A flat playlist list can be retrieved using `type=15` to limit the collection to just playlists. /// /// Task ListPlaylistsAsync(ListPlaylistsRequest? request = null); /// /// Retrieve Playlist /// /// /// Gets detailed metadata for a playlist. A playlist for many purposes (rating, editing metadata, tagging), can be treated like a regular metadata item:
/// Smart playlist details contain the `content` attribute. This is the content URI for the generator. This can then be parsed by a client to provide smart playlist editing. ///
///
Task GetPlaylistAsync(GetPlaylistRequest request); /// /// Retrieve Playlist Contents /// /// /// Gets the contents of a playlist. Should be paged by clients via standard mechanisms. By default leaves are returned (e.g. episodes, movies). In order to return other types you can use the `type` parameter. For example, you could use this to display a list of recently added albums vis a smart playlist. Note that for dumb playlists, items have a `playlistItemID` attribute which is used for deleting or moving items. /// /// Task GetPlaylistItemsAsync(GetPlaylistItemsRequest request); } /// /// Media playlists that can be created and played back /// public class Playlist: IPlaylist { public SDKConfig SDKConfiguration { get; private set; } private const string _language = Constants.Language; private const string _sdkVersion = Constants.SdkVersion; private const string _sdkGenVersion = Constants.SdkGenVersion; private const string _openapiDocVersion = Constants.OpenApiDocVersion; public Playlist(SDKConfig config) { SDKConfiguration = config; } public async Task ListPlaylistsAsync(ListPlaylistsRequest? 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 = URLBuilder.Build(baseUrl, "/playlists", request, null); 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, "listPlaylists", 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(); MediaContainerWithPlaylistMetadata obj; try { obj = ResponseBodyDeserializer.DeserializeNotNull(httpResponseBody, NullValueHandling.Include); } catch (Exception ex) { throw new ResponseValidationException("Failed to deserialize response body into MediaContainerWithPlaylistMetadata.", httpResponse, httpResponseBody, ex); } var response = new ListPlaylistsResponse() { StatusCode = responseStatusCode, ContentType = contentType, RawResponse = httpResponse }; response.MediaContainerWithPlaylistMetadata = 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 GetPlaylistAsync(GetPlaylistRequest request) { if (request == null) { request = new GetPlaylistRequest(); } 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, "/playlists/{playlistId}", request, null); 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, "getPlaylist", 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 == 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(); MediaContainerWithPlaylistMetadata obj; try { obj = ResponseBodyDeserializer.DeserializeNotNull(httpResponseBody, NullValueHandling.Ignore); } catch (Exception ex) { throw new ResponseValidationException("Failed to deserialize response body into MediaContainerWithPlaylistMetadata.", httpResponse, httpResponseBody, ex); } var response = new GetPlaylistResponse() { StatusCode = responseStatusCode, ContentType = contentType, RawResponse = httpResponse }; response.MediaContainerWithPlaylistMetadata = obj; return response; } throw new Models.Errors.SDKException("Unknown content type received", httpResponse, await httpResponse.Content.ReadAsStringAsync()); } else if(responseStatusCode == 404 || 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 GetPlaylistItemsAsync(GetPlaylistItemsRequest request) { if (request == null) { request = new GetPlaylistItemsRequest(); } 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, "/playlists/{playlistId}/items", request, null); 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, "getPlaylistItems", 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 == 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(); MediaContainerWithMetadata obj; try { obj = ResponseBodyDeserializer.DeserializeNotNull(httpResponseBody, NullValueHandling.Ignore); } catch (Exception ex) { throw new ResponseValidationException("Failed to deserialize response body into MediaContainerWithMetadata.", httpResponse, httpResponseBody, ex); } var response = new GetPlaylistItemsResponse() { StatusCode = responseStatusCode, ContentType = contentType, RawResponse = httpResponse }; response.MediaContainerWithMetadata = obj; return response; } throw new Models.Errors.SDKException("Unknown content type received", httpResponse, await httpResponse.Content.ReadAsStringAsync()); } else if(responseStatusCode == 404 || 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()); } } }