mirror of
https://github.com/LukeHagar/plexterraform.git
synced 2025-12-07 04:20:54 +00:00
ci: regenerated with OpenAPI Doc 0.0.3, Speakeasy CLI 1.129.1
This commit is contained in:
320
internal/sdk/sdk.go
Normal file
320
internal/sdk/sdk.go
Normal file
@@ -0,0 +1,320 @@
|
||||
// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT.
|
||||
|
||||
package sdk
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/LukeHagar/terraform-provider-PlexAPI/internal/sdk/pkg/models/shared"
|
||||
"github.com/LukeHagar/terraform-provider-PlexAPI/internal/sdk/pkg/utils"
|
||||
"net/http"
|
||||
"time"
|
||||
)
|
||||
|
||||
// ServerList contains the list of servers available to the SDK
|
||||
var ServerList = []string{
|
||||
// The full address of your Plex Server
|
||||
"http://10.10.10.47:32400",
|
||||
// The full address of your Plex Server
|
||||
"{protocol}://{ip}:{port}",
|
||||
}
|
||||
|
||||
// HTTPClient provides an interface for suplying the SDK with a custom HTTP client
|
||||
type HTTPClient interface {
|
||||
Do(req *http.Request) (*http.Response, error)
|
||||
}
|
||||
|
||||
// String provides a helper function to return a pointer to a string
|
||||
func String(s string) *string { return &s }
|
||||
|
||||
// Bool provides a helper function to return a pointer to a bool
|
||||
func Bool(b bool) *bool { return &b }
|
||||
|
||||
// Int provides a helper function to return a pointer to an int
|
||||
func Int(i int) *int { return &i }
|
||||
|
||||
// Int64 provides a helper function to return a pointer to an int64
|
||||
func Int64(i int64) *int64 { return &i }
|
||||
|
||||
// Float32 provides a helper function to return a pointer to a float32
|
||||
func Float32(f float32) *float32 { return &f }
|
||||
|
||||
// Float64 provides a helper function to return a pointer to a float64
|
||||
func Float64(f float64) *float64 { return &f }
|
||||
|
||||
type sdkConfiguration struct {
|
||||
DefaultClient HTTPClient
|
||||
SecurityClient HTTPClient
|
||||
Security func(context.Context) (interface{}, error)
|
||||
ServerURL string
|
||||
ServerIndex int
|
||||
ServerDefaults []map[string]string
|
||||
Language string
|
||||
OpenAPIDocVersion string
|
||||
SDKVersion string
|
||||
GenVersion string
|
||||
UserAgent string
|
||||
RetryConfig *utils.RetryConfig
|
||||
}
|
||||
|
||||
func (c *sdkConfiguration) GetServerDetails() (string, map[string]string) {
|
||||
if c.ServerURL != "" {
|
||||
return c.ServerURL, nil
|
||||
}
|
||||
|
||||
return ServerList[c.ServerIndex], c.ServerDefaults[c.ServerIndex]
|
||||
}
|
||||
|
||||
// PlexAPI - Plex-API: A Plex Media Server API Map
|
||||
// An Open API Spec for interacting with Plex.tv and Plex Servers
|
||||
type PlexAPI struct {
|
||||
// Operations against the Plex Media Server System.
|
||||
//
|
||||
Server *Server
|
||||
// API Calls interacting with Plex Media Server Media
|
||||
//
|
||||
Media *Media
|
||||
// Activities are awesome. They provide a way to monitor and control asynchronous operations on the server. In order to receive real-time updates for activities, a client would normally subscribe via either EventSource or Websocket endpoints.
|
||||
// Activities are associated with HTTP replies via a special `X-Plex-Activity` header which contains the UUID of the activity.
|
||||
// Activities are optional cancellable. If cancellable, they may be cancelled via the `DELETE` endpoint. Other details:
|
||||
// - They can contain a `progress` (from 0 to 100) marking the percent completion of the activity.
|
||||
// - They must contain an `type` which is used by clients to distinguish the specific activity.
|
||||
// - They may contain a `Context` object with attributes which associate the activity with various specific entities (items, libraries, etc.)
|
||||
// - The may contain a `Response` object which attributes which represent the result of the asynchronous operation.
|
||||
//
|
||||
Activities *Activities
|
||||
// Butler is the task manager of the Plex Media Server Ecosystem.
|
||||
//
|
||||
Butler *Butler
|
||||
// Hubs are a structured two-dimensional container for media, generally represented by multiple horizontal rows.
|
||||
//
|
||||
Hubs *Hubs
|
||||
// API Calls that perform search operations with Plex Media Server
|
||||
//
|
||||
Search *Search
|
||||
// API Calls interacting with Plex Media Server Libraries
|
||||
//
|
||||
Library *Library
|
||||
// Submit logs to the Log Handler for Plex Media Server
|
||||
//
|
||||
Log *Log
|
||||
// Playlists are ordered collections of media. They can be dumb (just a list of media) or smart (based on a media query, such as "all albums from 2017").
|
||||
// They can be organized in (optionally nesting) folders.
|
||||
// Retrieving a playlist, or its items, will trigger a refresh of its metadata.
|
||||
// This may cause the duration and number of items to change.
|
||||
//
|
||||
Playlists *Playlists
|
||||
// API Calls against Security for Plex Media Server
|
||||
//
|
||||
Security *Security
|
||||
// API Calls that perform search operations with Plex Media Server Sessions
|
||||
//
|
||||
Sessions *Sessions
|
||||
// This describes the API for searching and applying updates to the Plex Media Server.
|
||||
// Updates to the status can be observed via the Event API.
|
||||
//
|
||||
Updater *Updater
|
||||
// API Calls that perform operations with Plex Media Server Videos
|
||||
//
|
||||
Video *Video
|
||||
|
||||
sdkConfiguration sdkConfiguration
|
||||
}
|
||||
|
||||
type SDKOption func(*PlexAPI)
|
||||
|
||||
// WithServerURL allows the overriding of the default server URL
|
||||
func WithServerURL(serverURL string) SDKOption {
|
||||
return func(sdk *PlexAPI) {
|
||||
sdk.sdkConfiguration.ServerURL = serverURL
|
||||
}
|
||||
}
|
||||
|
||||
// WithTemplatedServerURL allows the overriding of the default server URL with a templated URL populated with the provided parameters
|
||||
func WithTemplatedServerURL(serverURL string, params map[string]string) SDKOption {
|
||||
return func(sdk *PlexAPI) {
|
||||
if params != nil {
|
||||
serverURL = utils.ReplaceParameters(serverURL, params)
|
||||
}
|
||||
|
||||
sdk.sdkConfiguration.ServerURL = serverURL
|
||||
}
|
||||
}
|
||||
|
||||
// WithServerIndex allows the overriding of the default server by index
|
||||
func WithServerIndex(serverIndex int) SDKOption {
|
||||
return func(sdk *PlexAPI) {
|
||||
if serverIndex < 0 || serverIndex >= len(ServerList) {
|
||||
panic(fmt.Errorf("server index %d out of range", serverIndex))
|
||||
}
|
||||
|
||||
sdk.sdkConfiguration.ServerIndex = serverIndex
|
||||
}
|
||||
}
|
||||
|
||||
// ServerProtocol - The protocol to use when connecting to your plex server.
|
||||
type ServerProtocol string
|
||||
|
||||
const (
|
||||
ServerProtocolHTTP ServerProtocol = "http"
|
||||
ServerProtocolHTTPS ServerProtocol = "https"
|
||||
)
|
||||
|
||||
func (e ServerProtocol) ToPointer() *ServerProtocol {
|
||||
return &e
|
||||
}
|
||||
|
||||
func (e *ServerProtocol) UnmarshalJSON(data []byte) error {
|
||||
var v string
|
||||
if err := json.Unmarshal(data, &v); err != nil {
|
||||
return err
|
||||
}
|
||||
switch v {
|
||||
case "http":
|
||||
fallthrough
|
||||
case "https":
|
||||
*e = ServerProtocol(v)
|
||||
return nil
|
||||
default:
|
||||
return fmt.Errorf("invalid value for ServerProtocol: %v", v)
|
||||
}
|
||||
}
|
||||
|
||||
// WithProtocol allows setting the protocol variable for url substitution
|
||||
func WithProtocol(protocol ServerProtocol) SDKOption {
|
||||
return func(sdk *PlexAPI) {
|
||||
for idx := range sdk.sdkConfiguration.ServerDefaults {
|
||||
if _, ok := sdk.sdkConfiguration.ServerDefaults[idx]["protocol"]; !ok {
|
||||
continue
|
||||
}
|
||||
|
||||
sdk.sdkConfiguration.ServerDefaults[idx]["protocol"] = fmt.Sprintf("%v", protocol)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// WithIP allows setting the ip variable for url substitution
|
||||
func WithIP(ip string) SDKOption {
|
||||
return func(sdk *PlexAPI) {
|
||||
for idx := range sdk.sdkConfiguration.ServerDefaults {
|
||||
if _, ok := sdk.sdkConfiguration.ServerDefaults[idx]["ip"]; !ok {
|
||||
continue
|
||||
}
|
||||
|
||||
sdk.sdkConfiguration.ServerDefaults[idx]["ip"] = fmt.Sprintf("%v", ip)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// WithPort allows setting the port variable for url substitution
|
||||
func WithPort(port string) SDKOption {
|
||||
return func(sdk *PlexAPI) {
|
||||
for idx := range sdk.sdkConfiguration.ServerDefaults {
|
||||
if _, ok := sdk.sdkConfiguration.ServerDefaults[idx]["port"]; !ok {
|
||||
continue
|
||||
}
|
||||
|
||||
sdk.sdkConfiguration.ServerDefaults[idx]["port"] = fmt.Sprintf("%v", port)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// WithClient allows the overriding of the default HTTP client used by the SDK
|
||||
func WithClient(client HTTPClient) SDKOption {
|
||||
return func(sdk *PlexAPI) {
|
||||
sdk.sdkConfiguration.DefaultClient = client
|
||||
}
|
||||
}
|
||||
|
||||
func withSecurity(security interface{}) func(context.Context) (interface{}, error) {
|
||||
return func(context.Context) (interface{}, error) {
|
||||
return &security, nil
|
||||
}
|
||||
}
|
||||
|
||||
// WithSecurity configures the SDK to use the provided security details
|
||||
func WithSecurity(security shared.Security) SDKOption {
|
||||
return func(sdk *PlexAPI) {
|
||||
sdk.sdkConfiguration.Security = withSecurity(security)
|
||||
}
|
||||
}
|
||||
|
||||
// WithSecuritySource configures the SDK to invoke the Security Source function on each method call to determine authentication
|
||||
func WithSecuritySource(security func(context.Context) (shared.Security, error)) SDKOption {
|
||||
return func(sdk *PlexAPI) {
|
||||
sdk.sdkConfiguration.Security = func(ctx context.Context) (interface{}, error) {
|
||||
return security(ctx)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func WithRetryConfig(retryConfig utils.RetryConfig) SDKOption {
|
||||
return func(sdk *PlexAPI) {
|
||||
sdk.sdkConfiguration.RetryConfig = &retryConfig
|
||||
}
|
||||
}
|
||||
|
||||
// New creates a new instance of the SDK with the provided options
|
||||
func New(opts ...SDKOption) *PlexAPI {
|
||||
sdk := &PlexAPI{
|
||||
sdkConfiguration: sdkConfiguration{
|
||||
Language: "go",
|
||||
OpenAPIDocVersion: "0.0.3",
|
||||
SDKVersion: "0.1.0",
|
||||
GenVersion: "2.223.3",
|
||||
UserAgent: "speakeasy-sdk/go 0.1.0 2.223.3 0.0.3 PlexAPI",
|
||||
ServerDefaults: []map[string]string{
|
||||
{},
|
||||
{
|
||||
"protocol": "http",
|
||||
"ip": "10.10.10.47",
|
||||
"port": "32400",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, opt := range opts {
|
||||
opt(sdk)
|
||||
}
|
||||
|
||||
// Use WithClient to override the default client if you would like to customize the timeout
|
||||
if sdk.sdkConfiguration.DefaultClient == nil {
|
||||
sdk.sdkConfiguration.DefaultClient = &http.Client{Timeout: 60 * time.Second}
|
||||
}
|
||||
if sdk.sdkConfiguration.SecurityClient == nil {
|
||||
if sdk.sdkConfiguration.Security != nil {
|
||||
sdk.sdkConfiguration.SecurityClient = utils.ConfigureSecurityClient(sdk.sdkConfiguration.DefaultClient, sdk.sdkConfiguration.Security)
|
||||
} else {
|
||||
sdk.sdkConfiguration.SecurityClient = sdk.sdkConfiguration.DefaultClient
|
||||
}
|
||||
}
|
||||
|
||||
sdk.Server = newServer(sdk.sdkConfiguration)
|
||||
|
||||
sdk.Media = newMedia(sdk.sdkConfiguration)
|
||||
|
||||
sdk.Activities = newActivities(sdk.sdkConfiguration)
|
||||
|
||||
sdk.Butler = newButler(sdk.sdkConfiguration)
|
||||
|
||||
sdk.Hubs = newHubs(sdk.sdkConfiguration)
|
||||
|
||||
sdk.Search = newSearch(sdk.sdkConfiguration)
|
||||
|
||||
sdk.Library = newLibrary(sdk.sdkConfiguration)
|
||||
|
||||
sdk.Log = newLog(sdk.sdkConfiguration)
|
||||
|
||||
sdk.Playlists = newPlaylists(sdk.sdkConfiguration)
|
||||
|
||||
sdk.Security = newSecurity(sdk.sdkConfiguration)
|
||||
|
||||
sdk.Sessions = newSessions(sdk.sdkConfiguration)
|
||||
|
||||
sdk.Updater = newUpdater(sdk.sdkConfiguration)
|
||||
|
||||
sdk.Video = newVideo(sdk.sdkConfiguration)
|
||||
|
||||
return sdk
|
||||
}
|
||||
Reference in New Issue
Block a user