mirror of
https://github.com/LukeHagar/plexgo.git
synced 2025-12-06 04:20:46 +00:00
ci: regenerated with OpenAPI Doc 0.0.3, Speakeasy CLI 1.193.0
This commit is contained in:
137
log.go
137
log.go
@@ -6,12 +6,13 @@ import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/LukeHagar/plexgo/internal/hooks"
|
||||
"github.com/LukeHagar/plexgo/internal/utils"
|
||||
"github.com/LukeHagar/plexgo/models/operations"
|
||||
"github.com/LukeHagar/plexgo/models/sdkerrors"
|
||||
"io"
|
||||
"net/http"
|
||||
"strings"
|
||||
"net/url"
|
||||
)
|
||||
|
||||
// Log - Submit logs to the Log Handler for Plex Media Server
|
||||
@@ -28,6 +29,8 @@ func newLog(sdkConfig sdkConfiguration) *Log {
|
||||
// LogLine - 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.
|
||||
func (s *Log) LogLine(ctx context.Context, level operations.Level, message string, source string) (*operations.LogLineResponse, error) {
|
||||
hookCtx := hooks.HookContext{OperationID: "logLine"}
|
||||
|
||||
request := operations.LogLineRequest{
|
||||
Level: level,
|
||||
Message: message,
|
||||
@@ -35,29 +38,50 @@ func (s *Log) LogLine(ctx context.Context, level operations.Level, message strin
|
||||
}
|
||||
|
||||
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
|
||||
url := strings.TrimSuffix(baseURL, "/") + "/log"
|
||||
opURL, err := url.JoinPath(baseURL, "/log")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error generating URL: %w", err)
|
||||
}
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", url, nil)
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", opURL, nil)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error creating request: %w", err)
|
||||
}
|
||||
req.Header.Set("Accept", "application/json")
|
||||
req.Header.Set("user-agent", s.sdkConfiguration.UserAgent)
|
||||
req.Header.Set("User-Agent", s.sdkConfiguration.UserAgent)
|
||||
|
||||
if err := utils.PopulateQueryParams(ctx, req, request, nil); err != nil {
|
||||
return nil, fmt.Errorf("error populating query params: %w", err)
|
||||
}
|
||||
|
||||
req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{hookCtx}, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
client := s.sdkConfiguration.SecurityClient
|
||||
|
||||
httpRes, err := client.Do(req)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error sending request: %w", err)
|
||||
}
|
||||
if httpRes == nil {
|
||||
return nil, fmt.Errorf("error sending request: no response")
|
||||
}
|
||||
if err != nil || httpRes == nil {
|
||||
if err != nil {
|
||||
err = fmt.Errorf("error sending request: %w", err)
|
||||
} else {
|
||||
err = fmt.Errorf("error sending request: no response")
|
||||
}
|
||||
|
||||
_, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{hookCtx}, nil, err)
|
||||
return nil, err
|
||||
} else if utils.MatchStatusCodes([]string{"400", "401", "4XX", "5XX"}, httpRes.StatusCode) {
|
||||
httpRes, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{hookCtx}, httpRes, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{hookCtx}, httpRes)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
contentType := httpRes.Header.Get("Content-Type")
|
||||
|
||||
res := &operations.LogLineResponse{
|
||||
@@ -72,6 +96,7 @@ func (s *Log) LogLine(ctx context.Context, level operations.Level, message strin
|
||||
}
|
||||
httpRes.Body.Close()
|
||||
httpRes.Body = io.NopCloser(bytes.NewBuffer(rawBody))
|
||||
|
||||
switch {
|
||||
case httpRes.StatusCode == 200:
|
||||
case httpRes.StatusCode == 400:
|
||||
@@ -121,36 +146,55 @@ func (s *Log) LogLine(ctx context.Context, level operations.Level, message strin
|
||||
//
|
||||
// Ensure each parameter is properly URL-encoded to avoid interpretation issues.
|
||||
func (s *Log) LogMultiLine(ctx context.Context, request string) (*operations.LogMultiLineResponse, error) {
|
||||
hookCtx := hooks.HookContext{OperationID: "logMultiLine"}
|
||||
|
||||
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
|
||||
url := strings.TrimSuffix(baseURL, "/") + "/log"
|
||||
opURL, err := url.JoinPath(baseURL, "/log")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error generating URL: %w", err)
|
||||
}
|
||||
|
||||
bodyReader, reqContentType, err := utils.SerializeRequestBody(ctx, request, false, false, "Request", "string", `request:"mediaType=text/plain"`)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error serializing request body: %w", err)
|
||||
}
|
||||
if bodyReader == nil {
|
||||
return nil, fmt.Errorf("request body is required")
|
||||
return nil, err
|
||||
}
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, "POST", url, bodyReader)
|
||||
req, err := http.NewRequestWithContext(ctx, "POST", opURL, bodyReader)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error creating request: %w", err)
|
||||
}
|
||||
req.Header.Set("Accept", "application/json")
|
||||
req.Header.Set("user-agent", s.sdkConfiguration.UserAgent)
|
||||
|
||||
req.Header.Set("User-Agent", s.sdkConfiguration.UserAgent)
|
||||
req.Header.Set("Content-Type", reqContentType)
|
||||
|
||||
req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{hookCtx}, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
client := s.sdkConfiguration.SecurityClient
|
||||
|
||||
httpRes, err := client.Do(req)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error sending request: %w", err)
|
||||
}
|
||||
if httpRes == nil {
|
||||
return nil, fmt.Errorf("error sending request: no response")
|
||||
}
|
||||
if err != nil || httpRes == nil {
|
||||
if err != nil {
|
||||
err = fmt.Errorf("error sending request: %w", err)
|
||||
} else {
|
||||
err = fmt.Errorf("error sending request: no response")
|
||||
}
|
||||
|
||||
_, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{hookCtx}, nil, err)
|
||||
return nil, err
|
||||
} else if utils.MatchStatusCodes([]string{"400", "401", "4XX", "5XX"}, httpRes.StatusCode) {
|
||||
httpRes, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{hookCtx}, httpRes, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{hookCtx}, httpRes)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
contentType := httpRes.Header.Get("Content-Type")
|
||||
|
||||
res := &operations.LogMultiLineResponse{
|
||||
@@ -165,6 +209,7 @@ func (s *Log) LogMultiLine(ctx context.Context, request string) (*operations.Log
|
||||
}
|
||||
httpRes.Body.Close()
|
||||
httpRes.Body = io.NopCloser(bytes.NewBuffer(rawBody))
|
||||
|
||||
switch {
|
||||
case httpRes.StatusCode == 200:
|
||||
case httpRes.StatusCode == 400:
|
||||
@@ -194,26 +239,49 @@ func (s *Log) LogMultiLine(ctx context.Context, request string) (*operations.Log
|
||||
// EnablePaperTrail - Enabling Papertrail
|
||||
// This endpoint will enable all Plex Media Serverlogs to be sent to the Papertrail networked logging site for a period of time.
|
||||
func (s *Log) EnablePaperTrail(ctx context.Context) (*operations.EnablePaperTrailResponse, error) {
|
||||
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
|
||||
url := strings.TrimSuffix(baseURL, "/") + "/log/networked"
|
||||
hookCtx := hooks.HookContext{OperationID: "enablePaperTrail"}
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", url, nil)
|
||||
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
|
||||
opURL, err := url.JoinPath(baseURL, "/log/networked")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error generating URL: %w", err)
|
||||
}
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", opURL, nil)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error creating request: %w", err)
|
||||
}
|
||||
req.Header.Set("Accept", "application/json")
|
||||
req.Header.Set("user-agent", s.sdkConfiguration.UserAgent)
|
||||
req.Header.Set("User-Agent", s.sdkConfiguration.UserAgent)
|
||||
|
||||
req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{hookCtx}, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
client := s.sdkConfiguration.SecurityClient
|
||||
|
||||
httpRes, err := client.Do(req)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error sending request: %w", err)
|
||||
}
|
||||
if httpRes == nil {
|
||||
return nil, fmt.Errorf("error sending request: no response")
|
||||
}
|
||||
if err != nil || httpRes == nil {
|
||||
if err != nil {
|
||||
err = fmt.Errorf("error sending request: %w", err)
|
||||
} else {
|
||||
err = fmt.Errorf("error sending request: no response")
|
||||
}
|
||||
|
||||
_, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{hookCtx}, nil, err)
|
||||
return nil, err
|
||||
} else if utils.MatchStatusCodes([]string{"400", "401", "403", "4XX", "5XX"}, httpRes.StatusCode) {
|
||||
httpRes, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{hookCtx}, httpRes, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{hookCtx}, httpRes)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
contentType := httpRes.Header.Get("Content-Type")
|
||||
|
||||
res := &operations.EnablePaperTrailResponse{
|
||||
@@ -228,6 +296,7 @@ func (s *Log) EnablePaperTrail(ctx context.Context) (*operations.EnablePaperTrai
|
||||
}
|
||||
httpRes.Body.Close()
|
||||
httpRes.Body = io.NopCloser(bytes.NewBuffer(rawBody))
|
||||
|
||||
switch {
|
||||
case httpRes.StatusCode == 200:
|
||||
case httpRes.StatusCode == 400:
|
||||
|
||||
Reference in New Issue
Block a user