mirror of
https://github.com/LukeHagar/plexterraform.git
synced 2025-12-06 12:37:47 +00:00
272 lines
8.3 KiB
Go
272 lines
8.3 KiB
Go
// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT.
|
|
|
|
package sdk
|
|
|
|
import (
|
|
"bytes"
|
|
"context"
|
|
"fmt"
|
|
"github.com/LukeHagar/terraform-provider-PlexAPI/internal/sdk/pkg/models/operations"
|
|
"github.com/LukeHagar/terraform-provider-PlexAPI/internal/sdk/pkg/models/sdkerrors"
|
|
"github.com/LukeHagar/terraform-provider-PlexAPI/internal/sdk/pkg/utils"
|
|
"io"
|
|
"net/http"
|
|
"strings"
|
|
)
|
|
|
|
// Sessions - API Calls that perform search operations with Plex Media Server Sessions
|
|
type Sessions struct {
|
|
sdkConfiguration sdkConfiguration
|
|
}
|
|
|
|
func newSessions(sdkConfig sdkConfiguration) *Sessions {
|
|
return &Sessions{
|
|
sdkConfiguration: sdkConfig,
|
|
}
|
|
}
|
|
|
|
// GetSessions - Get Active Sessions
|
|
// This will retrieve the "Now Playing" Information of the PMS.
|
|
func (s *Sessions) GetSessions(ctx context.Context) (*operations.GetSessionsResponse, error) {
|
|
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
|
|
url := strings.TrimSuffix(baseURL, "/") + "/status/sessions"
|
|
|
|
req, err := http.NewRequestWithContext(ctx, "GET", url, 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)
|
|
|
|
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")
|
|
}
|
|
|
|
rawBody, err := io.ReadAll(httpRes.Body)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("error reading response body: %w", err)
|
|
}
|
|
httpRes.Body.Close()
|
|
httpRes.Body = io.NopCloser(bytes.NewBuffer(rawBody))
|
|
|
|
contentType := httpRes.Header.Get("Content-Type")
|
|
|
|
res := &operations.GetSessionsResponse{
|
|
StatusCode: httpRes.StatusCode,
|
|
ContentType: contentType,
|
|
RawResponse: httpRes,
|
|
}
|
|
switch {
|
|
case httpRes.StatusCode == 200:
|
|
fallthrough
|
|
case httpRes.StatusCode == 400:
|
|
case httpRes.StatusCode == 401:
|
|
switch {
|
|
case utils.MatchContentType(contentType, `application/json`):
|
|
var out operations.GetSessionsResponseBody
|
|
if err := utils.UnmarshalJsonFromResponseBody(bytes.NewBuffer(rawBody), &out, ""); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
res.Object = &out
|
|
default:
|
|
return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", contentType), httpRes.StatusCode, string(rawBody), httpRes)
|
|
}
|
|
}
|
|
|
|
return res, nil
|
|
}
|
|
|
|
// GetSessionHistory - Get Session History
|
|
// This will Retrieve a listing of all history views.
|
|
func (s *Sessions) GetSessionHistory(ctx context.Context) (*operations.GetSessionHistoryResponse, error) {
|
|
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
|
|
url := strings.TrimSuffix(baseURL, "/") + "/status/sessions/history/all"
|
|
|
|
req, err := http.NewRequestWithContext(ctx, "GET", url, 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)
|
|
|
|
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")
|
|
}
|
|
|
|
rawBody, err := io.ReadAll(httpRes.Body)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("error reading response body: %w", err)
|
|
}
|
|
httpRes.Body.Close()
|
|
httpRes.Body = io.NopCloser(bytes.NewBuffer(rawBody))
|
|
|
|
contentType := httpRes.Header.Get("Content-Type")
|
|
|
|
res := &operations.GetSessionHistoryResponse{
|
|
StatusCode: httpRes.StatusCode,
|
|
ContentType: contentType,
|
|
RawResponse: httpRes,
|
|
}
|
|
switch {
|
|
case httpRes.StatusCode == 200:
|
|
fallthrough
|
|
case httpRes.StatusCode == 400:
|
|
case httpRes.StatusCode == 401:
|
|
switch {
|
|
case utils.MatchContentType(contentType, `application/json`):
|
|
var out operations.GetSessionHistoryResponseBody
|
|
if err := utils.UnmarshalJsonFromResponseBody(bytes.NewBuffer(rawBody), &out, ""); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
res.Object = &out
|
|
default:
|
|
return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", contentType), httpRes.StatusCode, string(rawBody), httpRes)
|
|
}
|
|
}
|
|
|
|
return res, nil
|
|
}
|
|
|
|
// GetTranscodeSessions - Get Transcode Sessions
|
|
// Get Transcode Sessions
|
|
func (s *Sessions) GetTranscodeSessions(ctx context.Context) (*operations.GetTranscodeSessionsResponse, error) {
|
|
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
|
|
url := strings.TrimSuffix(baseURL, "/") + "/transcode/sessions"
|
|
|
|
req, err := http.NewRequestWithContext(ctx, "GET", url, 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)
|
|
|
|
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")
|
|
}
|
|
|
|
rawBody, err := io.ReadAll(httpRes.Body)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("error reading response body: %w", err)
|
|
}
|
|
httpRes.Body.Close()
|
|
httpRes.Body = io.NopCloser(bytes.NewBuffer(rawBody))
|
|
|
|
contentType := httpRes.Header.Get("Content-Type")
|
|
|
|
res := &operations.GetTranscodeSessionsResponse{
|
|
StatusCode: httpRes.StatusCode,
|
|
ContentType: contentType,
|
|
RawResponse: httpRes,
|
|
}
|
|
switch {
|
|
case httpRes.StatusCode == 200:
|
|
switch {
|
|
case utils.MatchContentType(contentType, `application/json`):
|
|
var out operations.GetTranscodeSessionsResponseBody
|
|
if err := utils.UnmarshalJsonFromResponseBody(bytes.NewBuffer(rawBody), &out, ""); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
res.TwoHundredApplicationJSONObject = &out
|
|
default:
|
|
return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", contentType), httpRes.StatusCode, string(rawBody), httpRes)
|
|
}
|
|
case httpRes.StatusCode == 400:
|
|
case httpRes.StatusCode == 401:
|
|
switch {
|
|
case utils.MatchContentType(contentType, `application/json`):
|
|
var out operations.GetTranscodeSessionsSessionsResponseBody
|
|
if err := utils.UnmarshalJsonFromResponseBody(bytes.NewBuffer(rawBody), &out, ""); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
res.FourHundredAndOneApplicationJSONObject = &out
|
|
default:
|
|
return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", contentType), httpRes.StatusCode, string(rawBody), httpRes)
|
|
}
|
|
}
|
|
|
|
return res, nil
|
|
}
|
|
|
|
// StopTranscodeSession - Stop a Transcode Session
|
|
// Stop a Transcode Session
|
|
func (s *Sessions) StopTranscodeSession(ctx context.Context, request operations.StopTranscodeSessionRequest) (*operations.StopTranscodeSessionResponse, error) {
|
|
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
|
|
url, err := utils.GenerateURL(ctx, baseURL, "/transcode/sessions/{sessionKey}", request, nil)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("error generating URL: %w", err)
|
|
}
|
|
|
|
req, err := http.NewRequestWithContext(ctx, "DELETE", url, 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)
|
|
|
|
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")
|
|
}
|
|
|
|
rawBody, err := io.ReadAll(httpRes.Body)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("error reading response body: %w", err)
|
|
}
|
|
httpRes.Body.Close()
|
|
httpRes.Body = io.NopCloser(bytes.NewBuffer(rawBody))
|
|
|
|
contentType := httpRes.Header.Get("Content-Type")
|
|
|
|
res := &operations.StopTranscodeSessionResponse{
|
|
StatusCode: httpRes.StatusCode,
|
|
ContentType: contentType,
|
|
RawResponse: httpRes,
|
|
}
|
|
switch {
|
|
case httpRes.StatusCode == 200:
|
|
fallthrough
|
|
case httpRes.StatusCode == 400:
|
|
case httpRes.StatusCode == 401:
|
|
switch {
|
|
case utils.MatchContentType(contentType, `application/json`):
|
|
var out operations.StopTranscodeSessionResponseBody
|
|
if err := utils.UnmarshalJsonFromResponseBody(bytes.NewBuffer(rawBody), &out, ""); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
res.Object = &out
|
|
default:
|
|
return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", contentType), httpRes.StatusCode, string(rawBody), httpRes)
|
|
}
|
|
}
|
|
|
|
return res, nil
|
|
}
|