mirror of
https://github.com/LukeHagar/plexcsharp.git
synced 2025-12-06 04:20:46 +00:00
743 lines
32 KiB
C#
743 lines
32 KiB
C#
|
|
//------------------------------------------------------------------------------
|
|
// <auto-generated>
|
|
// This code was generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT.
|
|
//
|
|
// Changes to this file may cause incorrect behavior and will be lost when
|
|
// the code is regenerated.
|
|
// </auto-generated>
|
|
//------------------------------------------------------------------------------
|
|
#nullable enable
|
|
namespace PlexAPI
|
|
{
|
|
using Newtonsoft.Json;
|
|
using PlexAPI.Models.Requests;
|
|
using PlexAPI.Utils;
|
|
using System.Net.Http.Headers;
|
|
using System.Net.Http;
|
|
using System.Threading.Tasks;
|
|
using System;
|
|
|
|
/// <summary>
|
|
/// API Calls interacting with Plex Media Server Libraries<br/>
|
|
///
|
|
/// <remarks>
|
|
///
|
|
/// </remarks>
|
|
/// </summary>
|
|
public interface ILibrary
|
|
{
|
|
|
|
/// <summary>
|
|
/// Get Hash Value
|
|
///
|
|
/// <remarks>
|
|
/// This resource returns hash values for local files
|
|
/// </remarks>
|
|
/// </summary>
|
|
Task<GetFileHashResponse> GetFileHashAsync(string url, double? type = null);
|
|
|
|
/// <summary>
|
|
/// Get Recently Added
|
|
///
|
|
/// <remarks>
|
|
/// This endpoint will return the recently added content.<br/>
|
|
///
|
|
/// </remarks>
|
|
/// </summary>
|
|
Task<GetRecentlyAddedResponse> GetRecentlyAddedAsync();
|
|
|
|
/// <summary>
|
|
/// Get All Libraries
|
|
///
|
|
/// <remarks>
|
|
/// A library section (commonly referred to as just a library) is a collection of media. <br/>
|
|
/// Libraries are typed, and depending on their type provide either a flat or a hierarchical view of the media. <br/>
|
|
/// For example, a music library has an artist > albums > tracks structure, whereas a movie library is flat.<br/>
|
|
/// <br/>
|
|
/// Libraries have features beyond just being a collection of media; for starters, they include information about supported types, filters and sorts. <br/>
|
|
/// This allows a client to provide a rich interface around the media (e.g. allow sorting movies by release year).<br/>
|
|
///
|
|
/// </remarks>
|
|
/// </summary>
|
|
Task<GetLibrariesResponse> GetLibrariesAsync();
|
|
|
|
/// <summary>
|
|
/// Get Library Details
|
|
///
|
|
/// <remarks>
|
|
/// Returns details for the library. This can be thought of as an interstitial endpoint because it contains information about the library, rather than content itself. These details are:<br/>
|
|
/// <br/>
|
|
/// - A list of `Directory` objects: These used to be used by clients to build a menuing system. There are four flavors of directory found here:<br/>
|
|
/// - Primary: (e.g. all, On Deck) These are still used in some clients to provide "shortcuts" to subsets of media. However, with the exception of On Deck, all of them can be created by media queries, and the desire is to allow these to be customized by users.<br/>
|
|
/// - Secondary: These are marked with `secondary="1"` and were used by old clients to provide nested menus allowing for primative (but structured) navigation.<br/>
|
|
/// - Special: There is a By Folder entry which allows browsing the media by the underlying filesystem structure, and there's a completely obsolete entry marked `search="1"` which used to be used to allow clients to build search dialogs on the fly.<br/>
|
|
/// - A list of `Type` objects: These represent the types of things found in this library, and for each one, a list of `Filter` and `Sort` objects. These can be used to build rich controls around a grid of media to allow filtering and organizing. Note that these filters and sorts are optional, and without them, the client won't render any filtering controls. The `Type` object contains:<br/>
|
|
/// - `key`: This provides the root endpoint returning the actual media list for the type.<br/>
|
|
/// - `type`: This is the metadata type for the type (if a standard Plex type).<br/>
|
|
/// - `title`: The title for for the content of this type (e.g. "Movies").<br/>
|
|
/// - Each `Filter` object contains a description of the filter. Note that it is not an exhaustive list of the full media query language, but an inportant subset useful for top-level API.<br/>
|
|
/// - `filter`: This represents the filter name used for the filter, which can be used to construct complex media queries with.<br/>
|
|
/// - `filterType`: This is either `string`, `integer`, or `boolean`, and describes the type of values used for the filter.<br/>
|
|
/// - `key`: This provides the endpoint where the possible range of values for the filter can be retrieved (e.g. for a "Genre" filter, it returns a list of all the genres in the library). This will include a `type` argument that matches the metadata type of the Type element.<br/>
|
|
/// - `title`: The title for the filter.<br/>
|
|
/// - Each `Sort` object contains a description of the sort field.<br/>
|
|
/// - `defaultDirection`: Can be either `asc` or `desc`, and specifies the default direction for the sort field (e.g. titles default to alphabetically ascending).<br/>
|
|
/// - `descKey` and `key`: Contains the parameters passed to the `sort=...` media query for each direction of the sort.<br/>
|
|
/// - `title`: The title of the field.<br/>
|
|
///
|
|
/// </remarks>
|
|
/// </summary>
|
|
Task<GetLibraryResponse> GetLibraryAsync(double sectionId, IncludeDetails? includeDetails = null);
|
|
|
|
/// <summary>
|
|
/// Delete Library Section
|
|
///
|
|
/// <remarks>
|
|
/// Delate a library using a specific section
|
|
/// </remarks>
|
|
/// </summary>
|
|
Task<DeleteLibraryResponse> DeleteLibraryAsync(double sectionId);
|
|
|
|
/// <summary>
|
|
/// Get Library Items
|
|
///
|
|
/// <remarks>
|
|
/// This endpoint will return a list of library items filtered by the filter and type provided<br/>
|
|
///
|
|
/// </remarks>
|
|
/// </summary>
|
|
Task<GetLibraryItemsResponse> GetLibraryItemsAsync(double sectionId, double? type = null, string? filter = null);
|
|
|
|
/// <summary>
|
|
/// Refresh Library
|
|
///
|
|
/// <remarks>
|
|
/// This endpoint Refreshes the library.<br/>
|
|
///
|
|
/// </remarks>
|
|
/// </summary>
|
|
Task<RefreshLibraryResponse> RefreshLibraryAsync(double sectionId);
|
|
|
|
/// <summary>
|
|
/// Get Latest Library Items
|
|
///
|
|
/// <remarks>
|
|
/// This endpoint will return a list of the latest library items filtered by the filter and type provided<br/>
|
|
///
|
|
/// </remarks>
|
|
/// </summary>
|
|
Task<GetLatestLibraryItemsResponse> GetLatestLibraryItemsAsync(double sectionId, double type, string? filter = null);
|
|
|
|
/// <summary>
|
|
/// Get Common Library Items
|
|
///
|
|
/// <remarks>
|
|
/// Represents a "Common" item. It contains only the common attributes of the items selected by the provided filter<br/>
|
|
///
|
|
/// </remarks>
|
|
/// </summary>
|
|
Task<GetCommonLibraryItemsResponse> GetCommonLibraryItemsAsync(double sectionId, double type, string? filter = null);
|
|
|
|
/// <summary>
|
|
/// Get Items Metadata
|
|
///
|
|
/// <remarks>
|
|
/// This endpoint will return the metadata of a library item specified with the ratingKey.<br/>
|
|
///
|
|
/// </remarks>
|
|
/// </summary>
|
|
Task<GetMetadataResponse> GetMetadataAsync(double ratingKey);
|
|
|
|
/// <summary>
|
|
/// Get Items Children
|
|
///
|
|
/// <remarks>
|
|
/// This endpoint will return the children of of a library item specified with the ratingKey.<br/>
|
|
///
|
|
/// </remarks>
|
|
/// </summary>
|
|
Task<GetMetadataChildrenResponse> GetMetadataChildrenAsync(double ratingKey);
|
|
|
|
/// <summary>
|
|
/// Get On Deck
|
|
///
|
|
/// <remarks>
|
|
/// This endpoint will return the on deck content.<br/>
|
|
///
|
|
/// </remarks>
|
|
/// </summary>
|
|
Task<GetOnDeckResponse> GetOnDeckAsync();
|
|
}
|
|
|
|
/// <summary>
|
|
/// API Calls interacting with Plex Media Server Libraries<br/>
|
|
///
|
|
/// <remarks>
|
|
///
|
|
/// </remarks>
|
|
/// </summary>
|
|
public class Library: ILibrary
|
|
{
|
|
public SDKConfig SDKConfiguration { get; private set; }
|
|
private const string _language = "csharp";
|
|
private const string _sdkVersion = "0.1.0";
|
|
private const string _sdkGenVersion = "2.225.2";
|
|
private const string _openapiDocVersion = "0.0.3";
|
|
private const string _userAgent = "speakeasy-sdk/csharp 0.1.0 2.225.2 0.0.3 Plex-API";
|
|
private string _serverUrl = "";
|
|
private ISpeakeasyHttpClient _defaultClient;
|
|
private ISpeakeasyHttpClient _securityClient;
|
|
|
|
public Library(ISpeakeasyHttpClient defaultClient, ISpeakeasyHttpClient securityClient, string serverUrl, SDKConfig config)
|
|
{
|
|
_defaultClient = defaultClient;
|
|
_securityClient = securityClient;
|
|
_serverUrl = serverUrl;
|
|
SDKConfiguration = config;
|
|
}
|
|
|
|
|
|
public async Task<GetFileHashResponse> GetFileHashAsync(string url, double? type = null)
|
|
{
|
|
var request = new GetFileHashRequest()
|
|
{
|
|
Url = url,
|
|
Type = type,
|
|
};
|
|
string baseUrl = this.SDKConfiguration.GetTemplatedServerDetails();
|
|
var urlString = URLBuilder.Build(baseUrl, "/library/hashes", request);
|
|
|
|
var httpRequest = new HttpRequestMessage(HttpMethod.Get, urlString);
|
|
httpRequest.Headers.Add("user-agent", _userAgent);
|
|
|
|
|
|
var client = _securityClient;
|
|
|
|
var httpResponse = await client.SendAsync(httpRequest);
|
|
|
|
var contentType = httpResponse.Content.Headers.ContentType?.MediaType;
|
|
|
|
var response = new GetFileHashResponse
|
|
{
|
|
StatusCode = (int)httpResponse.StatusCode,
|
|
ContentType = contentType,
|
|
RawResponse = httpResponse
|
|
};
|
|
|
|
if((response.StatusCode == 200) || (response.StatusCode == 400))
|
|
{
|
|
|
|
return response;
|
|
}
|
|
if((response.StatusCode == 401))
|
|
{
|
|
if(Utilities.IsContentTypeMatch("application/json",response.ContentType))
|
|
{
|
|
response.Object = JsonConvert.DeserializeObject<GetFileHashResponseBody>(await httpResponse.Content.ReadAsStringAsync(), new JsonSerializerSettings(){ NullValueHandling = NullValueHandling.Ignore, Converters = new JsonConverter[] { new FlexibleObjectDeserializer(), new EnumSerializer() }});
|
|
}
|
|
|
|
return response;
|
|
}
|
|
return response;
|
|
}
|
|
|
|
|
|
public async Task<GetRecentlyAddedResponse> GetRecentlyAddedAsync()
|
|
{
|
|
string baseUrl = this.SDKConfiguration.GetTemplatedServerDetails();
|
|
var urlString = baseUrl + "/library/recentlyAdded";
|
|
|
|
var httpRequest = new HttpRequestMessage(HttpMethod.Get, urlString);
|
|
httpRequest.Headers.Add("user-agent", _userAgent);
|
|
|
|
|
|
var client = _securityClient;
|
|
|
|
var httpResponse = await client.SendAsync(httpRequest);
|
|
|
|
var contentType = httpResponse.Content.Headers.ContentType?.MediaType;
|
|
|
|
var response = new GetRecentlyAddedResponse
|
|
{
|
|
StatusCode = (int)httpResponse.StatusCode,
|
|
ContentType = contentType,
|
|
RawResponse = httpResponse
|
|
};
|
|
|
|
if((response.StatusCode == 200))
|
|
{
|
|
if(Utilities.IsContentTypeMatch("application/json",response.ContentType))
|
|
{
|
|
response.TwoHundredApplicationJsonObject = JsonConvert.DeserializeObject<GetRecentlyAddedResponseBody>(await httpResponse.Content.ReadAsStringAsync(), new JsonSerializerSettings(){ NullValueHandling = NullValueHandling.Ignore, Converters = new JsonConverter[] { new FlexibleObjectDeserializer(), new EnumSerializer() }});
|
|
}
|
|
|
|
return response;
|
|
}
|
|
if((response.StatusCode == 400))
|
|
{
|
|
|
|
return response;
|
|
}
|
|
if((response.StatusCode == 401))
|
|
{
|
|
if(Utilities.IsContentTypeMatch("application/json",response.ContentType))
|
|
{
|
|
response.FourHundredAndOneApplicationJsonObject = JsonConvert.DeserializeObject<GetRecentlyAddedLibraryResponseBody>(await httpResponse.Content.ReadAsStringAsync(), new JsonSerializerSettings(){ NullValueHandling = NullValueHandling.Ignore, Converters = new JsonConverter[] { new FlexibleObjectDeserializer(), new EnumSerializer() }});
|
|
}
|
|
|
|
return response;
|
|
}
|
|
return response;
|
|
}
|
|
|
|
|
|
public async Task<GetLibrariesResponse> GetLibrariesAsync()
|
|
{
|
|
string baseUrl = this.SDKConfiguration.GetTemplatedServerDetails();
|
|
var urlString = baseUrl + "/library/sections";
|
|
|
|
var httpRequest = new HttpRequestMessage(HttpMethod.Get, urlString);
|
|
httpRequest.Headers.Add("user-agent", _userAgent);
|
|
|
|
|
|
var client = _securityClient;
|
|
|
|
var httpResponse = await client.SendAsync(httpRequest);
|
|
|
|
var contentType = httpResponse.Content.Headers.ContentType?.MediaType;
|
|
|
|
var response = new GetLibrariesResponse
|
|
{
|
|
StatusCode = (int)httpResponse.StatusCode,
|
|
ContentType = contentType,
|
|
RawResponse = httpResponse
|
|
};
|
|
|
|
if((response.StatusCode == 200) || (response.StatusCode == 400))
|
|
{
|
|
|
|
return response;
|
|
}
|
|
if((response.StatusCode == 401))
|
|
{
|
|
if(Utilities.IsContentTypeMatch("application/json",response.ContentType))
|
|
{
|
|
response.Object = JsonConvert.DeserializeObject<GetLibrariesResponseBody>(await httpResponse.Content.ReadAsStringAsync(), new JsonSerializerSettings(){ NullValueHandling = NullValueHandling.Ignore, Converters = new JsonConverter[] { new FlexibleObjectDeserializer(), new EnumSerializer() }});
|
|
}
|
|
|
|
return response;
|
|
}
|
|
return response;
|
|
}
|
|
|
|
|
|
public async Task<GetLibraryResponse> GetLibraryAsync(double sectionId, IncludeDetails? includeDetails = null)
|
|
{
|
|
var request = new GetLibraryRequest()
|
|
{
|
|
SectionId = sectionId,
|
|
IncludeDetails = includeDetails,
|
|
};
|
|
string baseUrl = this.SDKConfiguration.GetTemplatedServerDetails();
|
|
var urlString = URLBuilder.Build(baseUrl, "/library/sections/{sectionId}", request);
|
|
|
|
var httpRequest = new HttpRequestMessage(HttpMethod.Get, urlString);
|
|
httpRequest.Headers.Add("user-agent", _userAgent);
|
|
|
|
|
|
var client = _securityClient;
|
|
|
|
var httpResponse = await client.SendAsync(httpRequest);
|
|
|
|
var contentType = httpResponse.Content.Headers.ContentType?.MediaType;
|
|
|
|
var response = new GetLibraryResponse
|
|
{
|
|
StatusCode = (int)httpResponse.StatusCode,
|
|
ContentType = contentType,
|
|
RawResponse = httpResponse
|
|
};
|
|
|
|
if((response.StatusCode == 200) || (response.StatusCode == 400))
|
|
{
|
|
|
|
return response;
|
|
}
|
|
if((response.StatusCode == 401))
|
|
{
|
|
if(Utilities.IsContentTypeMatch("application/json",response.ContentType))
|
|
{
|
|
response.Object = JsonConvert.DeserializeObject<GetLibraryResponseBody>(await httpResponse.Content.ReadAsStringAsync(), new JsonSerializerSettings(){ NullValueHandling = NullValueHandling.Ignore, Converters = new JsonConverter[] { new FlexibleObjectDeserializer(), new EnumSerializer() }});
|
|
}
|
|
|
|
return response;
|
|
}
|
|
return response;
|
|
}
|
|
|
|
|
|
public async Task<DeleteLibraryResponse> DeleteLibraryAsync(double sectionId)
|
|
{
|
|
var request = new DeleteLibraryRequest()
|
|
{
|
|
SectionId = sectionId,
|
|
};
|
|
string baseUrl = this.SDKConfiguration.GetTemplatedServerDetails();
|
|
var urlString = URLBuilder.Build(baseUrl, "/library/sections/{sectionId}", request);
|
|
|
|
var httpRequest = new HttpRequestMessage(HttpMethod.Delete, urlString);
|
|
httpRequest.Headers.Add("user-agent", _userAgent);
|
|
|
|
|
|
var client = _securityClient;
|
|
|
|
var httpResponse = await client.SendAsync(httpRequest);
|
|
|
|
var contentType = httpResponse.Content.Headers.ContentType?.MediaType;
|
|
|
|
var response = new DeleteLibraryResponse
|
|
{
|
|
StatusCode = (int)httpResponse.StatusCode,
|
|
ContentType = contentType,
|
|
RawResponse = httpResponse
|
|
};
|
|
|
|
if((response.StatusCode == 200) || (response.StatusCode == 400))
|
|
{
|
|
|
|
return response;
|
|
}
|
|
if((response.StatusCode == 401))
|
|
{
|
|
if(Utilities.IsContentTypeMatch("application/json",response.ContentType))
|
|
{
|
|
response.Object = JsonConvert.DeserializeObject<DeleteLibraryResponseBody>(await httpResponse.Content.ReadAsStringAsync(), new JsonSerializerSettings(){ NullValueHandling = NullValueHandling.Ignore, Converters = new JsonConverter[] { new FlexibleObjectDeserializer(), new EnumSerializer() }});
|
|
}
|
|
|
|
return response;
|
|
}
|
|
return response;
|
|
}
|
|
|
|
|
|
public async Task<GetLibraryItemsResponse> GetLibraryItemsAsync(double sectionId, double? type = null, string? filter = null)
|
|
{
|
|
var request = new GetLibraryItemsRequest()
|
|
{
|
|
SectionId = sectionId,
|
|
Type = type,
|
|
Filter = filter,
|
|
};
|
|
string baseUrl = this.SDKConfiguration.GetTemplatedServerDetails();
|
|
var urlString = URLBuilder.Build(baseUrl, "/library/sections/{sectionId}/all", request);
|
|
|
|
var httpRequest = new HttpRequestMessage(HttpMethod.Get, urlString);
|
|
httpRequest.Headers.Add("user-agent", _userAgent);
|
|
|
|
|
|
var client = _securityClient;
|
|
|
|
var httpResponse = await client.SendAsync(httpRequest);
|
|
|
|
var contentType = httpResponse.Content.Headers.ContentType?.MediaType;
|
|
|
|
var response = new GetLibraryItemsResponse
|
|
{
|
|
StatusCode = (int)httpResponse.StatusCode,
|
|
ContentType = contentType,
|
|
RawResponse = httpResponse
|
|
};
|
|
|
|
if((response.StatusCode == 200) || (response.StatusCode == 400))
|
|
{
|
|
|
|
return response;
|
|
}
|
|
if((response.StatusCode == 401))
|
|
{
|
|
if(Utilities.IsContentTypeMatch("application/json",response.ContentType))
|
|
{
|
|
response.Object = JsonConvert.DeserializeObject<GetLibraryItemsResponseBody>(await httpResponse.Content.ReadAsStringAsync(), new JsonSerializerSettings(){ NullValueHandling = NullValueHandling.Ignore, Converters = new JsonConverter[] { new FlexibleObjectDeserializer(), new EnumSerializer() }});
|
|
}
|
|
|
|
return response;
|
|
}
|
|
return response;
|
|
}
|
|
|
|
|
|
public async Task<RefreshLibraryResponse> RefreshLibraryAsync(double sectionId)
|
|
{
|
|
var request = new RefreshLibraryRequest()
|
|
{
|
|
SectionId = sectionId,
|
|
};
|
|
string baseUrl = this.SDKConfiguration.GetTemplatedServerDetails();
|
|
var urlString = URLBuilder.Build(baseUrl, "/library/sections/{sectionId}/refresh", request);
|
|
|
|
var httpRequest = new HttpRequestMessage(HttpMethod.Get, urlString);
|
|
httpRequest.Headers.Add("user-agent", _userAgent);
|
|
|
|
|
|
var client = _securityClient;
|
|
|
|
var httpResponse = await client.SendAsync(httpRequest);
|
|
|
|
var contentType = httpResponse.Content.Headers.ContentType?.MediaType;
|
|
|
|
var response = new RefreshLibraryResponse
|
|
{
|
|
StatusCode = (int)httpResponse.StatusCode,
|
|
ContentType = contentType,
|
|
RawResponse = httpResponse
|
|
};
|
|
|
|
if((response.StatusCode == 200) || (response.StatusCode == 400))
|
|
{
|
|
|
|
return response;
|
|
}
|
|
if((response.StatusCode == 401))
|
|
{
|
|
if(Utilities.IsContentTypeMatch("application/json",response.ContentType))
|
|
{
|
|
response.Object = JsonConvert.DeserializeObject<RefreshLibraryResponseBody>(await httpResponse.Content.ReadAsStringAsync(), new JsonSerializerSettings(){ NullValueHandling = NullValueHandling.Ignore, Converters = new JsonConverter[] { new FlexibleObjectDeserializer(), new EnumSerializer() }});
|
|
}
|
|
|
|
return response;
|
|
}
|
|
return response;
|
|
}
|
|
|
|
|
|
public async Task<GetLatestLibraryItemsResponse> GetLatestLibraryItemsAsync(double sectionId, double type, string? filter = null)
|
|
{
|
|
var request = new GetLatestLibraryItemsRequest()
|
|
{
|
|
SectionId = sectionId,
|
|
Type = type,
|
|
Filter = filter,
|
|
};
|
|
string baseUrl = this.SDKConfiguration.GetTemplatedServerDetails();
|
|
var urlString = URLBuilder.Build(baseUrl, "/library/sections/{sectionId}/latest", request);
|
|
|
|
var httpRequest = new HttpRequestMessage(HttpMethod.Get, urlString);
|
|
httpRequest.Headers.Add("user-agent", _userAgent);
|
|
|
|
|
|
var client = _securityClient;
|
|
|
|
var httpResponse = await client.SendAsync(httpRequest);
|
|
|
|
var contentType = httpResponse.Content.Headers.ContentType?.MediaType;
|
|
|
|
var response = new GetLatestLibraryItemsResponse
|
|
{
|
|
StatusCode = (int)httpResponse.StatusCode,
|
|
ContentType = contentType,
|
|
RawResponse = httpResponse
|
|
};
|
|
|
|
if((response.StatusCode == 200) || (response.StatusCode == 400))
|
|
{
|
|
|
|
return response;
|
|
}
|
|
if((response.StatusCode == 401))
|
|
{
|
|
if(Utilities.IsContentTypeMatch("application/json",response.ContentType))
|
|
{
|
|
response.Object = JsonConvert.DeserializeObject<GetLatestLibraryItemsResponseBody>(await httpResponse.Content.ReadAsStringAsync(), new JsonSerializerSettings(){ NullValueHandling = NullValueHandling.Ignore, Converters = new JsonConverter[] { new FlexibleObjectDeserializer(), new EnumSerializer() }});
|
|
}
|
|
|
|
return response;
|
|
}
|
|
return response;
|
|
}
|
|
|
|
|
|
public async Task<GetCommonLibraryItemsResponse> GetCommonLibraryItemsAsync(double sectionId, double type, string? filter = null)
|
|
{
|
|
var request = new GetCommonLibraryItemsRequest()
|
|
{
|
|
SectionId = sectionId,
|
|
Type = type,
|
|
Filter = filter,
|
|
};
|
|
string baseUrl = this.SDKConfiguration.GetTemplatedServerDetails();
|
|
var urlString = URLBuilder.Build(baseUrl, "/library/sections/{sectionId}/common", request);
|
|
|
|
var httpRequest = new HttpRequestMessage(HttpMethod.Get, urlString);
|
|
httpRequest.Headers.Add("user-agent", _userAgent);
|
|
|
|
|
|
var client = _securityClient;
|
|
|
|
var httpResponse = await client.SendAsync(httpRequest);
|
|
|
|
var contentType = httpResponse.Content.Headers.ContentType?.MediaType;
|
|
|
|
var response = new GetCommonLibraryItemsResponse
|
|
{
|
|
StatusCode = (int)httpResponse.StatusCode,
|
|
ContentType = contentType,
|
|
RawResponse = httpResponse
|
|
};
|
|
|
|
if((response.StatusCode == 200) || (response.StatusCode == 400) || (response.StatusCode == 404))
|
|
{
|
|
|
|
return response;
|
|
}
|
|
if((response.StatusCode == 401))
|
|
{
|
|
if(Utilities.IsContentTypeMatch("application/json",response.ContentType))
|
|
{
|
|
response.Object = JsonConvert.DeserializeObject<GetCommonLibraryItemsResponseBody>(await httpResponse.Content.ReadAsStringAsync(), new JsonSerializerSettings(){ NullValueHandling = NullValueHandling.Ignore, Converters = new JsonConverter[] { new FlexibleObjectDeserializer(), new EnumSerializer() }});
|
|
}
|
|
|
|
return response;
|
|
}
|
|
return response;
|
|
}
|
|
|
|
|
|
public async Task<GetMetadataResponse> GetMetadataAsync(double ratingKey)
|
|
{
|
|
var request = new GetMetadataRequest()
|
|
{
|
|
RatingKey = ratingKey,
|
|
};
|
|
string baseUrl = this.SDKConfiguration.GetTemplatedServerDetails();
|
|
var urlString = URLBuilder.Build(baseUrl, "/library/metadata/{ratingKey}", request);
|
|
|
|
var httpRequest = new HttpRequestMessage(HttpMethod.Get, urlString);
|
|
httpRequest.Headers.Add("user-agent", _userAgent);
|
|
|
|
|
|
var client = _securityClient;
|
|
|
|
var httpResponse = await client.SendAsync(httpRequest);
|
|
|
|
var contentType = httpResponse.Content.Headers.ContentType?.MediaType;
|
|
|
|
var response = new GetMetadataResponse
|
|
{
|
|
StatusCode = (int)httpResponse.StatusCode,
|
|
ContentType = contentType,
|
|
RawResponse = httpResponse
|
|
};
|
|
|
|
if((response.StatusCode == 200) || (response.StatusCode == 400))
|
|
{
|
|
|
|
return response;
|
|
}
|
|
if((response.StatusCode == 401))
|
|
{
|
|
if(Utilities.IsContentTypeMatch("application/json",response.ContentType))
|
|
{
|
|
response.Object = JsonConvert.DeserializeObject<GetMetadataResponseBody>(await httpResponse.Content.ReadAsStringAsync(), new JsonSerializerSettings(){ NullValueHandling = NullValueHandling.Ignore, Converters = new JsonConverter[] { new FlexibleObjectDeserializer(), new EnumSerializer() }});
|
|
}
|
|
|
|
return response;
|
|
}
|
|
return response;
|
|
}
|
|
|
|
|
|
public async Task<GetMetadataChildrenResponse> GetMetadataChildrenAsync(double ratingKey)
|
|
{
|
|
var request = new GetMetadataChildrenRequest()
|
|
{
|
|
RatingKey = ratingKey,
|
|
};
|
|
string baseUrl = this.SDKConfiguration.GetTemplatedServerDetails();
|
|
var urlString = URLBuilder.Build(baseUrl, "/library/metadata/{ratingKey}/children", request);
|
|
|
|
var httpRequest = new HttpRequestMessage(HttpMethod.Get, urlString);
|
|
httpRequest.Headers.Add("user-agent", _userAgent);
|
|
|
|
|
|
var client = _securityClient;
|
|
|
|
var httpResponse = await client.SendAsync(httpRequest);
|
|
|
|
var contentType = httpResponse.Content.Headers.ContentType?.MediaType;
|
|
|
|
var response = new GetMetadataChildrenResponse
|
|
{
|
|
StatusCode = (int)httpResponse.StatusCode,
|
|
ContentType = contentType,
|
|
RawResponse = httpResponse
|
|
};
|
|
|
|
if((response.StatusCode == 200) || (response.StatusCode == 400))
|
|
{
|
|
|
|
return response;
|
|
}
|
|
if((response.StatusCode == 401))
|
|
{
|
|
if(Utilities.IsContentTypeMatch("application/json",response.ContentType))
|
|
{
|
|
response.Object = JsonConvert.DeserializeObject<GetMetadataChildrenResponseBody>(await httpResponse.Content.ReadAsStringAsync(), new JsonSerializerSettings(){ NullValueHandling = NullValueHandling.Ignore, Converters = new JsonConverter[] { new FlexibleObjectDeserializer(), new EnumSerializer() }});
|
|
}
|
|
|
|
return response;
|
|
}
|
|
return response;
|
|
}
|
|
|
|
|
|
public async Task<GetOnDeckResponse> GetOnDeckAsync()
|
|
{
|
|
string baseUrl = this.SDKConfiguration.GetTemplatedServerDetails();
|
|
var urlString = baseUrl + "/library/onDeck";
|
|
|
|
var httpRequest = new HttpRequestMessage(HttpMethod.Get, urlString);
|
|
httpRequest.Headers.Add("user-agent", _userAgent);
|
|
|
|
|
|
var client = _securityClient;
|
|
|
|
var httpResponse = await client.SendAsync(httpRequest);
|
|
|
|
var contentType = httpResponse.Content.Headers.ContentType?.MediaType;
|
|
|
|
var response = new GetOnDeckResponse
|
|
{
|
|
StatusCode = (int)httpResponse.StatusCode,
|
|
ContentType = contentType,
|
|
RawResponse = httpResponse
|
|
};
|
|
|
|
if((response.StatusCode == 200))
|
|
{
|
|
if(Utilities.IsContentTypeMatch("application/json",response.ContentType))
|
|
{
|
|
response.TwoHundredApplicationJsonObject = JsonConvert.DeserializeObject<GetOnDeckResponseBody>(await httpResponse.Content.ReadAsStringAsync(), new JsonSerializerSettings(){ NullValueHandling = NullValueHandling.Ignore, Converters = new JsonConverter[] { new FlexibleObjectDeserializer(), new EnumSerializer() }});
|
|
}
|
|
|
|
return response;
|
|
}
|
|
if((response.StatusCode == 400))
|
|
{
|
|
|
|
return response;
|
|
}
|
|
if((response.StatusCode == 401))
|
|
{
|
|
if(Utilities.IsContentTypeMatch("application/json",response.ContentType))
|
|
{
|
|
response.FourHundredAndOneApplicationJsonObject = JsonConvert.DeserializeObject<GetOnDeckLibraryResponseBody>(await httpResponse.Content.ReadAsStringAsync(), new JsonSerializerSettings(){ NullValueHandling = NullValueHandling.Ignore, Converters = new JsonConverter[] { new FlexibleObjectDeserializer(), new EnumSerializer() }});
|
|
}
|
|
|
|
return response;
|
|
}
|
|
return response;
|
|
}
|
|
|
|
}
|
|
} |