mirror of
https://github.com/LukeHagar/plexruby.git
synced 2025-12-06 12:47:44 +00:00
160 lines
6.7 KiB
Ruby
160 lines
6.7 KiB
Ruby
# Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT.
|
|
|
|
# typed: true
|
|
# frozen_string_literal: true
|
|
|
|
require 'faraday'
|
|
require 'faraday/multipart'
|
|
require 'sorbet-runtime'
|
|
|
|
module OpenApiSDK
|
|
extend T::Sig
|
|
class Log
|
|
extend T::Sig
|
|
# Submit logs to the Log Handler for Plex Media Server
|
|
#
|
|
|
|
sig { params(sdk_config: SDKConfiguration).void }
|
|
def initialize(sdk_config)
|
|
@sdk_configuration = sdk_config
|
|
end
|
|
|
|
|
|
sig { params(level: ::OpenApiSDK::Operations::Level, message: ::String, source: ::String).returns(::OpenApiSDK::Operations::LogLineResponse) }
|
|
def log_line(level, message, source)
|
|
# log_line - 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.
|
|
#
|
|
request = ::OpenApiSDK::Operations::LogLineRequest.new(
|
|
|
|
level: level,
|
|
message: message,
|
|
source: source
|
|
)
|
|
url, params = @sdk_configuration.get_server_details
|
|
base_url = Utils.template_url(url, params)
|
|
url = "#{base_url}/log"
|
|
headers = {}
|
|
query_params = Utils.get_query_params(::OpenApiSDK::Operations::LogLineRequest, request, @sdk_configuration.globals)
|
|
headers['Accept'] = 'application/json'
|
|
headers['user-agent'] = @sdk_configuration.user_agent
|
|
|
|
r = @sdk_configuration.client.get(url) do |req|
|
|
req.headers = headers
|
|
req.params = query_params
|
|
Utils.configure_request_security(req, @sdk_configuration.security) if !@sdk_configuration.nil? && !@sdk_configuration.security.nil?
|
|
end
|
|
|
|
content_type = r.headers.fetch('Content-Type', 'application/octet-stream')
|
|
|
|
res = ::OpenApiSDK::Operations::LogLineResponse.new(
|
|
status_code: r.status, content_type: content_type, raw_response: r
|
|
)
|
|
if [200, 400].include?(r.status)
|
|
elsif r.status == 401
|
|
if Utils.match_content_type(content_type, 'application/json')
|
|
out = Utils.unmarshal_complex(r.env.response_body, ::OpenApiSDK::Operations::LogLineResponseBody)
|
|
res.object = out
|
|
end
|
|
end
|
|
res
|
|
end
|
|
|
|
|
|
sig { params(request: ::String).returns(::OpenApiSDK::Operations::LogMultiLineResponse) }
|
|
def log_multi_line(request)
|
|
# log_multi_line - Logging a multi-line message
|
|
# This endpoint allows for the batch addition of log entries to the main Plex Media Server log.
|
|
# It accepts a text/plain request body, where each line represents a distinct log entry.
|
|
# Each log entry consists of URL-encoded key-value pairs, specifying log attributes such as 'level', 'message', and 'source'.
|
|
#
|
|
# Log entries are separated by a newline character (`\n`).
|
|
# Each entry's parameters should be URL-encoded to ensure accurate parsing and handling of special characters.
|
|
# This method is efficient for logging multiple entries in a single API call, reducing the overhead of multiple individual requests.
|
|
#
|
|
# The 'level' parameter specifies the log entry's severity or importance, with the following integer values:
|
|
# - `0`: Error - Critical issues that require immediate attention.
|
|
# - `1`: Warning - Important events that are not critical but may indicate potential issues.
|
|
# - `2`: Info - General informational messages about system operation.
|
|
# - `3`: Debug - Detailed information useful for debugging purposes.
|
|
# - `4`: Verbose - Highly detailed diagnostic information for in-depth analysis.
|
|
#
|
|
# The 'message' parameter contains the log text, and 'source' identifies the log message's origin (e.g., an application name or module).
|
|
#
|
|
# Example of a single log entry format:
|
|
# `level=4&message=Sample%20log%20entry&source=applicationName`
|
|
#
|
|
# Ensure each parameter is properly URL-encoded to avoid interpretation issues.
|
|
#
|
|
url, params = @sdk_configuration.get_server_details
|
|
base_url = Utils.template_url(url, params)
|
|
url = "#{base_url}/log"
|
|
headers = {}
|
|
req_content_type, data, form = Utils.serialize_request_body(request, :request, :string)
|
|
headers['content-type'] = req_content_type
|
|
raise StandardError, 'request body is required' if data.nil? && form.nil?
|
|
headers['Accept'] = 'application/json'
|
|
headers['user-agent'] = @sdk_configuration.user_agent
|
|
|
|
r = @sdk_configuration.client.post(url) do |req|
|
|
req.headers = headers
|
|
Utils.configure_request_security(req, @sdk_configuration.security) if !@sdk_configuration.nil? && !@sdk_configuration.security.nil?
|
|
if form
|
|
req.body = Utils.encode_form(form)
|
|
elsif Utils.match_content_type(req_content_type, 'application/x-www-form-urlencoded')
|
|
req.body = URI.encode_www_form(data)
|
|
else
|
|
req.body = data
|
|
end
|
|
end
|
|
|
|
content_type = r.headers.fetch('Content-Type', 'application/octet-stream')
|
|
|
|
res = ::OpenApiSDK::Operations::LogMultiLineResponse.new(
|
|
status_code: r.status, content_type: content_type, raw_response: r
|
|
)
|
|
if [200, 400].include?(r.status)
|
|
elsif r.status == 401
|
|
if Utils.match_content_type(content_type, 'application/json')
|
|
out = Utils.unmarshal_complex(r.env.response_body, ::OpenApiSDK::Operations::LogMultiLineResponseBody)
|
|
res.object = out
|
|
end
|
|
end
|
|
res
|
|
end
|
|
|
|
|
|
sig { returns(::OpenApiSDK::Operations::EnablePaperTrailResponse) }
|
|
def enable_paper_trail
|
|
# enable_paper_trail - Enabling Papertrail
|
|
# This endpoint will enable all Plex Media Serverlogs to be sent to the Papertrail networked logging site for a period of time.
|
|
#
|
|
url, params = @sdk_configuration.get_server_details
|
|
base_url = Utils.template_url(url, params)
|
|
url = "#{base_url}/log/networked"
|
|
headers = {}
|
|
headers['Accept'] = 'application/json'
|
|
headers['user-agent'] = @sdk_configuration.user_agent
|
|
|
|
r = @sdk_configuration.client.get(url) do |req|
|
|
req.headers = headers
|
|
Utils.configure_request_security(req, @sdk_configuration.security) if !@sdk_configuration.nil? && !@sdk_configuration.security.nil?
|
|
end
|
|
|
|
content_type = r.headers.fetch('Content-Type', 'application/octet-stream')
|
|
|
|
res = ::OpenApiSDK::Operations::EnablePaperTrailResponse.new(
|
|
status_code: r.status, content_type: content_type, raw_response: r
|
|
)
|
|
if [200, 400, 403].include?(r.status)
|
|
elsif r.status == 401
|
|
if Utils.match_content_type(content_type, 'application/json')
|
|
out = Utils.unmarshal_complex(r.env.response_body, ::OpenApiSDK::Operations::EnablePaperTrailResponseBody)
|
|
res.object = out
|
|
end
|
|
end
|
|
res
|
|
end
|
|
end
|
|
end
|