//------------------------------------------------------------------------------
//
// 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;
///
/// Submit logs to the Log Handler for Plex Media Server
///
///
///
///
///
public interface ILog
{
///
/// Logging a single line message.
///
///
/// This endpoint will write a single-line log message, including a level and source to the main Plex Media Server log.
///
///
///
Task LogLineAsync(Level level, string message, string source);
///
/// Logging a multi-line message
///
///
/// This endpoint will write multiple lines to the main Plex Media Server log in a single request. It takes a set of query strings as would normally sent to the above GET endpoint as a linefeed-separated block of POST data. The parameters for each query string match as above.
///
///
///
Task LogMultiLineAsync();
///
/// Enabling Papertrail
///
///
/// This endpoint will enable all Plex Media Serverlogs to be sent to the Papertrail networked logging site for a period of time.
///
///
///
Task EnablePaperTrailAsync();
}
///
/// Submit logs to the Log Handler for Plex Media Server
///
///
///
///
///
public class Log: ILog
{
public SDKConfig SDKConfiguration { get; private set; }
private const string _language = "csharp";
private const string _sdkVersion = "0.1.1";
private const string _sdkGenVersion = "2.228.1";
private const string _openapiDocVersion = "0.0.3";
private const string _userAgent = "speakeasy-sdk/csharp 0.1.1 2.228.1 0.0.3 Plex-API";
private string _serverUrl = "";
private ISpeakeasyHttpClient _defaultClient;
private ISpeakeasyHttpClient _securityClient;
public Log(ISpeakeasyHttpClient defaultClient, ISpeakeasyHttpClient securityClient, string serverUrl, SDKConfig config)
{
_defaultClient = defaultClient;
_securityClient = securityClient;
_serverUrl = serverUrl;
SDKConfiguration = config;
}
public async Task LogLineAsync(Level level, string message, string source)
{
var request = new LogLineRequest()
{
Level = level,
Message = message,
Source = source,
};
string baseUrl = this.SDKConfiguration.GetTemplatedServerDetails();
var urlString = URLBuilder.Build(baseUrl, "/log", 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 LogLineResponse
{
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 LogMultiLineAsync()
{
string baseUrl = this.SDKConfiguration.GetTemplatedServerDetails();
var urlString = baseUrl + "/log";
var httpRequest = new HttpRequestMessage(HttpMethod.Post, 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 LogMultiLineResponse
{
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 EnablePaperTrailAsync()
{
string baseUrl = this.SDKConfiguration.GetTemplatedServerDetails();
var urlString = baseUrl + "/log/networked";
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 EnablePaperTrailResponse
{
StatusCode = (int)httpResponse.StatusCode,
ContentType = contentType,
RawResponse = httpResponse
};
if((response.StatusCode == 200) || (response.StatusCode == 400) || (response.StatusCode == 403))
{
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;
}
}
}