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.133.1
This commit is contained in:
176
activities.go
Normal file
176
activities.go
Normal file
@@ -0,0 +1,176 @@
|
||||
// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT.
|
||||
|
||||
package plexgo
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/LukeHagar/plexgo/internal/utils"
|
||||
"github.com/LukeHagar/plexgo/models/operations"
|
||||
"github.com/LukeHagar/plexgo/models/sdkerrors"
|
||||
"io"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// 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.
|
||||
type Activities struct {
|
||||
sdkConfiguration sdkConfiguration
|
||||
}
|
||||
|
||||
func newActivities(sdkConfig sdkConfiguration) *Activities {
|
||||
return &Activities{
|
||||
sdkConfiguration: sdkConfig,
|
||||
}
|
||||
}
|
||||
|
||||
// GetServerActivities - Get Server Activities
|
||||
// Get Server Activities
|
||||
func (s *Activities) GetServerActivities(ctx context.Context) (*operations.GetServerActivitiesResponse, error) {
|
||||
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
|
||||
url := strings.TrimSuffix(baseURL, "/") + "/activities"
|
||||
|
||||
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")
|
||||
}
|
||||
|
||||
contentType := httpRes.Header.Get("Content-Type")
|
||||
|
||||
res := &operations.GetServerActivitiesResponse{
|
||||
StatusCode: httpRes.StatusCode,
|
||||
ContentType: contentType,
|
||||
RawResponse: httpRes,
|
||||
}
|
||||
|
||||
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))
|
||||
switch {
|
||||
case httpRes.StatusCode == 200:
|
||||
switch {
|
||||
case utils.MatchContentType(contentType, `application/json`):
|
||||
var out operations.GetServerActivitiesResponseBody
|
||||
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)
|
||||
}
|
||||
case httpRes.StatusCode == 400:
|
||||
fallthrough
|
||||
case httpRes.StatusCode >= 400 && httpRes.StatusCode < 500:
|
||||
fallthrough
|
||||
case httpRes.StatusCode >= 500 && httpRes.StatusCode < 600:
|
||||
return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes)
|
||||
case httpRes.StatusCode == 401:
|
||||
switch {
|
||||
case utils.MatchContentType(contentType, `application/json`):
|
||||
var out sdkerrors.GetServerActivitiesResponseBody
|
||||
if err := utils.UnmarshalJsonFromResponseBody(bytes.NewBuffer(rawBody), &out, ""); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
out.RawResponse = httpRes
|
||||
|
||||
return nil, &out
|
||||
default:
|
||||
return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", contentType), httpRes.StatusCode, string(rawBody), httpRes)
|
||||
}
|
||||
}
|
||||
|
||||
return res, nil
|
||||
}
|
||||
|
||||
// CancelServerActivities - Cancel Server Activities
|
||||
// Cancel Server Activities
|
||||
func (s *Activities) CancelServerActivities(ctx context.Context, activityUUID string) (*operations.CancelServerActivitiesResponse, error) {
|
||||
request := operations.CancelServerActivitiesRequest{
|
||||
ActivityUUID: activityUUID,
|
||||
}
|
||||
|
||||
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
|
||||
url, err := utils.GenerateURL(ctx, baseURL, "/activities/{activityUUID}", 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")
|
||||
}
|
||||
|
||||
contentType := httpRes.Header.Get("Content-Type")
|
||||
|
||||
res := &operations.CancelServerActivitiesResponse{
|
||||
StatusCode: httpRes.StatusCode,
|
||||
ContentType: contentType,
|
||||
RawResponse: httpRes,
|
||||
}
|
||||
|
||||
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))
|
||||
switch {
|
||||
case httpRes.StatusCode == 200:
|
||||
case httpRes.StatusCode == 400:
|
||||
fallthrough
|
||||
case httpRes.StatusCode >= 400 && httpRes.StatusCode < 500:
|
||||
fallthrough
|
||||
case httpRes.StatusCode >= 500 && httpRes.StatusCode < 600:
|
||||
return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes)
|
||||
case httpRes.StatusCode == 401:
|
||||
switch {
|
||||
case utils.MatchContentType(contentType, `application/json`):
|
||||
var out sdkerrors.CancelServerActivitiesResponseBody
|
||||
if err := utils.UnmarshalJsonFromResponseBody(bytes.NewBuffer(rawBody), &out, ""); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
out.RawResponse = httpRes
|
||||
|
||||
return nil, &out
|
||||
default:
|
||||
return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", contentType), httpRes.StatusCode, string(rawBody), httpRes)
|
||||
}
|
||||
}
|
||||
|
||||
return res, nil
|
||||
}
|
||||
Reference in New Issue
Block a user