//------------------------------------------------------------------------------
//
// 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.
//
//------------------------------------------------------------------------------
#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;
///
/// Operations against the Plex Media Server System.
///
///
///
///
///
public interface IServer
{
///
/// Server Capabilities
///
///
/// Server Capabilities
///
///
Task GetServerCapabilitiesAsync();
///
/// Get Server Preferences
///
///
/// Get Server Preferences
///
///
Task GetServerPreferencesAsync();
///
/// Get Available Clients
///
///
/// Get Available Clients
///
///
Task GetAvailableClientsAsync();
///
/// Get Devices
///
///
/// Get Devices
///
///
Task GetDevicesAsync();
///
/// Get Server Identity
///
///
/// Get Server Identity
///
///
Task GetServerIdentityAsync();
///
/// Get MyPlex Account
///
///
/// Returns MyPlex Account Information
///
///
Task GetMyPlexAccountAsync();
///
/// Get a Resized Photo
///
///
/// Plex's Photo transcoder is used throughout the service to serve images at specified sizes.
///
///
///
Task GetResizedPhotoAsync(GetResizedPhotoRequest? request = null);
///
/// Get Server List
///
///
/// Get Server List
///
///
Task GetServerListAsync();
}
///
/// Operations against the Plex Media Server System.
///
///
///
///
///
public class Server: IServer
{
public SDKConfig SDKConfiguration { get; private set; }
private const string _language = "csharp";
private const string _sdkVersion = "0.2.0";
private const string _sdkGenVersion = "2.239.4";
private const string _openapiDocVersion = "0.0.3";
private const string _userAgent = "speakeasy-sdk/csharp 0.2.0 2.239.4 0.0.3 Plex-API";
private string _serverUrl = "";
private ISpeakeasyHttpClient _defaultClient;
private ISpeakeasyHttpClient _securityClient;
public Server(ISpeakeasyHttpClient defaultClient, ISpeakeasyHttpClient securityClient, string serverUrl, SDKConfig config)
{
_defaultClient = defaultClient;
_securityClient = securityClient;
_serverUrl = serverUrl;
SDKConfiguration = config;
}
public async Task GetServerCapabilitiesAsync()
{
string baseUrl = this.SDKConfiguration.GetTemplatedServerDetails();
var urlString = baseUrl + "/";
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 GetServerCapabilitiesResponse
{
StatusCode = (int)httpResponse.StatusCode,
ContentType = contentType,
RawResponse = httpResponse
};
if((response.StatusCode == 200))
{
if(Utilities.IsContentTypeMatch("application/json",response.ContentType))
{
response.TwoHundredApplicationJsonObject = JsonConvert.DeserializeObject(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(await httpResponse.Content.ReadAsStringAsync(), new JsonSerializerSettings(){ NullValueHandling = NullValueHandling.Ignore, Converters = new JsonConverter[] { new FlexibleObjectDeserializer(), new EnumSerializer() }});
}
return response;
}
return response;
}
public async Task GetServerPreferencesAsync()
{
string baseUrl = this.SDKConfiguration.GetTemplatedServerDetails();
var urlString = baseUrl + "/:/prefs";
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 GetServerPreferencesResponse
{
StatusCode = (int)httpResponse.StatusCode,
ContentType = contentType,
RawResponse = httpResponse
};
if((response.StatusCode == 200))
{
if(Utilities.IsContentTypeMatch("application/json",response.ContentType))
{
response.TwoHundredApplicationJsonObject = JsonConvert.DeserializeObject(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(await httpResponse.Content.ReadAsStringAsync(), new JsonSerializerSettings(){ NullValueHandling = NullValueHandling.Ignore, Converters = new JsonConverter[] { new FlexibleObjectDeserializer(), new EnumSerializer() }});
}
return response;
}
return response;
}
public async Task GetAvailableClientsAsync()
{
string baseUrl = this.SDKConfiguration.GetTemplatedServerDetails();
var urlString = baseUrl + "/clients";
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 GetAvailableClientsResponse
{
StatusCode = (int)httpResponse.StatusCode,
ContentType = contentType,
RawResponse = httpResponse
};
if((response.StatusCode == 200))
{
if(Utilities.IsContentTypeMatch("application/json",response.ContentType))
{
response.TwoHundredApplicationJsonObject = JsonConvert.DeserializeObject(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(await httpResponse.Content.ReadAsStringAsync(), new JsonSerializerSettings(){ NullValueHandling = NullValueHandling.Ignore, Converters = new JsonConverter[] { new FlexibleObjectDeserializer(), new EnumSerializer() }});
}
return response;
}
return response;
}
public async Task GetDevicesAsync()
{
string baseUrl = this.SDKConfiguration.GetTemplatedServerDetails();
var urlString = baseUrl + "/devices";
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 GetDevicesResponse
{
StatusCode = (int)httpResponse.StatusCode,
ContentType = contentType,
RawResponse = httpResponse
};
if((response.StatusCode == 200))
{
if(Utilities.IsContentTypeMatch("application/json",response.ContentType))
{
response.TwoHundredApplicationJsonObject = JsonConvert.DeserializeObject(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(await httpResponse.Content.ReadAsStringAsync(), new JsonSerializerSettings(){ NullValueHandling = NullValueHandling.Ignore, Converters = new JsonConverter[] { new FlexibleObjectDeserializer(), new EnumSerializer() }});
}
return response;
}
return response;
}
public async Task GetServerIdentityAsync()
{
string baseUrl = this.SDKConfiguration.GetTemplatedServerDetails();
var urlString = baseUrl + "/identity";
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 GetServerIdentityResponse
{
StatusCode = (int)httpResponse.StatusCode,
ContentType = contentType,
RawResponse = httpResponse
};
if((response.StatusCode == 200))
{
if(Utilities.IsContentTypeMatch("application/json",response.ContentType))
{
response.TwoHundredApplicationJsonObject = JsonConvert.DeserializeObject(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(await httpResponse.Content.ReadAsStringAsync(), new JsonSerializerSettings(){ NullValueHandling = NullValueHandling.Ignore, Converters = new JsonConverter[] { new FlexibleObjectDeserializer(), new EnumSerializer() }});
}
return response;
}
return response;
}
public async Task GetMyPlexAccountAsync()
{
string baseUrl = this.SDKConfiguration.GetTemplatedServerDetails();
var urlString = baseUrl + "/myplex/account";
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 GetMyPlexAccountResponse
{
StatusCode = (int)httpResponse.StatusCode,
ContentType = contentType,
RawResponse = httpResponse
};
if((response.StatusCode == 200))
{
if(Utilities.IsContentTypeMatch("application/json",response.ContentType))
{
response.TwoHundredApplicationJsonObject = JsonConvert.DeserializeObject(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(await httpResponse.Content.ReadAsStringAsync(), new JsonSerializerSettings(){ NullValueHandling = NullValueHandling.Ignore, Converters = new JsonConverter[] { new FlexibleObjectDeserializer(), new EnumSerializer() }});
}
return response;
}
return response;
}
public async Task GetResizedPhotoAsync(GetResizedPhotoRequest? request = null)
{
string baseUrl = this.SDKConfiguration.GetTemplatedServerDetails();
var urlString = URLBuilder.Build(baseUrl, "/photo/:/transcode", 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 GetResizedPhotoResponse
{
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(await httpResponse.Content.ReadAsStringAsync(), new JsonSerializerSettings(){ NullValueHandling = NullValueHandling.Ignore, Converters = new JsonConverter[] { new FlexibleObjectDeserializer(), new EnumSerializer() }});
}
return response;
}
return response;
}
public async Task GetServerListAsync()
{
string baseUrl = this.SDKConfiguration.GetTemplatedServerDetails();
var urlString = baseUrl + "/servers";
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 GetServerListResponse
{
StatusCode = (int)httpResponse.StatusCode,
ContentType = contentType,
RawResponse = httpResponse
};
if((response.StatusCode == 200))
{
if(Utilities.IsContentTypeMatch("application/json",response.ContentType))
{
response.TwoHundredApplicationJsonObject = JsonConvert.DeserializeObject(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(await httpResponse.Content.ReadAsStringAsync(), new JsonSerializerSettings(){ NullValueHandling = NullValueHandling.Ignore, Converters = new JsonConverter[] { new FlexibleObjectDeserializer(), new EnumSerializer() }});
}
return response;
}
return response;
}
}
}