mirror of
https://github.com/LukeHagar/plexcsharp.git
synced 2025-12-06 12:37:46 +00:00
1298 lines
61 KiB
C#
1298 lines
61 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.Concurrent;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Net.Http;
|
|
using System.Net.Http.Headers;
|
|
using System.Threading.Tasks;
|
|
|
|
/// <summary>
|
|
/// Playlists are ordered collections of media. They can be dumb (just a list of media) or smart (based on a media query, such as "all albums from 2017").<br/>
|
|
///
|
|
/// <remarks>
|
|
/// They can be organized in (optionally nesting) folders.<br/>
|
|
/// Retrieving a playlist, or its items, will trigger a refresh of its metadata.<br/>
|
|
/// This may cause the duration and number of items to change.<br/>
|
|
///
|
|
/// </remarks>
|
|
/// </summary>
|
|
public interface IPlaylists
|
|
{
|
|
|
|
/// <summary>
|
|
/// Create a Playlist
|
|
///
|
|
/// <remarks>
|
|
/// Create a new playlist. By default the playlist is blank. To create a playlist along with a first item, pass:<br/>
|
|
/// - `uri` - The content URI for what we're playing (e.g. `server://1234/com.plexapp.plugins.library/library/metadata/1`).<br/>
|
|
/// - `playQueueID` - To create a playlist from an existing play queue.<br/>
|
|
///
|
|
/// </remarks>
|
|
/// </summary>
|
|
Task<CreatePlaylistResponse> CreatePlaylistAsync(CreatePlaylistRequest request);
|
|
|
|
/// <summary>
|
|
/// Get All Playlists
|
|
///
|
|
/// <remarks>
|
|
/// Get All Playlists given the specified filters.
|
|
/// </remarks>
|
|
/// </summary>
|
|
Task<GetPlaylistsResponse> GetPlaylistsAsync(PlaylistType? playlistType = null, QueryParamSmart? smart = null);
|
|
|
|
/// <summary>
|
|
/// Retrieve Playlist
|
|
///
|
|
/// <remarks>
|
|
/// Gets detailed metadata for a playlist. A playlist for many purposes (rating, editing metadata, tagging), can be treated like a regular metadata item:<br/>
|
|
/// 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.<br/>
|
|
///
|
|
/// </remarks>
|
|
/// </summary>
|
|
Task<GetPlaylistResponse> GetPlaylistAsync(double playlistID);
|
|
|
|
/// <summary>
|
|
/// Deletes a Playlist
|
|
///
|
|
/// <remarks>
|
|
/// This endpoint will delete a playlist<br/>
|
|
///
|
|
/// </remarks>
|
|
/// </summary>
|
|
Task<DeletePlaylistResponse> DeletePlaylistAsync(double playlistID);
|
|
|
|
/// <summary>
|
|
/// Update a Playlist
|
|
///
|
|
/// <remarks>
|
|
/// From PMS version 1.9.1 clients can also edit playlist metadata using this endpoint as they would via `PUT /library/metadata/{playlistID}`<br/>
|
|
///
|
|
/// </remarks>
|
|
/// </summary>
|
|
Task<UpdatePlaylistResponse> UpdatePlaylistAsync(double playlistID, string? title = null, string? summary = null);
|
|
|
|
/// <summary>
|
|
/// Retrieve Playlist Contents
|
|
///
|
|
/// <remarks>
|
|
/// Gets the contents of a playlist. Should be paged by clients via standard mechanisms. <br/>
|
|
/// By default leaves are returned (e.g. episodes, movies). In order to return other types you can use the `type` parameter. <br/>
|
|
/// For example, you could use this to display a list of recently added albums vis a smart playlist. <br/>
|
|
/// Note that for dumb playlists, items have a `playlistItemID` attribute which is used for deleting or moving items.<br/>
|
|
///
|
|
/// </remarks>
|
|
/// </summary>
|
|
Task<GetPlaylistContentsResponse> GetPlaylistContentsAsync(double playlistID, GetPlaylistContentsQueryParamType type);
|
|
|
|
/// <summary>
|
|
/// Delete Playlist Contents
|
|
///
|
|
/// <remarks>
|
|
/// Clears a playlist, only works with dumb playlists. Returns the playlist.<br/>
|
|
///
|
|
/// </remarks>
|
|
/// </summary>
|
|
Task<ClearPlaylistContentsResponse> ClearPlaylistContentsAsync(double playlistID);
|
|
|
|
/// <summary>
|
|
/// Adding to a Playlist
|
|
///
|
|
/// <remarks>
|
|
/// Adds a generator to a playlist, same parameters as the POST to create. With a dumb playlist, this adds the specified items to the playlist.<br/>
|
|
/// With a smart playlist, passing a new `uri` parameter replaces the rules for the playlist. Returns the playlist.<br/>
|
|
///
|
|
/// </remarks>
|
|
/// </summary>
|
|
Task<AddPlaylistContentsResponse> AddPlaylistContentsAsync(double playlistID, string uri, double? playQueueID = null);
|
|
|
|
/// <summary>
|
|
/// Upload Playlist
|
|
///
|
|
/// <remarks>
|
|
/// Imports m3u playlists by passing a path on the server to scan for m3u-formatted playlist files, or a path to a single playlist file.<br/>
|
|
///
|
|
/// </remarks>
|
|
/// </summary>
|
|
Task<UploadPlaylistResponse> UploadPlaylistAsync(string path, QueryParamForce force, long sectionID = 1);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Playlists are ordered collections of media. They can be dumb (just a list of media) or smart (based on a media query, such as "all albums from 2017").<br/>
|
|
///
|
|
/// <remarks>
|
|
/// They can be organized in (optionally nesting) folders.<br/>
|
|
/// Retrieving a playlist, or its items, will trigger a refresh of its metadata.<br/>
|
|
/// This may cause the duration and number of items to change.<br/>
|
|
///
|
|
/// </remarks>
|
|
/// </summary>
|
|
public class Playlists: IPlaylists
|
|
{
|
|
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 Playlists(SDKConfig config)
|
|
{
|
|
SDKConfiguration = config;
|
|
}
|
|
|
|
public async Task<CreatePlaylistResponse> CreatePlaylistAsync(CreatePlaylistRequest request)
|
|
{
|
|
string baseUrl = this.SDKConfiguration.GetTemplatedServerUrl();
|
|
var urlString = URLBuilder.Build(baseUrl, "/playlists", request);
|
|
|
|
var httpRequest = new HttpRequestMessage(HttpMethod.Post, 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, "createPlaylist", 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();
|
|
CreatePlaylistResponseBody obj;
|
|
try
|
|
{
|
|
obj = ResponseBodyDeserializer.DeserializeNotNull<CreatePlaylistResponseBody>(httpResponseBody, NullValueHandling.Ignore);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw new ResponseValidationException("Failed to deserialize response body into CreatePlaylistResponseBody.", httpResponse, httpResponseBody, ex);
|
|
}
|
|
|
|
var response = new CreatePlaylistResponse()
|
|
{
|
|
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();
|
|
CreatePlaylistBadRequestPayload payload;
|
|
try
|
|
{
|
|
payload = ResponseBodyDeserializer.DeserializeNotNull<CreatePlaylistBadRequestPayload>(httpResponseBody, NullValueHandling.Ignore);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw new ResponseValidationException("Failed to deserialize response body into CreatePlaylistBadRequestPayload.", httpResponse, httpResponseBody, ex);
|
|
}
|
|
|
|
payload.RawResponse = httpResponse;
|
|
throw new CreatePlaylistBadRequest(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();
|
|
CreatePlaylistUnauthorizedPayload payload;
|
|
try
|
|
{
|
|
payload = ResponseBodyDeserializer.DeserializeNotNull<CreatePlaylistUnauthorizedPayload>(httpResponseBody, NullValueHandling.Ignore);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw new ResponseValidationException("Failed to deserialize response body into CreatePlaylistUnauthorizedPayload.", httpResponse, httpResponseBody, ex);
|
|
}
|
|
|
|
payload.RawResponse = httpResponse;
|
|
throw new CreatePlaylistUnauthorized(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<GetPlaylistsResponse> GetPlaylistsAsync(PlaylistType? playlistType = null, QueryParamSmart? smart = null)
|
|
{
|
|
var request = new GetPlaylistsRequest()
|
|
{
|
|
PlaylistType = playlistType,
|
|
Smart = smart,
|
|
};
|
|
string baseUrl = this.SDKConfiguration.GetTemplatedServerUrl();
|
|
var urlString = URLBuilder.Build(baseUrl, "/playlists", request);
|
|
|
|
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, "getPlaylists", 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();
|
|
GetPlaylistsResponseBody obj;
|
|
try
|
|
{
|
|
obj = ResponseBodyDeserializer.DeserializeNotNull<GetPlaylistsResponseBody>(httpResponseBody, NullValueHandling.Include);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw new ResponseValidationException("Failed to deserialize response body into GetPlaylistsResponseBody.", httpResponse, httpResponseBody, ex);
|
|
}
|
|
|
|
var response = new GetPlaylistsResponse()
|
|
{
|
|
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();
|
|
GetPlaylistsBadRequestPayload payload;
|
|
try
|
|
{
|
|
payload = ResponseBodyDeserializer.DeserializeNotNull<GetPlaylistsBadRequestPayload>(httpResponseBody, NullValueHandling.Include);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw new ResponseValidationException("Failed to deserialize response body into GetPlaylistsBadRequestPayload.", httpResponse, httpResponseBody, ex);
|
|
}
|
|
|
|
payload.RawResponse = httpResponse;
|
|
throw new GetPlaylistsBadRequest(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();
|
|
GetPlaylistsUnauthorizedPayload payload;
|
|
try
|
|
{
|
|
payload = ResponseBodyDeserializer.DeserializeNotNull<GetPlaylistsUnauthorizedPayload>(httpResponseBody, NullValueHandling.Include);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw new ResponseValidationException("Failed to deserialize response body into GetPlaylistsUnauthorizedPayload.", httpResponse, httpResponseBody, ex);
|
|
}
|
|
|
|
payload.RawResponse = httpResponse;
|
|
throw new GetPlaylistsUnauthorized(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<GetPlaylistResponse> GetPlaylistAsync(double playlistID)
|
|
{
|
|
var request = new GetPlaylistRequest()
|
|
{
|
|
PlaylistID = playlistID,
|
|
};
|
|
string baseUrl = this.SDKConfiguration.GetTemplatedServerUrl();
|
|
var urlString = URLBuilder.Build(baseUrl, "/playlists/{playlistID}", request);
|
|
|
|
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, "getPlaylist", 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();
|
|
GetPlaylistResponseBody obj;
|
|
try
|
|
{
|
|
obj = ResponseBodyDeserializer.DeserializeNotNull<GetPlaylistResponseBody>(httpResponseBody, NullValueHandling.Ignore);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw new ResponseValidationException("Failed to deserialize response body into GetPlaylistResponseBody.", httpResponse, httpResponseBody, ex);
|
|
}
|
|
|
|
var response = new GetPlaylistResponse()
|
|
{
|
|
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();
|
|
GetPlaylistBadRequestPayload payload;
|
|
try
|
|
{
|
|
payload = ResponseBodyDeserializer.DeserializeNotNull<GetPlaylistBadRequestPayload>(httpResponseBody, NullValueHandling.Ignore);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw new ResponseValidationException("Failed to deserialize response body into GetPlaylistBadRequestPayload.", httpResponse, httpResponseBody, ex);
|
|
}
|
|
|
|
payload.RawResponse = httpResponse;
|
|
throw new GetPlaylistBadRequest(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();
|
|
GetPlaylistUnauthorizedPayload payload;
|
|
try
|
|
{
|
|
payload = ResponseBodyDeserializer.DeserializeNotNull<GetPlaylistUnauthorizedPayload>(httpResponseBody, NullValueHandling.Ignore);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw new ResponseValidationException("Failed to deserialize response body into GetPlaylistUnauthorizedPayload.", httpResponse, httpResponseBody, ex);
|
|
}
|
|
|
|
payload.RawResponse = httpResponse;
|
|
throw new GetPlaylistUnauthorized(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<DeletePlaylistResponse> DeletePlaylistAsync(double playlistID)
|
|
{
|
|
var request = new DeletePlaylistRequest()
|
|
{
|
|
PlaylistID = playlistID,
|
|
};
|
|
string baseUrl = this.SDKConfiguration.GetTemplatedServerUrl();
|
|
var urlString = URLBuilder.Build(baseUrl, "/playlists/{playlistID}", request);
|
|
|
|
var httpRequest = new HttpRequestMessage(HttpMethod.Delete, 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, "deletePlaylist", 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 == 204)
|
|
{
|
|
return new DeletePlaylistResponse()
|
|
{
|
|
StatusCode = responseStatusCode,
|
|
ContentType = contentType,
|
|
RawResponse = httpResponse
|
|
};
|
|
}
|
|
else if(responseStatusCode == 400)
|
|
{
|
|
if(Utilities.IsContentTypeMatch("application/json", contentType))
|
|
{
|
|
var httpResponseBody = await httpResponse.Content.ReadAsStringAsync();
|
|
DeletePlaylistBadRequestPayload payload;
|
|
try
|
|
{
|
|
payload = ResponseBodyDeserializer.DeserializeNotNull<DeletePlaylistBadRequestPayload>(httpResponseBody, NullValueHandling.Ignore);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw new ResponseValidationException("Failed to deserialize response body into DeletePlaylistBadRequestPayload.", httpResponse, httpResponseBody, ex);
|
|
}
|
|
|
|
payload.RawResponse = httpResponse;
|
|
throw new DeletePlaylistBadRequest(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();
|
|
DeletePlaylistUnauthorizedPayload payload;
|
|
try
|
|
{
|
|
payload = ResponseBodyDeserializer.DeserializeNotNull<DeletePlaylistUnauthorizedPayload>(httpResponseBody, NullValueHandling.Ignore);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw new ResponseValidationException("Failed to deserialize response body into DeletePlaylistUnauthorizedPayload.", httpResponse, httpResponseBody, ex);
|
|
}
|
|
|
|
payload.RawResponse = httpResponse;
|
|
throw new DeletePlaylistUnauthorized(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<UpdatePlaylistResponse> UpdatePlaylistAsync(double playlistID, string? title = null, string? summary = null)
|
|
{
|
|
var request = new UpdatePlaylistRequest()
|
|
{
|
|
PlaylistID = playlistID,
|
|
Title = title,
|
|
Summary = summary,
|
|
};
|
|
string baseUrl = this.SDKConfiguration.GetTemplatedServerUrl();
|
|
var urlString = URLBuilder.Build(baseUrl, "/playlists/{playlistID}", request);
|
|
|
|
var httpRequest = new HttpRequestMessage(HttpMethod.Put, 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, "updatePlaylist", 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)
|
|
{
|
|
return new UpdatePlaylistResponse()
|
|
{
|
|
StatusCode = responseStatusCode,
|
|
ContentType = contentType,
|
|
RawResponse = httpResponse
|
|
};
|
|
}
|
|
else if(responseStatusCode == 400)
|
|
{
|
|
if(Utilities.IsContentTypeMatch("application/json", contentType))
|
|
{
|
|
var httpResponseBody = await httpResponse.Content.ReadAsStringAsync();
|
|
UpdatePlaylistBadRequestPayload payload;
|
|
try
|
|
{
|
|
payload = ResponseBodyDeserializer.DeserializeNotNull<UpdatePlaylistBadRequestPayload>(httpResponseBody, NullValueHandling.Ignore);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw new ResponseValidationException("Failed to deserialize response body into UpdatePlaylistBadRequestPayload.", httpResponse, httpResponseBody, ex);
|
|
}
|
|
|
|
payload.RawResponse = httpResponse;
|
|
throw new UpdatePlaylistBadRequest(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();
|
|
UpdatePlaylistUnauthorizedPayload payload;
|
|
try
|
|
{
|
|
payload = ResponseBodyDeserializer.DeserializeNotNull<UpdatePlaylistUnauthorizedPayload>(httpResponseBody, NullValueHandling.Ignore);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw new ResponseValidationException("Failed to deserialize response body into UpdatePlaylistUnauthorizedPayload.", httpResponse, httpResponseBody, ex);
|
|
}
|
|
|
|
payload.RawResponse = httpResponse;
|
|
throw new UpdatePlaylistUnauthorized(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<GetPlaylistContentsResponse> GetPlaylistContentsAsync(double playlistID, GetPlaylistContentsQueryParamType type)
|
|
{
|
|
var request = new GetPlaylistContentsRequest()
|
|
{
|
|
PlaylistID = playlistID,
|
|
Type = type,
|
|
};
|
|
string baseUrl = this.SDKConfiguration.GetTemplatedServerUrl();
|
|
var urlString = URLBuilder.Build(baseUrl, "/playlists/{playlistID}/items", request);
|
|
|
|
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, "getPlaylistContents", 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();
|
|
GetPlaylistContentsResponseBody obj;
|
|
try
|
|
{
|
|
obj = ResponseBodyDeserializer.DeserializeNotNull<GetPlaylistContentsResponseBody>(httpResponseBody, NullValueHandling.Ignore);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw new ResponseValidationException("Failed to deserialize response body into GetPlaylistContentsResponseBody.", httpResponse, httpResponseBody, ex);
|
|
}
|
|
|
|
var response = new GetPlaylistContentsResponse()
|
|
{
|
|
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();
|
|
GetPlaylistContentsBadRequestPayload payload;
|
|
try
|
|
{
|
|
payload = ResponseBodyDeserializer.DeserializeNotNull<GetPlaylistContentsBadRequestPayload>(httpResponseBody, NullValueHandling.Ignore);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw new ResponseValidationException("Failed to deserialize response body into GetPlaylistContentsBadRequestPayload.", httpResponse, httpResponseBody, ex);
|
|
}
|
|
|
|
payload.RawResponse = httpResponse;
|
|
throw new GetPlaylistContentsBadRequest(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();
|
|
GetPlaylistContentsUnauthorizedPayload payload;
|
|
try
|
|
{
|
|
payload = ResponseBodyDeserializer.DeserializeNotNull<GetPlaylistContentsUnauthorizedPayload>(httpResponseBody, NullValueHandling.Ignore);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw new ResponseValidationException("Failed to deserialize response body into GetPlaylistContentsUnauthorizedPayload.", httpResponse, httpResponseBody, ex);
|
|
}
|
|
|
|
payload.RawResponse = httpResponse;
|
|
throw new GetPlaylistContentsUnauthorized(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<ClearPlaylistContentsResponse> ClearPlaylistContentsAsync(double playlistID)
|
|
{
|
|
var request = new ClearPlaylistContentsRequest()
|
|
{
|
|
PlaylistID = playlistID,
|
|
};
|
|
string baseUrl = this.SDKConfiguration.GetTemplatedServerUrl();
|
|
var urlString = URLBuilder.Build(baseUrl, "/playlists/{playlistID}/items", request);
|
|
|
|
var httpRequest = new HttpRequestMessage(HttpMethod.Delete, 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, "clearPlaylistContents", 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)
|
|
{
|
|
return new ClearPlaylistContentsResponse()
|
|
{
|
|
StatusCode = responseStatusCode,
|
|
ContentType = contentType,
|
|
RawResponse = httpResponse
|
|
};
|
|
}
|
|
else if(responseStatusCode == 400)
|
|
{
|
|
if(Utilities.IsContentTypeMatch("application/json", contentType))
|
|
{
|
|
var httpResponseBody = await httpResponse.Content.ReadAsStringAsync();
|
|
ClearPlaylistContentsBadRequestPayload payload;
|
|
try
|
|
{
|
|
payload = ResponseBodyDeserializer.DeserializeNotNull<ClearPlaylistContentsBadRequestPayload>(httpResponseBody, NullValueHandling.Ignore);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw new ResponseValidationException("Failed to deserialize response body into ClearPlaylistContentsBadRequestPayload.", httpResponse, httpResponseBody, ex);
|
|
}
|
|
|
|
payload.RawResponse = httpResponse;
|
|
throw new ClearPlaylistContentsBadRequest(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();
|
|
ClearPlaylistContentsUnauthorizedPayload payload;
|
|
try
|
|
{
|
|
payload = ResponseBodyDeserializer.DeserializeNotNull<ClearPlaylistContentsUnauthorizedPayload>(httpResponseBody, NullValueHandling.Ignore);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw new ResponseValidationException("Failed to deserialize response body into ClearPlaylistContentsUnauthorizedPayload.", httpResponse, httpResponseBody, ex);
|
|
}
|
|
|
|
payload.RawResponse = httpResponse;
|
|
throw new ClearPlaylistContentsUnauthorized(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<AddPlaylistContentsResponse> AddPlaylistContentsAsync(double playlistID, string uri, double? playQueueID = null)
|
|
{
|
|
var request = new AddPlaylistContentsRequest()
|
|
{
|
|
PlaylistID = playlistID,
|
|
Uri = uri,
|
|
PlayQueueID = playQueueID,
|
|
};
|
|
string baseUrl = this.SDKConfiguration.GetTemplatedServerUrl();
|
|
var urlString = URLBuilder.Build(baseUrl, "/playlists/{playlistID}/items", request);
|
|
|
|
var httpRequest = new HttpRequestMessage(HttpMethod.Put, 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, "addPlaylistContents", 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();
|
|
AddPlaylistContentsResponseBody obj;
|
|
try
|
|
{
|
|
obj = ResponseBodyDeserializer.DeserializeNotNull<AddPlaylistContentsResponseBody>(httpResponseBody, NullValueHandling.Ignore);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw new ResponseValidationException("Failed to deserialize response body into AddPlaylistContentsResponseBody.", httpResponse, httpResponseBody, ex);
|
|
}
|
|
|
|
var response = new AddPlaylistContentsResponse()
|
|
{
|
|
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();
|
|
AddPlaylistContentsBadRequestPayload payload;
|
|
try
|
|
{
|
|
payload = ResponseBodyDeserializer.DeserializeNotNull<AddPlaylistContentsBadRequestPayload>(httpResponseBody, NullValueHandling.Ignore);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw new ResponseValidationException("Failed to deserialize response body into AddPlaylistContentsBadRequestPayload.", httpResponse, httpResponseBody, ex);
|
|
}
|
|
|
|
payload.RawResponse = httpResponse;
|
|
throw new AddPlaylistContentsBadRequest(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();
|
|
AddPlaylistContentsUnauthorizedPayload payload;
|
|
try
|
|
{
|
|
payload = ResponseBodyDeserializer.DeserializeNotNull<AddPlaylistContentsUnauthorizedPayload>(httpResponseBody, NullValueHandling.Ignore);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw new ResponseValidationException("Failed to deserialize response body into AddPlaylistContentsUnauthorizedPayload.", httpResponse, httpResponseBody, ex);
|
|
}
|
|
|
|
payload.RawResponse = httpResponse;
|
|
throw new AddPlaylistContentsUnauthorized(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<UploadPlaylistResponse> UploadPlaylistAsync(string path, QueryParamForce force, long sectionID = 1)
|
|
{
|
|
var request = new UploadPlaylistRequest()
|
|
{
|
|
Path = path,
|
|
Force = force,
|
|
SectionID = sectionID,
|
|
};
|
|
string baseUrl = this.SDKConfiguration.GetTemplatedServerUrl();
|
|
var urlString = URLBuilder.Build(baseUrl, "/playlists/upload", request);
|
|
|
|
var httpRequest = new HttpRequestMessage(HttpMethod.Post, 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, "uploadPlaylist", 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)
|
|
{
|
|
return new UploadPlaylistResponse()
|
|
{
|
|
StatusCode = responseStatusCode,
|
|
ContentType = contentType,
|
|
RawResponse = httpResponse
|
|
};
|
|
}
|
|
else if(responseStatusCode == 400)
|
|
{
|
|
if(Utilities.IsContentTypeMatch("application/json", contentType))
|
|
{
|
|
var httpResponseBody = await httpResponse.Content.ReadAsStringAsync();
|
|
UploadPlaylistBadRequestPayload payload;
|
|
try
|
|
{
|
|
payload = ResponseBodyDeserializer.DeserializeNotNull<UploadPlaylistBadRequestPayload>(httpResponseBody, NullValueHandling.Ignore);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw new ResponseValidationException("Failed to deserialize response body into UploadPlaylistBadRequestPayload.", httpResponse, httpResponseBody, ex);
|
|
}
|
|
|
|
payload.RawResponse = httpResponse;
|
|
throw new UploadPlaylistBadRequest(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();
|
|
UploadPlaylistUnauthorizedPayload payload;
|
|
try
|
|
{
|
|
payload = ResponseBodyDeserializer.DeserializeNotNull<UploadPlaylistUnauthorizedPayload>(httpResponseBody, NullValueHandling.Ignore);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw new ResponseValidationException("Failed to deserialize response body into UploadPlaylistUnauthorizedPayload.", httpResponse, httpResponseBody, ex);
|
|
}
|
|
|
|
payload.RawResponse = httpResponse;
|
|
throw new UploadPlaylistUnauthorized(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());
|
|
}
|
|
}
|
|
} |