mirror of
https://github.com/LukeHagar/plexcsharp.git
synced 2025-12-06 12:37:46 +00:00
170 lines
6.6 KiB
C#
170 lines
6.6 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 against Security for Plex Media Server<br/>
|
|
///
|
|
/// <remarks>
|
|
///
|
|
/// </remarks>
|
|
/// </summary>
|
|
public interface ISecurity
|
|
{
|
|
|
|
/// <summary>
|
|
/// Get a Transient Token.
|
|
///
|
|
/// <remarks>
|
|
/// This endpoint provides the caller with a temporary token with the same access level as the caller's token. These tokens are valid for up to 48 hours and are destroyed if the server instance is restarted.<br/>
|
|
///
|
|
/// </remarks>
|
|
/// </summary>
|
|
Task<GetTransientTokenResponse> GetTransientTokenAsync(GetTransientTokenQueryParamType type, Scope scope);
|
|
|
|
/// <summary>
|
|
/// Get Source Connection Information
|
|
///
|
|
/// <remarks>
|
|
/// If a caller requires connection details and a transient token for a source that is known to the server, for example a cloud media provider or shared PMS, then this endpoint can be called. This endpoint is only accessible with either an admin token or a valid transient token generated from an admin token.<br/>
|
|
/// Note: requires Plex Media Server >= 1.15.4.<br/>
|
|
///
|
|
/// </remarks>
|
|
/// </summary>
|
|
Task<GetSourceConnectionInformationResponse> GetSourceConnectionInformationAsync(string source);
|
|
}
|
|
|
|
/// <summary>
|
|
/// API Calls against Security for Plex Media Server<br/>
|
|
///
|
|
/// <remarks>
|
|
///
|
|
/// </remarks>
|
|
/// </summary>
|
|
public class Security: ISecurity
|
|
{
|
|
public SDKConfig SDKConfiguration { get; private set; }
|
|
private const string _language = "csharp";
|
|
private const string _sdkVersion = "0.2.0";
|
|
private const string _sdkGenVersion = "2.245.1";
|
|
private const string _openapiDocVersion = "0.0.3";
|
|
private const string _userAgent = "speakeasy-sdk/csharp 0.2.0 2.245.1 0.0.3 Plex-API";
|
|
private string _serverUrl = "";
|
|
private ISpeakeasyHttpClient _defaultClient;
|
|
private ISpeakeasyHttpClient _securityClient;
|
|
|
|
public Security(ISpeakeasyHttpClient defaultClient, ISpeakeasyHttpClient securityClient, string serverUrl, SDKConfig config)
|
|
{
|
|
_defaultClient = defaultClient;
|
|
_securityClient = securityClient;
|
|
_serverUrl = serverUrl;
|
|
SDKConfiguration = config;
|
|
}
|
|
|
|
|
|
public async Task<GetTransientTokenResponse> GetTransientTokenAsync(GetTransientTokenQueryParamType type, Scope scope)
|
|
{
|
|
var request = new GetTransientTokenRequest()
|
|
{
|
|
Type = type,
|
|
Scope = scope,
|
|
};
|
|
string baseUrl = this.SDKConfiguration.GetTemplatedServerDetails();
|
|
var urlString = URLBuilder.Build(baseUrl, "/security/token", 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 GetTransientTokenResponse
|
|
{
|
|
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<GetTransientTokenResponseBody>(await httpResponse.Content.ReadAsStringAsync(), new JsonSerializerSettings(){ NullValueHandling = NullValueHandling.Ignore, Converters = new JsonConverter[] { new FlexibleObjectDeserializer(), new EnumSerializer() }});
|
|
}
|
|
|
|
return response;
|
|
}
|
|
return response;
|
|
}
|
|
|
|
|
|
public async Task<GetSourceConnectionInformationResponse> GetSourceConnectionInformationAsync(string source)
|
|
{
|
|
var request = new GetSourceConnectionInformationRequest()
|
|
{
|
|
Source = source,
|
|
};
|
|
string baseUrl = this.SDKConfiguration.GetTemplatedServerDetails();
|
|
var urlString = URLBuilder.Build(baseUrl, "/security/resources", 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 GetSourceConnectionInformationResponse
|
|
{
|
|
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<GetSourceConnectionInformationResponseBody>(await httpResponse.Content.ReadAsStringAsync(), new JsonSerializerSettings(){ NullValueHandling = NullValueHandling.Ignore, Converters = new JsonConverter[] { new FlexibleObjectDeserializer(), new EnumSerializer() }});
|
|
}
|
|
|
|
return response;
|
|
}
|
|
return response;
|
|
}
|
|
|
|
}
|
|
} |