mirror of
https://github.com/LukeHagar/plexcsharp.git
synced 2025-12-06 12:37:46 +00:00
127 lines
4.5 KiB
C#
127 lines
4.5 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.Components;
|
|
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 that perform operations with Plex Media Server Statistics<br/>
|
|
///
|
|
/// <remarks>
|
|
///
|
|
/// </remarks>
|
|
/// </summary>
|
|
public interface IStatistics
|
|
{
|
|
|
|
/// <summary>
|
|
/// Get Media Statistics
|
|
///
|
|
/// <remarks>
|
|
/// This will return the media statistics for the server
|
|
/// </remarks>
|
|
/// </summary>
|
|
Task<GetStatisticsResponse> GetStatisticsAsync(long? timespan = null);
|
|
}
|
|
|
|
/// <summary>
|
|
/// API Calls that perform operations with Plex Media Server Statistics<br/>
|
|
///
|
|
/// <remarks>
|
|
///
|
|
/// </remarks>
|
|
/// </summary>
|
|
public class Statistics: IStatistics
|
|
{
|
|
public SDKConfig SDKConfiguration { get; private set; }
|
|
private const string _language = "csharp";
|
|
private const string _sdkVersion = "0.2.0";
|
|
private const string _sdkGenVersion = "2.279.1";
|
|
private const string _openapiDocVersion = "0.0.3";
|
|
private const string _userAgent = "speakeasy-sdk/csharp 0.2.0 2.279.1 0.0.3 Plex-API";
|
|
private string _serverUrl = "";
|
|
private ISpeakeasyHttpClient _defaultClient;
|
|
private Func<Security>? _securitySource;
|
|
|
|
public Statistics(ISpeakeasyHttpClient defaultClient, Func<Security>? securitySource, string serverUrl, SDKConfig config)
|
|
{
|
|
_defaultClient = defaultClient;
|
|
_securitySource = securitySource;
|
|
_serverUrl = serverUrl;
|
|
SDKConfiguration = config;
|
|
}
|
|
|
|
public async Task<GetStatisticsResponse> GetStatisticsAsync(long? timespan = null)
|
|
{
|
|
var request = new GetStatisticsRequest()
|
|
{
|
|
Timespan = timespan,
|
|
};
|
|
string baseUrl = this.SDKConfiguration.GetTemplatedServerDetails();
|
|
var urlString = URLBuilder.Build(baseUrl, "/statistics/media", request);
|
|
|
|
var httpRequest = new HttpRequestMessage(HttpMethod.Get, urlString);
|
|
httpRequest.Headers.Add("user-agent", _userAgent);
|
|
|
|
var client = _defaultClient;
|
|
if (_securitySource != null)
|
|
{
|
|
client = SecuritySerializer.Apply(_defaultClient, _securitySource);
|
|
}
|
|
|
|
var httpResponse = await client.SendAsync(httpRequest);
|
|
|
|
var contentType = httpResponse.Content.Headers.ContentType?.MediaType;
|
|
|
|
var response = new GetStatisticsResponse
|
|
{
|
|
StatusCode = (int)httpResponse.StatusCode,
|
|
ContentType = contentType,
|
|
RawResponse = httpResponse
|
|
};
|
|
|
|
if((response.StatusCode == 200))
|
|
{
|
|
if(Utilities.IsContentTypeMatch("application/json",response.ContentType))
|
|
{
|
|
response.TwoHundredApplicationJsonObject = JsonConvert.DeserializeObject<GetStatisticsResponseBody>(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<GetStatisticsStatisticsResponseBody>(await httpResponse.Content.ReadAsStringAsync(), new JsonSerializerSettings(){ NullValueHandling = NullValueHandling.Ignore, Converters = new JsonConverter[] { new FlexibleObjectDeserializer(), new EnumSerializer() }});
|
|
}
|
|
|
|
return response;
|
|
}
|
|
return response;
|
|
}
|
|
|
|
}
|
|
} |