mirror of
https://github.com/LukeHagar/plexcsharp.git
synced 2025-12-06 12:37:46 +00:00
207 lines
8.8 KiB
C#
207 lines
8.8 KiB
C#
//------------------------------------------------------------------------------
|
|
// <auto-generated>
|
|
// This code was generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
|
|
//
|
|
// Changes to this file may cause incorrect behavior and will be lost when
|
|
// the code is regenerated.
|
|
// </auto-generated>
|
|
//------------------------------------------------------------------------------
|
|
#nullable enable
|
|
namespace LukeHagar.PlexAPI.SDK
|
|
{
|
|
using LukeHagar.PlexAPI.SDK.Hooks;
|
|
using LukeHagar.PlexAPI.SDK.Models.Components;
|
|
using LukeHagar.PlexAPI.SDK.Models.Errors;
|
|
using LukeHagar.PlexAPI.SDK.Models.Requests;
|
|
using LukeHagar.PlexAPI.SDK.Utils;
|
|
using LukeHagar.PlexAPI.SDK.Utils.Retries;
|
|
using Newtonsoft.Json;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Net.Http;
|
|
using System.Net.Http.Headers;
|
|
using System.Threading.Tasks;
|
|
|
|
/// <summary>
|
|
/// API Calls that perform operations with Plex Media Server Watchlists<br/>
|
|
///
|
|
/// <remarks>
|
|
///
|
|
/// </remarks>
|
|
/// </summary>
|
|
public interface IWatchlist
|
|
{
|
|
|
|
/// <summary>
|
|
/// Get User Watchlist
|
|
///
|
|
/// <remarks>
|
|
/// Get User Watchlist
|
|
/// </remarks>
|
|
/// </summary>
|
|
Task<GetWatchListResponse> GetWatchListAsync(GetWatchListRequest request, string? serverUrl = null);
|
|
}
|
|
|
|
/// <summary>
|
|
/// API Calls that perform operations with Plex Media Server Watchlists<br/>
|
|
///
|
|
/// <remarks>
|
|
///
|
|
/// </remarks>
|
|
/// </summary>
|
|
public class Watchlist: IWatchlist
|
|
{
|
|
/// <summary>
|
|
/// List of server URLs available for the get-watch-list operation.
|
|
/// </summary>
|
|
public static readonly string[] GetWatchListServerList = {
|
|
"https://discover.provider.plex.tv",
|
|
};
|
|
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 Watchlist(SDKConfig config)
|
|
{
|
|
SDKConfiguration = config;
|
|
}
|
|
|
|
public async Task<GetWatchListResponse> GetWatchListAsync(GetWatchListRequest request, string? serverUrl = null)
|
|
{
|
|
string baseUrl = Utilities.TemplateUrl(GetWatchListServerList[0], new Dictionary<string, string>(){
|
|
});
|
|
if (serverUrl != null)
|
|
{
|
|
baseUrl = serverUrl;
|
|
}
|
|
var urlString = URLBuilder.Build(baseUrl, "/library/sections/watchlist/{filter}", request);
|
|
|
|
var httpRequest = new HttpRequestMessage(HttpMethod.Get, urlString);
|
|
httpRequest.Headers.Add("user-agent", SDKConfiguration.UserAgent);
|
|
HeaderSerializer.PopulateHeaders(ref httpRequest, request);
|
|
|
|
if (SDKConfiguration.SecuritySource != null)
|
|
{
|
|
httpRequest = new SecurityMetadata(SDKConfiguration.SecuritySource).Apply(httpRequest);
|
|
}
|
|
|
|
var hookCtx = new HookContext(SDKConfiguration, baseUrl, "get-watch-list", 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();
|
|
GetWatchListResponseBody obj;
|
|
try
|
|
{
|
|
obj = ResponseBodyDeserializer.DeserializeNotNull<GetWatchListResponseBody>(httpResponseBody, NullValueHandling.Ignore);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw new ResponseValidationException("Failed to deserialize response body into GetWatchListResponseBody.", httpResponse, httpResponseBody, ex);
|
|
}
|
|
|
|
var response = new GetWatchListResponse()
|
|
{
|
|
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();
|
|
GetWatchListBadRequestPayload payload;
|
|
try
|
|
{
|
|
payload = ResponseBodyDeserializer.DeserializeNotNull<GetWatchListBadRequestPayload>(httpResponseBody, NullValueHandling.Ignore);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw new ResponseValidationException("Failed to deserialize response body into GetWatchListBadRequestPayload.", httpResponse, httpResponseBody, ex);
|
|
}
|
|
|
|
payload.RawResponse = httpResponse;
|
|
throw new GetWatchListBadRequest(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();
|
|
GetWatchListUnauthorizedPayload payload;
|
|
try
|
|
{
|
|
payload = ResponseBodyDeserializer.DeserializeNotNull<GetWatchListUnauthorizedPayload>(httpResponseBody, NullValueHandling.Ignore);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw new ResponseValidationException("Failed to deserialize response body into GetWatchListUnauthorizedPayload.", httpResponse, httpResponseBody, ex);
|
|
}
|
|
|
|
payload.RawResponse = httpResponse;
|
|
throw new GetWatchListUnauthorized(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());
|
|
}
|
|
}
|
|
} |