mirror of
https://github.com/LukeHagar/plexgo.git
synced 2025-12-06 04:20:46 +00:00
295 lines
8.6 KiB
Go
295 lines
8.6 KiB
Go
/*
|
|
Plex-API
|
|
|
|
An Open API Spec for interacting with Plex.tv and Plex Servers
|
|
|
|
API version: 0.0.3
|
|
Contact: Lukeslakemail@gmail.com
|
|
*/
|
|
|
|
// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT.
|
|
|
|
package pms
|
|
|
|
import (
|
|
"bytes"
|
|
"context"
|
|
"io/ioutil"
|
|
"net/http"
|
|
"net/url"
|
|
"strings"
|
|
)
|
|
|
|
|
|
// HubsApiService HubsApi service
|
|
type HubsApiService service
|
|
|
|
type ApiGetGlobalHubsRequest struct {
|
|
ctx context.Context
|
|
ApiService *HubsApiService
|
|
count *interface{}
|
|
onlyTransient *interface{}
|
|
}
|
|
|
|
// The number of items to return with each hub.
|
|
func (r ApiGetGlobalHubsRequest) Count(count interface{}) ApiGetGlobalHubsRequest {
|
|
r.count = &count
|
|
return r
|
|
}
|
|
|
|
// Only return hubs which are \"transient\", meaning those which are prone to changing after media playback or addition (e.g. On Deck, or Recently Added).
|
|
func (r ApiGetGlobalHubsRequest) OnlyTransient(onlyTransient interface{}) ApiGetGlobalHubsRequest {
|
|
r.onlyTransient = &onlyTransient
|
|
return r
|
|
}
|
|
|
|
func (r ApiGetGlobalHubsRequest) Execute() (*http.Response, error) {
|
|
return r.ApiService.GetGlobalHubsExecute(r)
|
|
}
|
|
|
|
/*
|
|
GetGlobalHubs Get Global Hubs
|
|
|
|
Get Global Hubs filtered by the parameters provided.
|
|
|
|
@param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
|
|
@return ApiGetGlobalHubsRequest
|
|
*/
|
|
func (a *HubsApiService) GetGlobalHubs(ctx context.Context) ApiGetGlobalHubsRequest {
|
|
return ApiGetGlobalHubsRequest{
|
|
ApiService: a,
|
|
ctx: ctx,
|
|
}
|
|
}
|
|
|
|
// Execute executes the request
|
|
func (a *HubsApiService) GetGlobalHubsExecute(r ApiGetGlobalHubsRequest) (*http.Response, error) {
|
|
var (
|
|
localVarHTTPMethod = http.MethodGet
|
|
localVarPostBody interface{}
|
|
formFiles []formFile
|
|
)
|
|
|
|
localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "HubsApiService.GetGlobalHubs")
|
|
if err != nil {
|
|
return nil, &GenericOpenAPIError{error: err.Error()}
|
|
}
|
|
|
|
localVarPath := localBasePath + "/hubs"
|
|
|
|
localVarHeaderParams := make(map[string]string)
|
|
localVarQueryParams := url.Values{}
|
|
localVarFormParams := url.Values{}
|
|
|
|
if r.count != nil {
|
|
parameterAddToQuery(localVarQueryParams, "count", r.count, "")
|
|
}
|
|
if r.onlyTransient != nil {
|
|
parameterAddToQuery(localVarQueryParams, "onlyTransient", r.onlyTransient, "")
|
|
}
|
|
// to determine the Content-Type header
|
|
localVarHTTPContentTypes := []string{}
|
|
|
|
// set Content-Type header
|
|
localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes)
|
|
if localVarHTTPContentType != "" {
|
|
localVarHeaderParams["Content-Type"] = localVarHTTPContentType
|
|
}
|
|
|
|
// to determine the Accept header
|
|
localVarHTTPHeaderAccepts := []string{"application/json"}
|
|
|
|
// set Accept header
|
|
localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts)
|
|
if localVarHTTPHeaderAccept != "" {
|
|
localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept
|
|
}
|
|
if r.ctx != nil {
|
|
// API Key Authentication
|
|
if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok {
|
|
if apiKey, ok := auth["accessToken"]; ok {
|
|
var key string
|
|
if apiKey.Prefix != "" {
|
|
key = apiKey.Prefix + " " + apiKey.Key
|
|
} else {
|
|
key = apiKey.Key
|
|
}
|
|
localVarHeaderParams["X-Plex-Token"] = key
|
|
}
|
|
}
|
|
}
|
|
req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
localVarHTTPResponse, err := a.client.callAPI(req)
|
|
if err != nil || localVarHTTPResponse == nil {
|
|
return localVarHTTPResponse, err
|
|
}
|
|
|
|
localVarBody, err := ioutil.ReadAll(localVarHTTPResponse.Body)
|
|
localVarHTTPResponse.Body.Close()
|
|
localVarHTTPResponse.Body = ioutil.NopCloser(bytes.NewBuffer(localVarBody))
|
|
if err != nil {
|
|
return localVarHTTPResponse, err
|
|
}
|
|
|
|
if localVarHTTPResponse.StatusCode >= 300 {
|
|
newErr := &GenericOpenAPIError{
|
|
body: localVarBody,
|
|
error: localVarHTTPResponse.Status,
|
|
}
|
|
if localVarHTTPResponse.StatusCode == 401 {
|
|
var v GetServerCapabilities401Response
|
|
err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
|
|
if err != nil {
|
|
newErr.error = err.Error()
|
|
return localVarHTTPResponse, newErr
|
|
}
|
|
newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v)
|
|
newErr.model = v
|
|
}
|
|
return localVarHTTPResponse, newErr
|
|
}
|
|
|
|
return localVarHTTPResponse, nil
|
|
}
|
|
|
|
type ApiGetLibraryHubsRequest struct {
|
|
ctx context.Context
|
|
ApiService *HubsApiService
|
|
sectionId interface{}
|
|
count *interface{}
|
|
onlyTransient *interface{}
|
|
}
|
|
|
|
// The number of items to return with each hub.
|
|
func (r ApiGetLibraryHubsRequest) Count(count interface{}) ApiGetLibraryHubsRequest {
|
|
r.count = &count
|
|
return r
|
|
}
|
|
|
|
// Only return hubs which are \"transient\", meaning those which are prone to changing after media playback or addition (e.g. On Deck, or Recently Added).
|
|
func (r ApiGetLibraryHubsRequest) OnlyTransient(onlyTransient interface{}) ApiGetLibraryHubsRequest {
|
|
r.onlyTransient = &onlyTransient
|
|
return r
|
|
}
|
|
|
|
func (r ApiGetLibraryHubsRequest) Execute() (*http.Response, error) {
|
|
return r.ApiService.GetLibraryHubsExecute(r)
|
|
}
|
|
|
|
/*
|
|
GetLibraryHubs Get library specific hubs
|
|
|
|
This endpoint will return a list of library specific hubs
|
|
|
|
|
|
@param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
|
|
@param sectionId the Id of the library to query
|
|
@return ApiGetLibraryHubsRequest
|
|
*/
|
|
func (a *HubsApiService) GetLibraryHubs(ctx context.Context, sectionId interface{}) ApiGetLibraryHubsRequest {
|
|
return ApiGetLibraryHubsRequest{
|
|
ApiService: a,
|
|
ctx: ctx,
|
|
sectionId: sectionId,
|
|
}
|
|
}
|
|
|
|
// Execute executes the request
|
|
func (a *HubsApiService) GetLibraryHubsExecute(r ApiGetLibraryHubsRequest) (*http.Response, error) {
|
|
var (
|
|
localVarHTTPMethod = http.MethodGet
|
|
localVarPostBody interface{}
|
|
formFiles []formFile
|
|
)
|
|
|
|
localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "HubsApiService.GetLibraryHubs")
|
|
if err != nil {
|
|
return nil, &GenericOpenAPIError{error: err.Error()}
|
|
}
|
|
|
|
localVarPath := localBasePath + "/hubs/sections/{sectionId}"
|
|
localVarPath = strings.Replace(localVarPath, "{"+"sectionId"+"}", url.PathEscape(parameterValueToString(r.sectionId, "sectionId")), -1)
|
|
|
|
localVarHeaderParams := make(map[string]string)
|
|
localVarQueryParams := url.Values{}
|
|
localVarFormParams := url.Values{}
|
|
|
|
if r.count != nil {
|
|
parameterAddToQuery(localVarQueryParams, "count", r.count, "")
|
|
}
|
|
if r.onlyTransient != nil {
|
|
parameterAddToQuery(localVarQueryParams, "onlyTransient", r.onlyTransient, "")
|
|
}
|
|
// to determine the Content-Type header
|
|
localVarHTTPContentTypes := []string{}
|
|
|
|
// set Content-Type header
|
|
localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes)
|
|
if localVarHTTPContentType != "" {
|
|
localVarHeaderParams["Content-Type"] = localVarHTTPContentType
|
|
}
|
|
|
|
// to determine the Accept header
|
|
localVarHTTPHeaderAccepts := []string{"application/json"}
|
|
|
|
// set Accept header
|
|
localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts)
|
|
if localVarHTTPHeaderAccept != "" {
|
|
localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept
|
|
}
|
|
if r.ctx != nil {
|
|
// API Key Authentication
|
|
if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok {
|
|
if apiKey, ok := auth["accessToken"]; ok {
|
|
var key string
|
|
if apiKey.Prefix != "" {
|
|
key = apiKey.Prefix + " " + apiKey.Key
|
|
} else {
|
|
key = apiKey.Key
|
|
}
|
|
localVarHeaderParams["X-Plex-Token"] = key
|
|
}
|
|
}
|
|
}
|
|
req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
localVarHTTPResponse, err := a.client.callAPI(req)
|
|
if err != nil || localVarHTTPResponse == nil {
|
|
return localVarHTTPResponse, err
|
|
}
|
|
|
|
localVarBody, err := ioutil.ReadAll(localVarHTTPResponse.Body)
|
|
localVarHTTPResponse.Body.Close()
|
|
localVarHTTPResponse.Body = ioutil.NopCloser(bytes.NewBuffer(localVarBody))
|
|
if err != nil {
|
|
return localVarHTTPResponse, err
|
|
}
|
|
|
|
if localVarHTTPResponse.StatusCode >= 300 {
|
|
newErr := &GenericOpenAPIError{
|
|
body: localVarBody,
|
|
error: localVarHTTPResponse.Status,
|
|
}
|
|
if localVarHTTPResponse.StatusCode == 401 {
|
|
var v GetServerCapabilities401Response
|
|
err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
|
|
if err != nil {
|
|
newErr.error = err.Error()
|
|
return localVarHTTPResponse, newErr
|
|
}
|
|
newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v)
|
|
newErr.model = v
|
|
}
|
|
return localVarHTTPResponse, newErr
|
|
}
|
|
|
|
return localVarHTTPResponse, nil
|
|
}
|