mirror of
https://github.com/LukeHagar/plexcsharp.git
synced 2025-12-06 04:20:46 +00:00
692 lines
31 KiB
C#
692 lines
31 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 interacting with Plex Media Server Media<br/>
|
|
///
|
|
/// <remarks>
|
|
///
|
|
/// </remarks>
|
|
/// </summary>
|
|
public interface IMedia
|
|
{
|
|
|
|
/// <summary>
|
|
/// Mark Media Played
|
|
///
|
|
/// <remarks>
|
|
/// This will mark the provided media key as Played.
|
|
/// </remarks>
|
|
/// </summary>
|
|
Task<MarkPlayedResponse> MarkPlayedAsync(double key);
|
|
|
|
/// <summary>
|
|
/// Mark Media Unplayed
|
|
///
|
|
/// <remarks>
|
|
/// This will mark the provided media key as Unplayed.
|
|
/// </remarks>
|
|
/// </summary>
|
|
Task<MarkUnplayedResponse> MarkUnplayedAsync(double key);
|
|
|
|
/// <summary>
|
|
/// Update Media Play Progress
|
|
///
|
|
/// <remarks>
|
|
/// This API command can be used to update the play progress of a media item.<br/>
|
|
///
|
|
/// </remarks>
|
|
/// </summary>
|
|
Task<UpdatePlayProgressResponse> UpdatePlayProgressAsync(string key, double time, string state);
|
|
|
|
/// <summary>
|
|
/// Get Banner Image
|
|
///
|
|
/// <remarks>
|
|
/// Gets the banner image of the media item
|
|
/// </remarks>
|
|
/// </summary>
|
|
Task<GetBannerImageResponse> GetBannerImageAsync(GetBannerImageRequest request);
|
|
|
|
/// <summary>
|
|
/// Get Thumb Image
|
|
///
|
|
/// <remarks>
|
|
/// Gets the thumbnail image of the media item
|
|
/// </remarks>
|
|
/// </summary>
|
|
Task<GetThumbImageResponse> GetThumbImageAsync(GetThumbImageRequest request);
|
|
}
|
|
|
|
/// <summary>
|
|
/// API Calls interacting with Plex Media Server Media<br/>
|
|
///
|
|
/// <remarks>
|
|
///
|
|
/// </remarks>
|
|
/// </summary>
|
|
public class Media: IMedia
|
|
{
|
|
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 Media(SDKConfig config)
|
|
{
|
|
SDKConfiguration = config;
|
|
}
|
|
|
|
public async Task<MarkPlayedResponse> MarkPlayedAsync(double key)
|
|
{
|
|
var request = new MarkPlayedRequest()
|
|
{
|
|
Key = key,
|
|
};
|
|
string baseUrl = this.SDKConfiguration.GetTemplatedServerUrl();
|
|
var urlString = URLBuilder.Build(baseUrl, "/:/scrobble", 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, "markPlayed", 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 MarkPlayedResponse()
|
|
{
|
|
StatusCode = responseStatusCode,
|
|
ContentType = contentType,
|
|
RawResponse = httpResponse
|
|
};
|
|
}
|
|
else if(responseStatusCode == 400)
|
|
{
|
|
if(Utilities.IsContentTypeMatch("application/json", contentType))
|
|
{
|
|
var httpResponseBody = await httpResponse.Content.ReadAsStringAsync();
|
|
MarkPlayedBadRequestPayload payload;
|
|
try
|
|
{
|
|
payload = ResponseBodyDeserializer.DeserializeNotNull<MarkPlayedBadRequestPayload>(httpResponseBody, NullValueHandling.Ignore);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw new ResponseValidationException("Failed to deserialize response body into MarkPlayedBadRequestPayload.", httpResponse, httpResponseBody, ex);
|
|
}
|
|
|
|
payload.RawResponse = httpResponse;
|
|
throw new MarkPlayedBadRequest(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();
|
|
MarkPlayedUnauthorizedPayload payload;
|
|
try
|
|
{
|
|
payload = ResponseBodyDeserializer.DeserializeNotNull<MarkPlayedUnauthorizedPayload>(httpResponseBody, NullValueHandling.Ignore);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw new ResponseValidationException("Failed to deserialize response body into MarkPlayedUnauthorizedPayload.", httpResponse, httpResponseBody, ex);
|
|
}
|
|
|
|
payload.RawResponse = httpResponse;
|
|
throw new MarkPlayedUnauthorized(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<MarkUnplayedResponse> MarkUnplayedAsync(double key)
|
|
{
|
|
var request = new MarkUnplayedRequest()
|
|
{
|
|
Key = key,
|
|
};
|
|
string baseUrl = this.SDKConfiguration.GetTemplatedServerUrl();
|
|
var urlString = URLBuilder.Build(baseUrl, "/:/unscrobble", 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, "markUnplayed", 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 MarkUnplayedResponse()
|
|
{
|
|
StatusCode = responseStatusCode,
|
|
ContentType = contentType,
|
|
RawResponse = httpResponse
|
|
};
|
|
}
|
|
else if(responseStatusCode == 400)
|
|
{
|
|
if(Utilities.IsContentTypeMatch("application/json", contentType))
|
|
{
|
|
var httpResponseBody = await httpResponse.Content.ReadAsStringAsync();
|
|
MarkUnplayedBadRequestPayload payload;
|
|
try
|
|
{
|
|
payload = ResponseBodyDeserializer.DeserializeNotNull<MarkUnplayedBadRequestPayload>(httpResponseBody, NullValueHandling.Ignore);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw new ResponseValidationException("Failed to deserialize response body into MarkUnplayedBadRequestPayload.", httpResponse, httpResponseBody, ex);
|
|
}
|
|
|
|
payload.RawResponse = httpResponse;
|
|
throw new MarkUnplayedBadRequest(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();
|
|
MarkUnplayedUnauthorizedPayload payload;
|
|
try
|
|
{
|
|
payload = ResponseBodyDeserializer.DeserializeNotNull<MarkUnplayedUnauthorizedPayload>(httpResponseBody, NullValueHandling.Ignore);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw new ResponseValidationException("Failed to deserialize response body into MarkUnplayedUnauthorizedPayload.", httpResponse, httpResponseBody, ex);
|
|
}
|
|
|
|
payload.RawResponse = httpResponse;
|
|
throw new MarkUnplayedUnauthorized(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<UpdatePlayProgressResponse> UpdatePlayProgressAsync(string key, double time, string state)
|
|
{
|
|
var request = new UpdatePlayProgressRequest()
|
|
{
|
|
Key = key,
|
|
Time = time,
|
|
State = state,
|
|
};
|
|
string baseUrl = this.SDKConfiguration.GetTemplatedServerUrl();
|
|
var urlString = URLBuilder.Build(baseUrl, "/:/progress", 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, "updatePlayProgress", 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 UpdatePlayProgressResponse()
|
|
{
|
|
StatusCode = responseStatusCode,
|
|
ContentType = contentType,
|
|
RawResponse = httpResponse
|
|
};
|
|
}
|
|
else if(responseStatusCode == 400)
|
|
{
|
|
if(Utilities.IsContentTypeMatch("application/json", contentType))
|
|
{
|
|
var httpResponseBody = await httpResponse.Content.ReadAsStringAsync();
|
|
UpdatePlayProgressBadRequestPayload payload;
|
|
try
|
|
{
|
|
payload = ResponseBodyDeserializer.DeserializeNotNull<UpdatePlayProgressBadRequestPayload>(httpResponseBody, NullValueHandling.Ignore);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw new ResponseValidationException("Failed to deserialize response body into UpdatePlayProgressBadRequestPayload.", httpResponse, httpResponseBody, ex);
|
|
}
|
|
|
|
payload.RawResponse = httpResponse;
|
|
throw new UpdatePlayProgressBadRequest(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();
|
|
UpdatePlayProgressUnauthorizedPayload payload;
|
|
try
|
|
{
|
|
payload = ResponseBodyDeserializer.DeserializeNotNull<UpdatePlayProgressUnauthorizedPayload>(httpResponseBody, NullValueHandling.Ignore);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw new ResponseValidationException("Failed to deserialize response body into UpdatePlayProgressUnauthorizedPayload.", httpResponse, httpResponseBody, ex);
|
|
}
|
|
|
|
payload.RawResponse = httpResponse;
|
|
throw new UpdatePlayProgressUnauthorized(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<GetBannerImageResponse> GetBannerImageAsync(GetBannerImageRequest request)
|
|
{
|
|
string baseUrl = this.SDKConfiguration.GetTemplatedServerUrl();
|
|
var urlString = URLBuilder.Build(baseUrl, "/library/metadata/{ratingKey}/banner", 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-banner-image", 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("image/jpeg", contentType))
|
|
{
|
|
var response = new GetBannerImageResponse()
|
|
{
|
|
StatusCode = responseStatusCode,
|
|
ContentType = contentType,
|
|
RawResponse = httpResponse
|
|
};
|
|
response.Bytes = await httpResponse.Content.ReadAsByteArrayAsync();
|
|
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();
|
|
GetBannerImageBadRequestPayload payload;
|
|
try
|
|
{
|
|
payload = ResponseBodyDeserializer.DeserializeNotNull<GetBannerImageBadRequestPayload>(httpResponseBody, NullValueHandling.Ignore);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw new ResponseValidationException("Failed to deserialize response body into GetBannerImageBadRequestPayload.", httpResponse, httpResponseBody, ex);
|
|
}
|
|
|
|
payload.RawResponse = httpResponse;
|
|
throw new GetBannerImageBadRequest(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();
|
|
GetBannerImageUnauthorizedPayload payload;
|
|
try
|
|
{
|
|
payload = ResponseBodyDeserializer.DeserializeNotNull<GetBannerImageUnauthorizedPayload>(httpResponseBody, NullValueHandling.Ignore);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw new ResponseValidationException("Failed to deserialize response body into GetBannerImageUnauthorizedPayload.", httpResponse, httpResponseBody, ex);
|
|
}
|
|
|
|
payload.RawResponse = httpResponse;
|
|
throw new GetBannerImageUnauthorized(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<GetThumbImageResponse> GetThumbImageAsync(GetThumbImageRequest request)
|
|
{
|
|
string baseUrl = this.SDKConfiguration.GetTemplatedServerUrl();
|
|
var urlString = URLBuilder.Build(baseUrl, "/library/metadata/{ratingKey}/thumb", 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-thumb-image", 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("image/jpeg", contentType))
|
|
{
|
|
var response = new GetThumbImageResponse()
|
|
{
|
|
StatusCode = responseStatusCode,
|
|
ContentType = contentType,
|
|
RawResponse = httpResponse
|
|
};
|
|
response.Bytes = await httpResponse.Content.ReadAsByteArrayAsync();
|
|
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();
|
|
GetThumbImageBadRequestPayload payload;
|
|
try
|
|
{
|
|
payload = ResponseBodyDeserializer.DeserializeNotNull<GetThumbImageBadRequestPayload>(httpResponseBody, NullValueHandling.Ignore);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw new ResponseValidationException("Failed to deserialize response body into GetThumbImageBadRequestPayload.", httpResponse, httpResponseBody, ex);
|
|
}
|
|
|
|
payload.RawResponse = httpResponse;
|
|
throw new GetThumbImageBadRequest(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();
|
|
GetThumbImageUnauthorizedPayload payload;
|
|
try
|
|
{
|
|
payload = ResponseBodyDeserializer.DeserializeNotNull<GetThumbImageUnauthorizedPayload>(httpResponseBody, NullValueHandling.Ignore);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw new ResponseValidationException("Failed to deserialize response body into GetThumbImageUnauthorizedPayload.", httpResponse, httpResponseBody, ex);
|
|
}
|
|
|
|
payload.RawResponse = httpResponse;
|
|
throw new GetThumbImageUnauthorized(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());
|
|
}
|
|
}
|
|
} |