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:
355
server.go
355
server.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"
|
||||
)
|
||||
|
||||
// Server - Operations against the Plex Media Server System.
|
||||
@@ -28,26 +29,49 @@ func newServer(sdkConfig sdkConfiguration) *Server {
|
||||
// GetServerCapabilities - Server Capabilities
|
||||
// Server Capabilities
|
||||
func (s *Server) GetServerCapabilities(ctx context.Context) (*operations.GetServerCapabilitiesResponse, error) {
|
||||
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
|
||||
url := strings.TrimSuffix(baseURL, "/") + "/"
|
||||
hookCtx := hooks.HookContext{OperationID: "getServerCapabilities"}
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", url, nil)
|
||||
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
|
||||
opURL, err := url.JoinPath(baseURL, "/")
|
||||
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", "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.GetServerCapabilitiesResponse{
|
||||
@@ -62,6 +86,7 @@ func (s *Server) GetServerCapabilities(ctx context.Context) (*operations.GetServ
|
||||
}
|
||||
httpRes.Body.Close()
|
||||
httpRes.Body = io.NopCloser(bytes.NewBuffer(rawBody))
|
||||
|
||||
switch {
|
||||
case httpRes.StatusCode == 200:
|
||||
switch {
|
||||
@@ -102,26 +127,49 @@ func (s *Server) GetServerCapabilities(ctx context.Context) (*operations.GetServ
|
||||
// GetServerPreferences - Get Server Preferences
|
||||
// Get Server Preferences
|
||||
func (s *Server) GetServerPreferences(ctx context.Context) (*operations.GetServerPreferencesResponse, error) {
|
||||
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
|
||||
url := strings.TrimSuffix(baseURL, "/") + "/:/prefs"
|
||||
hookCtx := hooks.HookContext{OperationID: "getServerPreferences"}
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", url, nil)
|
||||
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
|
||||
opURL, err := url.JoinPath(baseURL, "/:/prefs")
|
||||
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", "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.GetServerPreferencesResponse{
|
||||
@@ -136,6 +184,7 @@ func (s *Server) GetServerPreferences(ctx context.Context) (*operations.GetServe
|
||||
}
|
||||
httpRes.Body.Close()
|
||||
httpRes.Body = io.NopCloser(bytes.NewBuffer(rawBody))
|
||||
|
||||
switch {
|
||||
case httpRes.StatusCode == 200:
|
||||
switch {
|
||||
@@ -176,26 +225,49 @@ func (s *Server) GetServerPreferences(ctx context.Context) (*operations.GetServe
|
||||
// GetAvailableClients - Get Available Clients
|
||||
// Get Available Clients
|
||||
func (s *Server) GetAvailableClients(ctx context.Context) (*operations.GetAvailableClientsResponse, error) {
|
||||
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
|
||||
url := strings.TrimSuffix(baseURL, "/") + "/clients"
|
||||
hookCtx := hooks.HookContext{OperationID: "getAvailableClients"}
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", url, nil)
|
||||
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
|
||||
opURL, err := url.JoinPath(baseURL, "/clients")
|
||||
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", "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.GetAvailableClientsResponse{
|
||||
@@ -210,6 +282,7 @@ func (s *Server) GetAvailableClients(ctx context.Context) (*operations.GetAvaila
|
||||
}
|
||||
httpRes.Body.Close()
|
||||
httpRes.Body = io.NopCloser(bytes.NewBuffer(rawBody))
|
||||
|
||||
switch {
|
||||
case httpRes.StatusCode == 200:
|
||||
switch {
|
||||
@@ -250,26 +323,49 @@ func (s *Server) GetAvailableClients(ctx context.Context) (*operations.GetAvaila
|
||||
// GetDevices - Get Devices
|
||||
// Get Devices
|
||||
func (s *Server) GetDevices(ctx context.Context) (*operations.GetDevicesResponse, error) {
|
||||
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
|
||||
url := strings.TrimSuffix(baseURL, "/") + "/devices"
|
||||
hookCtx := hooks.HookContext{OperationID: "getDevices"}
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", url, nil)
|
||||
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
|
||||
opURL, err := url.JoinPath(baseURL, "/devices")
|
||||
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", "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.GetDevicesResponse{
|
||||
@@ -284,6 +380,7 @@ func (s *Server) GetDevices(ctx context.Context) (*operations.GetDevicesResponse
|
||||
}
|
||||
httpRes.Body.Close()
|
||||
httpRes.Body = io.NopCloser(bytes.NewBuffer(rawBody))
|
||||
|
||||
switch {
|
||||
case httpRes.StatusCode == 200:
|
||||
switch {
|
||||
@@ -324,26 +421,49 @@ func (s *Server) GetDevices(ctx context.Context) (*operations.GetDevicesResponse
|
||||
// GetServerIdentity - Get Server Identity
|
||||
// Get Server Identity
|
||||
func (s *Server) GetServerIdentity(ctx context.Context) (*operations.GetServerIdentityResponse, error) {
|
||||
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
|
||||
url := strings.TrimSuffix(baseURL, "/") + "/identity"
|
||||
hookCtx := hooks.HookContext{OperationID: "getServerIdentity"}
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", url, nil)
|
||||
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
|
||||
opURL, err := url.JoinPath(baseURL, "/identity")
|
||||
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", "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.GetServerIdentityResponse{
|
||||
@@ -358,6 +478,7 @@ func (s *Server) GetServerIdentity(ctx context.Context) (*operations.GetServerId
|
||||
}
|
||||
httpRes.Body.Close()
|
||||
httpRes.Body = io.NopCloser(bytes.NewBuffer(rawBody))
|
||||
|
||||
switch {
|
||||
case httpRes.StatusCode == 200:
|
||||
switch {
|
||||
@@ -398,26 +519,49 @@ func (s *Server) GetServerIdentity(ctx context.Context) (*operations.GetServerId
|
||||
// GetMyPlexAccount - Get MyPlex Account
|
||||
// Returns MyPlex Account Information
|
||||
func (s *Server) GetMyPlexAccount(ctx context.Context) (*operations.GetMyPlexAccountResponse, error) {
|
||||
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
|
||||
url := strings.TrimSuffix(baseURL, "/") + "/myplex/account"
|
||||
hookCtx := hooks.HookContext{OperationID: "getMyPlexAccount"}
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", url, nil)
|
||||
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
|
||||
opURL, err := url.JoinPath(baseURL, "/myplex/account")
|
||||
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", "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.GetMyPlexAccountResponse{
|
||||
@@ -432,6 +576,7 @@ func (s *Server) GetMyPlexAccount(ctx context.Context) (*operations.GetMyPlexAcc
|
||||
}
|
||||
httpRes.Body.Close()
|
||||
httpRes.Body = io.NopCloser(bytes.NewBuffer(rawBody))
|
||||
|
||||
switch {
|
||||
case httpRes.StatusCode == 200:
|
||||
switch {
|
||||
@@ -472,30 +617,53 @@ func (s *Server) GetMyPlexAccount(ctx context.Context) (*operations.GetMyPlexAcc
|
||||
// GetResizedPhoto - Get a Resized Photo
|
||||
// Plex's Photo transcoder is used throughout the service to serve images at specified sizes.
|
||||
func (s *Server) GetResizedPhoto(ctx context.Context, request operations.GetResizedPhotoRequest) (*operations.GetResizedPhotoResponse, error) {
|
||||
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
|
||||
url := strings.TrimSuffix(baseURL, "/") + "/photo/:/transcode"
|
||||
hookCtx := hooks.HookContext{OperationID: "getResizedPhoto"}
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", url, nil)
|
||||
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
|
||||
opURL, err := url.JoinPath(baseURL, "/photo/:/transcode")
|
||||
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)
|
||||
|
||||
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.GetResizedPhotoResponse{
|
||||
@@ -510,6 +678,7 @@ func (s *Server) GetResizedPhoto(ctx context.Context, request operations.GetResi
|
||||
}
|
||||
httpRes.Body.Close()
|
||||
httpRes.Body = io.NopCloser(bytes.NewBuffer(rawBody))
|
||||
|
||||
switch {
|
||||
case httpRes.StatusCode == 200:
|
||||
case httpRes.StatusCode == 400:
|
||||
@@ -539,26 +708,49 @@ func (s *Server) GetResizedPhoto(ctx context.Context, request operations.GetResi
|
||||
// GetServerList - Get Server List
|
||||
// Get Server List
|
||||
func (s *Server) GetServerList(ctx context.Context) (*operations.GetServerListResponse, error) {
|
||||
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
|
||||
url := strings.TrimSuffix(baseURL, "/") + "/servers"
|
||||
hookCtx := hooks.HookContext{OperationID: "getServerList"}
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", url, nil)
|
||||
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
|
||||
opURL, err := url.JoinPath(baseURL, "/servers")
|
||||
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", "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.GetServerListResponse{
|
||||
@@ -573,6 +765,7 @@ func (s *Server) GetServerList(ctx context.Context) (*operations.GetServerListRe
|
||||
}
|
||||
httpRes.Body.Close()
|
||||
httpRes.Body = io.NopCloser(bytes.NewBuffer(rawBody))
|
||||
|
||||
switch {
|
||||
case httpRes.StatusCode == 200:
|
||||
switch {
|
||||
|
||||
Reference in New Issue
Block a user