Compare commits

...

6 Commits

Author SHA1 Message Date
speakeasybot
89fbd6238e ci: regenerated with OpenAPI Doc , Speakeasy CLI 1.476.2 2025-01-28 00:10:16 +00:00
speakeasybot
7af7441ac7 ci: regenerated with OpenAPI Doc , Speakeasy CLI 1.476.0 2025-01-25 00:10:13 +00:00
speakeasybot
d1945b544b ci: regenerated with OpenAPI Doc , Speakeasy CLI 1.459.2 2024-12-23 00:10:53 +00:00
speakeasybot
16bb49d558 ci: regenerated with OpenAPI Doc , Speakeasy CLI 1.459.2 2024-12-21 00:10:31 +00:00
speakeasybot
4bea7ae0d8 ci: regenerated with OpenAPI Doc , Speakeasy CLI 1.438.3 2024-11-14 00:10:23 +00:00
speakeasybot
da5491e935 ci: regenerated with OpenAPI Doc , Speakeasy CLI 1.438.1 2024-11-12 00:10:16 +00:00
103 changed files with 4264 additions and 6306 deletions

1
.gitignore vendored
View File

@@ -1 +1,2 @@
.speakeasy/reports
# .gitignore # .gitignore

File diff suppressed because one or more lines are too long

View File

@@ -11,11 +11,13 @@ generation:
requestResponseComponentNamesFeb2024: true requestResponseComponentNamesFeb2024: true
auth: auth:
oAuth2ClientCredentialsEnabled: true oAuth2ClientCredentialsEnabled: true
oAuth2PasswordEnabled: false
go: go:
version: 0.15.1 version: 0.17.3
additionalDependencies: {} additionalDependencies: {}
allowUnknownFieldsInWeakUnions: false allowUnknownFieldsInWeakUnions: false
clientServerStatusCodesAsErrors: true clientServerStatusCodesAsErrors: true
defaultErrorName: SDKError
flattenGlobalSecurity: true flattenGlobalSecurity: true
imports: imports:
option: openapi option: openapi

View File

@@ -1,4 +1,4 @@
speakeasyVersion: 1.406.0 speakeasyVersion: 1.476.2
sources: sources:
my-source: my-source:
sourceNamespace: my-source sourceNamespace: my-source
@@ -9,19 +9,19 @@ sources:
- main - main
plexapi: plexapi:
sourceNamespace: plexapi sourceNamespace: plexapi
sourceRevisionDigest: sha256:8d2eb3adbd97ce5976291c4b123d1eadfef62d1f6bf86c6a18bcd89443f2f390 sourceRevisionDigest: sha256:e73707dfae50d22dab2166b1661938446b9831bcee252ecd696a1172dfd6ae2c
sourceBlobDigest: sha256:3e48471b7e058840fc598ccd75b2cbf8187961c7e625fe7b606555ce9a9bf109 sourceBlobDigest: sha256:e06caa091ad527fd21714fc0d43e7ea385e181fbad8c4f60296457a89a23c696
tags: tags:
- latest - latest
- main - speakeasy-sdk-regen-1738022950
targets: targets:
plexgo: plexgo:
source: plexapi source: plexapi
sourceNamespace: plexapi sourceNamespace: plexapi
sourceRevisionDigest: sha256:8d2eb3adbd97ce5976291c4b123d1eadfef62d1f6bf86c6a18bcd89443f2f390 sourceRevisionDigest: sha256:e73707dfae50d22dab2166b1661938446b9831bcee252ecd696a1172dfd6ae2c
sourceBlobDigest: sha256:3e48471b7e058840fc598ccd75b2cbf8187961c7e625fe7b606555ce9a9bf109 sourceBlobDigest: sha256:e06caa091ad527fd21714fc0d43e7ea385e181fbad8c4f60296457a89a23c696
codeSamplesNamespace: code-samples-go-plexgo codeSamplesNamespace: code-samples-go-plexgo
codeSamplesRevisionDigest: sha256:321c24585c4a0c1ed0e924fe504aa2f02e26d9e6d539262e90861142fbf72882 codeSamplesRevisionDigest: sha256:d074910cd257c690cd88b954cb7adc3401529828c1a9b0b79a96d1fe780cab97
workflow: workflow:
workflowVersion: 1.0.0 workflowVersion: 1.0.0
speakeasyVersion: latest speakeasyVersion: latest

154
README.md
View File

@@ -40,16 +40,24 @@ The following SDKs are generated from the OpenAPI Specification. They are automa
<!-- Start Table of Contents [toc] --> <!-- Start Table of Contents [toc] -->
## Table of Contents ## Table of Contents
<!-- $toc-max-depth=2 -->
* [github.com/LukeHagar/plexgo](#githubcomlukehagarplexgo)
* [Plex Media Server OpenAPI Specification](#plex-media-server-openapi-specification)
* [Documentation](#documentation)
* [SDKs](#sdks)
* [SDK Installation](#sdk-installation)
* [SDK Example Usage](#sdk-example-usage)
* [Available Resources and Operations](#available-resources-and-operations)
* [Retries](#retries)
* [Error Handling](#error-handling)
* [Server Selection](#server-selection)
* [Custom HTTP Client](#custom-http-client)
* [Authentication](#authentication)
* [Special Types](#special-types)
* [Development](#development)
* [Maturity](#maturity)
* [Contributions](#contributions)
* [SDK Installation](#sdk-installation)
* [SDK Example Usage](#sdk-example-usage)
* [Available Resources and Operations](#available-resources-and-operations)
* [Retries](#retries)
* [Error Handling](#error-handling)
* [Server Selection](#server-selection)
* [Custom HTTP Client](#custom-http-client)
* [Authentication](#authentication)
* [Special Types](#special-types)
<!-- End Table of Contents [toc] --> <!-- End Table of Contents [toc] -->
<!-- Start SDK Installation [installation] --> <!-- Start SDK Installation [installation] -->
@@ -76,16 +84,12 @@ import (
) )
func main() { func main() {
ctx := context.Background()
s := plexgo.New( s := plexgo.New(
plexgo.WithSecurity("<YOUR_API_KEY_HERE>"), plexgo.WithSecurity("<YOUR_API_KEY_HERE>"),
plexgo.WithClientID("3381b62b-9ab7-4e37-827b-203e9809eb58"),
plexgo.WithClientName("Plex for Roku"),
plexgo.WithClientVersion("2.4.1"),
plexgo.WithPlatform("Roku"),
plexgo.WithDeviceNickname("Roku 3"),
) )
ctx := context.Background()
res, err := s.Server.GetServerCapabilities(ctx) res, err := s.Server.GetServerCapabilities(ctx)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
@@ -250,16 +254,12 @@ import (
) )
func main() { func main() {
ctx := context.Background()
s := plexgo.New( s := plexgo.New(
plexgo.WithSecurity("<YOUR_API_KEY_HERE>"), plexgo.WithSecurity("<YOUR_API_KEY_HERE>"),
plexgo.WithClientID("3381b62b-9ab7-4e37-827b-203e9809eb58"),
plexgo.WithClientName("Plex for Roku"),
plexgo.WithClientVersion("2.4.1"),
plexgo.WithPlatform("Roku"),
plexgo.WithDeviceNickname("Roku 3"),
) )
ctx := context.Background()
res, err := s.Server.GetServerCapabilities(ctx, operations.WithRetries( res, err := s.Server.GetServerCapabilities(ctx, operations.WithRetries(
retry.Config{ retry.Config{
Strategy: "backoff", Strategy: "backoff",
@@ -293,6 +293,8 @@ import (
) )
func main() { func main() {
ctx := context.Background()
s := plexgo.New( s := plexgo.New(
plexgo.WithRetryConfig( plexgo.WithRetryConfig(
retry.Config{ retry.Config{
@@ -306,14 +308,8 @@ func main() {
RetryConnectionErrors: false, RetryConnectionErrors: false,
}), }),
plexgo.WithSecurity("<YOUR_API_KEY_HERE>"), plexgo.WithSecurity("<YOUR_API_KEY_HERE>"),
plexgo.WithClientID("3381b62b-9ab7-4e37-827b-203e9809eb58"),
plexgo.WithClientName("Plex for Roku"),
plexgo.WithClientVersion("2.4.1"),
plexgo.WithPlatform("Roku"),
plexgo.WithDeviceNickname("Roku 3"),
) )
ctx := context.Background()
res, err := s.Server.GetServerCapabilities(ctx) res, err := s.Server.GetServerCapabilities(ctx)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
@@ -335,11 +331,11 @@ By Default, an API error will return `sdkerrors.SDKError`. When custom error res
For example, the `GetServerCapabilities` function may return the following errors: For example, the `GetServerCapabilities` function may return the following errors:
| Error Type | Status Code | Content Type | | Error Type | Status Code | Content Type |
| ------------------------------------------- | ------------------------------------------- | ------------------------------------------- | | ------------------------------------------- | ----------- | ---------------- |
| sdkerrors.GetServerCapabilitiesBadRequest | 400 | application/json | | sdkerrors.GetServerCapabilitiesBadRequest | 400 | application/json |
| sdkerrors.GetServerCapabilitiesUnauthorized | 401 | application/json | | sdkerrors.GetServerCapabilitiesUnauthorized | 401 | application/json |
| sdkerrors.SDKError | 4XX, 5XX | \*/\* | | sdkerrors.SDKError | 4XX, 5XX | \*/\* |
### Example ### Example
@@ -355,16 +351,12 @@ import (
) )
func main() { func main() {
ctx := context.Background()
s := plexgo.New( s := plexgo.New(
plexgo.WithSecurity("<YOUR_API_KEY_HERE>"), plexgo.WithSecurity("<YOUR_API_KEY_HERE>"),
plexgo.WithClientID("3381b62b-9ab7-4e37-827b-203e9809eb58"),
plexgo.WithClientName("Plex for Roku"),
plexgo.WithClientVersion("2.4.1"),
plexgo.WithPlatform("Roku"),
plexgo.WithDeviceNickname("Roku 3"),
) )
ctx := context.Background()
res, err := s.Server.GetServerCapabilities(ctx) res, err := s.Server.GetServerCapabilities(ctx)
if err != nil { if err != nil {
@@ -394,58 +386,16 @@ func main() {
<!-- Start Server Selection [server] --> <!-- Start Server Selection [server] -->
## Server Selection ## Server Selection
### Select Server by Index ### Server Variables
You can override the default server globally using the `WithServerIndex` option when initializing the SDK client instance. The selected server will then be used as the default on the operations that use it. This table lists the indexes associated with the available servers: The default server `{protocol}://{ip}:{port}` contains variables and is set to `https://10.10.10.47:32400` by default. To override default values, the following options are available when initializing the SDK client instance:
* `WithProtocol(protocol ServerProtocol)`
| # | Server | Variables | * `WithIP(ip string)`
| - | ------ | --------- | * `WithPort(port string)`
| 0 | `{protocol}://{ip}:{port}` | `protocol` (default is `https`), `ip` (default is `10.10.10.47`), `port` (default is `32400`) |
#### Example
```go
package main
import (
"context"
"github.com/LukeHagar/plexgo"
"log"
)
func main() {
s := plexgo.New(
plexgo.WithServerIndex(0),
plexgo.WithSecurity("<YOUR_API_KEY_HERE>"),
plexgo.WithClientID("3381b62b-9ab7-4e37-827b-203e9809eb58"),
plexgo.WithClientName("Plex for Roku"),
plexgo.WithClientVersion("2.4.1"),
plexgo.WithPlatform("Roku"),
plexgo.WithDeviceNickname("Roku 3"),
)
ctx := context.Background()
res, err := s.Server.GetServerCapabilities(ctx)
if err != nil {
log.Fatal(err)
}
if res.Object != nil {
// handle response
}
}
```
#### Variables
Some of the server options above contain variables. If you want to set the values of those variables, the following options are provided for doing so:
* `WithProtocol plexgo.ServerProtocol`
* `WithIP string`
* `WithPort string`
### Override Server URL Per-Client ### Override Server URL Per-Client
The default server can also be overridden globally using the `WithServerURL` option when initializing the SDK client instance. For example: The default server can also be overridden globally using the `WithServerURL(serverURL string)` option when initializing the SDK client instance. For example:
```go ```go
package main package main
@@ -456,17 +406,13 @@ import (
) )
func main() { func main() {
ctx := context.Background()
s := plexgo.New( s := plexgo.New(
plexgo.WithServerURL("{protocol}://{ip}:{port}"), plexgo.WithServerURL("https://10.10.10.47:32400"),
plexgo.WithSecurity("<YOUR_API_KEY_HERE>"), plexgo.WithSecurity("<YOUR_API_KEY_HERE>"),
plexgo.WithClientID("3381b62b-9ab7-4e37-827b-203e9809eb58"),
plexgo.WithClientName("Plex for Roku"),
plexgo.WithClientVersion("2.4.1"),
plexgo.WithPlatform("Roku"),
plexgo.WithDeviceNickname("Roku 3"),
) )
ctx := context.Background()
res, err := s.Server.GetServerCapabilities(ctx) res, err := s.Server.GetServerCapabilities(ctx)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
@@ -492,16 +438,12 @@ import (
) )
func main() { func main() {
ctx := context.Background()
s := plexgo.New( s := plexgo.New(
plexgo.WithSecurity("<YOUR_API_KEY_HERE>"), plexgo.WithSecurity("<YOUR_API_KEY_HERE>"),
plexgo.WithClientID("3381b62b-9ab7-4e37-827b-203e9809eb58"),
plexgo.WithClientName("Plex for Roku"),
plexgo.WithClientVersion("2.4.1"),
plexgo.WithPlatform("Roku"),
plexgo.WithDeviceNickname("Roku 3"),
) )
ctx := context.Background()
res, err := s.Plex.GetCompanionsData(ctx, operations.WithServerURL("https://plex.tv/api/v2")) res, err := s.Plex.GetCompanionsData(ctx, operations.WithServerURL("https://plex.tv/api/v2"))
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
@@ -550,9 +492,9 @@ This can be a convenient way to configure timeouts, cookies, proxies, custom hea
This SDK supports the following security scheme globally: This SDK supports the following security scheme globally:
| Name | Type | Scheme | | Name | Type | Scheme |
| ------------- | ------------- | ------------- | | ------------- | ------ | ------- |
| `AccessToken` | apiKey | API key | | `AccessToken` | apiKey | API key |
You can configure it using the `WithSecurity` option when initializing the SDK client instance. For example: You can configure it using the `WithSecurity` option when initializing the SDK client instance. For example:
```go ```go
@@ -565,16 +507,12 @@ import (
) )
func main() { func main() {
ctx := context.Background()
s := plexgo.New( s := plexgo.New(
plexgo.WithSecurity("<YOUR_API_KEY_HERE>"), plexgo.WithSecurity("<YOUR_API_KEY_HERE>"),
plexgo.WithClientID("3381b62b-9ab7-4e37-827b-203e9809eb58"),
plexgo.WithClientName("Plex for Roku"),
plexgo.WithClientVersion("2.4.1"),
plexgo.WithPlatform("Roku"),
plexgo.WithDeviceNickname("Roku 3"),
) )
ctx := context.Background()
res, err := s.Server.GetServerCapabilities(ctx) res, err := s.Server.GetServerCapabilities(ctx)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)

View File

@@ -952,4 +952,64 @@ Based on:
### Generated ### Generated
- [go v0.15.1] . - [go v0.15.1] .
### Releases ### Releases
- [Go v0.15.1] https://github.com/LukeHagar/plexgo/releases/tag/v0.15.1 - . - [Go v0.15.1] https://github.com/LukeHagar/plexgo/releases/tag/v0.15.1 - .
## 2024-11-12 00:08:55
### Changes
Based on:
- OpenAPI Doc
- Speakeasy CLI 1.438.1 (2.457.2) https://github.com/speakeasy-api/speakeasy
### Generated
- [go v0.16.0] .
### Releases
- [Go v0.16.0] https://github.com/LukeHagar/plexgo/releases/tag/v0.16.0 - .
## 2024-11-14 00:09:05
### Changes
Based on:
- OpenAPI Doc
- Speakeasy CLI 1.438.3 (2.457.9) https://github.com/speakeasy-api/speakeasy
### Generated
- [go v0.16.1] .
### Releases
- [Go v0.16.1] https://github.com/LukeHagar/plexgo/releases/tag/v0.16.1 - .
## 2024-12-21 00:09:02
### Changes
Based on:
- OpenAPI Doc
- Speakeasy CLI 1.459.2 (2.483.1) https://github.com/speakeasy-api/speakeasy
### Generated
- [go v0.17.0] .
### Releases
- [Go v0.17.0] https://github.com/LukeHagar/plexgo/releases/tag/v0.17.0 - .
## 2024-12-23 00:09:31
### Changes
Based on:
- OpenAPI Doc
- Speakeasy CLI 1.459.2 (2.483.1) https://github.com/speakeasy-api/speakeasy
### Generated
- [go v0.17.1] .
### Releases
- [Go v0.17.1] https://github.com/LukeHagar/plexgo/releases/tag/v0.17.1 - .
## 2025-01-25 00:08:47
### Changes
Based on:
- OpenAPI Doc
- Speakeasy CLI 1.476.0 (2.496.0) https://github.com/speakeasy-api/speakeasy
### Generated
- [go v0.17.2] .
### Releases
- [Go v0.17.2] https://github.com/LukeHagar/plexgo/releases/tag/v0.17.2 - .
## 2025-01-28 00:08:53
### Changes
Based on:
- OpenAPI Doc
- Speakeasy CLI 1.476.2 (2.495.1) https://github.com/speakeasy-api/speakeasy
### Generated
- [go v0.17.3] .
### Releases
- [Go v0.17.3] https://github.com/LukeHagar/plexgo/releases/tag/v0.17.3 - .

View File

@@ -9,16 +9,12 @@ import (
) )
func main() { func main() {
ctx := context.Background()
s := plexgo.New( s := plexgo.New(
plexgo.WithSecurity("<YOUR_API_KEY_HERE>"), plexgo.WithSecurity("<YOUR_API_KEY_HERE>"),
plexgo.WithClientID("3381b62b-9ab7-4e37-827b-203e9809eb58"),
plexgo.WithClientName("Plex for Roku"),
plexgo.WithClientVersion("2.4.1"),
plexgo.WithPlatform("Roku"),
plexgo.WithDeviceNickname("Roku 3"),
) )
ctx := context.Background()
res, err := s.Server.GetServerCapabilities(ctx) res, err := s.Server.GetServerCapabilities(ctx)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)

View File

@@ -10,8 +10,7 @@ import (
"github.com/LukeHagar/plexgo/internal/utils" "github.com/LukeHagar/plexgo/internal/utils"
"github.com/LukeHagar/plexgo/models/operations" "github.com/LukeHagar/plexgo/models/operations"
"github.com/LukeHagar/plexgo/models/sdkerrors" "github.com/LukeHagar/plexgo/models/sdkerrors"
"github.com/cenkalti/backoff/v4" "github.com/LukeHagar/plexgo/retry"
"io"
"net/http" "net/http"
"net/url" "net/url"
) )
@@ -55,7 +54,12 @@ func (s *Activities) GetServerActivities(ctx context.Context, opts ...operations
} }
} }
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) var baseURL string
if o.ServerURL == nil {
baseURL = utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
} else {
baseURL = *o.ServerURL
}
opURL, err := url.JoinPath(baseURL, "/activities") opURL, err := url.JoinPath(baseURL, "/activities")
if err != nil { if err != nil {
return nil, fmt.Errorf("error generating URL: %w", err) return nil, fmt.Errorf("error generating URL: %w", err)
@@ -83,6 +87,10 @@ func (s *Activities) GetServerActivities(ctx context.Context, opts ...operations
return nil, err return nil, err
} }
for k, v := range o.SetHeaders {
req.Header.Set(k, v)
}
globalRetryConfig := s.sdkConfiguration.RetryConfig globalRetryConfig := s.sdkConfiguration.RetryConfig
retryConfig := o.Retries retryConfig := o.Retries
if retryConfig == nil { if retryConfig == nil {
@@ -113,7 +121,11 @@ func (s *Activities) GetServerActivities(ctx context.Context, opts ...operations
req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req)
if err != nil { if err != nil {
return nil, backoff.Permanent(err) if retry.IsPermanentError(err) || retry.IsTemporaryError(err) {
return nil, err
}
return nil, retry.Permanent(err)
} }
httpRes, err := s.sdkConfiguration.Client.Do(req) httpRes, err := s.sdkConfiguration.Client.Do(req)
@@ -174,21 +186,11 @@ func (s *Activities) GetServerActivities(ctx context.Context, opts ...operations
RawResponse: httpRes, RawResponse: httpRes,
} }
getRawBody := func() ([]byte, error) {
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))
return rawBody, nil
}
switch { switch {
case httpRes.StatusCode == 200: case httpRes.StatusCode == 200:
switch { switch {
case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -200,17 +202,16 @@ func (s *Activities) GetServerActivities(ctx context.Context, opts ...operations
res.Object = &out res.Object = &out
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
} }
case httpRes.StatusCode == 400: case httpRes.StatusCode == 400:
switch { switch {
case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -223,17 +224,16 @@ func (s *Activities) GetServerActivities(ctx context.Context, opts ...operations
out.RawResponse = httpRes out.RawResponse = httpRes
return nil, &out return nil, &out
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
} }
case httpRes.StatusCode == 401: case httpRes.StatusCode == 401:
switch { switch {
case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -246,28 +246,29 @@ func (s *Activities) GetServerActivities(ctx context.Context, opts ...operations
out.RawResponse = httpRes out.RawResponse = httpRes
return nil, &out return nil, &out
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
} }
case httpRes.StatusCode >= 400 && httpRes.StatusCode < 500: case httpRes.StatusCode >= 400 && httpRes.StatusCode < 500:
fallthrough rawBody, err := utils.ConsumeRawBody(httpRes)
case httpRes.StatusCode >= 500 && httpRes.StatusCode < 600: if err != nil {
rawBody, err := getRawBody() return nil, err
}
return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes)
case httpRes.StatusCode >= 500 && httpRes.StatusCode < 600:
rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes)
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError("unknown status code returned", httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError("unknown status code returned", httpRes.StatusCode, string(rawBody), httpRes)
} }
@@ -301,7 +302,12 @@ func (s *Activities) CancelServerActivities(ctx context.Context, activityUUID st
} }
} }
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) var baseURL string
if o.ServerURL == nil {
baseURL = utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
} else {
baseURL = *o.ServerURL
}
opURL, err := utils.GenerateURL(ctx, baseURL, "/activities/{activityUUID}", request, nil) opURL, err := utils.GenerateURL(ctx, baseURL, "/activities/{activityUUID}", request, nil)
if err != nil { if err != nil {
return nil, fmt.Errorf("error generating URL: %w", err) return nil, fmt.Errorf("error generating URL: %w", err)
@@ -329,6 +335,10 @@ func (s *Activities) CancelServerActivities(ctx context.Context, activityUUID st
return nil, err return nil, err
} }
for k, v := range o.SetHeaders {
req.Header.Set(k, v)
}
globalRetryConfig := s.sdkConfiguration.RetryConfig globalRetryConfig := s.sdkConfiguration.RetryConfig
retryConfig := o.Retries retryConfig := o.Retries
if retryConfig == nil { if retryConfig == nil {
@@ -359,7 +369,11 @@ func (s *Activities) CancelServerActivities(ctx context.Context, activityUUID st
req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req)
if err != nil { if err != nil {
return nil, backoff.Permanent(err) if retry.IsPermanentError(err) || retry.IsTemporaryError(err) {
return nil, err
}
return nil, retry.Permanent(err)
} }
httpRes, err := s.sdkConfiguration.Client.Do(req) httpRes, err := s.sdkConfiguration.Client.Do(req)
@@ -420,22 +434,12 @@ func (s *Activities) CancelServerActivities(ctx context.Context, activityUUID st
RawResponse: httpRes, RawResponse: httpRes,
} }
getRawBody := func() ([]byte, error) {
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))
return rawBody, nil
}
switch { switch {
case httpRes.StatusCode == 200: case httpRes.StatusCode == 200:
case httpRes.StatusCode == 400: case httpRes.StatusCode == 400:
switch { switch {
case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -448,17 +452,16 @@ func (s *Activities) CancelServerActivities(ctx context.Context, activityUUID st
out.RawResponse = httpRes out.RawResponse = httpRes
return nil, &out return nil, &out
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
} }
case httpRes.StatusCode == 401: case httpRes.StatusCode == 401:
switch { switch {
case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -471,28 +474,29 @@ func (s *Activities) CancelServerActivities(ctx context.Context, activityUUID st
out.RawResponse = httpRes out.RawResponse = httpRes
return nil, &out return nil, &out
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
} }
case httpRes.StatusCode >= 400 && httpRes.StatusCode < 500: case httpRes.StatusCode >= 400 && httpRes.StatusCode < 500:
fallthrough rawBody, err := utils.ConsumeRawBody(httpRes)
case httpRes.StatusCode >= 500 && httpRes.StatusCode < 600: if err != nil {
rawBody, err := getRawBody() return nil, err
}
return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes)
case httpRes.StatusCode >= 500 && httpRes.StatusCode < 600:
rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes)
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError("unknown status code returned", httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError("unknown status code returned", httpRes.StatusCode, string(rawBody), httpRes)
} }

View File

@@ -10,8 +10,7 @@ import (
"github.com/LukeHagar/plexgo/internal/utils" "github.com/LukeHagar/plexgo/internal/utils"
"github.com/LukeHagar/plexgo/models/operations" "github.com/LukeHagar/plexgo/models/operations"
"github.com/LukeHagar/plexgo/models/sdkerrors" "github.com/LukeHagar/plexgo/models/sdkerrors"
"github.com/cenkalti/backoff/v4" "github.com/LukeHagar/plexgo/retry"
"io"
"net/http" "net/http"
"net/url" "net/url"
) )
@@ -54,7 +53,12 @@ func (s *Authentication) GetTransientToken(ctx context.Context, type_ operations
} }
} }
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) var baseURL string
if o.ServerURL == nil {
baseURL = utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
} else {
baseURL = *o.ServerURL
}
opURL, err := url.JoinPath(baseURL, "/security/token") opURL, err := url.JoinPath(baseURL, "/security/token")
if err != nil { if err != nil {
return nil, fmt.Errorf("error generating URL: %w", err) return nil, fmt.Errorf("error generating URL: %w", err)
@@ -86,6 +90,10 @@ func (s *Authentication) GetTransientToken(ctx context.Context, type_ operations
return nil, err return nil, err
} }
for k, v := range o.SetHeaders {
req.Header.Set(k, v)
}
globalRetryConfig := s.sdkConfiguration.RetryConfig globalRetryConfig := s.sdkConfiguration.RetryConfig
retryConfig := o.Retries retryConfig := o.Retries
if retryConfig == nil { if retryConfig == nil {
@@ -116,7 +124,11 @@ func (s *Authentication) GetTransientToken(ctx context.Context, type_ operations
req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req)
if err != nil { if err != nil {
return nil, backoff.Permanent(err) if retry.IsPermanentError(err) || retry.IsTemporaryError(err) {
return nil, err
}
return nil, retry.Permanent(err)
} }
httpRes, err := s.sdkConfiguration.Client.Do(req) httpRes, err := s.sdkConfiguration.Client.Do(req)
@@ -177,22 +189,12 @@ func (s *Authentication) GetTransientToken(ctx context.Context, type_ operations
RawResponse: httpRes, RawResponse: httpRes,
} }
getRawBody := func() ([]byte, error) {
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))
return rawBody, nil
}
switch { switch {
case httpRes.StatusCode == 200: case httpRes.StatusCode == 200:
case httpRes.StatusCode == 400: case httpRes.StatusCode == 400:
switch { switch {
case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -205,17 +207,16 @@ func (s *Authentication) GetTransientToken(ctx context.Context, type_ operations
out.RawResponse = httpRes out.RawResponse = httpRes
return nil, &out return nil, &out
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
} }
case httpRes.StatusCode == 401: case httpRes.StatusCode == 401:
switch { switch {
case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -228,28 +229,29 @@ func (s *Authentication) GetTransientToken(ctx context.Context, type_ operations
out.RawResponse = httpRes out.RawResponse = httpRes
return nil, &out return nil, &out
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
} }
case httpRes.StatusCode >= 400 && httpRes.StatusCode < 500: case httpRes.StatusCode >= 400 && httpRes.StatusCode < 500:
fallthrough rawBody, err := utils.ConsumeRawBody(httpRes)
case httpRes.StatusCode >= 500 && httpRes.StatusCode < 600: if err != nil {
rawBody, err := getRawBody() return nil, err
}
return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes)
case httpRes.StatusCode >= 500 && httpRes.StatusCode < 600:
rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes)
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError("unknown status code returned", httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError("unknown status code returned", httpRes.StatusCode, string(rawBody), httpRes)
} }
@@ -284,7 +286,12 @@ func (s *Authentication) GetSourceConnectionInformation(ctx context.Context, sou
} }
} }
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) var baseURL string
if o.ServerURL == nil {
baseURL = utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
} else {
baseURL = *o.ServerURL
}
opURL, err := url.JoinPath(baseURL, "/security/resources") opURL, err := url.JoinPath(baseURL, "/security/resources")
if err != nil { if err != nil {
return nil, fmt.Errorf("error generating URL: %w", err) return nil, fmt.Errorf("error generating URL: %w", err)
@@ -316,6 +323,10 @@ func (s *Authentication) GetSourceConnectionInformation(ctx context.Context, sou
return nil, err return nil, err
} }
for k, v := range o.SetHeaders {
req.Header.Set(k, v)
}
globalRetryConfig := s.sdkConfiguration.RetryConfig globalRetryConfig := s.sdkConfiguration.RetryConfig
retryConfig := o.Retries retryConfig := o.Retries
if retryConfig == nil { if retryConfig == nil {
@@ -346,7 +357,11 @@ func (s *Authentication) GetSourceConnectionInformation(ctx context.Context, sou
req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req)
if err != nil { if err != nil {
return nil, backoff.Permanent(err) if retry.IsPermanentError(err) || retry.IsTemporaryError(err) {
return nil, err
}
return nil, retry.Permanent(err)
} }
httpRes, err := s.sdkConfiguration.Client.Do(req) httpRes, err := s.sdkConfiguration.Client.Do(req)
@@ -407,22 +422,12 @@ func (s *Authentication) GetSourceConnectionInformation(ctx context.Context, sou
RawResponse: httpRes, RawResponse: httpRes,
} }
getRawBody := func() ([]byte, error) {
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))
return rawBody, nil
}
switch { switch {
case httpRes.StatusCode == 200: case httpRes.StatusCode == 200:
case httpRes.StatusCode == 400: case httpRes.StatusCode == 400:
switch { switch {
case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -435,17 +440,16 @@ func (s *Authentication) GetSourceConnectionInformation(ctx context.Context, sou
out.RawResponse = httpRes out.RawResponse = httpRes
return nil, &out return nil, &out
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
} }
case httpRes.StatusCode == 401: case httpRes.StatusCode == 401:
switch { switch {
case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -458,28 +462,29 @@ func (s *Authentication) GetSourceConnectionInformation(ctx context.Context, sou
out.RawResponse = httpRes out.RawResponse = httpRes
return nil, &out return nil, &out
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
} }
case httpRes.StatusCode >= 400 && httpRes.StatusCode < 500: case httpRes.StatusCode >= 400 && httpRes.StatusCode < 500:
fallthrough rawBody, err := utils.ConsumeRawBody(httpRes)
case httpRes.StatusCode >= 500 && httpRes.StatusCode < 600: if err != nil {
rawBody, err := getRawBody() return nil, err
}
return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes)
case httpRes.StatusCode >= 500 && httpRes.StatusCode < 600:
rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes)
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError("unknown status code returned", httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError("unknown status code returned", httpRes.StatusCode, string(rawBody), httpRes)
} }
@@ -499,7 +504,6 @@ func (s *Authentication) GetTokenDetails(ctx context.Context, opts ...operations
o := operations.Options{} o := operations.Options{}
supportedOptions := []string{ supportedOptions := []string{
operations.SupportedOptionServerURL,
operations.SupportedOptionRetries, operations.SupportedOptionRetries,
operations.SupportedOptionTimeout, operations.SupportedOptionTimeout,
} }
@@ -542,6 +546,10 @@ func (s *Authentication) GetTokenDetails(ctx context.Context, opts ...operations
return nil, err return nil, err
} }
for k, v := range o.SetHeaders {
req.Header.Set(k, v)
}
globalRetryConfig := s.sdkConfiguration.RetryConfig globalRetryConfig := s.sdkConfiguration.RetryConfig
retryConfig := o.Retries retryConfig := o.Retries
if retryConfig == nil { if retryConfig == nil {
@@ -572,7 +580,11 @@ func (s *Authentication) GetTokenDetails(ctx context.Context, opts ...operations
req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req)
if err != nil { if err != nil {
return nil, backoff.Permanent(err) if retry.IsPermanentError(err) || retry.IsTemporaryError(err) {
return nil, err
}
return nil, retry.Permanent(err)
} }
httpRes, err := s.sdkConfiguration.Client.Do(req) httpRes, err := s.sdkConfiguration.Client.Do(req)
@@ -633,21 +645,11 @@ func (s *Authentication) GetTokenDetails(ctx context.Context, opts ...operations
RawResponse: httpRes, RawResponse: httpRes,
} }
getRawBody := func() ([]byte, error) {
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))
return rawBody, nil
}
switch { switch {
case httpRes.StatusCode == 200: case httpRes.StatusCode == 200:
switch { switch {
case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -659,17 +661,16 @@ func (s *Authentication) GetTokenDetails(ctx context.Context, opts ...operations
res.UserPlexAccount = &out res.UserPlexAccount = &out
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
} }
case httpRes.StatusCode == 400: case httpRes.StatusCode == 400:
switch { switch {
case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -682,17 +683,16 @@ func (s *Authentication) GetTokenDetails(ctx context.Context, opts ...operations
out.RawResponse = httpRes out.RawResponse = httpRes
return nil, &out return nil, &out
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
} }
case httpRes.StatusCode == 401: case httpRes.StatusCode == 401:
switch { switch {
case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -705,28 +705,29 @@ func (s *Authentication) GetTokenDetails(ctx context.Context, opts ...operations
out.RawResponse = httpRes out.RawResponse = httpRes
return nil, &out return nil, &out
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
} }
case httpRes.StatusCode >= 400 && httpRes.StatusCode < 500: case httpRes.StatusCode >= 400 && httpRes.StatusCode < 500:
fallthrough rawBody, err := utils.ConsumeRawBody(httpRes)
case httpRes.StatusCode >= 500 && httpRes.StatusCode < 600: if err != nil {
rawBody, err := getRawBody() return nil, err
}
return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes)
case httpRes.StatusCode >= 500 && httpRes.StatusCode < 600:
rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes)
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError("unknown status code returned", httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError("unknown status code returned", httpRes.StatusCode, string(rawBody), httpRes)
} }
@@ -744,17 +745,8 @@ func (s *Authentication) PostUsersSignInData(ctx context.Context, request operat
SecuritySource: nil, SecuritySource: nil,
} }
globals := operations.PostUsersSignInDataGlobals{
ClientID: s.sdkConfiguration.Globals.ClientID,
ClientName: s.sdkConfiguration.Globals.ClientName,
DeviceNickname: s.sdkConfiguration.Globals.DeviceNickname,
ClientVersion: s.sdkConfiguration.Globals.ClientVersion,
Platform: s.sdkConfiguration.Globals.Platform,
}
o := operations.Options{} o := operations.Options{}
supportedOptions := []string{ supportedOptions := []string{
operations.SupportedOptionServerURL,
operations.SupportedOptionRetries, operations.SupportedOptionRetries,
operations.SupportedOptionTimeout, operations.SupportedOptionTimeout,
} }
@@ -797,9 +789,15 @@ func (s *Authentication) PostUsersSignInData(ctx context.Context, request operat
} }
req.Header.Set("Accept", "application/json") req.Header.Set("Accept", "application/json")
req.Header.Set("User-Agent", s.sdkConfiguration.UserAgent) req.Header.Set("User-Agent", s.sdkConfiguration.UserAgent)
req.Header.Set("Content-Type", reqContentType) if reqContentType != "" {
req.Header.Set("Content-Type", reqContentType)
}
utils.PopulateHeaders(ctx, req, request, globals) utils.PopulateHeaders(ctx, req, request, nil)
for k, v := range o.SetHeaders {
req.Header.Set(k, v)
}
globalRetryConfig := s.sdkConfiguration.RetryConfig globalRetryConfig := s.sdkConfiguration.RetryConfig
retryConfig := o.Retries retryConfig := o.Retries
@@ -831,7 +829,11 @@ func (s *Authentication) PostUsersSignInData(ctx context.Context, request operat
req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req)
if err != nil { if err != nil {
return nil, backoff.Permanent(err) if retry.IsPermanentError(err) || retry.IsTemporaryError(err) {
return nil, err
}
return nil, retry.Permanent(err)
} }
httpRes, err := s.sdkConfiguration.Client.Do(req) httpRes, err := s.sdkConfiguration.Client.Do(req)
@@ -892,21 +894,11 @@ func (s *Authentication) PostUsersSignInData(ctx context.Context, request operat
RawResponse: httpRes, RawResponse: httpRes,
} }
getRawBody := func() ([]byte, error) {
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))
return rawBody, nil
}
switch { switch {
case httpRes.StatusCode == 201: case httpRes.StatusCode == 201:
switch { switch {
case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -918,17 +910,16 @@ func (s *Authentication) PostUsersSignInData(ctx context.Context, request operat
res.UserPlexAccount = &out res.UserPlexAccount = &out
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
} }
case httpRes.StatusCode == 400: case httpRes.StatusCode == 400:
switch { switch {
case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -941,17 +932,16 @@ func (s *Authentication) PostUsersSignInData(ctx context.Context, request operat
out.RawResponse = httpRes out.RawResponse = httpRes
return nil, &out return nil, &out
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
} }
case httpRes.StatusCode == 401: case httpRes.StatusCode == 401:
switch { switch {
case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -964,28 +954,29 @@ func (s *Authentication) PostUsersSignInData(ctx context.Context, request operat
out.RawResponse = httpRes out.RawResponse = httpRes
return nil, &out return nil, &out
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
} }
case httpRes.StatusCode >= 400 && httpRes.StatusCode < 500: case httpRes.StatusCode >= 400 && httpRes.StatusCode < 500:
fallthrough rawBody, err := utils.ConsumeRawBody(httpRes)
case httpRes.StatusCode >= 500 && httpRes.StatusCode < 600: if err != nil {
rawBody, err := getRawBody() return nil, err
}
return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes)
case httpRes.StatusCode >= 500 && httpRes.StatusCode < 600:
rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes)
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError("unknown status code returned", httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError("unknown status code returned", httpRes.StatusCode, string(rawBody), httpRes)
} }

263
butler.go
View File

@@ -10,8 +10,7 @@ import (
"github.com/LukeHagar/plexgo/internal/utils" "github.com/LukeHagar/plexgo/internal/utils"
"github.com/LukeHagar/plexgo/models/operations" "github.com/LukeHagar/plexgo/models/operations"
"github.com/LukeHagar/plexgo/models/sdkerrors" "github.com/LukeHagar/plexgo/models/sdkerrors"
"github.com/cenkalti/backoff/v4" "github.com/LukeHagar/plexgo/retry"
"io"
"net/http" "net/http"
"net/url" "net/url"
) )
@@ -49,7 +48,12 @@ func (s *Butler) GetButlerTasks(ctx context.Context, opts ...operations.Option)
} }
} }
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) var baseURL string
if o.ServerURL == nil {
baseURL = utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
} else {
baseURL = *o.ServerURL
}
opURL, err := url.JoinPath(baseURL, "/butler") opURL, err := url.JoinPath(baseURL, "/butler")
if err != nil { if err != nil {
return nil, fmt.Errorf("error generating URL: %w", err) return nil, fmt.Errorf("error generating URL: %w", err)
@@ -77,6 +81,10 @@ func (s *Butler) GetButlerTasks(ctx context.Context, opts ...operations.Option)
return nil, err return nil, err
} }
for k, v := range o.SetHeaders {
req.Header.Set(k, v)
}
globalRetryConfig := s.sdkConfiguration.RetryConfig globalRetryConfig := s.sdkConfiguration.RetryConfig
retryConfig := o.Retries retryConfig := o.Retries
if retryConfig == nil { if retryConfig == nil {
@@ -107,7 +115,11 @@ func (s *Butler) GetButlerTasks(ctx context.Context, opts ...operations.Option)
req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req)
if err != nil { if err != nil {
return nil, backoff.Permanent(err) if retry.IsPermanentError(err) || retry.IsTemporaryError(err) {
return nil, err
}
return nil, retry.Permanent(err)
} }
httpRes, err := s.sdkConfiguration.Client.Do(req) httpRes, err := s.sdkConfiguration.Client.Do(req)
@@ -168,21 +180,11 @@ func (s *Butler) GetButlerTasks(ctx context.Context, opts ...operations.Option)
RawResponse: httpRes, RawResponse: httpRes,
} }
getRawBody := func() ([]byte, error) {
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))
return rawBody, nil
}
switch { switch {
case httpRes.StatusCode == 200: case httpRes.StatusCode == 200:
switch { switch {
case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -194,17 +196,16 @@ func (s *Butler) GetButlerTasks(ctx context.Context, opts ...operations.Option)
res.Object = &out res.Object = &out
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
} }
case httpRes.StatusCode == 400: case httpRes.StatusCode == 400:
switch { switch {
case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -217,17 +218,16 @@ func (s *Butler) GetButlerTasks(ctx context.Context, opts ...operations.Option)
out.RawResponse = httpRes out.RawResponse = httpRes
return nil, &out return nil, &out
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
} }
case httpRes.StatusCode == 401: case httpRes.StatusCode == 401:
switch { switch {
case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -240,28 +240,29 @@ func (s *Butler) GetButlerTasks(ctx context.Context, opts ...operations.Option)
out.RawResponse = httpRes out.RawResponse = httpRes
return nil, &out return nil, &out
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
} }
case httpRes.StatusCode >= 400 && httpRes.StatusCode < 500: case httpRes.StatusCode >= 400 && httpRes.StatusCode < 500:
fallthrough rawBody, err := utils.ConsumeRawBody(httpRes)
case httpRes.StatusCode >= 500 && httpRes.StatusCode < 600: if err != nil {
rawBody, err := getRawBody() return nil, err
}
return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes)
case httpRes.StatusCode >= 500 && httpRes.StatusCode < 600:
rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes)
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError("unknown status code returned", httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError("unknown status code returned", httpRes.StatusCode, string(rawBody), httpRes)
} }
@@ -295,7 +296,12 @@ func (s *Butler) StartAllTasks(ctx context.Context, opts ...operations.Option) (
} }
} }
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) var baseURL string
if o.ServerURL == nil {
baseURL = utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
} else {
baseURL = *o.ServerURL
}
opURL, err := url.JoinPath(baseURL, "/butler") opURL, err := url.JoinPath(baseURL, "/butler")
if err != nil { if err != nil {
return nil, fmt.Errorf("error generating URL: %w", err) return nil, fmt.Errorf("error generating URL: %w", err)
@@ -323,6 +329,10 @@ func (s *Butler) StartAllTasks(ctx context.Context, opts ...operations.Option) (
return nil, err return nil, err
} }
for k, v := range o.SetHeaders {
req.Header.Set(k, v)
}
globalRetryConfig := s.sdkConfiguration.RetryConfig globalRetryConfig := s.sdkConfiguration.RetryConfig
retryConfig := o.Retries retryConfig := o.Retries
if retryConfig == nil { if retryConfig == nil {
@@ -353,7 +363,11 @@ func (s *Butler) StartAllTasks(ctx context.Context, opts ...operations.Option) (
req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req)
if err != nil { if err != nil {
return nil, backoff.Permanent(err) if retry.IsPermanentError(err) || retry.IsTemporaryError(err) {
return nil, err
}
return nil, retry.Permanent(err)
} }
httpRes, err := s.sdkConfiguration.Client.Do(req) httpRes, err := s.sdkConfiguration.Client.Do(req)
@@ -414,22 +428,12 @@ func (s *Butler) StartAllTasks(ctx context.Context, opts ...operations.Option) (
RawResponse: httpRes, RawResponse: httpRes,
} }
getRawBody := func() ([]byte, error) {
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))
return rawBody, nil
}
switch { switch {
case httpRes.StatusCode == 200: case httpRes.StatusCode == 200:
case httpRes.StatusCode == 400: case httpRes.StatusCode == 400:
switch { switch {
case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -442,17 +446,16 @@ func (s *Butler) StartAllTasks(ctx context.Context, opts ...operations.Option) (
out.RawResponse = httpRes out.RawResponse = httpRes
return nil, &out return nil, &out
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
} }
case httpRes.StatusCode == 401: case httpRes.StatusCode == 401:
switch { switch {
case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -465,28 +468,29 @@ func (s *Butler) StartAllTasks(ctx context.Context, opts ...operations.Option) (
out.RawResponse = httpRes out.RawResponse = httpRes
return nil, &out return nil, &out
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
} }
case httpRes.StatusCode >= 400 && httpRes.StatusCode < 500: case httpRes.StatusCode >= 400 && httpRes.StatusCode < 500:
fallthrough rawBody, err := utils.ConsumeRawBody(httpRes)
case httpRes.StatusCode >= 500 && httpRes.StatusCode < 600: if err != nil {
rawBody, err := getRawBody() return nil, err
}
return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes)
case httpRes.StatusCode >= 500 && httpRes.StatusCode < 600:
rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes)
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError("unknown status code returned", httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError("unknown status code returned", httpRes.StatusCode, string(rawBody), httpRes)
} }
@@ -516,7 +520,12 @@ func (s *Butler) StopAllTasks(ctx context.Context, opts ...operations.Option) (*
} }
} }
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) var baseURL string
if o.ServerURL == nil {
baseURL = utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
} else {
baseURL = *o.ServerURL
}
opURL, err := url.JoinPath(baseURL, "/butler") opURL, err := url.JoinPath(baseURL, "/butler")
if err != nil { if err != nil {
return nil, fmt.Errorf("error generating URL: %w", err) return nil, fmt.Errorf("error generating URL: %w", err)
@@ -544,6 +553,10 @@ func (s *Butler) StopAllTasks(ctx context.Context, opts ...operations.Option) (*
return nil, err return nil, err
} }
for k, v := range o.SetHeaders {
req.Header.Set(k, v)
}
globalRetryConfig := s.sdkConfiguration.RetryConfig globalRetryConfig := s.sdkConfiguration.RetryConfig
retryConfig := o.Retries retryConfig := o.Retries
if retryConfig == nil { if retryConfig == nil {
@@ -574,7 +587,11 @@ func (s *Butler) StopAllTasks(ctx context.Context, opts ...operations.Option) (*
req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req)
if err != nil { if err != nil {
return nil, backoff.Permanent(err) if retry.IsPermanentError(err) || retry.IsTemporaryError(err) {
return nil, err
}
return nil, retry.Permanent(err)
} }
httpRes, err := s.sdkConfiguration.Client.Do(req) httpRes, err := s.sdkConfiguration.Client.Do(req)
@@ -635,22 +652,12 @@ func (s *Butler) StopAllTasks(ctx context.Context, opts ...operations.Option) (*
RawResponse: httpRes, RawResponse: httpRes,
} }
getRawBody := func() ([]byte, error) {
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))
return rawBody, nil
}
switch { switch {
case httpRes.StatusCode == 200: case httpRes.StatusCode == 200:
case httpRes.StatusCode == 400: case httpRes.StatusCode == 400:
switch { switch {
case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -663,17 +670,16 @@ func (s *Butler) StopAllTasks(ctx context.Context, opts ...operations.Option) (*
out.RawResponse = httpRes out.RawResponse = httpRes
return nil, &out return nil, &out
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
} }
case httpRes.StatusCode == 401: case httpRes.StatusCode == 401:
switch { switch {
case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -686,28 +692,29 @@ func (s *Butler) StopAllTasks(ctx context.Context, opts ...operations.Option) (*
out.RawResponse = httpRes out.RawResponse = httpRes
return nil, &out return nil, &out
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
} }
case httpRes.StatusCode >= 400 && httpRes.StatusCode < 500: case httpRes.StatusCode >= 400 && httpRes.StatusCode < 500:
fallthrough rawBody, err := utils.ConsumeRawBody(httpRes)
case httpRes.StatusCode >= 500 && httpRes.StatusCode < 600: if err != nil {
rawBody, err := getRawBody() return nil, err
}
return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes)
case httpRes.StatusCode >= 500 && httpRes.StatusCode < 600:
rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes)
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError("unknown status code returned", httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError("unknown status code returned", httpRes.StatusCode, string(rawBody), httpRes)
} }
@@ -745,7 +752,12 @@ func (s *Butler) StartTask(ctx context.Context, taskName operations.TaskName, op
} }
} }
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) var baseURL string
if o.ServerURL == nil {
baseURL = utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
} else {
baseURL = *o.ServerURL
}
opURL, err := utils.GenerateURL(ctx, baseURL, "/butler/{taskName}", request, nil) opURL, err := utils.GenerateURL(ctx, baseURL, "/butler/{taskName}", request, nil)
if err != nil { if err != nil {
return nil, fmt.Errorf("error generating URL: %w", err) return nil, fmt.Errorf("error generating URL: %w", err)
@@ -773,6 +785,10 @@ func (s *Butler) StartTask(ctx context.Context, taskName operations.TaskName, op
return nil, err return nil, err
} }
for k, v := range o.SetHeaders {
req.Header.Set(k, v)
}
globalRetryConfig := s.sdkConfiguration.RetryConfig globalRetryConfig := s.sdkConfiguration.RetryConfig
retryConfig := o.Retries retryConfig := o.Retries
if retryConfig == nil { if retryConfig == nil {
@@ -803,7 +819,11 @@ func (s *Butler) StartTask(ctx context.Context, taskName operations.TaskName, op
req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req)
if err != nil { if err != nil {
return nil, backoff.Permanent(err) if retry.IsPermanentError(err) || retry.IsTemporaryError(err) {
return nil, err
}
return nil, retry.Permanent(err)
} }
httpRes, err := s.sdkConfiguration.Client.Do(req) httpRes, err := s.sdkConfiguration.Client.Do(req)
@@ -864,16 +884,6 @@ func (s *Butler) StartTask(ctx context.Context, taskName operations.TaskName, op
RawResponse: httpRes, RawResponse: httpRes,
} }
getRawBody := func() ([]byte, error) {
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))
return rawBody, nil
}
switch { switch {
case httpRes.StatusCode == 200: case httpRes.StatusCode == 200:
fallthrough fallthrough
@@ -881,7 +891,7 @@ func (s *Butler) StartTask(ctx context.Context, taskName operations.TaskName, op
case httpRes.StatusCode == 400: case httpRes.StatusCode == 400:
switch { switch {
case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -894,17 +904,16 @@ func (s *Butler) StartTask(ctx context.Context, taskName operations.TaskName, op
out.RawResponse = httpRes out.RawResponse = httpRes
return nil, &out return nil, &out
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
} }
case httpRes.StatusCode == 401: case httpRes.StatusCode == 401:
switch { switch {
case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -917,28 +926,29 @@ func (s *Butler) StartTask(ctx context.Context, taskName operations.TaskName, op
out.RawResponse = httpRes out.RawResponse = httpRes
return nil, &out return nil, &out
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
} }
case httpRes.StatusCode >= 400 && httpRes.StatusCode < 500: case httpRes.StatusCode >= 400 && httpRes.StatusCode < 500:
fallthrough rawBody, err := utils.ConsumeRawBody(httpRes)
case httpRes.StatusCode >= 500 && httpRes.StatusCode < 600: if err != nil {
rawBody, err := getRawBody() return nil, err
}
return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes)
case httpRes.StatusCode >= 500 && httpRes.StatusCode < 600:
rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes)
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError("unknown status code returned", httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError("unknown status code returned", httpRes.StatusCode, string(rawBody), httpRes)
} }
@@ -972,7 +982,12 @@ func (s *Butler) StopTask(ctx context.Context, taskName operations.PathParamTask
} }
} }
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) var baseURL string
if o.ServerURL == nil {
baseURL = utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
} else {
baseURL = *o.ServerURL
}
opURL, err := utils.GenerateURL(ctx, baseURL, "/butler/{taskName}", request, nil) opURL, err := utils.GenerateURL(ctx, baseURL, "/butler/{taskName}", request, nil)
if err != nil { if err != nil {
return nil, fmt.Errorf("error generating URL: %w", err) return nil, fmt.Errorf("error generating URL: %w", err)
@@ -1000,6 +1015,10 @@ func (s *Butler) StopTask(ctx context.Context, taskName operations.PathParamTask
return nil, err return nil, err
} }
for k, v := range o.SetHeaders {
req.Header.Set(k, v)
}
globalRetryConfig := s.sdkConfiguration.RetryConfig globalRetryConfig := s.sdkConfiguration.RetryConfig
retryConfig := o.Retries retryConfig := o.Retries
if retryConfig == nil { if retryConfig == nil {
@@ -1030,7 +1049,11 @@ func (s *Butler) StopTask(ctx context.Context, taskName operations.PathParamTask
req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req)
if err != nil { if err != nil {
return nil, backoff.Permanent(err) if retry.IsPermanentError(err) || retry.IsTemporaryError(err) {
return nil, err
}
return nil, retry.Permanent(err)
} }
httpRes, err := s.sdkConfiguration.Client.Do(req) httpRes, err := s.sdkConfiguration.Client.Do(req)
@@ -1091,22 +1114,12 @@ func (s *Butler) StopTask(ctx context.Context, taskName operations.PathParamTask
RawResponse: httpRes, RawResponse: httpRes,
} }
getRawBody := func() ([]byte, error) {
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))
return rawBody, nil
}
switch { switch {
case httpRes.StatusCode == 200: case httpRes.StatusCode == 200:
case httpRes.StatusCode == 400: case httpRes.StatusCode == 400:
switch { switch {
case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -1119,17 +1132,16 @@ func (s *Butler) StopTask(ctx context.Context, taskName operations.PathParamTask
out.RawResponse = httpRes out.RawResponse = httpRes
return nil, &out return nil, &out
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
} }
case httpRes.StatusCode == 401: case httpRes.StatusCode == 401:
switch { switch {
case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -1142,30 +1154,31 @@ func (s *Butler) StopTask(ctx context.Context, taskName operations.PathParamTask
out.RawResponse = httpRes out.RawResponse = httpRes
return nil, &out return nil, &out
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
} }
case httpRes.StatusCode == 404: case httpRes.StatusCode == 404:
fallthrough fallthrough
case httpRes.StatusCode >= 400 && httpRes.StatusCode < 500: case httpRes.StatusCode >= 400 && httpRes.StatusCode < 500:
fallthrough rawBody, err := utils.ConsumeRawBody(httpRes)
case httpRes.StatusCode >= 500 && httpRes.StatusCode < 600: if err != nil {
rawBody, err := getRawBody() return nil, err
}
return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes)
case httpRes.StatusCode >= 500 && httpRes.StatusCode < 600:
rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes)
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError("unknown status code returned", httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError("unknown status code returned", httpRes.StatusCode, string(rawBody), httpRes)
} }

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,11 @@
# EnableCreditsMarkerGeneration
Setting that indicates if credits markers detection is enabled. (-1 = Library default, 0 = Disabled).
## Values
| Name | Value |
| --------------------------------------------- | --------------------------------------------- |
| `EnableCreditsMarkerGenerationLibraryDefault` | -1 |
| `EnableCreditsMarkerGenerationDisabled` | 0 |

View File

@@ -0,0 +1,12 @@
# EpisodeSort
Setting that indicates how episodes are sorted for the show. (-1 = Library default, 0 = Oldest first, 1 = Newest first).
## Values
| Name | Value |
| --------------------------- | --------------------------- |
| `EpisodeSortLibraryDefault` | -1 |
| `EpisodeSortOldestFirst` | 0 |
| `EpisodeSortNewestFirst` | 1 |

View File

@@ -1,9 +1,12 @@
# FlattenSeasons # FlattenSeasons
Setting that indicates if seasons are set to hidden for the show. (-1 = Library default, 0 = Hide, 1 = Show).
## Values ## Values
| Name | Value | | Name | Value |
| --------------------- | --------------------- | | ------------------------------ | ------------------------------ |
| `FlattenSeasonsFalse` | 0 | | `FlattenSeasonsLibraryDefault` | -1 |
| `FlattenSeasonsTrue` | 1 | | `FlattenSeasonsHide` | 0 |
| `FlattenSeasonsShow` | 1 |

View File

@@ -0,0 +1,11 @@
# GetLibraryItemsEnableCreditsMarkerGeneration
Setting that indicates if credits markers detection is enabled. (-1 = Library default, 0 = Disabled).
## Values
| Name | Value |
| ------------------------------------------------------------ | ------------------------------------------------------------ |
| `GetLibraryItemsEnableCreditsMarkerGenerationLibraryDefault` | -1 |
| `GetLibraryItemsEnableCreditsMarkerGenerationDisabled` | 0 |

View File

@@ -0,0 +1,12 @@
# GetLibraryItemsEpisodeSort
Setting that indicates how episodes are sorted for the show. (-1 = Library default, 0 = Oldest first, 1 = Newest first).
## Values
| Name | Value |
| ------------------------------------------ | ------------------------------------------ |
| `GetLibraryItemsEpisodeSortLibraryDefault` | -1 |
| `GetLibraryItemsEpisodeSortOldestFirst` | 0 |
| `GetLibraryItemsEpisodeSortNewestFirst` | 1 |

View File

@@ -1,9 +1,12 @@
# GetLibraryItemsFlattenSeasons # GetLibraryItemsFlattenSeasons
Setting that indicates if seasons are set to hidden for the show. (-1 = Library default, 0 = Hide, 1 = Show).
## Values ## Values
| Name | Value | | Name | Value |
| ------------------------------------ | ------------------------------------ | | --------------------------------------------- | --------------------------------------------- |
| `GetLibraryItemsFlattenSeasonsFalse` | 0 | | `GetLibraryItemsFlattenSeasonsLibraryDefault` | -1 |
| `GetLibraryItemsFlattenSeasonsTrue` | 1 | | `GetLibraryItemsFlattenSeasonsHide` | 0 |
| `GetLibraryItemsFlattenSeasonsShow` | 1 |

View File

@@ -23,8 +23,10 @@
| `Year` | **int* | :heavy_minus_sign: | N/A | 2022 | | `Year` | **int* | :heavy_minus_sign: | N/A | 2022 |
| `SeasonCount` | **int* | :heavy_minus_sign: | N/A | 2022 | | `SeasonCount` | **int* | :heavy_minus_sign: | N/A | 2022 |
| `Tagline` | **string* | :heavy_minus_sign: | N/A | Return to Pandora. | | `Tagline` | **string* | :heavy_minus_sign: | N/A | Return to Pandora. |
| `FlattenSeasons` | [*operations.GetLibraryItemsFlattenSeasons](../../models/operations/getlibraryitemsflattenseasons.md) | :heavy_minus_sign: | N/A | 1 | | `FlattenSeasons` | [*operations.GetLibraryItemsFlattenSeasons](../../models/operations/getlibraryitemsflattenseasons.md) | :heavy_minus_sign: | Setting that indicates if seasons are set to hidden for the show. (-1 = Library default, 0 = Hide, 1 = Show). | 1 |
| `ShowOrdering` | [*operations.GetLibraryItemsShowOrdering](../../models/operations/getlibraryitemsshowordering.md) | :heavy_minus_sign: | Setting that indicates the episode ordering for the show <br/>None = Library default, <br/>tmdbAiring = The Movie Database (Aired), <br/>aired = TheTVDB (Aired), <br/>dvd = TheTVDB (DVD), <br/>absolute = TheTVDB (Absolute)).<br/> | dvd | | `EpisodeSort` | [*operations.GetLibraryItemsEpisodeSort](../../models/operations/getlibraryitemsepisodesort.md) | :heavy_minus_sign: | Setting that indicates how episodes are sorted for the show. (-1 = Library default, 0 = Oldest first, 1 = Newest first). | 0 |
| `EnableCreditsMarkerGeneration` | [*operations.GetLibraryItemsEnableCreditsMarkerGeneration](../../models/operations/getlibraryitemsenablecreditsmarkergeneration.md) | :heavy_minus_sign: | Setting that indicates if credits markers detection is enabled. (-1 = Library default, 0 = Disabled). | -1 |
| `ShowOrdering` | [*operations.GetLibraryItemsShowOrdering](../../models/operations/getlibraryitemsshowordering.md) | :heavy_minus_sign: | Setting that indicates the episode ordering for the show.<br/>None = Library default,<br/>tmdbAiring = The Movie Database (Aired),<br/>aired = TheTVDB (Aired),<br/>dvd = TheTVDB (DVD),<br/>absolute = TheTVDB (Absolute)).<br/> | absolute |
| `Thumb` | **string* | :heavy_minus_sign: | N/A | /library/metadata/58683/thumb/1703239236 | | `Thumb` | **string* | :heavy_minus_sign: | N/A | /library/metadata/58683/thumb/1703239236 |
| `Art` | **string* | :heavy_minus_sign: | N/A | /library/metadata/58683/art/1703239236 | | `Art` | **string* | :heavy_minus_sign: | N/A | /library/metadata/58683/art/1703239236 |
| `Banner` | **string* | :heavy_minus_sign: | N/A | /library/metadata/58683/banner/1703239236 | | `Banner` | **string* | :heavy_minus_sign: | N/A | /library/metadata/58683/banner/1703239236 |

View File

@@ -16,4 +16,7 @@ E.g. A movie library will not return anything with type 3 as there are no season
| `GetLibraryItemsQueryParamTypeMovie` | 1 | | `GetLibraryItemsQueryParamTypeMovie` | 1 |
| `GetLibraryItemsQueryParamTypeTvShow` | 2 | | `GetLibraryItemsQueryParamTypeTvShow` | 2 |
| `GetLibraryItemsQueryParamTypeSeason` | 3 | | `GetLibraryItemsQueryParamTypeSeason` | 3 |
| `GetLibraryItemsQueryParamTypeEpisode` | 4 | | `GetLibraryItemsQueryParamTypeEpisode` | 4 |
| `GetLibraryItemsQueryParamTypeAudio` | 8 |
| `GetLibraryItemsQueryParamTypeAlbum` | 9 |
| `GetLibraryItemsQueryParamTypeTrack` | 10 |

View File

@@ -1,20 +1,20 @@
# GetLibraryItemsShowOrdering # GetLibraryItemsShowOrdering
Setting that indicates the episode ordering for the show Setting that indicates the episode ordering for the show.
None = Library default, None = Library default,
tmdbAiring = The Movie Database (Aired), tmdbAiring = The Movie Database (Aired),
aired = TheTVDB (Aired), aired = TheTVDB (Aired),
dvd = TheTVDB (DVD), dvd = TheTVDB (DVD),
absolute = TheTVDB (Absolute)). absolute = TheTVDB (Absolute)).
## Values ## Values
| Name | Value | | Name | Value |
| --------------------------------------- | --------------------------------------- | | ----------------------------------------- | ----------------------------------------- |
| `GetLibraryItemsShowOrderingNone` | None | | `GetLibraryItemsShowOrderingNone` | None |
| `GetLibraryItemsShowOrderingTmdbAiring` | tmdbAiring | | `GetLibraryItemsShowOrderingTmdbAiring` | tmdbAiring |
| `GetLibraryItemsShowOrderingAired` | aired | | `GetLibraryItemsShowOrderingTvdbAired` | aired |
| `GetLibraryItemsShowOrderingDvd` | dvd | | `GetLibraryItemsShowOrderingTvdbDvd` | dvd |
| `GetLibraryItemsShowOrderingAbsolute` | absolute | | `GetLibraryItemsShowOrderingTvdbAbsolute` | absolute |

View File

@@ -14,6 +14,11 @@
| `LibrarySectionTitle` | **string* | :heavy_minus_sign: | N/A | Movies | | `LibrarySectionTitle` | **string* | :heavy_minus_sign: | N/A | Movies |
| `LibrarySectionID` | **int* | :heavy_minus_sign: | N/A | 1 | | `LibrarySectionID` | **int* | :heavy_minus_sign: | N/A | 1 |
| `LibrarySectionKey` | **string* | :heavy_minus_sign: | N/A | /library/sections/1 | | `LibrarySectionKey` | **string* | :heavy_minus_sign: | N/A | /library/sections/1 |
| `GrandparentTitle` | **string* | :heavy_minus_sign: | The name of the album artist for the track when audio, and the name of the TV show for the episode when video. | |
| `ParentTitle` | **string* | :heavy_minus_sign: | The name of the album for the track when audio, and the name of the season for the episode when TV show. | |
| `OriginalTitle` | **string* | :heavy_minus_sign: | The orginal untranslated name of the media item when non-english. | |
| `Index` | **int64* | :heavy_minus_sign: | The index starting from 0 of this media item in the MetaData array. | |
| `ParentIndex` | **int64* | :heavy_minus_sign: | The parent index starting from 0 of this media item in the parent MetaData array. | |
| `ContentRating` | **string* | :heavy_minus_sign: | N/A | PG-13 | | `ContentRating` | **string* | :heavy_minus_sign: | N/A | PG-13 |
| `Summary` | **string* | :heavy_minus_sign: | N/A | Serenity continues the story of the TV series it was based upon ("Firefly"). River Tam had a secret - one in which she's not even aware - so dangerous, no one's safe, as an Alliance operative's sent to capture her, and all others are considered irrelevant to his job. | | `Summary` | **string* | :heavy_minus_sign: | N/A | Serenity continues the story of the TV series it was based upon ("Firefly"). River Tam had a secret - one in which she's not even aware - so dangerous, no one's safe, as an Alliance operative's sent to capture her, and all others are considered irrelevant to his job. |
| `Rating` | **float64* | :heavy_minus_sign: | N/A | 8.2 | | `Rating` | **float64* | :heavy_minus_sign: | N/A | 8.2 |

View File

@@ -1,12 +0,0 @@
# GetPinGlobals
## Fields
| Field | Type | Required | Description | Example |
| ------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------ |
| `ClientID` | **string* | :heavy_minus_sign: | An opaque identifier unique to the client (UUID, serial number, or other unique device ID) | 3381b62b-9ab7-4e37-827b-203e9809eb58 |
| `ClientName` | **string* | :heavy_minus_sign: | The name of the client application. (Plex Web, Plex Media Server, etc.) | Plex for Roku |
| `DeviceNickname` | **string* | :heavy_minus_sign: | A relatively friendly name for the client device | Roku 3 |
| `ClientVersion` | **string* | :heavy_minus_sign: | The version of the client application. | 2.4.1 |
| `Platform` | **string* | :heavy_minus_sign: | The platform of the client application. | Roku |

View File

@@ -6,7 +6,7 @@
| Field | Type | Required | Description | Example | | Field | Type | Required | Description | Example |
| ----------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | ----------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- |
| `Strong` | **bool* | :heavy_minus_sign: | Determines the kind of code returned by the API call<br/>Strong codes are used for Pin authentication flows<br/>Non-Strong codes are used for `Plex.tv/link`<br/> | | | `Strong` | **bool* | :heavy_minus_sign: | Determines the kind of code returned by the API call<br/>Strong codes are used for Pin authentication flows<br/>Non-Strong codes are used for `Plex.tv/link`<br/> | |
| `ClientID` | **string* | :heavy_minus_sign: | An opaque identifier unique to the client (UUID, serial number, or other unique device ID) | 3381b62b-9ab7-4e37-827b-203e9809eb58 | | `ClientID` | *string* | :heavy_check_mark: | An opaque identifier unique to the client (UUID, serial number, or other unique device ID) | 3381b62b-9ab7-4e37-827b-203e9809eb58 |
| `ClientName` | **string* | :heavy_minus_sign: | The name of the client application. (Plex Web, Plex Media Server, etc.) | Plex for Roku | | `ClientName` | **string* | :heavy_minus_sign: | The name of the client application. (Plex Web, Plex Media Server, etc.) | Plex for Roku |
| `DeviceNickname` | **string* | :heavy_minus_sign: | A relatively friendly name for the client device | Roku 3 | | `DeviceNickname` | **string* | :heavy_minus_sign: | A relatively friendly name for the client device | Roku 3 |
| `ClientVersion` | **string* | :heavy_minus_sign: | The version of the client application. | 2.4.1 | | `ClientVersion` | **string* | :heavy_minus_sign: | The version of the client application. | 2.4.1 |

View File

@@ -16,4 +16,7 @@ E.g. A movie library will not return anything with type 3 as there are no season
| `GetPlaylistContentsQueryParamTypeMovie` | 1 | | `GetPlaylistContentsQueryParamTypeMovie` | 1 |
| `GetPlaylistContentsQueryParamTypeTvShow` | 2 | | `GetPlaylistContentsQueryParamTypeTvShow` | 2 |
| `GetPlaylistContentsQueryParamTypeSeason` | 3 | | `GetPlaylistContentsQueryParamTypeSeason` | 3 |
| `GetPlaylistContentsQueryParamTypeEpisode` | 4 | | `GetPlaylistContentsQueryParamTypeEpisode` | 4 |
| `GetPlaylistContentsQueryParamTypeAudio` | 8 |
| `GetPlaylistContentsQueryParamTypeAlbum` | 9 |
| `GetPlaylistContentsQueryParamTypeTrack` | 10 |

View File

@@ -23,8 +23,10 @@
| `Year` | **int* | :heavy_minus_sign: | N/A | 2022 | | `Year` | **int* | :heavy_minus_sign: | N/A | 2022 |
| `SeasonCount` | **int* | :heavy_minus_sign: | N/A | 2022 | | `SeasonCount` | **int* | :heavy_minus_sign: | N/A | 2022 |
| `Tagline` | **string* | :heavy_minus_sign: | N/A | Return to Pandora. | | `Tagline` | **string* | :heavy_minus_sign: | N/A | Return to Pandora. |
| `FlattenSeasons` | [*operations.FlattenSeasons](../../models/operations/flattenseasons.md) | :heavy_minus_sign: | N/A | 1 | | `FlattenSeasons` | [*operations.FlattenSeasons](../../models/operations/flattenseasons.md) | :heavy_minus_sign: | Setting that indicates if seasons are set to hidden for the show. (-1 = Library default, 0 = Hide, 1 = Show). | 1 |
| `ShowOrdering` | [*operations.ShowOrdering](../../models/operations/showordering.md) | :heavy_minus_sign: | Setting that indicates the episode ordering for the show <br/>None = Library default, <br/>tmdbAiring = The Movie Database (Aired), <br/>aired = TheTVDB (Aired), <br/>dvd = TheTVDB (DVD), <br/>absolute = TheTVDB (Absolute)).<br/> | dvd | | `EpisodeSort` | [*operations.EpisodeSort](../../models/operations/episodesort.md) | :heavy_minus_sign: | Setting that indicates how episodes are sorted for the show. (-1 = Library default, 0 = Oldest first, 1 = Newest first). | 0 |
| `EnableCreditsMarkerGeneration` | [*operations.EnableCreditsMarkerGeneration](../../models/operations/enablecreditsmarkergeneration.md) | :heavy_minus_sign: | Setting that indicates if credits markers detection is enabled. (-1 = Library default, 0 = Disabled). | -1 |
| `ShowOrdering` | [*operations.ShowOrdering](../../models/operations/showordering.md) | :heavy_minus_sign: | Setting that indicates the episode ordering for the show.<br/>None = Library default,<br/>tmdbAiring = The Movie Database (Aired),<br/>aired = TheTVDB (Aired),<br/>dvd = TheTVDB (DVD),<br/>absolute = TheTVDB (Absolute)).<br/> | absolute |
| `Thumb` | **string* | :heavy_minus_sign: | N/A | /library/metadata/58683/thumb/1703239236 | | `Thumb` | **string* | :heavy_minus_sign: | N/A | /library/metadata/58683/thumb/1703239236 |
| `Art` | **string* | :heavy_minus_sign: | N/A | /library/metadata/58683/art/1703239236 | | `Art` | **string* | :heavy_minus_sign: | N/A | /library/metadata/58683/art/1703239236 |
| `Banner` | **string* | :heavy_minus_sign: | N/A | /library/metadata/58683/banner/1703239236 | | `Banner` | **string* | :heavy_minus_sign: | N/A | /library/metadata/58683/banner/1703239236 |

View File

@@ -0,0 +1,11 @@
# GetSearchAllLibrariesEnableCreditsMarkerGeneration
Setting that indicates if credits markers detection is enabled. (-1 = Library default, 0 = Disabled).
## Values
| Name | Value |
| ------------------------------------------------------------------ | ------------------------------------------------------------------ |
| `GetSearchAllLibrariesEnableCreditsMarkerGenerationLibraryDefault` | -1 |
| `GetSearchAllLibrariesEnableCreditsMarkerGenerationDisabled` | 0 |

View File

@@ -0,0 +1,12 @@
# GetSearchAllLibrariesEpisodeSort
Setting that indicates how episodes are sorted for the show. (-1 = Library default, 0 = Oldest first, 1 = Newest first).
## Values
| Name | Value |
| ------------------------------------------------ | ------------------------------------------------ |
| `GetSearchAllLibrariesEpisodeSortLibraryDefault` | -1 |
| `GetSearchAllLibrariesEpisodeSortOldestFirst` | 0 |
| `GetSearchAllLibrariesEpisodeSortNewestFirst` | 1 |

View File

@@ -1,9 +1,12 @@
# GetSearchAllLibrariesFlattenSeasons # GetSearchAllLibrariesFlattenSeasons
Setting that indicates if seasons are set to hidden for the show. (-1 = Library default, 0 = Hide, 1 = Show).
## Values ## Values
| Name | Value | | Name | Value |
| ------------------------------------------ | ------------------------------------------ | | --------------------------------------------------- | --------------------------------------------------- |
| `GetSearchAllLibrariesFlattenSeasonsFalse` | 0 | | `GetSearchAllLibrariesFlattenSeasonsLibraryDefault` | -1 |
| `GetSearchAllLibrariesFlattenSeasonsTrue` | 1 | | `GetSearchAllLibrariesFlattenSeasonsHide` | 0 |
| `GetSearchAllLibrariesFlattenSeasonsShow` | 1 |

View File

@@ -1,8 +0,0 @@
# GetSearchAllLibrariesGlobals
## Fields
| Field | Type | Required | Description | Example |
| ------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------ |
| `ClientID` | **string* | :heavy_minus_sign: | An opaque identifier unique to the client (UUID, serial number, or other unique device ID) | 3381b62b-9ab7-4e37-827b-203e9809eb58 |

View File

@@ -23,8 +23,10 @@
| `Year` | **int* | :heavy_minus_sign: | N/A | 2022 | | `Year` | **int* | :heavy_minus_sign: | N/A | 2022 |
| `SeasonCount` | **int* | :heavy_minus_sign: | N/A | 2022 | | `SeasonCount` | **int* | :heavy_minus_sign: | N/A | 2022 |
| `Tagline` | **string* | :heavy_minus_sign: | N/A | Return to Pandora. | | `Tagline` | **string* | :heavy_minus_sign: | N/A | Return to Pandora. |
| `FlattenSeasons` | [*operations.GetSearchAllLibrariesFlattenSeasons](../../models/operations/getsearchalllibrariesflattenseasons.md) | :heavy_minus_sign: | N/A | 1 | | `FlattenSeasons` | [*operations.GetSearchAllLibrariesFlattenSeasons](../../models/operations/getsearchalllibrariesflattenseasons.md) | :heavy_minus_sign: | Setting that indicates if seasons are set to hidden for the show. (-1 = Library default, 0 = Hide, 1 = Show). | 1 |
| `ShowOrdering` | [*operations.GetSearchAllLibrariesShowOrdering](../../models/operations/getsearchalllibrariesshowordering.md) | :heavy_minus_sign: | Setting that indicates the episode ordering for the show <br/>None = Library default, <br/>tmdbAiring = The Movie Database (Aired), <br/>aired = TheTVDB (Aired), <br/>dvd = TheTVDB (DVD), <br/>absolute = TheTVDB (Absolute)).<br/> | dvd | | `EpisodeSort` | [*operations.GetSearchAllLibrariesEpisodeSort](../../models/operations/getsearchalllibrariesepisodesort.md) | :heavy_minus_sign: | Setting that indicates how episodes are sorted for the show. (-1 = Library default, 0 = Oldest first, 1 = Newest first). | 0 |
| `EnableCreditsMarkerGeneration` | [*operations.GetSearchAllLibrariesEnableCreditsMarkerGeneration](../../models/operations/getsearchalllibrariesenablecreditsmarkergeneration.md) | :heavy_minus_sign: | Setting that indicates if credits markers detection is enabled. (-1 = Library default, 0 = Disabled). | -1 |
| `ShowOrdering` | [*operations.GetSearchAllLibrariesShowOrdering](../../models/operations/getsearchalllibrariesshowordering.md) | :heavy_minus_sign: | Setting that indicates the episode ordering for the show.<br/>None = Library default,<br/>tmdbAiring = The Movie Database (Aired),<br/>aired = TheTVDB (Aired),<br/>dvd = TheTVDB (DVD),<br/>absolute = TheTVDB (Absolute)).<br/> | absolute |
| `Thumb` | **string* | :heavy_minus_sign: | N/A | /library/metadata/58683/thumb/1703239236 | | `Thumb` | **string* | :heavy_minus_sign: | N/A | /library/metadata/58683/thumb/1703239236 |
| `Art` | **string* | :heavy_minus_sign: | N/A | /library/metadata/58683/art/1703239236 | | `Art` | **string* | :heavy_minus_sign: | N/A | /library/metadata/58683/art/1703239236 |
| `Banner` | **string* | :heavy_minus_sign: | N/A | /library/metadata/58683/banner/1703239236 | | `Banner` | **string* | :heavy_minus_sign: | N/A | /library/metadata/58683/banner/1703239236 |

View File

@@ -6,7 +6,7 @@
| Field | Type | Required | Description | Example | | Field | Type | Required | Description | Example |
| ------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------- | | ------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------- |
| `Query` | *string* | :heavy_check_mark: | The search query term. | | | `Query` | *string* | :heavy_check_mark: | The search query term. | |
| `ClientID` | **string* | :heavy_minus_sign: | An opaque identifier unique to the client (UUID, serial number, or other unique device ID) | 3381b62b-9ab7-4e37-827b-203e9809eb58 | | `ClientID` | *string* | :heavy_check_mark: | An opaque identifier unique to the client (UUID, serial number, or other unique device ID) | 3381b62b-9ab7-4e37-827b-203e9809eb58 |
| `Limit` | **int64* | :heavy_minus_sign: | Limit the number of results returned. | | | `Limit` | **int64* | :heavy_minus_sign: | Limit the number of results returned. | |
| `SearchTypes` | [][operations.SearchTypes](../../models/operations/searchtypes.md) | :heavy_minus_sign: | A comma-separated list of search types to include. Valid values are: movies, music, otherVideos, people, tv.<br/> | movies,music,otherVideos,people,tv | | `SearchTypes` | [][operations.SearchTypes](../../models/operations/searchtypes.md) | :heavy_minus_sign: | A comma-separated list of search types to include. Valid values are: movies, music, otherVideos, people, tv.<br/> | movies,music,otherVideos,people,tv |
| `IncludeCollections` | [*operations.QueryParamIncludeCollections](../../models/operations/queryparamincludecollections.md) | :heavy_minus_sign: | Whether to include collections in the search results. | 1 | | `IncludeCollections` | [*operations.QueryParamIncludeCollections](../../models/operations/queryparamincludecollections.md) | :heavy_minus_sign: | Whether to include collections in the search results. | 1 |

View File

@@ -1,20 +1,20 @@
# GetSearchAllLibrariesShowOrdering # GetSearchAllLibrariesShowOrdering
Setting that indicates the episode ordering for the show Setting that indicates the episode ordering for the show.
None = Library default, None = Library default,
tmdbAiring = The Movie Database (Aired), tmdbAiring = The Movie Database (Aired),
aired = TheTVDB (Aired), aired = TheTVDB (Aired),
dvd = TheTVDB (DVD), dvd = TheTVDB (DVD),
absolute = TheTVDB (Absolute)). absolute = TheTVDB (Absolute)).
## Values ## Values
| Name | Value | | Name | Value |
| --------------------------------------------- | --------------------------------------------- | | ----------------------------------------------- | ----------------------------------------------- |
| `GetSearchAllLibrariesShowOrderingNone` | None | | `GetSearchAllLibrariesShowOrderingNone` | None |
| `GetSearchAllLibrariesShowOrderingTmdbAiring` | tmdbAiring | | `GetSearchAllLibrariesShowOrderingTmdbAiring` | tmdbAiring |
| `GetSearchAllLibrariesShowOrderingAired` | aired | | `GetSearchAllLibrariesShowOrderingTvdbAired` | aired |
| `GetSearchAllLibrariesShowOrderingDvd` | dvd | | `GetSearchAllLibrariesShowOrderingTvdbDvd` | dvd |
| `GetSearchAllLibrariesShowOrderingAbsolute` | absolute | | `GetSearchAllLibrariesShowOrderingTvdbAbsolute` | absolute |

View File

@@ -16,4 +16,7 @@ E.g. A movie library will not return anything with type 3 as there are no season
| `GetSearchLibraryQueryParamTypeMovie` | 1 | | `GetSearchLibraryQueryParamTypeMovie` | 1 |
| `GetSearchLibraryQueryParamTypeTvShow` | 2 | | `GetSearchLibraryQueryParamTypeTvShow` | 2 |
| `GetSearchLibraryQueryParamTypeSeason` | 3 | | `GetSearchLibraryQueryParamTypeSeason` | 3 |
| `GetSearchLibraryQueryParamTypeEpisode` | 4 | | `GetSearchLibraryQueryParamTypeEpisode` | 4 |
| `GetSearchLibraryQueryParamTypeAudio` | 8 |
| `GetSearchLibraryQueryParamTypeAlbum` | 9 |
| `GetSearchLibraryQueryParamTypeTrack` | 10 |

View File

@@ -1,8 +0,0 @@
# GetServerResourcesGlobals
## Fields
| Field | Type | Required | Description | Example |
| ------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------ |
| `ClientID` | **string* | :heavy_minus_sign: | An opaque identifier unique to the client (UUID, serial number, or other unique device ID) | 3381b62b-9ab7-4e37-827b-203e9809eb58 |

View File

@@ -8,4 +8,4 @@
| `IncludeHTTPS` | [*operations.IncludeHTTPS](../../models/operations/includehttps.md) | :heavy_minus_sign: | Include Https entries in the results | 1 | | `IncludeHTTPS` | [*operations.IncludeHTTPS](../../models/operations/includehttps.md) | :heavy_minus_sign: | Include Https entries in the results | 1 |
| `IncludeRelay` | [*operations.IncludeRelay](../../models/operations/includerelay.md) | :heavy_minus_sign: | Include Relay addresses in the results <br/>E.g: https://10-0-0-25.bbf8e10c7fa20447cacee74cd9914cde.plex.direct:32400<br/> | 1 | | `IncludeRelay` | [*operations.IncludeRelay](../../models/operations/includerelay.md) | :heavy_minus_sign: | Include Relay addresses in the results <br/>E.g: https://10-0-0-25.bbf8e10c7fa20447cacee74cd9914cde.plex.direct:32400<br/> | 1 |
| `IncludeIPv6` | [*operations.IncludeIPv6](../../models/operations/includeipv6.md) | :heavy_minus_sign: | Include IPv6 entries in the results | 1 | | `IncludeIPv6` | [*operations.IncludeIPv6](../../models/operations/includeipv6.md) | :heavy_minus_sign: | Include IPv6 entries in the results | 1 |
| `ClientID` | **string* | :heavy_minus_sign: | An opaque identifier unique to the client (UUID, serial number, or other unique device ID) | 3381b62b-9ab7-4e37-827b-203e9809eb58 | | `ClientID` | *string* | :heavy_check_mark: | An opaque identifier unique to the client (UUID, serial number, or other unique device ID) | 3381b62b-9ab7-4e37-827b-203e9809eb58 |

View File

@@ -3,42 +3,43 @@
## Fields ## Fields
| Field | Type | Required | Description | Example | | Field | Type | Required | Description | Example |
| ---------------------------------------------------------------------------- | ---------------------------------------------------------------------------- | ---------------------------------------------------------------------------- | ---------------------------------------------------------------------------- | ---------------------------------------------------------------------------- | | --------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------- |
| `AddedAt` | **int* | :heavy_minus_sign: | N/A | 1705543312 | | `AddedAt` | **int* | :heavy_minus_sign: | N/A | 1705543312 |
| `Art` | **string* | :heavy_minus_sign: | N/A | /library/metadata/39904/art/1705310687 | | `Art` | **string* | :heavy_minus_sign: | N/A | /library/metadata/39904/art/1705310687 |
| `Duration` | **int* | :heavy_minus_sign: | N/A | 186240 | | `Duration` | **int* | :heavy_minus_sign: | N/A | 186240 |
| `GrandparentArt` | **string* | :heavy_minus_sign: | N/A | /library/metadata/39904/art/1705310687 | | `GrandparentArt` | **string* | :heavy_minus_sign: | N/A | /library/metadata/39904/art/1705310687 |
| `GrandparentGUID` | **string* | :heavy_minus_sign: | N/A | plex://artist/5d07bbfd403c6402904a6480 | | `GrandparentGUID` | **string* | :heavy_minus_sign: | N/A | plex://artist/5d07bbfd403c6402904a6480 |
| `GrandparentKey` | **string* | :heavy_minus_sign: | N/A | /library/metadata/39904 | | `GrandparentKey` | **string* | :heavy_minus_sign: | N/A | /library/metadata/39904 |
| `GrandparentRatingKey` | **string* | :heavy_minus_sign: | N/A | 39904 | | `GrandparentRatingKey` | **string* | :heavy_minus_sign: | N/A | 39904 |
| `GrandparentThumb` | **string* | :heavy_minus_sign: | N/A | /library/metadata/39904/thumb/1705310687 | | `GrandparentThumb` | **string* | :heavy_minus_sign: | N/A | /library/metadata/39904/thumb/1705310687 |
| `GrandparentTitle` | **string* | :heavy_minus_sign: | N/A | Green Day | | `GrandparentTitle` | **string* | :heavy_minus_sign: | N/A | Green Day |
| `GUID` | **string* | :heavy_minus_sign: | N/A | plex://track/6535834f71f22f36f71a8e8f | | `GUID` | **string* | :heavy_minus_sign: | N/A | plex://track/6535834f71f22f36f71a8e8f |
| `Index` | **int* | :heavy_minus_sign: | N/A | 1 | | `Index` | **int* | :heavy_minus_sign: | N/A | 1 |
| `Key` | **string* | :heavy_minus_sign: | N/A | /library/metadata/67085 | | `Key` | **string* | :heavy_minus_sign: | N/A | /library/metadata/67085 |
| `LibrarySectionID` | **string* | :heavy_minus_sign: | N/A | 3 | | `LibrarySectionID` | **string* | :heavy_minus_sign: | N/A | 3 |
| `LibrarySectionKey` | **string* | :heavy_minus_sign: | N/A | /library/sections/3 | | `LibrarySectionKey` | **string* | :heavy_minus_sign: | N/A | /library/sections/3 |
| `LibrarySectionTitle` | **string* | :heavy_minus_sign: | N/A | Music | | `LibrarySectionTitle` | **string* | :heavy_minus_sign: | N/A | Music |
| `MusicAnalysisVersion` | **string* | :heavy_minus_sign: | N/A | 1 | | `MusicAnalysisVersion` | **string* | :heavy_minus_sign: | N/A | 1 |
| `ParentGUID` | **string* | :heavy_minus_sign: | N/A | plex://album/65394d6d472b8ab03ef47f12 | | `OriginalTitle` | **string* | :heavy_minus_sign: | The original untranslated name of the media item when non-english, or the track artist if an audio Item has an album artist | The American Dream Is Killing Me |
| `ParentIndex` | **int* | :heavy_minus_sign: | N/A | 1 | | `ParentGUID` | **string* | :heavy_minus_sign: | N/A | plex://album/65394d6d472b8ab03ef47f12 |
| `ParentKey` | **string* | :heavy_minus_sign: | N/A | /library/metadata/67084 | | `ParentIndex` | **int* | :heavy_minus_sign: | N/A | 1 |
| `ParentRatingKey` | **string* | :heavy_minus_sign: | N/A | 67084 | | `ParentKey` | **string* | :heavy_minus_sign: | N/A | /library/metadata/67084 |
| `ParentStudio` | **string* | :heavy_minus_sign: | N/A | Reprise Records | | `ParentRatingKey` | **string* | :heavy_minus_sign: | N/A | 67084 |
| `ParentThumb` | **string* | :heavy_minus_sign: | N/A | /library/metadata/67084/thumb/1705543314 | | `ParentStudio` | **string* | :heavy_minus_sign: | N/A | Reprise Records |
| `ParentTitle` | **string* | :heavy_minus_sign: | N/A | Saviors | | `ParentThumb` | **string* | :heavy_minus_sign: | N/A | /library/metadata/67084/thumb/1705543314 |
| `ParentYear` | **int* | :heavy_minus_sign: | N/A | 2024 | | `ParentTitle` | **string* | :heavy_minus_sign: | N/A | Saviors |
| `RatingCount` | **int* | :heavy_minus_sign: | N/A | 45885 | | `ParentYear` | **int* | :heavy_minus_sign: | N/A | 2024 |
| `RatingKey` | **string* | :heavy_minus_sign: | N/A | 67085 | | `RatingCount` | **int* | :heavy_minus_sign: | N/A | 45885 |
| `SessionKey` | **string* | :heavy_minus_sign: | N/A | 203 | | `RatingKey` | **string* | :heavy_minus_sign: | N/A | 67085 |
| `Thumb` | **string* | :heavy_minus_sign: | N/A | /library/metadata/67084/thumb/1705543314 | | `SessionKey` | **string* | :heavy_minus_sign: | N/A | 203 |
| `Title` | **string* | :heavy_minus_sign: | N/A | The American Dream Is Killing Me | | `Thumb` | **string* | :heavy_minus_sign: | N/A | /library/metadata/67084/thumb/1705543314 |
| `TitleSort` | **string* | :heavy_minus_sign: | N/A | American Dream Is Killing Me | | `Title` | **string* | :heavy_minus_sign: | N/A | The American Dream Is Killing Me |
| `Type` | **string* | :heavy_minus_sign: | N/A | track | | `TitleSort` | **string* | :heavy_minus_sign: | N/A | American Dream Is Killing Me |
| `UpdatedAt` | **int* | :heavy_minus_sign: | N/A | 1705543314 | | `Type` | **string* | :heavy_minus_sign: | N/A | track |
| `ViewOffset` | **int* | :heavy_minus_sign: | N/A | 1000 | | `UpdatedAt` | **int* | :heavy_minus_sign: | N/A | 1705543314 |
| `Media` | [][operations.GetSessionsMedia](../../models/operations/getsessionsmedia.md) | :heavy_minus_sign: | N/A | | | `ViewOffset` | **int* | :heavy_minus_sign: | N/A | 1000 |
| `User` | [*operations.GetSessionsUser](../../models/operations/getsessionsuser.md) | :heavy_minus_sign: | N/A | | | `Media` | [][operations.GetSessionsMedia](../../models/operations/getsessionsmedia.md) | :heavy_minus_sign: | N/A | |
| `Player` | [*operations.Player](../../models/operations/player.md) | :heavy_minus_sign: | N/A | | | `User` | [*operations.GetSessionsUser](../../models/operations/getsessionsuser.md) | :heavy_minus_sign: | N/A | |
| `Session` | [*operations.Session](../../models/operations/session.md) | :heavy_minus_sign: | N/A | | | `Player` | [*operations.Player](../../models/operations/player.md) | :heavy_minus_sign: | N/A | |
| `Session` | [*operations.Session](../../models/operations/session.md) | :heavy_minus_sign: | N/A | |

View File

@@ -1,12 +0,0 @@
# GetTokenByPinIDGlobals
## Fields
| Field | Type | Required | Description | Example |
| ------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------ |
| `ClientID` | **string* | :heavy_minus_sign: | An opaque identifier unique to the client (UUID, serial number, or other unique device ID) | 3381b62b-9ab7-4e37-827b-203e9809eb58 |
| `ClientName` | **string* | :heavy_minus_sign: | The name of the client application. (Plex Web, Plex Media Server, etc.) | Plex for Roku |
| `DeviceNickname` | **string* | :heavy_minus_sign: | A relatively friendly name for the client device | Roku 3 |
| `ClientVersion` | **string* | :heavy_minus_sign: | The version of the client application. | 2.4.1 |
| `Platform` | **string* | :heavy_minus_sign: | The platform of the client application. | Roku |

View File

@@ -6,7 +6,7 @@
| Field | Type | Required | Description | Example | | Field | Type | Required | Description | Example |
| ------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------ | | ------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------ |
| `PinID` | *int64* | :heavy_check_mark: | The PinID to retrieve an access token for | | | `PinID` | *int64* | :heavy_check_mark: | The PinID to retrieve an access token for | |
| `ClientID` | **string* | :heavy_minus_sign: | An opaque identifier unique to the client (UUID, serial number, or other unique device ID) | 3381b62b-9ab7-4e37-827b-203e9809eb58 | | `ClientID` | *string* | :heavy_check_mark: | An opaque identifier unique to the client (UUID, serial number, or other unique device ID) | 3381b62b-9ab7-4e37-827b-203e9809eb58 |
| `ClientName` | **string* | :heavy_minus_sign: | The name of the client application. (Plex Web, Plex Media Server, etc.) | Plex for Roku | | `ClientName` | **string* | :heavy_minus_sign: | The name of the client application. (Plex Web, Plex Media Server, etc.) | Plex for Roku |
| `DeviceNickname` | **string* | :heavy_minus_sign: | A relatively friendly name for the client device | Roku 3 | | `DeviceNickname` | **string* | :heavy_minus_sign: | A relatively friendly name for the client device | Roku 3 |
| `ClientVersion` | **string* | :heavy_minus_sign: | The version of the client application. | 2.4.1 | | `ClientVersion` | **string* | :heavy_minus_sign: | The version of the client application. | 2.4.1 |

View File

@@ -16,4 +16,7 @@ E.g. A movie library will not return anything with type 3 as there are no season
| `GetTopWatchedContentQueryParamTypeMovie` | 1 | | `GetTopWatchedContentQueryParamTypeMovie` | 1 |
| `GetTopWatchedContentQueryParamTypeTvShow` | 2 | | `GetTopWatchedContentQueryParamTypeTvShow` | 2 |
| `GetTopWatchedContentQueryParamTypeSeason` | 3 | | `GetTopWatchedContentQueryParamTypeSeason` | 3 |
| `GetTopWatchedContentQueryParamTypeEpisode` | 4 | | `GetTopWatchedContentQueryParamTypeEpisode` | 4 |
| `GetTopWatchedContentQueryParamTypeAudio` | 8 |
| `GetTopWatchedContentQueryParamTypeAlbum` | 9 |
| `GetTopWatchedContentQueryParamTypeTrack` | 10 |

View File

@@ -1,12 +0,0 @@
# PostUsersSignInDataGlobals
## Fields
| Field | Type | Required | Description | Example |
| ------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------ |
| `ClientID` | **string* | :heavy_minus_sign: | An opaque identifier unique to the client (UUID, serial number, or other unique device ID) | 3381b62b-9ab7-4e37-827b-203e9809eb58 |
| `ClientName` | **string* | :heavy_minus_sign: | The name of the client application. (Plex Web, Plex Media Server, etc.) | Plex for Roku |
| `DeviceNickname` | **string* | :heavy_minus_sign: | A relatively friendly name for the client device | Roku 3 |
| `ClientVersion` | **string* | :heavy_minus_sign: | The version of the client application. | 2.4.1 |
| `Platform` | **string* | :heavy_minus_sign: | The platform of the client application. | Roku |

View File

@@ -5,7 +5,7 @@
| Field | Type | Required | Description | Example | | Field | Type | Required | Description | Example |
| ------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------- | | ------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------- |
| `ClientID` | **string* | :heavy_minus_sign: | An opaque identifier unique to the client (UUID, serial number, or other unique device ID) | 3381b62b-9ab7-4e37-827b-203e9809eb58 | | `ClientID` | *string* | :heavy_check_mark: | An opaque identifier unique to the client (UUID, serial number, or other unique device ID) | 3381b62b-9ab7-4e37-827b-203e9809eb58 |
| `ClientName` | **string* | :heavy_minus_sign: | The name of the client application. (Plex Web, Plex Media Server, etc.) | Plex for Roku | | `ClientName` | **string* | :heavy_minus_sign: | The name of the client application. (Plex Web, Plex Media Server, etc.) | Plex for Roku |
| `DeviceNickname` | **string* | :heavy_minus_sign: | A relatively friendly name for the client device | Roku 3 | | `DeviceNickname` | **string* | :heavy_minus_sign: | A relatively friendly name for the client device | Roku 3 |
| `ClientVersion` | **string* | :heavy_minus_sign: | The version of the client application. | 2.4.1 | | `ClientVersion` | **string* | :heavy_minus_sign: | The version of the client application. | 2.4.1 |

View File

@@ -16,4 +16,7 @@ E.g. A movie library will not return anything with type 3 as there are no season
| `QueryParamTypeMovie` | 1 | | `QueryParamTypeMovie` | 1 |
| `QueryParamTypeTvShow` | 2 | | `QueryParamTypeTvShow` | 2 |
| `QueryParamTypeSeason` | 3 | | `QueryParamTypeSeason` | 3 |
| `QueryParamTypeEpisode` | 4 | | `QueryParamTypeEpisode` | 4 |
| `QueryParamTypeAudio` | 8 |
| `QueryParamTypeAlbum` | 9 |
| `QueryParamTypeTrack` | 10 |

View File

@@ -1,20 +1,20 @@
# ShowOrdering # ShowOrdering
Setting that indicates the episode ordering for the show Setting that indicates the episode ordering for the show.
None = Library default, None = Library default,
tmdbAiring = The Movie Database (Aired), tmdbAiring = The Movie Database (Aired),
aired = TheTVDB (Aired), aired = TheTVDB (Aired),
dvd = TheTVDB (DVD), dvd = TheTVDB (DVD),
absolute = TheTVDB (Absolute)). absolute = TheTVDB (Absolute)).
## Values ## Values
| Name | Value | | Name | Value |
| ------------------------ | ------------------------ | | -------------------------- | -------------------------- |
| `ShowOrderingNone` | None | | `ShowOrderingNone` | None |
| `ShowOrderingTmdbAiring` | tmdbAiring | | `ShowOrderingTmdbAiring` | tmdbAiring |
| `ShowOrderingAired` | aired | | `ShowOrderingTvdbAired` | aired |
| `ShowOrderingDvd` | dvd | | `ShowOrderingTvdbDvd` | dvd |
| `ShowOrderingAbsolute` | absolute | | `ShowOrderingTvdbAbsolute` | absolute |

View File

@@ -25,4 +25,5 @@ A key representing a specific tag within the section.
| `TagRating` | rating | | `TagRating` | rating |
| `TagResolution` | resolution | | `TagResolution` | resolution |
| `TagFirstCharacter` | firstCharacter | | `TagFirstCharacter` | firstCharacter |
| `TagFolder` | folder | | `TagFolder` | folder |
| `TagAlbums` | albums |

View File

@@ -16,4 +16,7 @@ E.g. A movie library will not return anything with type 3 as there are no season
| `TypeMovie` | 1 | | `TypeMovie` | 1 |
| `TypeTvShow` | 2 | | `TypeTvShow` | 2 |
| `TypeSeason` | 3 | | `TypeSeason` | 3 |
| `TypeEpisode` | 4 | | `TypeEpisode` | 4 |
| `TypeAudio` | 8 |
| `TypeAlbum` | 9 |
| `TypeTrack` | 10 |

View File

@@ -27,22 +27,18 @@ Get Server Activities
package main package main
import( import(
"github.com/LukeHagar/plexgo"
"context" "context"
"github.com/LukeHagar/plexgo"
"log" "log"
) )
func main() { func main() {
ctx := context.Background()
s := plexgo.New( s := plexgo.New(
plexgo.WithSecurity("<YOUR_API_KEY_HERE>"), plexgo.WithSecurity("<YOUR_API_KEY_HERE>"),
plexgo.WithClientID("3381b62b-9ab7-4e37-827b-203e9809eb58"),
plexgo.WithClientName("Plex for Roku"),
plexgo.WithClientVersion("2.4.1"),
plexgo.WithPlatform("Roku"),
plexgo.WithDeviceNickname("Roku 3"),
) )
ctx := context.Background()
res, err := s.Activities.GetServerActivities(ctx) res, err := s.Activities.GetServerActivities(ctx)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
@@ -82,22 +78,18 @@ Cancel Server Activities
package main package main
import( import(
"github.com/LukeHagar/plexgo"
"context" "context"
"github.com/LukeHagar/plexgo"
"log" "log"
) )
func main() { func main() {
ctx := context.Background()
s := plexgo.New( s := plexgo.New(
plexgo.WithSecurity("<YOUR_API_KEY_HERE>"), plexgo.WithSecurity("<YOUR_API_KEY_HERE>"),
plexgo.WithClientID("3381b62b-9ab7-4e37-827b-203e9809eb58"),
plexgo.WithClientName("Plex for Roku"),
plexgo.WithClientVersion("2.4.1"),
plexgo.WithPlatform("Roku"),
plexgo.WithDeviceNickname("Roku 3"),
) )
ctx := context.Background()
res, err := s.Activities.CancelServerActivities(ctx, "25b71ed5-0f9d-461c-baa7-d404e9e10d3e") res, err := s.Activities.CancelServerActivities(ctx, "25b71ed5-0f9d-461c-baa7-d404e9e10d3e")
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)

View File

@@ -24,23 +24,19 @@ This endpoint provides the caller with a temporary token with the same access le
package main package main
import( import(
"github.com/LukeHagar/plexgo"
"context" "context"
"github.com/LukeHagar/plexgo"
"github.com/LukeHagar/plexgo/models/operations" "github.com/LukeHagar/plexgo/models/operations"
"log" "log"
) )
func main() { func main() {
ctx := context.Background()
s := plexgo.New( s := plexgo.New(
plexgo.WithSecurity("<YOUR_API_KEY_HERE>"), plexgo.WithSecurity("<YOUR_API_KEY_HERE>"),
plexgo.WithClientID("3381b62b-9ab7-4e37-827b-203e9809eb58"),
plexgo.WithClientName("Plex for Roku"),
plexgo.WithClientVersion("2.4.1"),
plexgo.WithPlatform("Roku"),
plexgo.WithDeviceNickname("Roku 3"),
) )
ctx := context.Background()
res, err := s.Authentication.GetTransientToken(ctx, operations.GetTransientTokenQueryParamTypeDelegation, operations.ScopeAll) res, err := s.Authentication.GetTransientToken(ctx, operations.GetTransientTokenQueryParamTypeDelegation, operations.ScopeAll)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
@@ -84,22 +80,18 @@ Note: requires Plex Media Server >= 1.15.4.
package main package main
import( import(
"github.com/LukeHagar/plexgo"
"context" "context"
"github.com/LukeHagar/plexgo"
"log" "log"
) )
func main() { func main() {
ctx := context.Background()
s := plexgo.New( s := plexgo.New(
plexgo.WithSecurity("<YOUR_API_KEY_HERE>"), plexgo.WithSecurity("<YOUR_API_KEY_HERE>"),
plexgo.WithClientID("3381b62b-9ab7-4e37-827b-203e9809eb58"),
plexgo.WithClientName("Plex for Roku"),
plexgo.WithClientVersion("2.4.1"),
plexgo.WithPlatform("Roku"),
plexgo.WithDeviceNickname("Roku 3"),
) )
ctx := context.Background()
res, err := s.Authentication.GetSourceConnectionInformation(ctx, "provider://provider-identifier") res, err := s.Authentication.GetSourceConnectionInformation(ctx, "provider://provider-identifier")
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
@@ -140,22 +132,18 @@ Get the User data from the provided X-Plex-Token
package main package main
import( import(
"github.com/LukeHagar/plexgo"
"context" "context"
"github.com/LukeHagar/plexgo"
"log" "log"
) )
func main() { func main() {
ctx := context.Background()
s := plexgo.New( s := plexgo.New(
plexgo.WithSecurity("<YOUR_API_KEY_HERE>"), plexgo.WithSecurity("<YOUR_API_KEY_HERE>"),
plexgo.WithClientID("3381b62b-9ab7-4e37-827b-203e9809eb58"),
plexgo.WithClientName("Plex for Roku"),
plexgo.WithClientVersion("2.4.1"),
plexgo.WithPlatform("Roku"),
plexgo.WithDeviceNickname("Roku 3"),
) )
ctx := context.Background()
res, err := s.Authentication.GetTokenDetails(ctx) res, err := s.Authentication.GetTokenDetails(ctx)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
@@ -195,26 +183,27 @@ Sign in user with username and password and return user data with Plex authentic
package main package main
import( import(
"github.com/LukeHagar/plexgo"
"context" "context"
"github.com/LukeHagar/plexgo"
"github.com/LukeHagar/plexgo/models/operations" "github.com/LukeHagar/plexgo/models/operations"
"log" "log"
) )
func main() { func main() {
s := plexgo.New(
plexgo.WithClientID("3381b62b-9ab7-4e37-827b-203e9809eb58"),
plexgo.WithClientName("Plex for Roku"),
plexgo.WithClientVersion("2.4.1"),
plexgo.WithPlatform("Roku"),
plexgo.WithDeviceNickname("Roku 3"),
)
ctx := context.Background() ctx := context.Background()
s := plexgo.New()
res, err := s.Authentication.PostUsersSignInData(ctx, operations.PostUsersSignInDataRequest{ res, err := s.Authentication.PostUsersSignInData(ctx, operations.PostUsersSignInDataRequest{
ClientID: "3381b62b-9ab7-4e37-827b-203e9809eb58",
ClientName: plexgo.String("Plex for Roku"),
DeviceNickname: plexgo.String("Roku 3"),
ClientVersion: plexgo.String("2.4.1"),
Platform: plexgo.String("Roku"),
RequestBody: &operations.PostUsersSignInDataRequestBody{ RequestBody: &operations.PostUsersSignInDataRequestBody{
Login: "username@email.com", Login: "username@email.com",
Password: "password123", Password: "password123",
RememberMe: plexgo.Bool(false),
VerificationCode: plexgo.String("123456"), VerificationCode: plexgo.String("123456"),
}, },
}) })

View File

@@ -24,22 +24,18 @@ Returns a list of butler tasks
package main package main
import( import(
"github.com/LukeHagar/plexgo"
"context" "context"
"github.com/LukeHagar/plexgo"
"log" "log"
) )
func main() { func main() {
ctx := context.Background()
s := plexgo.New( s := plexgo.New(
plexgo.WithSecurity("<YOUR_API_KEY_HERE>"), plexgo.WithSecurity("<YOUR_API_KEY_HERE>"),
plexgo.WithClientID("3381b62b-9ab7-4e37-827b-203e9809eb58"),
plexgo.WithClientName("Plex for Roku"),
plexgo.WithClientVersion("2.4.1"),
plexgo.WithPlatform("Roku"),
plexgo.WithDeviceNickname("Roku 3"),
) )
ctx := context.Background()
res, err := s.Butler.GetButlerTasks(ctx) res, err := s.Butler.GetButlerTasks(ctx)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
@@ -84,22 +80,18 @@ This endpoint will attempt to start all Butler tasks that are enabled in the set
package main package main
import( import(
"github.com/LukeHagar/plexgo"
"context" "context"
"github.com/LukeHagar/plexgo"
"log" "log"
) )
func main() { func main() {
ctx := context.Background()
s := plexgo.New( s := plexgo.New(
plexgo.WithSecurity("<YOUR_API_KEY_HERE>"), plexgo.WithSecurity("<YOUR_API_KEY_HERE>"),
plexgo.WithClientID("3381b62b-9ab7-4e37-827b-203e9809eb58"),
plexgo.WithClientName("Plex for Roku"),
plexgo.WithClientVersion("2.4.1"),
plexgo.WithPlatform("Roku"),
plexgo.WithDeviceNickname("Roku 3"),
) )
ctx := context.Background()
res, err := s.Butler.StartAllTasks(ctx) res, err := s.Butler.StartAllTasks(ctx)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
@@ -140,22 +132,18 @@ This endpoint will stop all currently running tasks and remove any scheduled tas
package main package main
import( import(
"github.com/LukeHagar/plexgo"
"context" "context"
"github.com/LukeHagar/plexgo"
"log" "log"
) )
func main() { func main() {
ctx := context.Background()
s := plexgo.New( s := plexgo.New(
plexgo.WithSecurity("<YOUR_API_KEY_HERE>"), plexgo.WithSecurity("<YOUR_API_KEY_HERE>"),
plexgo.WithClientID("3381b62b-9ab7-4e37-827b-203e9809eb58"),
plexgo.WithClientName("Plex for Roku"),
plexgo.WithClientVersion("2.4.1"),
plexgo.WithPlatform("Roku"),
plexgo.WithDeviceNickname("Roku 3"),
) )
ctx := context.Background()
res, err := s.Butler.StopAllTasks(ctx) res, err := s.Butler.StopAllTasks(ctx)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
@@ -200,23 +188,19 @@ This endpoint will attempt to start a single Butler task that is enabled in the
package main package main
import( import(
"github.com/LukeHagar/plexgo"
"context" "context"
"github.com/LukeHagar/plexgo"
"github.com/LukeHagar/plexgo/models/operations" "github.com/LukeHagar/plexgo/models/operations"
"log" "log"
) )
func main() { func main() {
ctx := context.Background()
s := plexgo.New( s := plexgo.New(
plexgo.WithSecurity("<YOUR_API_KEY_HERE>"), plexgo.WithSecurity("<YOUR_API_KEY_HERE>"),
plexgo.WithClientID("3381b62b-9ab7-4e37-827b-203e9809eb58"),
plexgo.WithClientName("Plex for Roku"),
plexgo.WithClientVersion("2.4.1"),
plexgo.WithPlatform("Roku"),
plexgo.WithDeviceNickname("Roku 3"),
) )
ctx := context.Background()
res, err := s.Butler.StartTask(ctx, operations.TaskNameCleanOldBundles) res, err := s.Butler.StartTask(ctx, operations.TaskNameCleanOldBundles)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
@@ -258,23 +242,19 @@ This endpoint will stop a currently running task by name, or remove it from the
package main package main
import( import(
"github.com/LukeHagar/plexgo"
"context" "context"
"github.com/LukeHagar/plexgo"
"github.com/LukeHagar/plexgo/models/operations" "github.com/LukeHagar/plexgo/models/operations"
"log" "log"
) )
func main() { func main() {
ctx := context.Background()
s := plexgo.New( s := plexgo.New(
plexgo.WithSecurity("<YOUR_API_KEY_HERE>"), plexgo.WithSecurity("<YOUR_API_KEY_HERE>"),
plexgo.WithClientID("3381b62b-9ab7-4e37-827b-203e9809eb58"),
plexgo.WithClientName("Plex for Roku"),
plexgo.WithClientVersion("2.4.1"),
plexgo.WithPlatform("Roku"),
plexgo.WithDeviceNickname("Roku 3"),
) )
ctx := context.Background()
res, err := s.Butler.StopTask(ctx, operations.PathParamTaskNameBackupDatabase) res, err := s.Butler.StopTask(ctx, operations.PathParamTaskNameBackupDatabase)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)

View File

@@ -22,22 +22,18 @@ Get Global Hubs filtered by the parameters provided.
package main package main
import( import(
"github.com/LukeHagar/plexgo"
"context" "context"
"github.com/LukeHagar/plexgo"
"log" "log"
) )
func main() { func main() {
ctx := context.Background()
s := plexgo.New( s := plexgo.New(
plexgo.WithSecurity("<YOUR_API_KEY_HERE>"), plexgo.WithSecurity("<YOUR_API_KEY_HERE>"),
plexgo.WithClientID("3381b62b-9ab7-4e37-827b-203e9809eb58"),
plexgo.WithClientName("Plex for Roku"),
plexgo.WithClientVersion("2.4.1"),
plexgo.WithPlatform("Roku"),
plexgo.WithDeviceNickname("Roku 3"),
) )
ctx := context.Background()
res, err := s.Hubs.GetGlobalHubs(ctx, nil, nil) res, err := s.Hubs.GetGlobalHubs(ctx, nil, nil)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
@@ -80,23 +76,19 @@ This endpoint will return the recently added content.
package main package main
import( import(
"github.com/LukeHagar/plexgo"
"context" "context"
"github.com/LukeHagar/plexgo"
"github.com/LukeHagar/plexgo/models/operations" "github.com/LukeHagar/plexgo/models/operations"
"log" "log"
) )
func main() { func main() {
ctx := context.Background()
s := plexgo.New( s := plexgo.New(
plexgo.WithSecurity("<YOUR_API_KEY_HERE>"), plexgo.WithSecurity("<YOUR_API_KEY_HERE>"),
plexgo.WithClientID("3381b62b-9ab7-4e37-827b-203e9809eb58"),
plexgo.WithClientName("Plex for Roku"),
plexgo.WithClientVersion("2.4.1"),
plexgo.WithPlatform("Roku"),
plexgo.WithDeviceNickname("Roku 3"),
) )
ctx := context.Background()
res, err := s.Hubs.GetRecentlyAdded(ctx, operations.GetRecentlyAddedRequest{ res, err := s.Hubs.GetRecentlyAdded(ctx, operations.GetRecentlyAddedRequest{
ContentDirectoryID: 470161, ContentDirectoryID: 470161,
SectionID: plexgo.Int64(2), SectionID: plexgo.Int64(2),
@@ -143,22 +135,18 @@ This endpoint will return a list of library specific hubs
package main package main
import( import(
"github.com/LukeHagar/plexgo"
"context" "context"
"github.com/LukeHagar/plexgo"
"log" "log"
) )
func main() { func main() {
ctx := context.Background()
s := plexgo.New( s := plexgo.New(
plexgo.WithSecurity("<YOUR_API_KEY_HERE>"), plexgo.WithSecurity("<YOUR_API_KEY_HERE>"),
plexgo.WithClientID("3381b62b-9ab7-4e37-827b-203e9809eb58"),
plexgo.WithClientName("Plex for Roku"),
plexgo.WithClientVersion("2.4.1"),
plexgo.WithPlatform("Roku"),
plexgo.WithDeviceNickname("Roku 3"),
) )
ctx := context.Background()
res, err := s.Hubs.GetLibraryHubs(ctx, 6728.76, nil, nil) res, err := s.Hubs.GetLibraryHubs(ctx, 6728.76, nil, nil)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)

View File

@@ -32,22 +32,18 @@ This resource returns hash values for local files
package main package main
import( import(
"github.com/LukeHagar/plexgo"
"context" "context"
"github.com/LukeHagar/plexgo"
"log" "log"
) )
func main() { func main() {
ctx := context.Background()
s := plexgo.New( s := plexgo.New(
plexgo.WithSecurity("<YOUR_API_KEY_HERE>"), plexgo.WithSecurity("<YOUR_API_KEY_HERE>"),
plexgo.WithClientID("3381b62b-9ab7-4e37-827b-203e9809eb58"),
plexgo.WithClientName("Plex for Roku"),
plexgo.WithClientVersion("2.4.1"),
plexgo.WithPlatform("Roku"),
plexgo.WithDeviceNickname("Roku 3"),
) )
ctx := context.Background()
res, err := s.Library.GetFileHash(ctx, "file://C:\Image.png&type=13", nil) res, err := s.Library.GetFileHash(ctx, "file://C:\Image.png&type=13", nil)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
@@ -90,23 +86,19 @@ This endpoint will return the recently added content.
package main package main
import( import(
"github.com/LukeHagar/plexgo"
"context" "context"
"github.com/LukeHagar/plexgo"
"github.com/LukeHagar/plexgo/models/operations" "github.com/LukeHagar/plexgo/models/operations"
"log" "log"
) )
func main() { func main() {
ctx := context.Background()
s := plexgo.New( s := plexgo.New(
plexgo.WithSecurity("<YOUR_API_KEY_HERE>"), plexgo.WithSecurity("<YOUR_API_KEY_HERE>"),
plexgo.WithClientID("3381b62b-9ab7-4e37-827b-203e9809eb58"),
plexgo.WithClientName("Plex for Roku"),
plexgo.WithClientVersion("2.4.1"),
plexgo.WithPlatform("Roku"),
plexgo.WithDeviceNickname("Roku 3"),
) )
ctx := context.Background()
res, err := s.Library.GetRecentlyAddedLibrary(ctx, operations.GetRecentlyAddedLibraryRequest{ res, err := s.Library.GetRecentlyAddedLibrary(ctx, operations.GetRecentlyAddedLibraryRequest{
ContentDirectoryID: plexgo.Int64(2), ContentDirectoryID: plexgo.Int64(2),
PinnedContentDirectoryID: []int64{ PinnedContentDirectoryID: []int64{
@@ -174,22 +166,18 @@ This allows a client to provide a rich interface around the media (e.g. allow so
package main package main
import( import(
"github.com/LukeHagar/plexgo"
"context" "context"
"github.com/LukeHagar/plexgo"
"log" "log"
) )
func main() { func main() {
ctx := context.Background()
s := plexgo.New( s := plexgo.New(
plexgo.WithSecurity("<YOUR_API_KEY_HERE>"), plexgo.WithSecurity("<YOUR_API_KEY_HERE>"),
plexgo.WithClientID("3381b62b-9ab7-4e37-827b-203e9809eb58"),
plexgo.WithClientName("Plex for Roku"),
plexgo.WithClientVersion("2.4.1"),
plexgo.WithPlatform("Roku"),
plexgo.WithDeviceNickname("Roku 3"),
) )
ctx := context.Background()
res, err := s.Library.GetAllLibraries(ctx) res, err := s.Library.GetAllLibraries(ctx)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
@@ -268,23 +256,20 @@ Each type in the library comes with a set of filters and sorts, aiding in buildi
package main package main
import( import(
"github.com/LukeHagar/plexgo"
"context" "context"
"github.com/LukeHagar/plexgo"
"github.com/LukeHagar/plexgo/models/operations"
"log" "log"
) )
func main() { func main() {
ctx := context.Background()
s := plexgo.New( s := plexgo.New(
plexgo.WithSecurity("<YOUR_API_KEY_HERE>"), plexgo.WithSecurity("<YOUR_API_KEY_HERE>"),
plexgo.WithClientID("3381b62b-9ab7-4e37-827b-203e9809eb58"),
plexgo.WithClientName("Plex for Roku"),
plexgo.WithClientVersion("2.4.1"),
plexgo.WithPlatform("Roku"),
plexgo.WithDeviceNickname("Roku 3"),
) )
ctx := context.Background() res, err := s.Library.GetLibraryDetails(ctx, 9518, operations.IncludeDetailsZero.ToPointer())
res, err := s.Library.GetLibraryDetails(ctx, 9518, nil)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
@@ -325,22 +310,18 @@ Delete a library using a specific section id
package main package main
import( import(
"github.com/LukeHagar/plexgo"
"context" "context"
"github.com/LukeHagar/plexgo"
"log" "log"
) )
func main() { func main() {
ctx := context.Background()
s := plexgo.New( s := plexgo.New(
plexgo.WithSecurity("<YOUR_API_KEY_HERE>"), plexgo.WithSecurity("<YOUR_API_KEY_HERE>"),
plexgo.WithClientID("3381b62b-9ab7-4e37-827b-203e9809eb58"),
plexgo.WithClientName("Plex for Roku"),
plexgo.WithClientVersion("2.4.1"),
plexgo.WithPlatform("Roku"),
plexgo.WithDeviceNickname("Roku 3"),
) )
ctx := context.Background()
res, err := s.Library.DeleteLibrary(ctx, 9518) res, err := s.Library.DeleteLibrary(ctx, 9518)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
@@ -393,6 +374,7 @@ Fetches details from a specific section of the library identified by a section k
- `resolution`: Items categorized by resolution. - `resolution`: Items categorized by resolution.
- `firstCharacter`: Items categorized by the first letter. - `firstCharacter`: Items categorized by the first letter.
- `folder`: Items categorized by folder. - `folder`: Items categorized by folder.
- `albums`: Items categorized by album.
### Example Usage ### Example Usage
@@ -401,23 +383,19 @@ Fetches details from a specific section of the library identified by a section k
package main package main
import( import(
"github.com/LukeHagar/plexgo"
"context" "context"
"github.com/LukeHagar/plexgo"
"github.com/LukeHagar/plexgo/models/operations" "github.com/LukeHagar/plexgo/models/operations"
"log" "log"
) )
func main() { func main() {
ctx := context.Background()
s := plexgo.New( s := plexgo.New(
plexgo.WithSecurity("<YOUR_API_KEY_HERE>"), plexgo.WithSecurity("<YOUR_API_KEY_HERE>"),
plexgo.WithClientID("3381b62b-9ab7-4e37-827b-203e9809eb58"),
plexgo.WithClientName("Plex for Roku"),
plexgo.WithClientVersion("2.4.1"),
plexgo.WithPlatform("Roku"),
plexgo.WithDeviceNickname("Roku 3"),
) )
ctx := context.Background()
res, err := s.Library.GetLibraryItems(ctx, operations.GetLibraryItemsRequest{ res, err := s.Library.GetLibraryItems(ctx, operations.GetLibraryItemsRequest{
Tag: operations.TagEdition, Tag: operations.TagEdition,
IncludeGuids: operations.IncludeGuidsEnable.ToPointer(), IncludeGuids: operations.IncludeGuidsEnable.ToPointer(),
@@ -467,23 +445,19 @@ This endpoint Refreshes all the Metadata of the library.
package main package main
import( import(
"github.com/LukeHagar/plexgo"
"context" "context"
"github.com/LukeHagar/plexgo"
"github.com/LukeHagar/plexgo/models/operations" "github.com/LukeHagar/plexgo/models/operations"
"log" "log"
) )
func main() { func main() {
ctx := context.Background()
s := plexgo.New( s := plexgo.New(
plexgo.WithSecurity("<YOUR_API_KEY_HERE>"), plexgo.WithSecurity("<YOUR_API_KEY_HERE>"),
plexgo.WithClientID("3381b62b-9ab7-4e37-827b-203e9809eb58"),
plexgo.WithClientName("Plex for Roku"),
plexgo.WithClientVersion("2.4.1"),
plexgo.WithPlatform("Roku"),
plexgo.WithDeviceNickname("Roku 3"),
) )
ctx := context.Background()
res, err := s.Library.GetRefreshLibraryMetadata(ctx, 9518, operations.ForceOne.ToPointer()) res, err := s.Library.GetRefreshLibraryMetadata(ctx, 9518, operations.ForceOne.ToPointer())
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
@@ -543,23 +517,19 @@ Each type in the library comes with a set of filters and sorts, aiding in buildi
package main package main
import( import(
"github.com/LukeHagar/plexgo"
"context" "context"
"github.com/LukeHagar/plexgo"
"github.com/LukeHagar/plexgo/models/operations" "github.com/LukeHagar/plexgo/models/operations"
"log" "log"
) )
func main() { func main() {
ctx := context.Background()
s := plexgo.New( s := plexgo.New(
plexgo.WithSecurity("<YOUR_API_KEY_HERE>"), plexgo.WithSecurity("<YOUR_API_KEY_HERE>"),
plexgo.WithClientID("3381b62b-9ab7-4e37-827b-203e9809eb58"),
plexgo.WithClientName("Plex for Roku"),
plexgo.WithClientVersion("2.4.1"),
plexgo.WithPlatform("Roku"),
plexgo.WithDeviceNickname("Roku 3"),
) )
ctx := context.Background()
res, err := s.Library.GetSearchLibrary(ctx, 9518, operations.GetSearchLibraryQueryParamTypeTvShow) res, err := s.Library.GetSearchLibrary(ctx, 9518, operations.GetSearchLibraryQueryParamTypeTvShow)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
@@ -602,25 +572,22 @@ Search the provided query across all library sections, or a single section, and
package main package main
import( import(
"github.com/LukeHagar/plexgo"
"context" "context"
"github.com/LukeHagar/plexgo"
"github.com/LukeHagar/plexgo/models/operations" "github.com/LukeHagar/plexgo/models/operations"
"log" "log"
) )
func main() { func main() {
ctx := context.Background()
s := plexgo.New( s := plexgo.New(
plexgo.WithSecurity("<YOUR_API_KEY_HERE>"), plexgo.WithSecurity("<YOUR_API_KEY_HERE>"),
plexgo.WithClientID("3381b62b-9ab7-4e37-827b-203e9809eb58"),
plexgo.WithClientName("Plex for Roku"),
plexgo.WithClientVersion("2.4.1"),
plexgo.WithPlatform("Roku"),
plexgo.WithDeviceNickname("Roku 3"),
) )
ctx := context.Background()
res, err := s.Library.GetSearchAllLibraries(ctx, operations.GetSearchAllLibrariesRequest{ res, err := s.Library.GetSearchAllLibraries(ctx, operations.GetSearchAllLibrariesRequest{
Query: "<value>", Query: "<value>",
ClientID: "3381b62b-9ab7-4e37-827b-203e9809eb58",
SearchTypes: []operations.SearchTypes{ SearchTypes: []operations.SearchTypes{
operations.SearchTypesPeople, operations.SearchTypesPeople,
}, },
@@ -667,22 +634,18 @@ This endpoint will return the metadata of a library item specified with the rati
package main package main
import( import(
"github.com/LukeHagar/plexgo"
"context" "context"
"github.com/LukeHagar/plexgo"
"log" "log"
) )
func main() { func main() {
ctx := context.Background()
s := plexgo.New( s := plexgo.New(
plexgo.WithSecurity("<YOUR_API_KEY_HERE>"), plexgo.WithSecurity("<YOUR_API_KEY_HERE>"),
plexgo.WithClientID("3381b62b-9ab7-4e37-827b-203e9809eb58"),
plexgo.WithClientName("Plex for Roku"),
plexgo.WithClientVersion("2.4.1"),
plexgo.WithPlatform("Roku"),
plexgo.WithDeviceNickname("Roku 3"),
) )
ctx := context.Background()
res, err := s.Library.GetMetaDataByRatingKey(ctx, 9518) res, err := s.Library.GetMetaDataByRatingKey(ctx, 9518)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
@@ -724,22 +687,18 @@ This endpoint will return the children of of a library item specified with the r
package main package main
import( import(
"github.com/LukeHagar/plexgo"
"context" "context"
"github.com/LukeHagar/plexgo"
"log" "log"
) )
func main() { func main() {
ctx := context.Background()
s := plexgo.New( s := plexgo.New(
plexgo.WithSecurity("<YOUR_API_KEY_HERE>"), plexgo.WithSecurity("<YOUR_API_KEY_HERE>"),
plexgo.WithClientID("3381b62b-9ab7-4e37-827b-203e9809eb58"),
plexgo.WithClientName("Plex for Roku"),
plexgo.WithClientVersion("2.4.1"),
plexgo.WithPlatform("Roku"),
plexgo.WithDeviceNickname("Roku 3"),
) )
ctx := context.Background()
res, err := s.Library.GetMetadataChildren(ctx, 1539.14, plexgo.String("Stream")) res, err := s.Library.GetMetadataChildren(ctx, 1539.14, plexgo.String("Stream"))
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
@@ -782,23 +741,19 @@ This endpoint will return the top watched content from libraries of a certain ty
package main package main
import( import(
"github.com/LukeHagar/plexgo"
"context" "context"
"github.com/LukeHagar/plexgo"
"github.com/LukeHagar/plexgo/models/operations" "github.com/LukeHagar/plexgo/models/operations"
"log" "log"
) )
func main() { func main() {
ctx := context.Background()
s := plexgo.New( s := plexgo.New(
plexgo.WithSecurity("<YOUR_API_KEY_HERE>"), plexgo.WithSecurity("<YOUR_API_KEY_HERE>"),
plexgo.WithClientID("3381b62b-9ab7-4e37-827b-203e9809eb58"),
plexgo.WithClientName("Plex for Roku"),
plexgo.WithClientVersion("2.4.1"),
plexgo.WithPlatform("Roku"),
plexgo.WithDeviceNickname("Roku 3"),
) )
ctx := context.Background()
res, err := s.Library.GetTopWatchedContent(ctx, operations.GetTopWatchedContentQueryParamTypeTvShow, plexgo.Int64(1)) res, err := s.Library.GetTopWatchedContent(ctx, operations.GetTopWatchedContentQueryParamTypeTvShow, plexgo.Int64(1))
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
@@ -841,22 +796,18 @@ This endpoint will return the on deck content.
package main package main
import( import(
"github.com/LukeHagar/plexgo"
"context" "context"
"github.com/LukeHagar/plexgo"
"log" "log"
) )
func main() { func main() {
ctx := context.Background()
s := plexgo.New( s := plexgo.New(
plexgo.WithSecurity("<YOUR_API_KEY_HERE>"), plexgo.WithSecurity("<YOUR_API_KEY_HERE>"),
plexgo.WithClientID("3381b62b-9ab7-4e37-827b-203e9809eb58"),
plexgo.WithClientName("Plex for Roku"),
plexgo.WithClientVersion("2.4.1"),
plexgo.WithPlatform("Roku"),
plexgo.WithDeviceNickname("Roku 3"),
) )
ctx := context.Background()
res, err := s.Library.GetOnDeck(ctx) res, err := s.Library.GetOnDeck(ctx)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)

View File

@@ -23,23 +23,19 @@ This endpoint will write a single-line log message, including a level and source
package main package main
import( import(
"github.com/LukeHagar/plexgo"
"context" "context"
"github.com/LukeHagar/plexgo"
"github.com/LukeHagar/plexgo/models/operations" "github.com/LukeHagar/plexgo/models/operations"
"log" "log"
) )
func main() { func main() {
ctx := context.Background()
s := plexgo.New( s := plexgo.New(
plexgo.WithSecurity("<YOUR_API_KEY_HERE>"), plexgo.WithSecurity("<YOUR_API_KEY_HERE>"),
plexgo.WithClientID("3381b62b-9ab7-4e37-827b-203e9809eb58"),
plexgo.WithClientName("Plex for Roku"),
plexgo.WithClientVersion("2.4.1"),
plexgo.WithPlatform("Roku"),
plexgo.WithDeviceNickname("Roku 3"),
) )
ctx := context.Background()
res, err := s.Log.LogLine(ctx, operations.LevelThree, "Test log message", "Postman") res, err := s.Log.LogLine(ctx, operations.LevelThree, "Test log message", "Postman")
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
@@ -103,22 +99,18 @@ Ensure each parameter is properly URL-encoded to avoid interpretation issues.
package main package main
import( import(
"github.com/LukeHagar/plexgo"
"context" "context"
"github.com/LukeHagar/plexgo"
"log" "log"
) )
func main() { func main() {
ctx := context.Background()
s := plexgo.New( s := plexgo.New(
plexgo.WithSecurity("<YOUR_API_KEY_HERE>"), plexgo.WithSecurity("<YOUR_API_KEY_HERE>"),
plexgo.WithClientID("3381b62b-9ab7-4e37-827b-203e9809eb58"),
plexgo.WithClientName("Plex for Roku"),
plexgo.WithClientVersion("2.4.1"),
plexgo.WithPlatform("Roku"),
plexgo.WithDeviceNickname("Roku 3"),
) )
ctx := context.Background()
res, err := s.Log.LogMultiLine(ctx, "level=4&message=Test%20message%201&source=postman\n" + res, err := s.Log.LogMultiLine(ctx, "level=4&message=Test%20message%201&source=postman\n" +
"level=3&message=Test%20message%202&source=postman\n" + "level=3&message=Test%20message%202&source=postman\n" +
"level=1&message=Test%20message%203&source=postman") "level=1&message=Test%20message%203&source=postman")
@@ -162,22 +154,18 @@ This endpoint will enable all Plex Media Serverlogs to be sent to the Papertrail
package main package main
import( import(
"github.com/LukeHagar/plexgo"
"context" "context"
"github.com/LukeHagar/plexgo"
"log" "log"
) )
func main() { func main() {
ctx := context.Background()
s := plexgo.New( s := plexgo.New(
plexgo.WithSecurity("<YOUR_API_KEY_HERE>"), plexgo.WithSecurity("<YOUR_API_KEY_HERE>"),
plexgo.WithClientID("3381b62b-9ab7-4e37-827b-203e9809eb58"),
plexgo.WithClientName("Plex for Roku"),
plexgo.WithClientVersion("2.4.1"),
plexgo.WithPlatform("Roku"),
plexgo.WithDeviceNickname("Roku 3"),
) )
ctx := context.Background()
res, err := s.Log.EnablePaperTrail(ctx) res, err := s.Log.EnablePaperTrail(ctx)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)

View File

@@ -24,22 +24,18 @@ This will mark the provided media key as Played.
package main package main
import( import(
"github.com/LukeHagar/plexgo"
"context" "context"
"github.com/LukeHagar/plexgo"
"log" "log"
) )
func main() { func main() {
ctx := context.Background()
s := plexgo.New( s := plexgo.New(
plexgo.WithSecurity("<YOUR_API_KEY_HERE>"), plexgo.WithSecurity("<YOUR_API_KEY_HERE>"),
plexgo.WithClientID("3381b62b-9ab7-4e37-827b-203e9809eb58"),
plexgo.WithClientName("Plex for Roku"),
plexgo.WithClientVersion("2.4.1"),
plexgo.WithPlatform("Roku"),
plexgo.WithDeviceNickname("Roku 3"),
) )
ctx := context.Background()
res, err := s.Media.MarkPlayed(ctx, 59398) res, err := s.Media.MarkPlayed(ctx, 59398)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
@@ -80,22 +76,18 @@ This will mark the provided media key as Unplayed.
package main package main
import( import(
"github.com/LukeHagar/plexgo"
"context" "context"
"github.com/LukeHagar/plexgo"
"log" "log"
) )
func main() { func main() {
ctx := context.Background()
s := plexgo.New( s := plexgo.New(
plexgo.WithSecurity("<YOUR_API_KEY_HERE>"), plexgo.WithSecurity("<YOUR_API_KEY_HERE>"),
plexgo.WithClientID("3381b62b-9ab7-4e37-827b-203e9809eb58"),
plexgo.WithClientName("Plex for Roku"),
plexgo.WithClientVersion("2.4.1"),
plexgo.WithPlatform("Roku"),
plexgo.WithDeviceNickname("Roku 3"),
) )
ctx := context.Background()
res, err := s.Media.MarkUnplayed(ctx, 59398) res, err := s.Media.MarkUnplayed(ctx, 59398)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
@@ -137,22 +129,18 @@ This API command can be used to update the play progress of a media item.
package main package main
import( import(
"github.com/LukeHagar/plexgo"
"context" "context"
"github.com/LukeHagar/plexgo"
"log" "log"
) )
func main() { func main() {
ctx := context.Background()
s := plexgo.New( s := plexgo.New(
plexgo.WithSecurity("<YOUR_API_KEY_HERE>"), plexgo.WithSecurity("<YOUR_API_KEY_HERE>"),
plexgo.WithClientID("3381b62b-9ab7-4e37-827b-203e9809eb58"),
plexgo.WithClientName("Plex for Roku"),
plexgo.WithClientVersion("2.4.1"),
plexgo.WithPlatform("Roku"),
plexgo.WithDeviceNickname("Roku 3"),
) )
ctx := context.Background()
res, err := s.Media.UpdatePlayProgress(ctx, "<key>", 90000, "played") res, err := s.Media.UpdatePlayProgress(ctx, "<key>", 90000, "played")
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
@@ -195,23 +183,19 @@ Gets the banner image of the media item
package main package main
import( import(
"github.com/LukeHagar/plexgo"
"context" "context"
"github.com/LukeHagar/plexgo"
"github.com/LukeHagar/plexgo/models/operations" "github.com/LukeHagar/plexgo/models/operations"
"log" "log"
) )
func main() { func main() {
ctx := context.Background()
s := plexgo.New( s := plexgo.New(
plexgo.WithSecurity("<YOUR_API_KEY_HERE>"), plexgo.WithSecurity("<YOUR_API_KEY_HERE>"),
plexgo.WithClientID("3381b62b-9ab7-4e37-827b-203e9809eb58"),
plexgo.WithClientName("Plex for Roku"),
plexgo.WithClientVersion("2.4.1"),
plexgo.WithPlatform("Roku"),
plexgo.WithDeviceNickname("Roku 3"),
) )
ctx := context.Background()
res, err := s.Media.GetBannerImage(ctx, operations.GetBannerImageRequest{ res, err := s.Media.GetBannerImage(ctx, operations.GetBannerImageRequest{
RatingKey: 9518, RatingKey: 9518,
Width: 396, Width: 396,
@@ -259,23 +243,19 @@ Gets the thumbnail image of the media item
package main package main
import( import(
"github.com/LukeHagar/plexgo"
"context" "context"
"github.com/LukeHagar/plexgo"
"github.com/LukeHagar/plexgo/models/operations" "github.com/LukeHagar/plexgo/models/operations"
"log" "log"
) )
func main() { func main() {
ctx := context.Background()
s := plexgo.New( s := plexgo.New(
plexgo.WithSecurity("<YOUR_API_KEY_HERE>"), plexgo.WithSecurity("<YOUR_API_KEY_HERE>"),
plexgo.WithClientID("3381b62b-9ab7-4e37-827b-203e9809eb58"),
plexgo.WithClientName("Plex for Roku"),
plexgo.WithClientVersion("2.4.1"),
plexgo.WithPlatform("Roku"),
plexgo.WithDeviceNickname("Roku 3"),
) )
ctx := context.Background()
res, err := s.Media.GetThumbImage(ctx, operations.GetThumbImageRequest{ res, err := s.Media.GetThumbImage(ctx, operations.GetThumbImageRequest{
RatingKey: 9518, RatingKey: 9518,
Width: 396, Width: 396,

View File

@@ -34,28 +34,24 @@ Create a new playlist. By default the playlist is blank. To create a playlist al
package main package main
import( import(
"github.com/LukeHagar/plexgo"
"context" "context"
"github.com/LukeHagar/plexgo"
"github.com/LukeHagar/plexgo/models/operations" "github.com/LukeHagar/plexgo/models/operations"
"log" "log"
) )
func main() { func main() {
ctx := context.Background()
s := plexgo.New( s := plexgo.New(
plexgo.WithSecurity("<YOUR_API_KEY_HERE>"), plexgo.WithSecurity("<YOUR_API_KEY_HERE>"),
plexgo.WithClientID("3381b62b-9ab7-4e37-827b-203e9809eb58"),
plexgo.WithClientName("Plex for Roku"),
plexgo.WithClientVersion("2.4.1"),
plexgo.WithPlatform("Roku"),
plexgo.WithDeviceNickname("Roku 3"),
) )
ctx := context.Background()
res, err := s.Playlists.CreatePlaylist(ctx, operations.CreatePlaylistRequest{ res, err := s.Playlists.CreatePlaylist(ctx, operations.CreatePlaylistRequest{
Title: "<value>", Title: "<value>",
Type: operations.CreatePlaylistQueryParamTypePhoto, Type: operations.CreatePlaylistQueryParamTypePhoto,
Smart: operations.SmartOne, Smart: operations.SmartOne,
URI: "https://inborn-brochure.biz", URI: "https://hoarse-testing.info/",
}) })
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
@@ -96,22 +92,18 @@ Get All Playlists given the specified filters.
package main package main
import( import(
"github.com/LukeHagar/plexgo"
"context" "context"
"github.com/LukeHagar/plexgo"
"log" "log"
) )
func main() { func main() {
ctx := context.Background()
s := plexgo.New( s := plexgo.New(
plexgo.WithSecurity("<YOUR_API_KEY_HERE>"), plexgo.WithSecurity("<YOUR_API_KEY_HERE>"),
plexgo.WithClientID("3381b62b-9ab7-4e37-827b-203e9809eb58"),
plexgo.WithClientName("Plex for Roku"),
plexgo.WithClientVersion("2.4.1"),
plexgo.WithPlatform("Roku"),
plexgo.WithDeviceNickname("Roku 3"),
) )
ctx := context.Background()
res, err := s.Playlists.GetPlaylists(ctx, nil, nil) res, err := s.Playlists.GetPlaylists(ctx, nil, nil)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
@@ -155,22 +147,18 @@ Smart playlist details contain the `content` attribute. This is the content URI
package main package main
import( import(
"github.com/LukeHagar/plexgo"
"context" "context"
"github.com/LukeHagar/plexgo"
"log" "log"
) )
func main() { func main() {
ctx := context.Background()
s := plexgo.New( s := plexgo.New(
plexgo.WithSecurity("<YOUR_API_KEY_HERE>"), plexgo.WithSecurity("<YOUR_API_KEY_HERE>"),
plexgo.WithClientID("3381b62b-9ab7-4e37-827b-203e9809eb58"),
plexgo.WithClientName("Plex for Roku"),
plexgo.WithClientVersion("2.4.1"),
plexgo.WithPlatform("Roku"),
plexgo.WithDeviceNickname("Roku 3"),
) )
ctx := context.Background()
res, err := s.Playlists.GetPlaylist(ctx, 4109.48) res, err := s.Playlists.GetPlaylist(ctx, 4109.48)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
@@ -212,22 +200,18 @@ This endpoint will delete a playlist
package main package main
import( import(
"github.com/LukeHagar/plexgo"
"context" "context"
"github.com/LukeHagar/plexgo"
"log" "log"
) )
func main() { func main() {
ctx := context.Background()
s := plexgo.New( s := plexgo.New(
plexgo.WithSecurity("<YOUR_API_KEY_HERE>"), plexgo.WithSecurity("<YOUR_API_KEY_HERE>"),
plexgo.WithClientID("3381b62b-9ab7-4e37-827b-203e9809eb58"),
plexgo.WithClientName("Plex for Roku"),
plexgo.WithClientVersion("2.4.1"),
plexgo.WithPlatform("Roku"),
plexgo.WithDeviceNickname("Roku 3"),
) )
ctx := context.Background()
res, err := s.Playlists.DeletePlaylist(ctx, 216.22) res, err := s.Playlists.DeletePlaylist(ctx, 216.22)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
@@ -269,22 +253,18 @@ From PMS version 1.9.1 clients can also edit playlist metadata using this endpoi
package main package main
import( import(
"github.com/LukeHagar/plexgo"
"context" "context"
"github.com/LukeHagar/plexgo"
"log" "log"
) )
func main() { func main() {
ctx := context.Background()
s := plexgo.New( s := plexgo.New(
plexgo.WithSecurity("<YOUR_API_KEY_HERE>"), plexgo.WithSecurity("<YOUR_API_KEY_HERE>"),
plexgo.WithClientID("3381b62b-9ab7-4e37-827b-203e9809eb58"),
plexgo.WithClientName("Plex for Roku"),
plexgo.WithClientVersion("2.4.1"),
plexgo.WithPlatform("Roku"),
plexgo.WithDeviceNickname("Roku 3"),
) )
ctx := context.Background()
res, err := s.Playlists.UpdatePlaylist(ctx, 3915, nil, nil) res, err := s.Playlists.UpdatePlaylist(ctx, 3915, nil, nil)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
@@ -331,23 +311,19 @@ Note that for dumb playlists, items have a `playlistItemID` attribute which is u
package main package main
import( import(
"github.com/LukeHagar/plexgo"
"context" "context"
"github.com/LukeHagar/plexgo"
"github.com/LukeHagar/plexgo/models/operations" "github.com/LukeHagar/plexgo/models/operations"
"log" "log"
) )
func main() { func main() {
ctx := context.Background()
s := plexgo.New( s := plexgo.New(
plexgo.WithSecurity("<YOUR_API_KEY_HERE>"), plexgo.WithSecurity("<YOUR_API_KEY_HERE>"),
plexgo.WithClientID("3381b62b-9ab7-4e37-827b-203e9809eb58"),
plexgo.WithClientName("Plex for Roku"),
plexgo.WithClientVersion("2.4.1"),
plexgo.WithPlatform("Roku"),
plexgo.WithDeviceNickname("Roku 3"),
) )
ctx := context.Background()
res, err := s.Playlists.GetPlaylistContents(ctx, 5004.46, operations.GetPlaylistContentsQueryParamTypeTvShow) res, err := s.Playlists.GetPlaylistContents(ctx, 5004.46, operations.GetPlaylistContentsQueryParamTypeTvShow)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
@@ -390,22 +366,18 @@ Clears a playlist, only works with dumb playlists. Returns the playlist.
package main package main
import( import(
"github.com/LukeHagar/plexgo"
"context" "context"
"github.com/LukeHagar/plexgo"
"log" "log"
) )
func main() { func main() {
ctx := context.Background()
s := plexgo.New( s := plexgo.New(
plexgo.WithSecurity("<YOUR_API_KEY_HERE>"), plexgo.WithSecurity("<YOUR_API_KEY_HERE>"),
plexgo.WithClientID("3381b62b-9ab7-4e37-827b-203e9809eb58"),
plexgo.WithClientName("Plex for Roku"),
plexgo.WithClientVersion("2.4.1"),
plexgo.WithPlatform("Roku"),
plexgo.WithDeviceNickname("Roku 3"),
) )
ctx := context.Background()
res, err := s.Playlists.ClearPlaylistContents(ctx, 1893.18) res, err := s.Playlists.ClearPlaylistContents(ctx, 1893.18)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
@@ -448,22 +420,18 @@ With a smart playlist, passing a new `uri` parameter replaces the rules for the
package main package main
import( import(
"github.com/LukeHagar/plexgo"
"context" "context"
"github.com/LukeHagar/plexgo"
"log" "log"
) )
func main() { func main() {
ctx := context.Background()
s := plexgo.New( s := plexgo.New(
plexgo.WithSecurity("<YOUR_API_KEY_HERE>"), plexgo.WithSecurity("<YOUR_API_KEY_HERE>"),
plexgo.WithClientID("3381b62b-9ab7-4e37-827b-203e9809eb58"),
plexgo.WithClientName("Plex for Roku"),
plexgo.WithClientVersion("2.4.1"),
plexgo.WithPlatform("Roku"),
plexgo.WithDeviceNickname("Roku 3"),
) )
ctx := context.Background()
res, err := s.Playlists.AddPlaylistContents(ctx, 8502.01, "server://12345/com.plexapp.plugins.library/library/metadata/1", plexgo.Float64(123)) res, err := s.Playlists.AddPlaylistContents(ctx, 8502.01, "server://12345/com.plexapp.plugins.library/library/metadata/1", plexgo.Float64(123))
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
@@ -507,23 +475,19 @@ Imports m3u playlists by passing a path on the server to scan for m3u-formatted
package main package main
import( import(
"github.com/LukeHagar/plexgo"
"context" "context"
"github.com/LukeHagar/plexgo"
"github.com/LukeHagar/plexgo/models/operations" "github.com/LukeHagar/plexgo/models/operations"
"log" "log"
) )
func main() { func main() {
ctx := context.Background()
s := plexgo.New( s := plexgo.New(
plexgo.WithSecurity("<YOUR_API_KEY_HERE>"), plexgo.WithSecurity("<YOUR_API_KEY_HERE>"),
plexgo.WithClientID("3381b62b-9ab7-4e37-827b-203e9809eb58"),
plexgo.WithClientName("Plex for Roku"),
plexgo.WithClientVersion("2.4.1"),
plexgo.WithPlatform("Roku"),
plexgo.WithDeviceNickname("Roku 3"),
) )
ctx := context.Background()
res, err := s.Playlists.UploadPlaylist(ctx, "/home/barkley/playlist.m3u", operations.QueryParamForceZero, 1) res, err := s.Playlists.UploadPlaylist(ctx, "/home/barkley/playlist.m3u", operations.QueryParamForceZero, 1)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)

View File

@@ -26,22 +26,18 @@ Get Companions Data
package main package main
import( import(
"github.com/LukeHagar/plexgo"
"context" "context"
"github.com/LukeHagar/plexgo"
"log" "log"
) )
func main() { func main() {
ctx := context.Background()
s := plexgo.New( s := plexgo.New(
plexgo.WithSecurity("<YOUR_API_KEY_HERE>"), plexgo.WithSecurity("<YOUR_API_KEY_HERE>"),
plexgo.WithClientID("3381b62b-9ab7-4e37-827b-203e9809eb58"),
plexgo.WithClientName("Plex for Roku"),
plexgo.WithClientVersion("2.4.1"),
plexgo.WithPlatform("Roku"),
plexgo.WithDeviceNickname("Roku 3"),
) )
ctx := context.Background()
res, err := s.Plex.GetCompanionsData(ctx) res, err := s.Plex.GetCompanionsData(ctx)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
@@ -81,22 +77,18 @@ Get friends of provided auth token.
package main package main
import( import(
"github.com/LukeHagar/plexgo"
"context" "context"
"github.com/LukeHagar/plexgo"
"log" "log"
) )
func main() { func main() {
ctx := context.Background()
s := plexgo.New( s := plexgo.New(
plexgo.WithSecurity("<YOUR_API_KEY_HERE>"), plexgo.WithSecurity("<YOUR_API_KEY_HERE>"),
plexgo.WithClientID("3381b62b-9ab7-4e37-827b-203e9809eb58"),
plexgo.WithClientName("Plex for Roku"),
plexgo.WithClientVersion("2.4.1"),
plexgo.WithPlatform("Roku"),
plexgo.WithDeviceNickname("Roku 3"),
) )
ctx := context.Background()
res, err := s.Plex.GetUserFriends(ctx) res, err := s.Plex.GetUserFriends(ctx)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
@@ -136,21 +128,16 @@ Returns the geolocation and locale data of the caller
package main package main
import( import(
"github.com/LukeHagar/plexgo"
"context" "context"
"github.com/LukeHagar/plexgo"
"log" "log"
) )
func main() { func main() {
s := plexgo.New(
plexgo.WithClientID("3381b62b-9ab7-4e37-827b-203e9809eb58"),
plexgo.WithClientName("Plex for Roku"),
plexgo.WithClientVersion("2.4.1"),
plexgo.WithPlatform("Roku"),
plexgo.WithDeviceNickname("Roku 3"),
)
ctx := context.Background() ctx := context.Background()
s := plexgo.New()
res, err := s.Plex.GetGeoData(ctx) res, err := s.Plex.GetGeoData(ctx)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
@@ -190,22 +177,18 @@ Retrieves the home data for the authenticated user, including details like home
package main package main
import( import(
"github.com/LukeHagar/plexgo"
"context" "context"
"github.com/LukeHagar/plexgo"
"log" "log"
) )
func main() { func main() {
ctx := context.Background()
s := plexgo.New( s := plexgo.New(
plexgo.WithSecurity("<YOUR_API_KEY_HERE>"), plexgo.WithSecurity("<YOUR_API_KEY_HERE>"),
plexgo.WithClientID("3381b62b-9ab7-4e37-827b-203e9809eb58"),
plexgo.WithClientName("Plex for Roku"),
plexgo.WithClientVersion("2.4.1"),
plexgo.WithPlatform("Roku"),
plexgo.WithDeviceNickname("Roku 3"),
) )
ctx := context.Background()
res, err := s.Plex.GetHomeData(ctx) res, err := s.Plex.GetHomeData(ctx)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
@@ -245,24 +228,20 @@ Get Plex server access tokens and server connections
package main package main
import( import(
"github.com/LukeHagar/plexgo"
"context" "context"
"github.com/LukeHagar/plexgo"
"github.com/LukeHagar/plexgo/models/operations" "github.com/LukeHagar/plexgo/models/operations"
"log" "log"
) )
func main() { func main() {
ctx := context.Background()
s := plexgo.New( s := plexgo.New(
plexgo.WithSecurity("<YOUR_API_KEY_HERE>"), plexgo.WithSecurity("<YOUR_API_KEY_HERE>"),
plexgo.WithClientID("3381b62b-9ab7-4e37-827b-203e9809eb58"),
plexgo.WithClientName("Plex for Roku"),
plexgo.WithClientVersion("2.4.1"),
plexgo.WithPlatform("Roku"),
plexgo.WithDeviceNickname("Roku 3"),
) )
ctx := context.Background() res, err := s.Plex.GetServerResources(ctx, "3381b62b-9ab7-4e37-827b-203e9809eb58", operations.IncludeHTTPSEnable.ToPointer(), operations.IncludeRelayEnable.ToPointer(), operations.IncludeIPv6Enable.ToPointer())
res, err := s.Plex.GetServerResources(ctx, operations.IncludeHTTPSEnable.ToPointer(), operations.IncludeRelayEnable.ToPointer(), operations.IncludeIPv6Enable.ToPointer(), plexgo.String("3381b62b-9ab7-4e37-827b-203e9809eb58"))
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
@@ -277,10 +256,10 @@ func main() {
| Parameter | Type | Required | Description | Example | | Parameter | Type | Required | Description | Example |
| ------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------ | | ------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------ |
| `ctx` | [context.Context](https://pkg.go.dev/context#Context) | :heavy_check_mark: | The context to use for the request. | | | `ctx` | [context.Context](https://pkg.go.dev/context#Context) | :heavy_check_mark: | The context to use for the request. | |
| `clientID` | *string* | :heavy_check_mark: | An opaque identifier unique to the client (UUID, serial number, or other unique device ID) | 3381b62b-9ab7-4e37-827b-203e9809eb58 |
| `includeHTTPS` | [*operations.IncludeHTTPS](../../models/operations/includehttps.md) | :heavy_minus_sign: | Include Https entries in the results | 1 | | `includeHTTPS` | [*operations.IncludeHTTPS](../../models/operations/includehttps.md) | :heavy_minus_sign: | Include Https entries in the results | 1 |
| `includeRelay` | [*operations.IncludeRelay](../../models/operations/includerelay.md) | :heavy_minus_sign: | Include Relay addresses in the results <br/>E.g: https://10-0-0-25.bbf8e10c7fa20447cacee74cd9914cde.plex.direct:32400<br/> | 1 | | `includeRelay` | [*operations.IncludeRelay](../../models/operations/includerelay.md) | :heavy_minus_sign: | Include Relay addresses in the results <br/>E.g: https://10-0-0-25.bbf8e10c7fa20447cacee74cd9914cde.plex.direct:32400<br/> | 1 |
| `includeIPv6` | [*operations.IncludeIPv6](../../models/operations/includeipv6.md) | :heavy_minus_sign: | Include IPv6 entries in the results | 1 | | `includeIPv6` | [*operations.IncludeIPv6](../../models/operations/includeipv6.md) | :heavy_minus_sign: | Include IPv6 entries in the results | 1 |
| `clientID` | **string* | :heavy_minus_sign: | An opaque identifier unique to the client (UUID, serial number, or other unique device ID) | 3381b62b-9ab7-4e37-827b-203e9809eb58 |
| `opts` | [][operations.Option](../../models/operations/option.md) | :heavy_minus_sign: | The options for this request. | | | `opts` | [][operations.Option](../../models/operations/option.md) | :heavy_minus_sign: | The options for this request. | |
### Response ### Response
@@ -305,23 +284,25 @@ Retrieve a Pin ID from Plex.tv to use for authentication flows
package main package main
import( import(
"github.com/LukeHagar/plexgo"
"context" "context"
"github.com/LukeHagar/plexgo"
"github.com/LukeHagar/plexgo/models/operations" "github.com/LukeHagar/plexgo/models/operations"
"log" "log"
) )
func main() { func main() {
s := plexgo.New(
plexgo.WithClientID("3381b62b-9ab7-4e37-827b-203e9809eb58"),
plexgo.WithClientName("Plex for Roku"),
plexgo.WithClientVersion("2.4.1"),
plexgo.WithPlatform("Roku"),
plexgo.WithDeviceNickname("Roku 3"),
)
ctx := context.Background() ctx := context.Background()
res, err := s.Plex.GetPin(ctx, operations.GetPinRequest{})
s := plexgo.New()
res, err := s.Plex.GetPin(ctx, operations.GetPinRequest{
Strong: plexgo.Bool(false),
ClientID: "3381b62b-9ab7-4e37-827b-203e9809eb58",
ClientName: plexgo.String("Plex for Roku"),
DeviceNickname: plexgo.String("Roku 3"),
ClientVersion: plexgo.String("2.4.1"),
Platform: plexgo.String("Roku"),
})
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
@@ -360,24 +341,24 @@ Retrieve an Access Token from Plex.tv after the Pin has been authenticated
package main package main
import( import(
"github.com/LukeHagar/plexgo"
"context" "context"
"github.com/LukeHagar/plexgo"
"github.com/LukeHagar/plexgo/models/operations" "github.com/LukeHagar/plexgo/models/operations"
"log" "log"
) )
func main() { func main() {
s := plexgo.New(
plexgo.WithClientID("3381b62b-9ab7-4e37-827b-203e9809eb58"),
plexgo.WithClientName("Plex for Roku"),
plexgo.WithClientVersion("2.4.1"),
plexgo.WithPlatform("Roku"),
plexgo.WithDeviceNickname("Roku 3"),
)
ctx := context.Background() ctx := context.Background()
s := plexgo.New()
res, err := s.Plex.GetTokenByPinID(ctx, operations.GetTokenByPinIDRequest{ res, err := s.Plex.GetTokenByPinID(ctx, operations.GetTokenByPinIDRequest{
PinID: 408895, PinID: 408895,
ClientID: "3381b62b-9ab7-4e37-827b-203e9809eb58",
ClientName: plexgo.String("Plex for Roku"),
DeviceNickname: plexgo.String("Roku 3"),
ClientVersion: plexgo.String("2.4.1"),
Platform: plexgo.String("Roku"),
}) })
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)

View File

@@ -26,3 +26,6 @@ The following SDKs are generated from the OpenAPI Specification. They are automa
| PHP | [GitHub](https://github.com/LukeHagar/plexphp) | [Releases](https://github.com/LukeHagar/plexphp/releases) | - | | PHP | [GitHub](https://github.com/LukeHagar/plexphp) | [Releases](https://github.com/LukeHagar/plexphp/releases) | - |
| Java | [GitHub](https://github.com/LukeHagar/plexjava) | [Releases](https://github.com/LukeHagar/plexjava/releases) | - | | Java | [GitHub](https://github.com/LukeHagar/plexjava) | [Releases](https://github.com/LukeHagar/plexjava/releases) | - |
| C# | [GitHub](https://github.com/LukeHagar/plexcsharp) | [Releases](https://github.com/LukeHagar/plexcsharp/releases) | - | C# | [GitHub](https://github.com/LukeHagar/plexcsharp) | [Releases](https://github.com/LukeHagar/plexcsharp/releases) | -
### Available Operations

View File

@@ -34,22 +34,18 @@ This request is intended to be very fast, and called as the user types.
package main package main
import( import(
"github.com/LukeHagar/plexgo"
"context" "context"
"github.com/LukeHagar/plexgo"
"log" "log"
) )
func main() { func main() {
ctx := context.Background()
s := plexgo.New( s := plexgo.New(
plexgo.WithSecurity("<YOUR_API_KEY_HERE>"), plexgo.WithSecurity("<YOUR_API_KEY_HERE>"),
plexgo.WithClientID("3381b62b-9ab7-4e37-827b-203e9809eb58"),
plexgo.WithClientName("Plex for Roku"),
plexgo.WithClientVersion("2.4.1"),
plexgo.WithPlatform("Roku"),
plexgo.WithDeviceNickname("Roku 3"),
) )
ctx := context.Background()
res, err := s.Search.PerformSearch(ctx, "dylan", nil, plexgo.Float64(5)) res, err := s.Search.PerformSearch(ctx, "dylan", nil, plexgo.Float64(5))
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
@@ -96,22 +92,18 @@ Results, as well as their containing per-type hubs, contain a `distance` attribu
package main package main
import( import(
"github.com/LukeHagar/plexgo"
"context" "context"
"github.com/LukeHagar/plexgo"
"log" "log"
) )
func main() { func main() {
ctx := context.Background()
s := plexgo.New( s := plexgo.New(
plexgo.WithSecurity("<YOUR_API_KEY_HERE>"), plexgo.WithSecurity("<YOUR_API_KEY_HERE>"),
plexgo.WithClientID("3381b62b-9ab7-4e37-827b-203e9809eb58"),
plexgo.WithClientName("Plex for Roku"),
plexgo.WithClientVersion("2.4.1"),
plexgo.WithPlatform("Roku"),
plexgo.WithDeviceNickname("Roku 3"),
) )
ctx := context.Background()
res, err := s.Search.PerformVoiceSearch(ctx, "dead+poop", nil, plexgo.Float64(5)) res, err := s.Search.PerformVoiceSearch(ctx, "dead+poop", nil, plexgo.Float64(5))
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
@@ -154,22 +146,18 @@ This will search the database for the string provided.
package main package main
import( import(
"github.com/LukeHagar/plexgo"
"context" "context"
"github.com/LukeHagar/plexgo"
"log" "log"
) )
func main() { func main() {
ctx := context.Background()
s := plexgo.New( s := plexgo.New(
plexgo.WithSecurity("<YOUR_API_KEY_HERE>"), plexgo.WithSecurity("<YOUR_API_KEY_HERE>"),
plexgo.WithClientID("3381b62b-9ab7-4e37-827b-203e9809eb58"),
plexgo.WithClientName("Plex for Roku"),
plexgo.WithClientVersion("2.4.1"),
plexgo.WithPlatform("Roku"),
plexgo.WithDeviceNickname("Roku 3"),
) )
ctx := context.Background()
res, err := s.Search.GetSearchResults(ctx, "110") res, err := s.Search.GetSearchResults(ctx, "110")
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)

View File

@@ -28,22 +28,18 @@ Get Server Capabilities
package main package main
import( import(
"github.com/LukeHagar/plexgo"
"context" "context"
"github.com/LukeHagar/plexgo"
"log" "log"
) )
func main() { func main() {
ctx := context.Background()
s := plexgo.New( s := plexgo.New(
plexgo.WithSecurity("<YOUR_API_KEY_HERE>"), plexgo.WithSecurity("<YOUR_API_KEY_HERE>"),
plexgo.WithClientID("3381b62b-9ab7-4e37-827b-203e9809eb58"),
plexgo.WithClientName("Plex for Roku"),
plexgo.WithClientVersion("2.4.1"),
plexgo.WithPlatform("Roku"),
plexgo.WithDeviceNickname("Roku 3"),
) )
ctx := context.Background()
res, err := s.Server.GetServerCapabilities(ctx) res, err := s.Server.GetServerCapabilities(ctx)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
@@ -83,22 +79,18 @@ Get Server Preferences
package main package main
import( import(
"github.com/LukeHagar/plexgo"
"context" "context"
"github.com/LukeHagar/plexgo"
"log" "log"
) )
func main() { func main() {
ctx := context.Background()
s := plexgo.New( s := plexgo.New(
plexgo.WithSecurity("<YOUR_API_KEY_HERE>"), plexgo.WithSecurity("<YOUR_API_KEY_HERE>"),
plexgo.WithClientID("3381b62b-9ab7-4e37-827b-203e9809eb58"),
plexgo.WithClientName("Plex for Roku"),
plexgo.WithClientVersion("2.4.1"),
plexgo.WithPlatform("Roku"),
plexgo.WithDeviceNickname("Roku 3"),
) )
ctx := context.Background()
res, err := s.Server.GetServerPreferences(ctx) res, err := s.Server.GetServerPreferences(ctx)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
@@ -138,22 +130,18 @@ Get Available Clients
package main package main
import( import(
"github.com/LukeHagar/plexgo"
"context" "context"
"github.com/LukeHagar/plexgo"
"log" "log"
) )
func main() { func main() {
ctx := context.Background()
s := plexgo.New( s := plexgo.New(
plexgo.WithSecurity("<YOUR_API_KEY_HERE>"), plexgo.WithSecurity("<YOUR_API_KEY_HERE>"),
plexgo.WithClientID("3381b62b-9ab7-4e37-827b-203e9809eb58"),
plexgo.WithClientName("Plex for Roku"),
plexgo.WithClientVersion("2.4.1"),
plexgo.WithPlatform("Roku"),
plexgo.WithDeviceNickname("Roku 3"),
) )
ctx := context.Background()
res, err := s.Server.GetAvailableClients(ctx) res, err := s.Server.GetAvailableClients(ctx)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
@@ -193,22 +181,18 @@ Get Devices
package main package main
import( import(
"github.com/LukeHagar/plexgo"
"context" "context"
"github.com/LukeHagar/plexgo"
"log" "log"
) )
func main() { func main() {
ctx := context.Background()
s := plexgo.New( s := plexgo.New(
plexgo.WithSecurity("<YOUR_API_KEY_HERE>"), plexgo.WithSecurity("<YOUR_API_KEY_HERE>"),
plexgo.WithClientID("3381b62b-9ab7-4e37-827b-203e9809eb58"),
plexgo.WithClientName("Plex for Roku"),
plexgo.WithClientVersion("2.4.1"),
plexgo.WithPlatform("Roku"),
plexgo.WithDeviceNickname("Roku 3"),
) )
ctx := context.Background()
res, err := s.Server.GetDevices(ctx) res, err := s.Server.GetDevices(ctx)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
@@ -248,21 +232,16 @@ This request is useful to determine if the server is online or offline
package main package main
import( import(
"github.com/LukeHagar/plexgo"
"context" "context"
"github.com/LukeHagar/plexgo"
"log" "log"
) )
func main() { func main() {
s := plexgo.New(
plexgo.WithClientID("3381b62b-9ab7-4e37-827b-203e9809eb58"),
plexgo.WithClientName("Plex for Roku"),
plexgo.WithClientVersion("2.4.1"),
plexgo.WithPlatform("Roku"),
plexgo.WithDeviceNickname("Roku 3"),
)
ctx := context.Background() ctx := context.Background()
s := plexgo.New()
res, err := s.Server.GetServerIdentity(ctx) res, err := s.Server.GetServerIdentity(ctx)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
@@ -301,22 +280,18 @@ Returns MyPlex Account Information
package main package main
import( import(
"github.com/LukeHagar/plexgo"
"context" "context"
"github.com/LukeHagar/plexgo"
"log" "log"
) )
func main() { func main() {
ctx := context.Background()
s := plexgo.New( s := plexgo.New(
plexgo.WithSecurity("<YOUR_API_KEY_HERE>"), plexgo.WithSecurity("<YOUR_API_KEY_HERE>"),
plexgo.WithClientID("3381b62b-9ab7-4e37-827b-203e9809eb58"),
plexgo.WithClientName("Plex for Roku"),
plexgo.WithClientVersion("2.4.1"),
plexgo.WithPlatform("Roku"),
plexgo.WithDeviceNickname("Roku 3"),
) )
ctx := context.Background()
res, err := s.Server.GetMyPlexAccount(ctx) res, err := s.Server.GetMyPlexAccount(ctx)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
@@ -357,23 +332,19 @@ Plex's Photo transcoder is used throughout the service to serve images at specif
package main package main
import( import(
"github.com/LukeHagar/plexgo"
"context" "context"
"github.com/LukeHagar/plexgo"
"github.com/LukeHagar/plexgo/models/operations" "github.com/LukeHagar/plexgo/models/operations"
"log" "log"
) )
func main() { func main() {
ctx := context.Background()
s := plexgo.New( s := plexgo.New(
plexgo.WithSecurity("<YOUR_API_KEY_HERE>"), plexgo.WithSecurity("<YOUR_API_KEY_HERE>"),
plexgo.WithClientID("3381b62b-9ab7-4e37-827b-203e9809eb58"),
plexgo.WithClientName("Plex for Roku"),
plexgo.WithClientVersion("2.4.1"),
plexgo.WithPlatform("Roku"),
plexgo.WithDeviceNickname("Roku 3"),
) )
ctx := context.Background()
res, err := s.Server.GetResizedPhoto(ctx, operations.GetResizedPhotoRequest{ res, err := s.Server.GetResizedPhoto(ctx, operations.GetResizedPhotoRequest{
Width: 110, Width: 110,
Height: 165, Height: 165,
@@ -422,22 +393,18 @@ Retrieves media providers and their features from the Plex server.
package main package main
import( import(
"github.com/LukeHagar/plexgo"
"context" "context"
"github.com/LukeHagar/plexgo"
"log" "log"
) )
func main() { func main() {
ctx := context.Background()
s := plexgo.New( s := plexgo.New(
plexgo.WithSecurity("<YOUR_API_KEY_HERE>"), plexgo.WithSecurity("<YOUR_API_KEY_HERE>"),
plexgo.WithClientID("3381b62b-9ab7-4e37-827b-203e9809eb58"),
plexgo.WithClientName("Plex for Roku"),
plexgo.WithClientVersion("2.4.1"),
plexgo.WithPlatform("Roku"),
plexgo.WithDeviceNickname("Roku 3"),
) )
ctx := context.Background()
res, err := s.Server.GetMediaProviders(ctx, "CV5xoxjTpFKUzBTShsaf") res, err := s.Server.GetMediaProviders(ctx, "CV5xoxjTpFKUzBTShsaf")
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
@@ -478,22 +445,18 @@ Get Server List
package main package main
import( import(
"github.com/LukeHagar/plexgo"
"context" "context"
"github.com/LukeHagar/plexgo"
"log" "log"
) )
func main() { func main() {
ctx := context.Background()
s := plexgo.New( s := plexgo.New(
plexgo.WithSecurity("<YOUR_API_KEY_HERE>"), plexgo.WithSecurity("<YOUR_API_KEY_HERE>"),
plexgo.WithClientID("3381b62b-9ab7-4e37-827b-203e9809eb58"),
plexgo.WithClientName("Plex for Roku"),
plexgo.WithClientVersion("2.4.1"),
plexgo.WithPlatform("Roku"),
plexgo.WithDeviceNickname("Roku 3"),
) )
ctx := context.Background()
res, err := s.Server.GetServerList(ctx) res, err := s.Server.GetServerList(ctx)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)

View File

@@ -23,22 +23,18 @@ This will retrieve the "Now Playing" Information of the PMS.
package main package main
import( import(
"github.com/LukeHagar/plexgo"
"context" "context"
"github.com/LukeHagar/plexgo"
"log" "log"
) )
func main() { func main() {
ctx := context.Background()
s := plexgo.New( s := plexgo.New(
plexgo.WithSecurity("<YOUR_API_KEY_HERE>"), plexgo.WithSecurity("<YOUR_API_KEY_HERE>"),
plexgo.WithClientID("3381b62b-9ab7-4e37-827b-203e9809eb58"),
plexgo.WithClientName("Plex for Roku"),
plexgo.WithClientVersion("2.4.1"),
plexgo.WithPlatform("Roku"),
plexgo.WithDeviceNickname("Roku 3"),
) )
ctx := context.Background()
res, err := s.Sessions.GetSessions(ctx) res, err := s.Sessions.GetSessions(ctx)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
@@ -78,23 +74,19 @@ This will Retrieve a listing of all history views.
package main package main
import( import(
"github.com/LukeHagar/plexgo"
"context" "context"
"github.com/LukeHagar/plexgo"
"github.com/LukeHagar/plexgo/models/operations" "github.com/LukeHagar/plexgo/models/operations"
"log" "log"
) )
func main() { func main() {
ctx := context.Background()
s := plexgo.New( s := plexgo.New(
plexgo.WithSecurity("<YOUR_API_KEY_HERE>"), plexgo.WithSecurity("<YOUR_API_KEY_HERE>"),
plexgo.WithClientID("3381b62b-9ab7-4e37-827b-203e9809eb58"),
plexgo.WithClientName("Plex for Roku"),
plexgo.WithClientVersion("2.4.1"),
plexgo.WithPlatform("Roku"),
plexgo.WithDeviceNickname("Roku 3"),
) )
ctx := context.Background()
res, err := s.Sessions.GetSessionHistory(ctx, plexgo.String("viewedAt:desc"), plexgo.Int64(1), &operations.QueryParamFilter{}, plexgo.Int64(12)) res, err := s.Sessions.GetSessionHistory(ctx, plexgo.String("viewedAt:desc"), plexgo.Int64(1), &operations.QueryParamFilter{}, plexgo.Int64(12))
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
@@ -138,22 +130,18 @@ Get Transcode Sessions
package main package main
import( import(
"github.com/LukeHagar/plexgo"
"context" "context"
"github.com/LukeHagar/plexgo"
"log" "log"
) )
func main() { func main() {
ctx := context.Background()
s := plexgo.New( s := plexgo.New(
plexgo.WithSecurity("<YOUR_API_KEY_HERE>"), plexgo.WithSecurity("<YOUR_API_KEY_HERE>"),
plexgo.WithClientID("3381b62b-9ab7-4e37-827b-203e9809eb58"),
plexgo.WithClientName("Plex for Roku"),
plexgo.WithClientVersion("2.4.1"),
plexgo.WithPlatform("Roku"),
plexgo.WithDeviceNickname("Roku 3"),
) )
ctx := context.Background()
res, err := s.Sessions.GetTranscodeSessions(ctx) res, err := s.Sessions.GetTranscodeSessions(ctx)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
@@ -193,22 +181,18 @@ Stop a Transcode Session
package main package main
import( import(
"github.com/LukeHagar/plexgo"
"context" "context"
"github.com/LukeHagar/plexgo"
"log" "log"
) )
func main() { func main() {
ctx := context.Background()
s := plexgo.New( s := plexgo.New(
plexgo.WithSecurity("<YOUR_API_KEY_HERE>"), plexgo.WithSecurity("<YOUR_API_KEY_HERE>"),
plexgo.WithClientID("3381b62b-9ab7-4e37-827b-203e9809eb58"),
plexgo.WithClientName("Plex for Roku"),
plexgo.WithClientVersion("2.4.1"),
plexgo.WithPlatform("Roku"),
plexgo.WithDeviceNickname("Roku 3"),
) )
ctx := context.Background()
res, err := s.Sessions.StopTranscodeSession(ctx, "zz7llzqlx8w9vnrsbnwhbmep") res, err := s.Sessions.StopTranscodeSession(ctx, "zz7llzqlx8w9vnrsbnwhbmep")
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)

View File

@@ -22,22 +22,18 @@ This will return the media statistics for the server
package main package main
import( import(
"github.com/LukeHagar/plexgo"
"context" "context"
"github.com/LukeHagar/plexgo"
"log" "log"
) )
func main() { func main() {
ctx := context.Background()
s := plexgo.New( s := plexgo.New(
plexgo.WithSecurity("<YOUR_API_KEY_HERE>"), plexgo.WithSecurity("<YOUR_API_KEY_HERE>"),
plexgo.WithClientID("3381b62b-9ab7-4e37-827b-203e9809eb58"),
plexgo.WithClientName("Plex for Roku"),
plexgo.WithClientVersion("2.4.1"),
plexgo.WithPlatform("Roku"),
plexgo.WithDeviceNickname("Roku 3"),
) )
ctx := context.Background()
res, err := s.Statistics.GetStatistics(ctx, plexgo.Int64(4)) res, err := s.Statistics.GetStatistics(ctx, plexgo.Int64(4))
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
@@ -78,22 +74,18 @@ This will return the resources for the server
package main package main
import( import(
"github.com/LukeHagar/plexgo"
"context" "context"
"github.com/LukeHagar/plexgo"
"log" "log"
) )
func main() { func main() {
ctx := context.Background()
s := plexgo.New( s := plexgo.New(
plexgo.WithSecurity("<YOUR_API_KEY_HERE>"), plexgo.WithSecurity("<YOUR_API_KEY_HERE>"),
plexgo.WithClientID("3381b62b-9ab7-4e37-827b-203e9809eb58"),
plexgo.WithClientName("Plex for Roku"),
plexgo.WithClientVersion("2.4.1"),
plexgo.WithPlatform("Roku"),
plexgo.WithDeviceNickname("Roku 3"),
) )
ctx := context.Background()
res, err := s.Statistics.GetResourcesStatistics(ctx, plexgo.Int64(4)) res, err := s.Statistics.GetResourcesStatistics(ctx, plexgo.Int64(4))
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
@@ -134,22 +126,18 @@ This will return the bandwidth statistics for the server
package main package main
import( import(
"github.com/LukeHagar/plexgo"
"context" "context"
"github.com/LukeHagar/plexgo"
"log" "log"
) )
func main() { func main() {
ctx := context.Background()
s := plexgo.New( s := plexgo.New(
plexgo.WithSecurity("<YOUR_API_KEY_HERE>"), plexgo.WithSecurity("<YOUR_API_KEY_HERE>"),
plexgo.WithClientID("3381b62b-9ab7-4e37-827b-203e9809eb58"),
plexgo.WithClientName("Plex for Roku"),
plexgo.WithClientVersion("2.4.1"),
plexgo.WithPlatform("Roku"),
plexgo.WithDeviceNickname("Roku 3"),
) )
ctx := context.Background()
res, err := s.Statistics.GetBandwidthStatistics(ctx, plexgo.Int64(4)) res, err := s.Statistics.GetBandwidthStatistics(ctx, plexgo.Int64(4))
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)

View File

@@ -23,22 +23,18 @@ Querying status of updates
package main package main
import( import(
"github.com/LukeHagar/plexgo"
"context" "context"
"github.com/LukeHagar/plexgo"
"log" "log"
) )
func main() { func main() {
ctx := context.Background()
s := plexgo.New( s := plexgo.New(
plexgo.WithSecurity("<YOUR_API_KEY_HERE>"), plexgo.WithSecurity("<YOUR_API_KEY_HERE>"),
plexgo.WithClientID("3381b62b-9ab7-4e37-827b-203e9809eb58"),
plexgo.WithClientName("Plex for Roku"),
plexgo.WithClientVersion("2.4.1"),
plexgo.WithPlatform("Roku"),
plexgo.WithDeviceNickname("Roku 3"),
) )
ctx := context.Background()
res, err := s.Updater.GetUpdateStatus(ctx) res, err := s.Updater.GetUpdateStatus(ctx)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
@@ -78,23 +74,19 @@ Checking for updates
package main package main
import( import(
"github.com/LukeHagar/plexgo"
"context" "context"
"github.com/LukeHagar/plexgo"
"github.com/LukeHagar/plexgo/models/operations" "github.com/LukeHagar/plexgo/models/operations"
"log" "log"
) )
func main() { func main() {
ctx := context.Background()
s := plexgo.New( s := plexgo.New(
plexgo.WithSecurity("<YOUR_API_KEY_HERE>"), plexgo.WithSecurity("<YOUR_API_KEY_HERE>"),
plexgo.WithClientID("3381b62b-9ab7-4e37-827b-203e9809eb58"),
plexgo.WithClientName("Plex for Roku"),
plexgo.WithClientVersion("2.4.1"),
plexgo.WithPlatform("Roku"),
plexgo.WithDeviceNickname("Roku 3"),
) )
ctx := context.Background()
res, err := s.Updater.CheckForUpdates(ctx, operations.DownloadOne.ToPointer()) res, err := s.Updater.CheckForUpdates(ctx, operations.DownloadOne.ToPointer())
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
@@ -136,23 +128,19 @@ Note that these two parameters are effectively mutually exclusive. The `tonight`
package main package main
import( import(
"github.com/LukeHagar/plexgo"
"context" "context"
"github.com/LukeHagar/plexgo"
"github.com/LukeHagar/plexgo/models/operations" "github.com/LukeHagar/plexgo/models/operations"
"log" "log"
) )
func main() { func main() {
ctx := context.Background()
s := plexgo.New( s := plexgo.New(
plexgo.WithSecurity("<YOUR_API_KEY_HERE>"), plexgo.WithSecurity("<YOUR_API_KEY_HERE>"),
plexgo.WithClientID("3381b62b-9ab7-4e37-827b-203e9809eb58"),
plexgo.WithClientName("Plex for Roku"),
plexgo.WithClientVersion("2.4.1"),
plexgo.WithPlatform("Roku"),
plexgo.WithDeviceNickname("Roku 3"),
) )
ctx := context.Background()
res, err := s.Updater.ApplyUpdates(ctx, operations.TonightOne.ToPointer(), operations.SkipOne.ToPointer()) res, err := s.Updater.ApplyUpdates(ctx, operations.TonightOne.ToPointer(), operations.SkipOne.ToPointer())
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)

View File

@@ -21,23 +21,19 @@ Get the timeline for a media item
package main package main
import( import(
"github.com/LukeHagar/plexgo"
"context" "context"
"github.com/LukeHagar/plexgo"
"github.com/LukeHagar/plexgo/models/operations" "github.com/LukeHagar/plexgo/models/operations"
"log" "log"
) )
func main() { func main() {
ctx := context.Background()
s := plexgo.New( s := plexgo.New(
plexgo.WithSecurity("<YOUR_API_KEY_HERE>"), plexgo.WithSecurity("<YOUR_API_KEY_HERE>"),
plexgo.WithClientID("3381b62b-9ab7-4e37-827b-203e9809eb58"),
plexgo.WithClientName("Plex for Roku"),
plexgo.WithClientVersion("2.4.1"),
plexgo.WithPlatform("Roku"),
plexgo.WithDeviceNickname("Roku 3"),
) )
ctx := context.Background()
res, err := s.Video.GetTimeline(ctx, operations.GetTimelineRequest{ res, err := s.Video.GetTimeline(ctx, operations.GetTimelineRequest{
RatingKey: 23409, RatingKey: 23409,
Key: "/library/metadata/23409", Key: "/library/metadata/23409",
@@ -89,23 +85,19 @@ Begin a Universal Transcode Session
package main package main
import( import(
"github.com/LukeHagar/plexgo"
"context" "context"
"github.com/LukeHagar/plexgo"
"github.com/LukeHagar/plexgo/models/operations" "github.com/LukeHagar/plexgo/models/operations"
"log" "log"
) )
func main() { func main() {
ctx := context.Background()
s := plexgo.New( s := plexgo.New(
plexgo.WithSecurity("<YOUR_API_KEY_HERE>"), plexgo.WithSecurity("<YOUR_API_KEY_HERE>"),
plexgo.WithClientID("3381b62b-9ab7-4e37-827b-203e9809eb58"),
plexgo.WithClientName("Plex for Roku"),
plexgo.WithClientVersion("2.4.1"),
plexgo.WithPlatform("Roku"),
plexgo.WithDeviceNickname("Roku 3"),
) )
ctx := context.Background()
res, err := s.Video.StartUniversalTranscode(ctx, operations.StartUniversalTranscodeRequest{ res, err := s.Video.StartUniversalTranscode(ctx, operations.StartUniversalTranscodeRequest{
HasMDE: 1, HasMDE: 1,
Path: "/library/metadata/23409", Path: "/library/metadata/23409",

View File

@@ -20,23 +20,19 @@ Get User Watchlist
package main package main
import( import(
"github.com/LukeHagar/plexgo"
"context" "context"
"github.com/LukeHagar/plexgo"
"github.com/LukeHagar/plexgo/models/operations" "github.com/LukeHagar/plexgo/models/operations"
"log" "log"
) )
func main() { func main() {
ctx := context.Background()
s := plexgo.New( s := plexgo.New(
plexgo.WithSecurity("<YOUR_API_KEY_HERE>"), plexgo.WithSecurity("<YOUR_API_KEY_HERE>"),
plexgo.WithClientID("3381b62b-9ab7-4e37-827b-203e9809eb58"),
plexgo.WithClientName("Plex for Roku"),
plexgo.WithClientVersion("2.4.1"),
plexgo.WithPlatform("Roku"),
plexgo.WithDeviceNickname("Roku 3"),
) )
ctx := context.Background()
res, err := s.Watchlist.GetWatchList(ctx, operations.GetWatchListRequest{ res, err := s.Watchlist.GetWatchList(ctx, operations.GetWatchListRequest{
Filter: operations.FilterAvailable, Filter: operations.FilterAvailable,
XPlexContainerStart: plexgo.Int(0), XPlexContainerStart: plexgo.Int(0),

5
go.mod
View File

@@ -2,7 +2,4 @@ module github.com/LukeHagar/plexgo
go 1.20 go 1.20
require ( require github.com/ericlagergren/decimal v0.0.0-20221120152707-495c53812d05
github.com/cenkalti/backoff/v4 v4.2.0
github.com/ericlagergren/decimal v0.0.0-20221120152707-495c53812d05
)

2
go.sum
View File

@@ -1,4 +1,2 @@
github.com/cenkalti/backoff/v4 v4.2.0 h1:HN5dHm3WBOgndBH6E8V0q2jIYIR3s9yglV8k/+MN3u4=
github.com/cenkalti/backoff/v4 v4.2.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=
github.com/ericlagergren/decimal v0.0.0-20221120152707-495c53812d05 h1:S92OBrGuLLZsyM5ybUzgc/mPjIYk2AZqufieooe98uw= github.com/ericlagergren/decimal v0.0.0-20221120152707-495c53812d05 h1:S92OBrGuLLZsyM5ybUzgc/mPjIYk2AZqufieooe98uw=
github.com/ericlagergren/decimal v0.0.0-20221120152707-495c53812d05/go.mod h1:M9R1FoZ3y//hwwnJtO51ypFGwm8ZfpxPT/ZLtO1mcgQ= github.com/ericlagergren/decimal v0.0.0-20221120152707-495c53812d05/go.mod h1:M9R1FoZ3y//hwwnJtO51ypFGwm8ZfpxPT/ZLtO1mcgQ=

161
hubs.go
View File

@@ -10,8 +10,7 @@ import (
"github.com/LukeHagar/plexgo/internal/utils" "github.com/LukeHagar/plexgo/internal/utils"
"github.com/LukeHagar/plexgo/models/operations" "github.com/LukeHagar/plexgo/models/operations"
"github.com/LukeHagar/plexgo/models/sdkerrors" "github.com/LukeHagar/plexgo/models/sdkerrors"
"github.com/cenkalti/backoff/v4" "github.com/LukeHagar/plexgo/retry"
"io"
"net/http" "net/http"
"net/url" "net/url"
) )
@@ -54,7 +53,12 @@ func (s *Hubs) GetGlobalHubs(ctx context.Context, count *float64, onlyTransient
} }
} }
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) var baseURL string
if o.ServerURL == nil {
baseURL = utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
} else {
baseURL = *o.ServerURL
}
opURL, err := url.JoinPath(baseURL, "/hubs") opURL, err := url.JoinPath(baseURL, "/hubs")
if err != nil { if err != nil {
return nil, fmt.Errorf("error generating URL: %w", err) return nil, fmt.Errorf("error generating URL: %w", err)
@@ -86,6 +90,10 @@ func (s *Hubs) GetGlobalHubs(ctx context.Context, count *float64, onlyTransient
return nil, err return nil, err
} }
for k, v := range o.SetHeaders {
req.Header.Set(k, v)
}
globalRetryConfig := s.sdkConfiguration.RetryConfig globalRetryConfig := s.sdkConfiguration.RetryConfig
retryConfig := o.Retries retryConfig := o.Retries
if retryConfig == nil { if retryConfig == nil {
@@ -116,7 +124,11 @@ func (s *Hubs) GetGlobalHubs(ctx context.Context, count *float64, onlyTransient
req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req)
if err != nil { if err != nil {
return nil, backoff.Permanent(err) if retry.IsPermanentError(err) || retry.IsTemporaryError(err) {
return nil, err
}
return nil, retry.Permanent(err)
} }
httpRes, err := s.sdkConfiguration.Client.Do(req) httpRes, err := s.sdkConfiguration.Client.Do(req)
@@ -177,21 +189,11 @@ func (s *Hubs) GetGlobalHubs(ctx context.Context, count *float64, onlyTransient
RawResponse: httpRes, RawResponse: httpRes,
} }
getRawBody := func() ([]byte, error) {
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))
return rawBody, nil
}
switch { switch {
case httpRes.StatusCode == 200: case httpRes.StatusCode == 200:
switch { switch {
case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -203,17 +205,16 @@ func (s *Hubs) GetGlobalHubs(ctx context.Context, count *float64, onlyTransient
res.Object = &out res.Object = &out
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
} }
case httpRes.StatusCode == 400: case httpRes.StatusCode == 400:
switch { switch {
case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -226,17 +227,16 @@ func (s *Hubs) GetGlobalHubs(ctx context.Context, count *float64, onlyTransient
out.RawResponse = httpRes out.RawResponse = httpRes
return nil, &out return nil, &out
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
} }
case httpRes.StatusCode == 401: case httpRes.StatusCode == 401:
switch { switch {
case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -249,28 +249,29 @@ func (s *Hubs) GetGlobalHubs(ctx context.Context, count *float64, onlyTransient
out.RawResponse = httpRes out.RawResponse = httpRes
return nil, &out return nil, &out
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
} }
case httpRes.StatusCode >= 400 && httpRes.StatusCode < 500: case httpRes.StatusCode >= 400 && httpRes.StatusCode < 500:
fallthrough rawBody, err := utils.ConsumeRawBody(httpRes)
case httpRes.StatusCode >= 500 && httpRes.StatusCode < 600: if err != nil {
rawBody, err := getRawBody() return nil, err
}
return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes)
case httpRes.StatusCode >= 500 && httpRes.StatusCode < 600:
rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes)
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError("unknown status code returned", httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError("unknown status code returned", httpRes.StatusCode, string(rawBody), httpRes)
} }
@@ -300,7 +301,12 @@ func (s *Hubs) GetRecentlyAdded(ctx context.Context, request operations.GetRecen
} }
} }
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) var baseURL string
if o.ServerURL == nil {
baseURL = utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
} else {
baseURL = *o.ServerURL
}
opURL, err := url.JoinPath(baseURL, "/hubs/home/recentlyAdded") opURL, err := url.JoinPath(baseURL, "/hubs/home/recentlyAdded")
if err != nil { if err != nil {
return nil, fmt.Errorf("error generating URL: %w", err) return nil, fmt.Errorf("error generating URL: %w", err)
@@ -332,6 +338,10 @@ func (s *Hubs) GetRecentlyAdded(ctx context.Context, request operations.GetRecen
return nil, err return nil, err
} }
for k, v := range o.SetHeaders {
req.Header.Set(k, v)
}
globalRetryConfig := s.sdkConfiguration.RetryConfig globalRetryConfig := s.sdkConfiguration.RetryConfig
retryConfig := o.Retries retryConfig := o.Retries
if retryConfig == nil { if retryConfig == nil {
@@ -362,7 +372,11 @@ func (s *Hubs) GetRecentlyAdded(ctx context.Context, request operations.GetRecen
req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req)
if err != nil { if err != nil {
return nil, backoff.Permanent(err) if retry.IsPermanentError(err) || retry.IsTemporaryError(err) {
return nil, err
}
return nil, retry.Permanent(err)
} }
httpRes, err := s.sdkConfiguration.Client.Do(req) httpRes, err := s.sdkConfiguration.Client.Do(req)
@@ -423,21 +437,11 @@ func (s *Hubs) GetRecentlyAdded(ctx context.Context, request operations.GetRecen
RawResponse: httpRes, RawResponse: httpRes,
} }
getRawBody := func() ([]byte, error) {
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))
return rawBody, nil
}
switch { switch {
case httpRes.StatusCode == 200: case httpRes.StatusCode == 200:
switch { switch {
case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -449,11 +453,10 @@ func (s *Hubs) GetRecentlyAdded(ctx context.Context, request operations.GetRecen
res.Object = &out res.Object = &out
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
} }
case httpRes.StatusCode == 400: case httpRes.StatusCode == 400:
@@ -461,20 +464,22 @@ func (s *Hubs) GetRecentlyAdded(ctx context.Context, request operations.GetRecen
case httpRes.StatusCode == 401: case httpRes.StatusCode == 401:
fallthrough fallthrough
case httpRes.StatusCode >= 400 && httpRes.StatusCode < 500: case httpRes.StatusCode >= 400 && httpRes.StatusCode < 500:
fallthrough rawBody, err := utils.ConsumeRawBody(httpRes)
case httpRes.StatusCode >= 500 && httpRes.StatusCode < 600: if err != nil {
rawBody, err := getRawBody() return nil, err
}
return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes)
case httpRes.StatusCode >= 500 && httpRes.StatusCode < 600:
rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes)
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError("unknown status code returned", httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError("unknown status code returned", httpRes.StatusCode, string(rawBody), httpRes)
} }
@@ -510,7 +515,12 @@ func (s *Hubs) GetLibraryHubs(ctx context.Context, sectionID float64, count *flo
} }
} }
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) var baseURL string
if o.ServerURL == nil {
baseURL = utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
} else {
baseURL = *o.ServerURL
}
opURL, err := utils.GenerateURL(ctx, baseURL, "/hubs/sections/{sectionId}", request, nil) opURL, err := utils.GenerateURL(ctx, baseURL, "/hubs/sections/{sectionId}", request, nil)
if err != nil { if err != nil {
return nil, fmt.Errorf("error generating URL: %w", err) return nil, fmt.Errorf("error generating URL: %w", err)
@@ -542,6 +552,10 @@ func (s *Hubs) GetLibraryHubs(ctx context.Context, sectionID float64, count *flo
return nil, err return nil, err
} }
for k, v := range o.SetHeaders {
req.Header.Set(k, v)
}
globalRetryConfig := s.sdkConfiguration.RetryConfig globalRetryConfig := s.sdkConfiguration.RetryConfig
retryConfig := o.Retries retryConfig := o.Retries
if retryConfig == nil { if retryConfig == nil {
@@ -572,7 +586,11 @@ func (s *Hubs) GetLibraryHubs(ctx context.Context, sectionID float64, count *flo
req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req)
if err != nil { if err != nil {
return nil, backoff.Permanent(err) if retry.IsPermanentError(err) || retry.IsTemporaryError(err) {
return nil, err
}
return nil, retry.Permanent(err)
} }
httpRes, err := s.sdkConfiguration.Client.Do(req) httpRes, err := s.sdkConfiguration.Client.Do(req)
@@ -633,21 +651,11 @@ func (s *Hubs) GetLibraryHubs(ctx context.Context, sectionID float64, count *flo
RawResponse: httpRes, RawResponse: httpRes,
} }
getRawBody := func() ([]byte, error) {
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))
return rawBody, nil
}
switch { switch {
case httpRes.StatusCode == 200: case httpRes.StatusCode == 200:
switch { switch {
case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -659,17 +667,16 @@ func (s *Hubs) GetLibraryHubs(ctx context.Context, sectionID float64, count *flo
res.Object = &out res.Object = &out
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
} }
case httpRes.StatusCode == 400: case httpRes.StatusCode == 400:
switch { switch {
case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -682,17 +689,16 @@ func (s *Hubs) GetLibraryHubs(ctx context.Context, sectionID float64, count *flo
out.RawResponse = httpRes out.RawResponse = httpRes
return nil, &out return nil, &out
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
} }
case httpRes.StatusCode == 401: case httpRes.StatusCode == 401:
switch { switch {
case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -705,28 +711,29 @@ func (s *Hubs) GetLibraryHubs(ctx context.Context, sectionID float64, count *flo
out.RawResponse = httpRes out.RawResponse = httpRes
return nil, &out return nil, &out
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
} }
case httpRes.StatusCode >= 400 && httpRes.StatusCode < 500: case httpRes.StatusCode >= 400 && httpRes.StatusCode < 500:
fallthrough rawBody, err := utils.ConsumeRawBody(httpRes)
case httpRes.StatusCode >= 500 && httpRes.StatusCode < 600: if err != nil {
rawBody, err := getRawBody() return nil, err
}
return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes)
case httpRes.StatusCode >= 500 && httpRes.StatusCode < 600:
rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes)
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError("unknown status code returned", httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError("unknown status code returned", httpRes.StatusCode, string(rawBody), httpRes)
} }

View File

@@ -1,51 +0,0 @@
// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
package globals
type Globals struct {
// An opaque identifier unique to the client (UUID, serial number, or other unique device ID)
ClientID *string `header:"style=simple,explode=false,name=X-Plex-Client-Identifier"`
// The name of the client application. (Plex Web, Plex Media Server, etc.)
ClientName *string `header:"style=simple,explode=false,name=X-Plex-Product"`
// The version of the client application.
ClientVersion *string `header:"style=simple,explode=false,name=X-Plex-Version"`
// The platform of the client application.
Platform *string `header:"style=simple,explode=false,name=X-Plex-Platform"`
// A relatively friendly name for the client device
DeviceNickname *string `header:"style=simple,explode=false,name=X-Plex-Device"`
}
func (o *Globals) GetClientID() *string {
if o == nil {
return nil
}
return o.ClientID
}
func (o *Globals) GetClientName() *string {
if o == nil {
return nil
}
return o.ClientName
}
func (o *Globals) GetClientVersion() *string {
if o == nil {
return nil
}
return o.ClientVersion
}
func (o *Globals) GetPlatform() *string {
if o == nil {
return nil
}
return o.Platform
}
func (o *Globals) GetDeviceNickname() *string {
if o == nil {
return nil
}
return o.DeviceNickname
}

16
internal/utils/env.go Normal file
View File

@@ -0,0 +1,16 @@
// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
package utils
import (
"os"
)
// GetEnv returns the value of the environment variable named by the key or the defaultValue if the environment variable is not set.
func GetEnv(name, defaultValue string) string {
value := os.Getenv(name)
if value == "" {
return defaultValue
}
return value
}

View File

@@ -214,7 +214,11 @@ func populateDeepObjectParamsStruct(qsValues url.Values, priorScope string, stru
continue continue
} }
scope := priorScope + "[" + qpTag.ParamName + "]" scope := priorScope
if !qpTag.Inline {
scope = priorScope + "[" + qpTag.ParamName + "]"
}
switch fieldValue.Kind() { switch fieldValue.Kind() {
case reflect.Array, reflect.Slice: case reflect.Array, reflect.Slice:
@@ -252,6 +256,13 @@ type paramTag struct {
Explode bool Explode bool
ParamName string ParamName string
Serialization string Serialization string
// Inline is a special case for union/oneOf. When a wrapper struct type is
// used, each union/oneOf value field should be inlined (e.g. not appended
// in deepObject style with the name) as if the value was directly on the
// parent struct field. Without this annotation, the value would not be
// encoded by downstream logic that requires the struct field tag.
Inline bool
} }
func parseQueryParamTag(field reflect.StructField) *paramTag { func parseQueryParamTag(field reflect.StructField) *paramTag {

View File

@@ -166,7 +166,7 @@ func encodeMultipartFormData(w io.Writer, data interface{}) (string, error) {
tag := parseMultipartFormTag(field) tag := parseMultipartFormTag(field)
if tag.File { if tag.File {
if err := encodeMultipartFormDataFile(writer, fieldType, valType); err != nil { if err := encodeMultipartFormDataFile(writer, tag.Name, fieldType, valType); err != nil {
writer.Close() writer.Close()
return "", err return "", err
} }
@@ -211,12 +211,11 @@ func encodeMultipartFormData(w io.Writer, data interface{}) (string, error) {
return writer.FormDataContentType(), nil return writer.FormDataContentType(), nil
} }
func encodeMultipartFormDataFile(w *multipart.Writer, fieldType reflect.Type, valType reflect.Value) error { func encodeMultipartFormDataFile(w *multipart.Writer, fieldName string, fieldType reflect.Type, valType reflect.Value) error {
if fieldType.Kind() != reflect.Struct { if fieldType.Kind() != reflect.Struct {
return fmt.Errorf("invalid type %s for multipart/form-data file", valType.Type()) return fmt.Errorf("invalid type %s for multipart/form-data file", valType.Type())
} }
var fieldName string
var fileName string var fileName string
var reader io.Reader var reader io.Reader
@@ -236,12 +235,11 @@ func encodeMultipartFormDataFile(w *multipart.Writer, fieldType reflect.Type, va
reader = val.Interface().(io.Reader) reader = val.Interface().(io.Reader)
} }
} else { } else {
fieldName = tag.Name
fileName = val.String() fileName = val.String()
} }
} }
if fieldName == "" || fileName == "" || reader == nil { if fileName == "" || reader == nil {
return fmt.Errorf("invalid multipart/form-data file") return fmt.Errorf("invalid multipart/form-data file")
} }

View File

@@ -7,7 +7,8 @@ import (
"errors" "errors"
"fmt" "fmt"
"github.com/LukeHagar/plexgo/retry" "github.com/LukeHagar/plexgo/retry"
"github.com/cenkalti/backoff/v4" "math"
"math/rand"
"net/http" "net/http"
"net/url" "net/url"
"strconv" "strconv"
@@ -15,8 +16,6 @@ import (
"time" "time"
) )
var errRequestFailed = errors.New("request failed")
// Deprecated: Use retry.BackoffStrategy instead. // Deprecated: Use retry.BackoffStrategy instead.
type BackoffStrategy = retry.BackoffStrategy type BackoffStrategy = retry.BackoffStrategy
@@ -28,34 +27,27 @@ type Retries struct {
StatusCodes []string StatusCodes []string
} }
func Retry(ctx context.Context, r Retries, action func() (*http.Response, error)) (*http.Response, error) { func Retry(ctx context.Context, r Retries, operation func() (*http.Response, error)) (*http.Response, error) {
switch r.Config.Strategy { switch r.Config.Strategy {
case "backoff": case "backoff":
if r.Config.Backoff == nil { if r.Config.Backoff == nil {
return action() return operation()
} }
config := backoff.NewExponentialBackOff()
config.InitialInterval = time.Duration(r.Config.Backoff.InitialInterval) * time.Millisecond
config.MaxInterval = time.Duration(r.Config.Backoff.MaxInterval) * time.Millisecond
config.Multiplier = r.Config.Backoff.Exponent
config.MaxElapsedTime = time.Duration(r.Config.Backoff.MaxElapsedTime) * time.Millisecond
config.Reset()
var resp *http.Response var resp *http.Response
err := backoff.Retry(func() error { err := retryWithBackoff(ctx, r.Config.Backoff, func() error {
if resp != nil { if resp != nil {
resp.Body.Close() resp.Body.Close()
} }
select { select {
case <-ctx.Done(): case <-ctx.Done():
return backoff.Permanent(ctx.Err()) return retry.Permanent(ctx.Err())
default: default:
} }
res, err := action() res, err := operation()
if err != nil { if err != nil {
urlError := new(url.Error) urlError := new(url.Error)
if errors.As(err, &urlError) { if errors.As(err, &urlError) {
@@ -64,7 +56,7 @@ func Retry(ctx context.Context, r Retries, action func() (*http.Response, error)
} }
} }
return backoff.Permanent(err) return retry.Permanent(err)
} }
resp = res resp = res
if res == nil { if res == nil {
@@ -81,7 +73,7 @@ func Retry(ctx context.Context, r Retries, action func() (*http.Response, error)
s := res.StatusCode / 100 s := res.StatusCode / 100
if s >= codeRange && s < codeRange+1 { if s >= codeRange && s < codeRange+1 {
return errRequestFailed return retry.TemporaryFromResponse("request failed", res)
} }
} else { } else {
parsedCode, err := strconv.Atoi(code) parsedCode, err := strconv.Atoi(code)
@@ -90,7 +82,7 @@ func Retry(ctx context.Context, r Retries, action func() (*http.Response, error)
} }
if res.StatusCode == parsedCode { if res.StatusCode == parsedCode {
return errRequestFailed return retry.TemporaryFromResponse("request failed", res)
} }
} }
} }
@@ -98,13 +90,131 @@ func Retry(ctx context.Context, r Retries, action func() (*http.Response, error)
resp = res resp = res
return nil return nil
}, config) })
if err != nil && !errors.Is(err, errRequestFailed) {
var tempErr *retry.TemporaryError
if err != nil && !errors.As(err, &tempErr) {
return nil, err return nil, err
} }
return resp, nil return resp, nil
default: default:
return action() return operation()
} }
} }
func retryWithBackoff(ctx context.Context, s *retry.BackoffStrategy, operation func() error) error {
var (
err error
next time.Duration
attempt int
start = time.Now()
maxElapsedTime = time.Duration(s.MaxElapsedTime) * time.Millisecond
)
timer := &defaultTimer{}
defer func() {
timer.Stop()
}()
for {
err = operation()
if err == nil {
return nil
}
var permanent *retry.PermanentError
if errors.As(err, &permanent) {
return permanent.Unwrap()
}
if time.Since(start) >= maxElapsedTime {
return err
}
var temporary *retry.TemporaryError
if errors.As(err, &temporary) {
next = temporary.RetryAfter()
}
if next <= 0 {
next = nextInterval(s, attempt)
}
timer.Start(next)
select {
case <-ctx.Done():
return ctx.Err()
case <-timer.C():
}
attempt += 1
}
}
type Timer interface {
Start(duration time.Duration)
Stop()
C() <-chan time.Time
}
// defaultTimer implements Timer interface using time.Timer
type defaultTimer struct {
timer *time.Timer
}
// C returns the timers channel which receives the current time when the timer fires.
func (t *defaultTimer) C() <-chan time.Time {
return t.timer.C
}
// Start starts the timer to fire after the given duration
func (t *defaultTimer) Start(duration time.Duration) {
if t.timer == nil {
t.timer = time.NewTimer(duration)
return
}
if !t.timer.Stop() {
select {
case <-t.timer.C:
default:
}
}
t.timer.Reset(duration)
}
// Stop is called when the timer is not used anymore and resources may be freed.
func (t *defaultTimer) Stop() {
if t.timer != nil {
t.timer.Stop()
}
}
func nextInterval(s *retry.BackoffStrategy, attempt int) time.Duration {
initialInterval := float64(time.Duration(s.InitialInterval) * time.Millisecond)
maxInterval := float64(time.Duration(s.MaxInterval) * time.Millisecond)
exponent := s.Exponent
jitterFactor := float64(0.25)
interval := initialInterval * math.Pow(float64(attempt+1), exponent)
jitter := rand.Float64() * jitterFactor * interval
if rand.Float64() < 0.5 {
jitter = -1 * jitter
}
interval = interval + jitter
if interval <= 0 {
interval = initialInterval
}
if interval > maxInterval {
interval = maxInterval
}
return time.Duration(interval)
}

View File

@@ -3,10 +3,12 @@
package utils package utils
import ( import (
"bytes"
"context" "context"
"fmt" "fmt"
"io" "io"
"math/big" "math/big"
"net/http"
"reflect" "reflect"
"regexp" "regexp"
"strconv" "strconv"
@@ -125,6 +127,7 @@ func parseStructTag(tagKey string, field reflect.StructField) map[string]string
func parseParamTag(tagKey string, field reflect.StructField, defaultStyle string, defaultExplode bool) *paramTag { func parseParamTag(tagKey string, field reflect.StructField, defaultStyle string, defaultExplode bool) *paramTag {
// example `{tagKey}:"style=simple,explode=false,name=apiID"` // example `{tagKey}:"style=simple,explode=false,name=apiID"`
// example `{tagKey}:"inline"`
values := parseStructTag(tagKey, field) values := parseStructTag(tagKey, field)
if values == nil { if values == nil {
return nil return nil
@@ -138,6 +141,8 @@ func parseParamTag(tagKey string, field reflect.StructField, defaultStyle string
for k, v := range values { for k, v := range values {
switch k { switch k {
case "inline":
tag.Inline = v == "true"
case "style": case "style":
tag.Style = v tag.Style = v
case "explode": case "explode":
@@ -228,3 +233,15 @@ func contains(arr []string, str string) bool {
} }
return false return false
} }
func ConsumeRawBody(res *http.Response) ([]byte, error) {
rawBody, err := io.ReadAll(res.Body)
if err != nil {
return nil, fmt.Errorf("error reading response body: %w", err)
}
res.Body.Close()
res.Body = io.NopCloser(bytes.NewBuffer(rawBody))
return rawBody, nil
}

File diff suppressed because it is too large Load Diff

160
log.go
View File

@@ -10,8 +10,7 @@ import (
"github.com/LukeHagar/plexgo/internal/utils" "github.com/LukeHagar/plexgo/internal/utils"
"github.com/LukeHagar/plexgo/models/operations" "github.com/LukeHagar/plexgo/models/operations"
"github.com/LukeHagar/plexgo/models/sdkerrors" "github.com/LukeHagar/plexgo/models/sdkerrors"
"github.com/cenkalti/backoff/v4" "github.com/LukeHagar/plexgo/retry"
"io"
"net/http" "net/http"
"net/url" "net/url"
) )
@@ -55,7 +54,12 @@ func (s *Log) LogLine(ctx context.Context, level operations.Level, message strin
} }
} }
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) var baseURL string
if o.ServerURL == nil {
baseURL = utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
} else {
baseURL = *o.ServerURL
}
opURL, err := url.JoinPath(baseURL, "/log") opURL, err := url.JoinPath(baseURL, "/log")
if err != nil { if err != nil {
return nil, fmt.Errorf("error generating URL: %w", err) return nil, fmt.Errorf("error generating URL: %w", err)
@@ -87,6 +91,10 @@ func (s *Log) LogLine(ctx context.Context, level operations.Level, message strin
return nil, err return nil, err
} }
for k, v := range o.SetHeaders {
req.Header.Set(k, v)
}
globalRetryConfig := s.sdkConfiguration.RetryConfig globalRetryConfig := s.sdkConfiguration.RetryConfig
retryConfig := o.Retries retryConfig := o.Retries
if retryConfig == nil { if retryConfig == nil {
@@ -117,7 +125,11 @@ func (s *Log) LogLine(ctx context.Context, level operations.Level, message strin
req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req)
if err != nil { if err != nil {
return nil, backoff.Permanent(err) if retry.IsPermanentError(err) || retry.IsTemporaryError(err) {
return nil, err
}
return nil, retry.Permanent(err)
} }
httpRes, err := s.sdkConfiguration.Client.Do(req) httpRes, err := s.sdkConfiguration.Client.Do(req)
@@ -178,22 +190,12 @@ func (s *Log) LogLine(ctx context.Context, level operations.Level, message strin
RawResponse: httpRes, RawResponse: httpRes,
} }
getRawBody := func() ([]byte, error) {
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))
return rawBody, nil
}
switch { switch {
case httpRes.StatusCode == 200: case httpRes.StatusCode == 200:
case httpRes.StatusCode == 400: case httpRes.StatusCode == 400:
switch { switch {
case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -206,17 +208,16 @@ func (s *Log) LogLine(ctx context.Context, level operations.Level, message strin
out.RawResponse = httpRes out.RawResponse = httpRes
return nil, &out return nil, &out
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
} }
case httpRes.StatusCode == 401: case httpRes.StatusCode == 401:
switch { switch {
case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -229,28 +230,29 @@ func (s *Log) LogLine(ctx context.Context, level operations.Level, message strin
out.RawResponse = httpRes out.RawResponse = httpRes
return nil, &out return nil, &out
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
} }
case httpRes.StatusCode >= 400 && httpRes.StatusCode < 500: case httpRes.StatusCode >= 400 && httpRes.StatusCode < 500:
fallthrough rawBody, err := utils.ConsumeRawBody(httpRes)
case httpRes.StatusCode >= 500 && httpRes.StatusCode < 600: if err != nil {
rawBody, err := getRawBody() return nil, err
}
return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes)
case httpRes.StatusCode >= 500 && httpRes.StatusCode < 600:
rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes)
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError("unknown status code returned", httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError("unknown status code returned", httpRes.StatusCode, string(rawBody), httpRes)
} }
@@ -300,7 +302,12 @@ func (s *Log) LogMultiLine(ctx context.Context, request string, opts ...operatio
} }
} }
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) var baseURL string
if o.ServerURL == nil {
baseURL = utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
} else {
baseURL = *o.ServerURL
}
opURL, err := url.JoinPath(baseURL, "/log") opURL, err := url.JoinPath(baseURL, "/log")
if err != nil { if err != nil {
return nil, fmt.Errorf("error generating URL: %w", err) return nil, fmt.Errorf("error generating URL: %w", err)
@@ -328,12 +335,18 @@ func (s *Log) LogMultiLine(ctx context.Context, request string, opts ...operatio
} }
req.Header.Set("Accept", "application/json") req.Header.Set("Accept", "application/json")
req.Header.Set("User-Agent", s.sdkConfiguration.UserAgent) req.Header.Set("User-Agent", s.sdkConfiguration.UserAgent)
req.Header.Set("Content-Type", reqContentType) if reqContentType != "" {
req.Header.Set("Content-Type", reqContentType)
}
if err := utils.PopulateSecurity(ctx, req, s.sdkConfiguration.Security); err != nil { if err := utils.PopulateSecurity(ctx, req, s.sdkConfiguration.Security); err != nil {
return nil, err return nil, err
} }
for k, v := range o.SetHeaders {
req.Header.Set(k, v)
}
globalRetryConfig := s.sdkConfiguration.RetryConfig globalRetryConfig := s.sdkConfiguration.RetryConfig
retryConfig := o.Retries retryConfig := o.Retries
if retryConfig == nil { if retryConfig == nil {
@@ -364,7 +377,11 @@ func (s *Log) LogMultiLine(ctx context.Context, request string, opts ...operatio
req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req)
if err != nil { if err != nil {
return nil, backoff.Permanent(err) if retry.IsPermanentError(err) || retry.IsTemporaryError(err) {
return nil, err
}
return nil, retry.Permanent(err)
} }
httpRes, err := s.sdkConfiguration.Client.Do(req) httpRes, err := s.sdkConfiguration.Client.Do(req)
@@ -425,22 +442,12 @@ func (s *Log) LogMultiLine(ctx context.Context, request string, opts ...operatio
RawResponse: httpRes, RawResponse: httpRes,
} }
getRawBody := func() ([]byte, error) {
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))
return rawBody, nil
}
switch { switch {
case httpRes.StatusCode == 200: case httpRes.StatusCode == 200:
case httpRes.StatusCode == 400: case httpRes.StatusCode == 400:
switch { switch {
case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -453,17 +460,16 @@ func (s *Log) LogMultiLine(ctx context.Context, request string, opts ...operatio
out.RawResponse = httpRes out.RawResponse = httpRes
return nil, &out return nil, &out
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
} }
case httpRes.StatusCode == 401: case httpRes.StatusCode == 401:
switch { switch {
case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -476,28 +482,29 @@ func (s *Log) LogMultiLine(ctx context.Context, request string, opts ...operatio
out.RawResponse = httpRes out.RawResponse = httpRes
return nil, &out return nil, &out
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
} }
case httpRes.StatusCode >= 400 && httpRes.StatusCode < 500: case httpRes.StatusCode >= 400 && httpRes.StatusCode < 500:
fallthrough rawBody, err := utils.ConsumeRawBody(httpRes)
case httpRes.StatusCode >= 500 && httpRes.StatusCode < 600: if err != nil {
rawBody, err := getRawBody() return nil, err
}
return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes)
case httpRes.StatusCode >= 500 && httpRes.StatusCode < 600:
rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes)
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError("unknown status code returned", httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError("unknown status code returned", httpRes.StatusCode, string(rawBody), httpRes)
} }
@@ -527,7 +534,12 @@ func (s *Log) EnablePaperTrail(ctx context.Context, opts ...operations.Option) (
} }
} }
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) var baseURL string
if o.ServerURL == nil {
baseURL = utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
} else {
baseURL = *o.ServerURL
}
opURL, err := url.JoinPath(baseURL, "/log/networked") opURL, err := url.JoinPath(baseURL, "/log/networked")
if err != nil { if err != nil {
return nil, fmt.Errorf("error generating URL: %w", err) return nil, fmt.Errorf("error generating URL: %w", err)
@@ -555,6 +567,10 @@ func (s *Log) EnablePaperTrail(ctx context.Context, opts ...operations.Option) (
return nil, err return nil, err
} }
for k, v := range o.SetHeaders {
req.Header.Set(k, v)
}
globalRetryConfig := s.sdkConfiguration.RetryConfig globalRetryConfig := s.sdkConfiguration.RetryConfig
retryConfig := o.Retries retryConfig := o.Retries
if retryConfig == nil { if retryConfig == nil {
@@ -585,7 +601,11 @@ func (s *Log) EnablePaperTrail(ctx context.Context, opts ...operations.Option) (
req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req)
if err != nil { if err != nil {
return nil, backoff.Permanent(err) if retry.IsPermanentError(err) || retry.IsTemporaryError(err) {
return nil, err
}
return nil, retry.Permanent(err)
} }
httpRes, err := s.sdkConfiguration.Client.Do(req) httpRes, err := s.sdkConfiguration.Client.Do(req)
@@ -646,22 +666,12 @@ func (s *Log) EnablePaperTrail(ctx context.Context, opts ...operations.Option) (
RawResponse: httpRes, RawResponse: httpRes,
} }
getRawBody := func() ([]byte, error) {
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))
return rawBody, nil
}
switch { switch {
case httpRes.StatusCode == 200: case httpRes.StatusCode == 200:
case httpRes.StatusCode == 400: case httpRes.StatusCode == 400:
switch { switch {
case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -674,17 +684,16 @@ func (s *Log) EnablePaperTrail(ctx context.Context, opts ...operations.Option) (
out.RawResponse = httpRes out.RawResponse = httpRes
return nil, &out return nil, &out
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
} }
case httpRes.StatusCode == 401: case httpRes.StatusCode == 401:
switch { switch {
case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -697,30 +706,31 @@ func (s *Log) EnablePaperTrail(ctx context.Context, opts ...operations.Option) (
out.RawResponse = httpRes out.RawResponse = httpRes
return nil, &out return nil, &out
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
} }
case httpRes.StatusCode == 403: case httpRes.StatusCode == 403:
fallthrough fallthrough
case httpRes.StatusCode >= 400 && httpRes.StatusCode < 500: case httpRes.StatusCode >= 400 && httpRes.StatusCode < 500:
fallthrough rawBody, err := utils.ConsumeRawBody(httpRes)
case httpRes.StatusCode >= 500 && httpRes.StatusCode < 600: if err != nil {
rawBody, err := getRawBody() return nil, err
}
return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes)
case httpRes.StatusCode >= 500 && httpRes.StatusCode < 600:
rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes)
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError("unknown status code returned", httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError("unknown status code returned", httpRes.StatusCode, string(rawBody), httpRes)
} }

264
media.go
View File

@@ -10,8 +10,7 @@ import (
"github.com/LukeHagar/plexgo/internal/utils" "github.com/LukeHagar/plexgo/internal/utils"
"github.com/LukeHagar/plexgo/models/operations" "github.com/LukeHagar/plexgo/models/operations"
"github.com/LukeHagar/plexgo/models/sdkerrors" "github.com/LukeHagar/plexgo/models/sdkerrors"
"github.com/cenkalti/backoff/v4" "github.com/LukeHagar/plexgo/retry"
"io"
"net/http" "net/http"
"net/url" "net/url"
) )
@@ -53,7 +52,12 @@ func (s *Media) MarkPlayed(ctx context.Context, key float64, opts ...operations.
} }
} }
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) var baseURL string
if o.ServerURL == nil {
baseURL = utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
} else {
baseURL = *o.ServerURL
}
opURL, err := url.JoinPath(baseURL, "/:/scrobble") opURL, err := url.JoinPath(baseURL, "/:/scrobble")
if err != nil { if err != nil {
return nil, fmt.Errorf("error generating URL: %w", err) return nil, fmt.Errorf("error generating URL: %w", err)
@@ -85,6 +89,10 @@ func (s *Media) MarkPlayed(ctx context.Context, key float64, opts ...operations.
return nil, err return nil, err
} }
for k, v := range o.SetHeaders {
req.Header.Set(k, v)
}
globalRetryConfig := s.sdkConfiguration.RetryConfig globalRetryConfig := s.sdkConfiguration.RetryConfig
retryConfig := o.Retries retryConfig := o.Retries
if retryConfig == nil { if retryConfig == nil {
@@ -115,7 +123,11 @@ func (s *Media) MarkPlayed(ctx context.Context, key float64, opts ...operations.
req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req)
if err != nil { if err != nil {
return nil, backoff.Permanent(err) if retry.IsPermanentError(err) || retry.IsTemporaryError(err) {
return nil, err
}
return nil, retry.Permanent(err)
} }
httpRes, err := s.sdkConfiguration.Client.Do(req) httpRes, err := s.sdkConfiguration.Client.Do(req)
@@ -176,22 +188,12 @@ func (s *Media) MarkPlayed(ctx context.Context, key float64, opts ...operations.
RawResponse: httpRes, RawResponse: httpRes,
} }
getRawBody := func() ([]byte, error) {
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))
return rawBody, nil
}
switch { switch {
case httpRes.StatusCode == 200: case httpRes.StatusCode == 200:
case httpRes.StatusCode == 400: case httpRes.StatusCode == 400:
switch { switch {
case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -204,17 +206,16 @@ func (s *Media) MarkPlayed(ctx context.Context, key float64, opts ...operations.
out.RawResponse = httpRes out.RawResponse = httpRes
return nil, &out return nil, &out
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
} }
case httpRes.StatusCode == 401: case httpRes.StatusCode == 401:
switch { switch {
case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -227,28 +228,29 @@ func (s *Media) MarkPlayed(ctx context.Context, key float64, opts ...operations.
out.RawResponse = httpRes out.RawResponse = httpRes
return nil, &out return nil, &out
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
} }
case httpRes.StatusCode >= 400 && httpRes.StatusCode < 500: case httpRes.StatusCode >= 400 && httpRes.StatusCode < 500:
fallthrough rawBody, err := utils.ConsumeRawBody(httpRes)
case httpRes.StatusCode >= 500 && httpRes.StatusCode < 600: if err != nil {
rawBody, err := getRawBody() return nil, err
}
return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes)
case httpRes.StatusCode >= 500 && httpRes.StatusCode < 600:
rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes)
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError("unknown status code returned", httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError("unknown status code returned", httpRes.StatusCode, string(rawBody), httpRes)
} }
@@ -282,7 +284,12 @@ func (s *Media) MarkUnplayed(ctx context.Context, key float64, opts ...operation
} }
} }
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) var baseURL string
if o.ServerURL == nil {
baseURL = utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
} else {
baseURL = *o.ServerURL
}
opURL, err := url.JoinPath(baseURL, "/:/unscrobble") opURL, err := url.JoinPath(baseURL, "/:/unscrobble")
if err != nil { if err != nil {
return nil, fmt.Errorf("error generating URL: %w", err) return nil, fmt.Errorf("error generating URL: %w", err)
@@ -314,6 +321,10 @@ func (s *Media) MarkUnplayed(ctx context.Context, key float64, opts ...operation
return nil, err return nil, err
} }
for k, v := range o.SetHeaders {
req.Header.Set(k, v)
}
globalRetryConfig := s.sdkConfiguration.RetryConfig globalRetryConfig := s.sdkConfiguration.RetryConfig
retryConfig := o.Retries retryConfig := o.Retries
if retryConfig == nil { if retryConfig == nil {
@@ -344,7 +355,11 @@ func (s *Media) MarkUnplayed(ctx context.Context, key float64, opts ...operation
req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req)
if err != nil { if err != nil {
return nil, backoff.Permanent(err) if retry.IsPermanentError(err) || retry.IsTemporaryError(err) {
return nil, err
}
return nil, retry.Permanent(err)
} }
httpRes, err := s.sdkConfiguration.Client.Do(req) httpRes, err := s.sdkConfiguration.Client.Do(req)
@@ -405,22 +420,12 @@ func (s *Media) MarkUnplayed(ctx context.Context, key float64, opts ...operation
RawResponse: httpRes, RawResponse: httpRes,
} }
getRawBody := func() ([]byte, error) {
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))
return rawBody, nil
}
switch { switch {
case httpRes.StatusCode == 200: case httpRes.StatusCode == 200:
case httpRes.StatusCode == 400: case httpRes.StatusCode == 400:
switch { switch {
case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -433,17 +438,16 @@ func (s *Media) MarkUnplayed(ctx context.Context, key float64, opts ...operation
out.RawResponse = httpRes out.RawResponse = httpRes
return nil, &out return nil, &out
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
} }
case httpRes.StatusCode == 401: case httpRes.StatusCode == 401:
switch { switch {
case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -456,28 +460,29 @@ func (s *Media) MarkUnplayed(ctx context.Context, key float64, opts ...operation
out.RawResponse = httpRes out.RawResponse = httpRes
return nil, &out return nil, &out
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
} }
case httpRes.StatusCode >= 400 && httpRes.StatusCode < 500: case httpRes.StatusCode >= 400 && httpRes.StatusCode < 500:
fallthrough rawBody, err := utils.ConsumeRawBody(httpRes)
case httpRes.StatusCode >= 500 && httpRes.StatusCode < 600: if err != nil {
rawBody, err := getRawBody() return nil, err
}
return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes)
case httpRes.StatusCode >= 500 && httpRes.StatusCode < 600:
rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes)
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError("unknown status code returned", httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError("unknown status code returned", httpRes.StatusCode, string(rawBody), httpRes)
} }
@@ -513,7 +518,12 @@ func (s *Media) UpdatePlayProgress(ctx context.Context, key string, time float64
} }
} }
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) var baseURL string
if o.ServerURL == nil {
baseURL = utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
} else {
baseURL = *o.ServerURL
}
opURL, err := url.JoinPath(baseURL, "/:/progress") opURL, err := url.JoinPath(baseURL, "/:/progress")
if err != nil { if err != nil {
return nil, fmt.Errorf("error generating URL: %w", err) return nil, fmt.Errorf("error generating URL: %w", err)
@@ -545,6 +555,10 @@ func (s *Media) UpdatePlayProgress(ctx context.Context, key string, time float64
return nil, err return nil, err
} }
for k, v := range o.SetHeaders {
req.Header.Set(k, v)
}
globalRetryConfig := s.sdkConfiguration.RetryConfig globalRetryConfig := s.sdkConfiguration.RetryConfig
retryConfig := o.Retries retryConfig := o.Retries
if retryConfig == nil { if retryConfig == nil {
@@ -575,7 +589,11 @@ func (s *Media) UpdatePlayProgress(ctx context.Context, key string, time float64
req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req)
if err != nil { if err != nil {
return nil, backoff.Permanent(err) if retry.IsPermanentError(err) || retry.IsTemporaryError(err) {
return nil, err
}
return nil, retry.Permanent(err)
} }
httpRes, err := s.sdkConfiguration.Client.Do(req) httpRes, err := s.sdkConfiguration.Client.Do(req)
@@ -636,22 +654,12 @@ func (s *Media) UpdatePlayProgress(ctx context.Context, key string, time float64
RawResponse: httpRes, RawResponse: httpRes,
} }
getRawBody := func() ([]byte, error) {
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))
return rawBody, nil
}
switch { switch {
case httpRes.StatusCode == 200: case httpRes.StatusCode == 200:
case httpRes.StatusCode == 400: case httpRes.StatusCode == 400:
switch { switch {
case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -664,17 +672,16 @@ func (s *Media) UpdatePlayProgress(ctx context.Context, key string, time float64
out.RawResponse = httpRes out.RawResponse = httpRes
return nil, &out return nil, &out
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
} }
case httpRes.StatusCode == 401: case httpRes.StatusCode == 401:
switch { switch {
case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -687,28 +694,29 @@ func (s *Media) UpdatePlayProgress(ctx context.Context, key string, time float64
out.RawResponse = httpRes out.RawResponse = httpRes
return nil, &out return nil, &out
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
} }
case httpRes.StatusCode >= 400 && httpRes.StatusCode < 500: case httpRes.StatusCode >= 400 && httpRes.StatusCode < 500:
fallthrough rawBody, err := utils.ConsumeRawBody(httpRes)
case httpRes.StatusCode >= 500 && httpRes.StatusCode < 600: if err != nil {
rawBody, err := getRawBody() return nil, err
}
return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes)
case httpRes.StatusCode >= 500 && httpRes.StatusCode < 600:
rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes)
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError("unknown status code returned", httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError("unknown status code returned", httpRes.StatusCode, string(rawBody), httpRes)
} }
@@ -738,7 +746,12 @@ func (s *Media) GetBannerImage(ctx context.Context, request operations.GetBanner
} }
} }
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) var baseURL string
if o.ServerURL == nil {
baseURL = utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
} else {
baseURL = *o.ServerURL
}
opURL, err := utils.GenerateURL(ctx, baseURL, "/library/metadata/{ratingKey}/banner", request, nil) opURL, err := utils.GenerateURL(ctx, baseURL, "/library/metadata/{ratingKey}/banner", request, nil)
if err != nil { if err != nil {
return nil, fmt.Errorf("error generating URL: %w", err) return nil, fmt.Errorf("error generating URL: %w", err)
@@ -772,6 +785,10 @@ func (s *Media) GetBannerImage(ctx context.Context, request operations.GetBanner
return nil, err return nil, err
} }
for k, v := range o.SetHeaders {
req.Header.Set(k, v)
}
globalRetryConfig := s.sdkConfiguration.RetryConfig globalRetryConfig := s.sdkConfiguration.RetryConfig
retryConfig := o.Retries retryConfig := o.Retries
if retryConfig == nil { if retryConfig == nil {
@@ -802,7 +819,11 @@ func (s *Media) GetBannerImage(ctx context.Context, request operations.GetBanner
req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req)
if err != nil { if err != nil {
return nil, backoff.Permanent(err) if retry.IsPermanentError(err) || retry.IsTemporaryError(err) {
return nil, err
}
return nil, retry.Permanent(err)
} }
httpRes, err := s.sdkConfiguration.Client.Do(req) httpRes, err := s.sdkConfiguration.Client.Do(req)
@@ -863,16 +884,6 @@ func (s *Media) GetBannerImage(ctx context.Context, request operations.GetBanner
RawResponse: httpRes, RawResponse: httpRes,
} }
getRawBody := func() ([]byte, error) {
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))
return rawBody, nil
}
switch { switch {
case httpRes.StatusCode == 200: case httpRes.StatusCode == 200:
res.Headers = httpRes.Header res.Headers = httpRes.Header
@@ -883,17 +894,16 @@ func (s *Media) GetBannerImage(ctx context.Context, request operations.GetBanner
return res, nil return res, nil
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
} }
case httpRes.StatusCode == 400: case httpRes.StatusCode == 400:
switch { switch {
case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -906,17 +916,16 @@ func (s *Media) GetBannerImage(ctx context.Context, request operations.GetBanner
out.RawResponse = httpRes out.RawResponse = httpRes
return nil, &out return nil, &out
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
} }
case httpRes.StatusCode == 401: case httpRes.StatusCode == 401:
switch { switch {
case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -929,28 +938,29 @@ func (s *Media) GetBannerImage(ctx context.Context, request operations.GetBanner
out.RawResponse = httpRes out.RawResponse = httpRes
return nil, &out return nil, &out
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
} }
case httpRes.StatusCode >= 400 && httpRes.StatusCode < 500: case httpRes.StatusCode >= 400 && httpRes.StatusCode < 500:
fallthrough rawBody, err := utils.ConsumeRawBody(httpRes)
case httpRes.StatusCode >= 500 && httpRes.StatusCode < 600: if err != nil {
rawBody, err := getRawBody() return nil, err
}
return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes)
case httpRes.StatusCode >= 500 && httpRes.StatusCode < 600:
rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes)
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError("unknown status code returned", httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError("unknown status code returned", httpRes.StatusCode, string(rawBody), httpRes)
} }
@@ -980,7 +990,12 @@ func (s *Media) GetThumbImage(ctx context.Context, request operations.GetThumbIm
} }
} }
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) var baseURL string
if o.ServerURL == nil {
baseURL = utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
} else {
baseURL = *o.ServerURL
}
opURL, err := utils.GenerateURL(ctx, baseURL, "/library/metadata/{ratingKey}/thumb", request, nil) opURL, err := utils.GenerateURL(ctx, baseURL, "/library/metadata/{ratingKey}/thumb", request, nil)
if err != nil { if err != nil {
return nil, fmt.Errorf("error generating URL: %w", err) return nil, fmt.Errorf("error generating URL: %w", err)
@@ -1014,6 +1029,10 @@ func (s *Media) GetThumbImage(ctx context.Context, request operations.GetThumbIm
return nil, err return nil, err
} }
for k, v := range o.SetHeaders {
req.Header.Set(k, v)
}
globalRetryConfig := s.sdkConfiguration.RetryConfig globalRetryConfig := s.sdkConfiguration.RetryConfig
retryConfig := o.Retries retryConfig := o.Retries
if retryConfig == nil { if retryConfig == nil {
@@ -1044,7 +1063,11 @@ func (s *Media) GetThumbImage(ctx context.Context, request operations.GetThumbIm
req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req)
if err != nil { if err != nil {
return nil, backoff.Permanent(err) if retry.IsPermanentError(err) || retry.IsTemporaryError(err) {
return nil, err
}
return nil, retry.Permanent(err)
} }
httpRes, err := s.sdkConfiguration.Client.Do(req) httpRes, err := s.sdkConfiguration.Client.Do(req)
@@ -1105,16 +1128,6 @@ func (s *Media) GetThumbImage(ctx context.Context, request operations.GetThumbIm
RawResponse: httpRes, RawResponse: httpRes,
} }
getRawBody := func() ([]byte, error) {
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))
return rawBody, nil
}
switch { switch {
case httpRes.StatusCode == 200: case httpRes.StatusCode == 200:
res.Headers = httpRes.Header res.Headers = httpRes.Header
@@ -1125,17 +1138,16 @@ func (s *Media) GetThumbImage(ctx context.Context, request operations.GetThumbIm
return res, nil return res, nil
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
} }
case httpRes.StatusCode == 400: case httpRes.StatusCode == 400:
switch { switch {
case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -1148,17 +1160,16 @@ func (s *Media) GetThumbImage(ctx context.Context, request operations.GetThumbIm
out.RawResponse = httpRes out.RawResponse = httpRes
return nil, &out return nil, &out
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
} }
case httpRes.StatusCode == 401: case httpRes.StatusCode == 401:
switch { switch {
case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -1171,28 +1182,29 @@ func (s *Media) GetThumbImage(ctx context.Context, request operations.GetThumbIm
out.RawResponse = httpRes out.RawResponse = httpRes
return nil, &out return nil, &out
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
} }
case httpRes.StatusCode >= 400 && httpRes.StatusCode < 500: case httpRes.StatusCode >= 400 && httpRes.StatusCode < 500:
fallthrough rawBody, err := utils.ConsumeRawBody(httpRes)
case httpRes.StatusCode >= 500 && httpRes.StatusCode < 600: if err != nil {
rawBody, err := getRawBody() return nil, err
}
return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes)
case httpRes.StatusCode >= 500 && httpRes.StatusCode < 600:
rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes)
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError("unknown status code returned", httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError("unknown status code returned", httpRes.StatusCode, string(rawBody), httpRes)
} }

View File

@@ -10,7 +10,7 @@ type GetBandwidthStatisticsRequest struct {
// The timespan to retrieve statistics for // The timespan to retrieve statistics for
// the exact meaning of this parameter is not known // the exact meaning of this parameter is not known
// //
Timespan *int64 `queryParam:"style=form,explode=true,name=Timespan"` Timespan *int64 `queryParam:"style=form,explode=true,name=timespan"`
} }
func (o *GetBandwidthStatisticsRequest) GetTimespan() *int64 { func (o *GetBandwidthStatisticsRequest) GetTimespan() *int64 {

View File

@@ -33,6 +33,7 @@ const (
TagResolution Tag = "resolution" TagResolution Tag = "resolution"
TagFirstCharacter Tag = "firstCharacter" TagFirstCharacter Tag = "firstCharacter"
TagFolder Tag = "folder" TagFolder Tag = "folder"
TagAlbums Tag = "albums"
) )
func (e Tag) ToPointer() *Tag { func (e Tag) ToPointer() *Tag {
@@ -81,6 +82,8 @@ func (e *Tag) UnmarshalJSON(data []byte) error {
case "firstCharacter": case "firstCharacter":
fallthrough fallthrough
case "folder": case "folder":
fallthrough
case "albums":
*e = Tag(v) *e = Tag(v)
return nil return nil
default: default:
@@ -128,6 +131,9 @@ const (
GetLibraryItemsQueryParamTypeTvShow GetLibraryItemsQueryParamType = 2 GetLibraryItemsQueryParamTypeTvShow GetLibraryItemsQueryParamType = 2
GetLibraryItemsQueryParamTypeSeason GetLibraryItemsQueryParamType = 3 GetLibraryItemsQueryParamTypeSeason GetLibraryItemsQueryParamType = 3
GetLibraryItemsQueryParamTypeEpisode GetLibraryItemsQueryParamType = 4 GetLibraryItemsQueryParamTypeEpisode GetLibraryItemsQueryParamType = 4
GetLibraryItemsQueryParamTypeAudio GetLibraryItemsQueryParamType = 8
GetLibraryItemsQueryParamTypeAlbum GetLibraryItemsQueryParamType = 9
GetLibraryItemsQueryParamTypeTrack GetLibraryItemsQueryParamType = 10
) )
func (e GetLibraryItemsQueryParamType) ToPointer() *GetLibraryItemsQueryParamType { func (e GetLibraryItemsQueryParamType) ToPointer() *GetLibraryItemsQueryParamType {
@@ -146,6 +152,12 @@ func (e *GetLibraryItemsQueryParamType) UnmarshalJSON(data []byte) error {
case 3: case 3:
fallthrough fallthrough
case 4: case 4:
fallthrough
case 8:
fallthrough
case 9:
fallthrough
case 10:
*e = GetLibraryItemsQueryParamType(v) *e = GetLibraryItemsQueryParamType(v)
return nil return nil
default: default:
@@ -617,11 +629,13 @@ func (e *GetLibraryItemsLibraryType) UnmarshalJSON(data []byte) error {
} }
} }
// GetLibraryItemsFlattenSeasons - Setting that indicates if seasons are set to hidden for the show. (-1 = Library default, 0 = Hide, 1 = Show).
type GetLibraryItemsFlattenSeasons string type GetLibraryItemsFlattenSeasons string
const ( const (
GetLibraryItemsFlattenSeasonsFalse GetLibraryItemsFlattenSeasons = "0" GetLibraryItemsFlattenSeasonsLibraryDefault GetLibraryItemsFlattenSeasons = "-1"
GetLibraryItemsFlattenSeasonsTrue GetLibraryItemsFlattenSeasons = "1" GetLibraryItemsFlattenSeasonsHide GetLibraryItemsFlattenSeasons = "0"
GetLibraryItemsFlattenSeasonsShow GetLibraryItemsFlattenSeasons = "1"
) )
func (e GetLibraryItemsFlattenSeasons) ToPointer() *GetLibraryItemsFlattenSeasons { func (e GetLibraryItemsFlattenSeasons) ToPointer() *GetLibraryItemsFlattenSeasons {
@@ -633,6 +647,8 @@ func (e *GetLibraryItemsFlattenSeasons) UnmarshalJSON(data []byte) error {
return err return err
} }
switch v { switch v {
case "-1":
fallthrough
case "0": case "0":
fallthrough fallthrough
case "1": case "1":
@@ -643,7 +659,64 @@ func (e *GetLibraryItemsFlattenSeasons) UnmarshalJSON(data []byte) error {
} }
} }
// GetLibraryItemsShowOrdering - Setting that indicates the episode ordering for the show // GetLibraryItemsEpisodeSort - Setting that indicates how episodes are sorted for the show. (-1 = Library default, 0 = Oldest first, 1 = Newest first).
type GetLibraryItemsEpisodeSort string
const (
GetLibraryItemsEpisodeSortLibraryDefault GetLibraryItemsEpisodeSort = "-1"
GetLibraryItemsEpisodeSortOldestFirst GetLibraryItemsEpisodeSort = "0"
GetLibraryItemsEpisodeSortNewestFirst GetLibraryItemsEpisodeSort = "1"
)
func (e GetLibraryItemsEpisodeSort) ToPointer() *GetLibraryItemsEpisodeSort {
return &e
}
func (e *GetLibraryItemsEpisodeSort) UnmarshalJSON(data []byte) error {
var v string
if err := json.Unmarshal(data, &v); err != nil {
return err
}
switch v {
case "-1":
fallthrough
case "0":
fallthrough
case "1":
*e = GetLibraryItemsEpisodeSort(v)
return nil
default:
return fmt.Errorf("invalid value for GetLibraryItemsEpisodeSort: %v", v)
}
}
// GetLibraryItemsEnableCreditsMarkerGeneration - Setting that indicates if credits markers detection is enabled. (-1 = Library default, 0 = Disabled).
type GetLibraryItemsEnableCreditsMarkerGeneration string
const (
GetLibraryItemsEnableCreditsMarkerGenerationLibraryDefault GetLibraryItemsEnableCreditsMarkerGeneration = "-1"
GetLibraryItemsEnableCreditsMarkerGenerationDisabled GetLibraryItemsEnableCreditsMarkerGeneration = "0"
)
func (e GetLibraryItemsEnableCreditsMarkerGeneration) ToPointer() *GetLibraryItemsEnableCreditsMarkerGeneration {
return &e
}
func (e *GetLibraryItemsEnableCreditsMarkerGeneration) UnmarshalJSON(data []byte) error {
var v string
if err := json.Unmarshal(data, &v); err != nil {
return err
}
switch v {
case "-1":
fallthrough
case "0":
*e = GetLibraryItemsEnableCreditsMarkerGeneration(v)
return nil
default:
return fmt.Errorf("invalid value for GetLibraryItemsEnableCreditsMarkerGeneration: %v", v)
}
}
// GetLibraryItemsShowOrdering - Setting that indicates the episode ordering for the show.
// None = Library default, // None = Library default,
// tmdbAiring = The Movie Database (Aired), // tmdbAiring = The Movie Database (Aired),
// aired = TheTVDB (Aired), // aired = TheTVDB (Aired),
@@ -652,11 +725,11 @@ func (e *GetLibraryItemsFlattenSeasons) UnmarshalJSON(data []byte) error {
type GetLibraryItemsShowOrdering string type GetLibraryItemsShowOrdering string
const ( const (
GetLibraryItemsShowOrderingNone GetLibraryItemsShowOrdering = "None" GetLibraryItemsShowOrderingNone GetLibraryItemsShowOrdering = "None"
GetLibraryItemsShowOrderingTmdbAiring GetLibraryItemsShowOrdering = "tmdbAiring" GetLibraryItemsShowOrderingTmdbAiring GetLibraryItemsShowOrdering = "tmdbAiring"
GetLibraryItemsShowOrderingAired GetLibraryItemsShowOrdering = "aired" GetLibraryItemsShowOrderingTvdbAired GetLibraryItemsShowOrdering = "aired"
GetLibraryItemsShowOrderingDvd GetLibraryItemsShowOrdering = "dvd" GetLibraryItemsShowOrderingTvdbDvd GetLibraryItemsShowOrdering = "dvd"
GetLibraryItemsShowOrderingAbsolute GetLibraryItemsShowOrdering = "absolute" GetLibraryItemsShowOrderingTvdbAbsolute GetLibraryItemsShowOrdering = "absolute"
) )
func (e GetLibraryItemsShowOrdering) ToPointer() *GetLibraryItemsShowOrdering { func (e GetLibraryItemsShowOrdering) ToPointer() *GetLibraryItemsShowOrdering {
@@ -1630,18 +1703,23 @@ type GetLibraryItemsMetadata struct {
LibrarySectionKey *string `json:"librarySectionKey,omitempty"` LibrarySectionKey *string `json:"librarySectionKey,omitempty"`
// The type of media content // The type of media content
// //
Type GetLibraryItemsLibraryType `json:"type"` Type GetLibraryItemsLibraryType `json:"type"`
Title string `json:"title"` Title string `json:"title"`
Slug *string `json:"slug,omitempty"` Slug *string `json:"slug,omitempty"`
ContentRating *string `json:"contentRating,omitempty"` ContentRating *string `json:"contentRating,omitempty"`
Summary string `json:"summary"` Summary string `json:"summary"`
Rating *float64 `json:"rating,omitempty"` Rating *float64 `json:"rating,omitempty"`
AudienceRating *float64 `json:"audienceRating,omitempty"` AudienceRating *float64 `json:"audienceRating,omitempty"`
Year *int `json:"year,omitempty"` Year *int `json:"year,omitempty"`
SeasonCount *int `json:"seasonCount,omitempty"` SeasonCount *int `json:"seasonCount,omitempty"`
Tagline *string `json:"tagline,omitempty"` Tagline *string `json:"tagline,omitempty"`
FlattenSeasons *GetLibraryItemsFlattenSeasons `default:"0" json:"flattenSeasons"` // Setting that indicates if seasons are set to hidden for the show. (-1 = Library default, 0 = Hide, 1 = Show).
// Setting that indicates the episode ordering for the show FlattenSeasons *GetLibraryItemsFlattenSeasons `json:"flattenSeasons,omitempty"`
// Setting that indicates how episodes are sorted for the show. (-1 = Library default, 0 = Oldest first, 1 = Newest first).
EpisodeSort *GetLibraryItemsEpisodeSort `json:"episodeSort,omitempty"`
// Setting that indicates if credits markers detection is enabled. (-1 = Library default, 0 = Disabled).
EnableCreditsMarkerGeneration *GetLibraryItemsEnableCreditsMarkerGeneration `json:"enableCreditsMarkerGeneration,omitempty"`
// Setting that indicates the episode ordering for the show.
// None = Library default, // None = Library default,
// tmdbAiring = The Movie Database (Aired), // tmdbAiring = The Movie Database (Aired),
// aired = TheTVDB (Aired), // aired = TheTVDB (Aired),
@@ -1857,6 +1935,20 @@ func (o *GetLibraryItemsMetadata) GetFlattenSeasons() *GetLibraryItemsFlattenSea
return o.FlattenSeasons return o.FlattenSeasons
} }
func (o *GetLibraryItemsMetadata) GetEpisodeSort() *GetLibraryItemsEpisodeSort {
if o == nil {
return nil
}
return o.EpisodeSort
}
func (o *GetLibraryItemsMetadata) GetEnableCreditsMarkerGeneration() *GetLibraryItemsEnableCreditsMarkerGeneration {
if o == nil {
return nil
}
return o.EnableCreditsMarkerGeneration
}
func (o *GetLibraryItemsMetadata) GetShowOrdering() *GetLibraryItemsShowOrdering { func (o *GetLibraryItemsMetadata) GetShowOrdering() *GetLibraryItemsShowOrdering {
if o == nil { if o == nil {
return nil return nil

View File

@@ -782,15 +782,25 @@ func (o *Producer) GetThumb() *string {
} }
type GetMetaDataByRatingKeyMetadata struct { type GetMetaDataByRatingKeyMetadata struct {
RatingKey *string `json:"ratingKey,omitempty"` RatingKey *string `json:"ratingKey,omitempty"`
Key *string `json:"key,omitempty"` Key *string `json:"key,omitempty"`
GUID *string `json:"guid,omitempty"` GUID *string `json:"guid,omitempty"`
Studio *string `json:"studio,omitempty"` Studio *string `json:"studio,omitempty"`
Type *string `json:"type,omitempty"` Type *string `json:"type,omitempty"`
Title *string `json:"title,omitempty"` Title *string `json:"title,omitempty"`
LibrarySectionTitle *string `json:"librarySectionTitle,omitempty"` LibrarySectionTitle *string `json:"librarySectionTitle,omitempty"`
LibrarySectionID *int `json:"librarySectionID,omitempty"` LibrarySectionID *int `json:"librarySectionID,omitempty"`
LibrarySectionKey *string `json:"librarySectionKey,omitempty"` LibrarySectionKey *string `json:"librarySectionKey,omitempty"`
// The name of the album artist for the track when audio, and the name of the TV show for the episode when video.
GrandparentTitle *string `json:"grandparentTitle,omitempty"`
// The name of the album for the track when audio, and the name of the season for the episode when TV show.
ParentTitle *string `json:"parentTitle,omitempty"`
// The orginal untranslated name of the media item when non-english.
OriginalTitle *string `json:"originalTitle,omitempty"`
// The index starting from 0 of this media item in the MetaData array.
Index *int64 `json:"index,omitempty"`
// The parent index starting from 0 of this media item in the parent MetaData array.
ParentIndex *int64 `json:"parentIndex,omitempty"`
ContentRating *string `json:"contentRating,omitempty"` ContentRating *string `json:"contentRating,omitempty"`
Summary *string `json:"summary,omitempty"` Summary *string `json:"summary,omitempty"`
Rating *float64 `json:"rating,omitempty"` Rating *float64 `json:"rating,omitempty"`
@@ -891,6 +901,41 @@ func (o *GetMetaDataByRatingKeyMetadata) GetLibrarySectionKey() *string {
return o.LibrarySectionKey return o.LibrarySectionKey
} }
func (o *GetMetaDataByRatingKeyMetadata) GetGrandparentTitle() *string {
if o == nil {
return nil
}
return o.GrandparentTitle
}
func (o *GetMetaDataByRatingKeyMetadata) GetParentTitle() *string {
if o == nil {
return nil
}
return o.ParentTitle
}
func (o *GetMetaDataByRatingKeyMetadata) GetOriginalTitle() *string {
if o == nil {
return nil
}
return o.OriginalTitle
}
func (o *GetMetaDataByRatingKeyMetadata) GetIndex() *int64 {
if o == nil {
return nil
}
return o.Index
}
func (o *GetMetaDataByRatingKeyMetadata) GetParentIndex() *int64 {
if o == nil {
return nil
}
return o.ParentIndex
}
func (o *GetMetaDataByRatingKeyMetadata) GetContentRating() *string { func (o *GetMetaDataByRatingKeyMetadata) GetContentRating() *string {
if o == nil { if o == nil {
return nil return nil

View File

@@ -12,54 +12,6 @@ var GetPinServerList = []string{
"https://plex.tv/api/v2", "https://plex.tv/api/v2",
} }
type GetPinGlobals struct {
// An opaque identifier unique to the client (UUID, serial number, or other unique device ID)
ClientID *string `header:"style=simple,explode=false,name=X-Plex-Client-Identifier"`
// The name of the client application. (Plex Web, Plex Media Server, etc.)
ClientName *string `header:"style=simple,explode=false,name=X-Plex-Product"`
// A relatively friendly name for the client device
DeviceNickname *string `header:"style=simple,explode=false,name=X-Plex-Device"`
// The version of the client application.
ClientVersion *string `header:"style=simple,explode=false,name=X-Plex-Version"`
// The platform of the client application.
Platform *string `header:"style=simple,explode=false,name=X-Plex-Platform"`
}
func (o *GetPinGlobals) GetClientID() *string {
if o == nil {
return nil
}
return o.ClientID
}
func (o *GetPinGlobals) GetClientName() *string {
if o == nil {
return nil
}
return o.ClientName
}
func (o *GetPinGlobals) GetDeviceNickname() *string {
if o == nil {
return nil
}
return o.DeviceNickname
}
func (o *GetPinGlobals) GetClientVersion() *string {
if o == nil {
return nil
}
return o.ClientVersion
}
func (o *GetPinGlobals) GetPlatform() *string {
if o == nil {
return nil
}
return o.Platform
}
type GetPinRequest struct { type GetPinRequest struct {
// Determines the kind of code returned by the API call // Determines the kind of code returned by the API call
// Strong codes are used for Pin authentication flows // Strong codes are used for Pin authentication flows
@@ -67,7 +19,7 @@ type GetPinRequest struct {
// //
Strong *bool `default:"false" queryParam:"style=form,explode=true,name=strong"` Strong *bool `default:"false" queryParam:"style=form,explode=true,name=strong"`
// An opaque identifier unique to the client (UUID, serial number, or other unique device ID) // An opaque identifier unique to the client (UUID, serial number, or other unique device ID)
ClientID *string `header:"style=simple,explode=false,name=X-Plex-Client-Identifier"` ClientID string `header:"style=simple,explode=false,name=X-Plex-Client-Identifier"`
// The name of the client application. (Plex Web, Plex Media Server, etc.) // The name of the client application. (Plex Web, Plex Media Server, etc.)
ClientName *string `header:"style=simple,explode=false,name=X-Plex-Product"` ClientName *string `header:"style=simple,explode=false,name=X-Plex-Product"`
// A relatively friendly name for the client device // A relatively friendly name for the client device
@@ -96,9 +48,9 @@ func (o *GetPinRequest) GetStrong() *bool {
return o.Strong return o.Strong
} }
func (o *GetPinRequest) GetClientID() *string { func (o *GetPinRequest) GetClientID() string {
if o == nil { if o == nil {
return nil return ""
} }
return o.ClientID return o.ClientID
} }

View File

@@ -23,6 +23,9 @@ const (
GetPlaylistContentsQueryParamTypeTvShow GetPlaylistContentsQueryParamType = 2 GetPlaylistContentsQueryParamTypeTvShow GetPlaylistContentsQueryParamType = 2
GetPlaylistContentsQueryParamTypeSeason GetPlaylistContentsQueryParamType = 3 GetPlaylistContentsQueryParamTypeSeason GetPlaylistContentsQueryParamType = 3
GetPlaylistContentsQueryParamTypeEpisode GetPlaylistContentsQueryParamType = 4 GetPlaylistContentsQueryParamTypeEpisode GetPlaylistContentsQueryParamType = 4
GetPlaylistContentsQueryParamTypeAudio GetPlaylistContentsQueryParamType = 8
GetPlaylistContentsQueryParamTypeAlbum GetPlaylistContentsQueryParamType = 9
GetPlaylistContentsQueryParamTypeTrack GetPlaylistContentsQueryParamType = 10
) )
func (e GetPlaylistContentsQueryParamType) ToPointer() *GetPlaylistContentsQueryParamType { func (e GetPlaylistContentsQueryParamType) ToPointer() *GetPlaylistContentsQueryParamType {
@@ -41,6 +44,12 @@ func (e *GetPlaylistContentsQueryParamType) UnmarshalJSON(data []byte) error {
case 3: case 3:
fallthrough fallthrough
case 4: case 4:
fallthrough
case 8:
fallthrough
case 9:
fallthrough
case 10:
*e = GetPlaylistContentsQueryParamType(v) *e = GetPlaylistContentsQueryParamType(v)
return nil return nil
default: default:

View File

@@ -23,6 +23,9 @@ const (
TypeTvShow Type = 2 TypeTvShow Type = 2
TypeSeason Type = 3 TypeSeason Type = 3
TypeEpisode Type = 4 TypeEpisode Type = 4
TypeAudio Type = 8
TypeAlbum Type = 9
TypeTrack Type = 10
) )
func (e Type) ToPointer() *Type { func (e Type) ToPointer() *Type {
@@ -41,6 +44,12 @@ func (e *Type) UnmarshalJSON(data []byte) error {
case 3: case 3:
fallthrough fallthrough
case 4: case 4:
fallthrough
case 8:
fallthrough
case 9:
fallthrough
case 10:
*e = Type(v) *e = Type(v)
return nil return nil
default: default:
@@ -529,11 +538,13 @@ func (e *GetRecentlyAddedHubsType) UnmarshalJSON(data []byte) error {
} }
} }
// FlattenSeasons - Setting that indicates if seasons are set to hidden for the show. (-1 = Library default, 0 = Hide, 1 = Show).
type FlattenSeasons string type FlattenSeasons string
const ( const (
FlattenSeasonsFalse FlattenSeasons = "0" FlattenSeasonsLibraryDefault FlattenSeasons = "-1"
FlattenSeasonsTrue FlattenSeasons = "1" FlattenSeasonsHide FlattenSeasons = "0"
FlattenSeasonsShow FlattenSeasons = "1"
) )
func (e FlattenSeasons) ToPointer() *FlattenSeasons { func (e FlattenSeasons) ToPointer() *FlattenSeasons {
@@ -545,6 +556,8 @@ func (e *FlattenSeasons) UnmarshalJSON(data []byte) error {
return err return err
} }
switch v { switch v {
case "-1":
fallthrough
case "0": case "0":
fallthrough fallthrough
case "1": case "1":
@@ -555,7 +568,64 @@ func (e *FlattenSeasons) UnmarshalJSON(data []byte) error {
} }
} }
// ShowOrdering - Setting that indicates the episode ordering for the show // EpisodeSort - Setting that indicates how episodes are sorted for the show. (-1 = Library default, 0 = Oldest first, 1 = Newest first).
type EpisodeSort string
const (
EpisodeSortLibraryDefault EpisodeSort = "-1"
EpisodeSortOldestFirst EpisodeSort = "0"
EpisodeSortNewestFirst EpisodeSort = "1"
)
func (e EpisodeSort) ToPointer() *EpisodeSort {
return &e
}
func (e *EpisodeSort) UnmarshalJSON(data []byte) error {
var v string
if err := json.Unmarshal(data, &v); err != nil {
return err
}
switch v {
case "-1":
fallthrough
case "0":
fallthrough
case "1":
*e = EpisodeSort(v)
return nil
default:
return fmt.Errorf("invalid value for EpisodeSort: %v", v)
}
}
// EnableCreditsMarkerGeneration - Setting that indicates if credits markers detection is enabled. (-1 = Library default, 0 = Disabled).
type EnableCreditsMarkerGeneration string
const (
EnableCreditsMarkerGenerationLibraryDefault EnableCreditsMarkerGeneration = "-1"
EnableCreditsMarkerGenerationDisabled EnableCreditsMarkerGeneration = "0"
)
func (e EnableCreditsMarkerGeneration) ToPointer() *EnableCreditsMarkerGeneration {
return &e
}
func (e *EnableCreditsMarkerGeneration) UnmarshalJSON(data []byte) error {
var v string
if err := json.Unmarshal(data, &v); err != nil {
return err
}
switch v {
case "-1":
fallthrough
case "0":
*e = EnableCreditsMarkerGeneration(v)
return nil
default:
return fmt.Errorf("invalid value for EnableCreditsMarkerGeneration: %v", v)
}
}
// ShowOrdering - Setting that indicates the episode ordering for the show.
// None = Library default, // None = Library default,
// tmdbAiring = The Movie Database (Aired), // tmdbAiring = The Movie Database (Aired),
// aired = TheTVDB (Aired), // aired = TheTVDB (Aired),
@@ -564,11 +634,11 @@ func (e *FlattenSeasons) UnmarshalJSON(data []byte) error {
type ShowOrdering string type ShowOrdering string
const ( const (
ShowOrderingNone ShowOrdering = "None" ShowOrderingNone ShowOrdering = "None"
ShowOrderingTmdbAiring ShowOrdering = "tmdbAiring" ShowOrderingTmdbAiring ShowOrdering = "tmdbAiring"
ShowOrderingAired ShowOrdering = "aired" ShowOrderingTvdbAired ShowOrdering = "aired"
ShowOrderingDvd ShowOrdering = "dvd" ShowOrderingTvdbDvd ShowOrdering = "dvd"
ShowOrderingAbsolute ShowOrdering = "absolute" ShowOrderingTvdbAbsolute ShowOrdering = "absolute"
) )
func (e ShowOrdering) ToPointer() *ShowOrdering { func (e ShowOrdering) ToPointer() *ShowOrdering {
@@ -1552,8 +1622,13 @@ type GetRecentlyAddedMetadata struct {
Year *int `json:"year,omitempty"` Year *int `json:"year,omitempty"`
SeasonCount *int `json:"seasonCount,omitempty"` SeasonCount *int `json:"seasonCount,omitempty"`
Tagline *string `json:"tagline,omitempty"` Tagline *string `json:"tagline,omitempty"`
FlattenSeasons *FlattenSeasons `default:"0" json:"flattenSeasons"` // Setting that indicates if seasons are set to hidden for the show. (-1 = Library default, 0 = Hide, 1 = Show).
// Setting that indicates the episode ordering for the show FlattenSeasons *FlattenSeasons `json:"flattenSeasons,omitempty"`
// Setting that indicates how episodes are sorted for the show. (-1 = Library default, 0 = Oldest first, 1 = Newest first).
EpisodeSort *EpisodeSort `json:"episodeSort,omitempty"`
// Setting that indicates if credits markers detection is enabled. (-1 = Library default, 0 = Disabled).
EnableCreditsMarkerGeneration *EnableCreditsMarkerGeneration `json:"enableCreditsMarkerGeneration,omitempty"`
// Setting that indicates the episode ordering for the show.
// None = Library default, // None = Library default,
// tmdbAiring = The Movie Database (Aired), // tmdbAiring = The Movie Database (Aired),
// aired = TheTVDB (Aired), // aired = TheTVDB (Aired),
@@ -1769,6 +1844,20 @@ func (o *GetRecentlyAddedMetadata) GetFlattenSeasons() *FlattenSeasons {
return o.FlattenSeasons return o.FlattenSeasons
} }
func (o *GetRecentlyAddedMetadata) GetEpisodeSort() *EpisodeSort {
if o == nil {
return nil
}
return o.EpisodeSort
}
func (o *GetRecentlyAddedMetadata) GetEnableCreditsMarkerGeneration() *EnableCreditsMarkerGeneration {
if o == nil {
return nil
}
return o.EnableCreditsMarkerGeneration
}
func (o *GetRecentlyAddedMetadata) GetShowOrdering() *ShowOrdering { func (o *GetRecentlyAddedMetadata) GetShowOrdering() *ShowOrdering {
if o == nil { if o == nil {
return nil return nil

View File

@@ -23,6 +23,9 @@ const (
QueryParamTypeTvShow QueryParamType = 2 QueryParamTypeTvShow QueryParamType = 2
QueryParamTypeSeason QueryParamType = 3 QueryParamTypeSeason QueryParamType = 3
QueryParamTypeEpisode QueryParamType = 4 QueryParamTypeEpisode QueryParamType = 4
QueryParamTypeAudio QueryParamType = 8
QueryParamTypeAlbum QueryParamType = 9
QueryParamTypeTrack QueryParamType = 10
) )
func (e QueryParamType) ToPointer() *QueryParamType { func (e QueryParamType) ToPointer() *QueryParamType {
@@ -41,6 +44,12 @@ func (e *QueryParamType) UnmarshalJSON(data []byte) error {
case 3: case 3:
fallthrough fallthrough
case 4: case 4:
fallthrough
case 8:
fallthrough
case 9:
fallthrough
case 10:
*e = QueryParamType(v) *e = QueryParamType(v)
return nil return nil
default: default:

View File

@@ -10,7 +10,7 @@ type GetResourcesStatisticsRequest struct {
// The timespan to retrieve statistics for // The timespan to retrieve statistics for
// the exact meaning of this parameter is not known // the exact meaning of this parameter is not known
// //
Timespan *int64 `queryParam:"style=form,explode=true,name=Timespan"` Timespan *int64 `queryParam:"style=form,explode=true,name=timespan"`
} }
func (o *GetResourcesStatisticsRequest) GetTimespan() *int64 { func (o *GetResourcesStatisticsRequest) GetTimespan() *int64 {

View File

@@ -10,18 +10,6 @@ import (
"net/http" "net/http"
) )
type GetSearchAllLibrariesGlobals struct {
// An opaque identifier unique to the client (UUID, serial number, or other unique device ID)
ClientID *string `header:"style=simple,explode=false,name=X-Plex-Client-Identifier"`
}
func (o *GetSearchAllLibrariesGlobals) GetClientID() *string {
if o == nil {
return nil
}
return o.ClientID
}
type SearchTypes string type SearchTypes string
const ( const (
@@ -115,7 +103,7 @@ type GetSearchAllLibrariesRequest struct {
// The search query term. // The search query term.
Query string `queryParam:"style=form,explode=true,name=query"` Query string `queryParam:"style=form,explode=true,name=query"`
// An opaque identifier unique to the client (UUID, serial number, or other unique device ID) // An opaque identifier unique to the client (UUID, serial number, or other unique device ID)
ClientID *string `header:"style=simple,explode=false,name=X-Plex-Client-Identifier"` ClientID string `header:"style=simple,explode=false,name=X-Plex-Client-Identifier"`
// Limit the number of results returned. // Limit the number of results returned.
Limit *int64 `queryParam:"style=form,explode=true,name=limit"` Limit *int64 `queryParam:"style=form,explode=true,name=limit"`
// A comma-separated list of search types to include. Valid values are: movies, music, otherVideos, people, tv. // A comma-separated list of search types to include. Valid values are: movies, music, otherVideos, people, tv.
@@ -145,9 +133,9 @@ func (o *GetSearchAllLibrariesRequest) GetQuery() string {
return o.Query return o.Query
} }
func (o *GetSearchAllLibrariesRequest) GetClientID() *string { func (o *GetSearchAllLibrariesRequest) GetClientID() string {
if o == nil { if o == nil {
return nil return ""
} }
return o.ClientID return o.ClientID
} }
@@ -213,11 +201,13 @@ func (e *GetSearchAllLibrariesType) UnmarshalJSON(data []byte) error {
} }
} }
// GetSearchAllLibrariesFlattenSeasons - Setting that indicates if seasons are set to hidden for the show. (-1 = Library default, 0 = Hide, 1 = Show).
type GetSearchAllLibrariesFlattenSeasons string type GetSearchAllLibrariesFlattenSeasons string
const ( const (
GetSearchAllLibrariesFlattenSeasonsFalse GetSearchAllLibrariesFlattenSeasons = "0" GetSearchAllLibrariesFlattenSeasonsLibraryDefault GetSearchAllLibrariesFlattenSeasons = "-1"
GetSearchAllLibrariesFlattenSeasonsTrue GetSearchAllLibrariesFlattenSeasons = "1" GetSearchAllLibrariesFlattenSeasonsHide GetSearchAllLibrariesFlattenSeasons = "0"
GetSearchAllLibrariesFlattenSeasonsShow GetSearchAllLibrariesFlattenSeasons = "1"
) )
func (e GetSearchAllLibrariesFlattenSeasons) ToPointer() *GetSearchAllLibrariesFlattenSeasons { func (e GetSearchAllLibrariesFlattenSeasons) ToPointer() *GetSearchAllLibrariesFlattenSeasons {
@@ -229,6 +219,8 @@ func (e *GetSearchAllLibrariesFlattenSeasons) UnmarshalJSON(data []byte) error {
return err return err
} }
switch v { switch v {
case "-1":
fallthrough
case "0": case "0":
fallthrough fallthrough
case "1": case "1":
@@ -239,7 +231,64 @@ func (e *GetSearchAllLibrariesFlattenSeasons) UnmarshalJSON(data []byte) error {
} }
} }
// GetSearchAllLibrariesShowOrdering - Setting that indicates the episode ordering for the show // GetSearchAllLibrariesEpisodeSort - Setting that indicates how episodes are sorted for the show. (-1 = Library default, 0 = Oldest first, 1 = Newest first).
type GetSearchAllLibrariesEpisodeSort string
const (
GetSearchAllLibrariesEpisodeSortLibraryDefault GetSearchAllLibrariesEpisodeSort = "-1"
GetSearchAllLibrariesEpisodeSortOldestFirst GetSearchAllLibrariesEpisodeSort = "0"
GetSearchAllLibrariesEpisodeSortNewestFirst GetSearchAllLibrariesEpisodeSort = "1"
)
func (e GetSearchAllLibrariesEpisodeSort) ToPointer() *GetSearchAllLibrariesEpisodeSort {
return &e
}
func (e *GetSearchAllLibrariesEpisodeSort) UnmarshalJSON(data []byte) error {
var v string
if err := json.Unmarshal(data, &v); err != nil {
return err
}
switch v {
case "-1":
fallthrough
case "0":
fallthrough
case "1":
*e = GetSearchAllLibrariesEpisodeSort(v)
return nil
default:
return fmt.Errorf("invalid value for GetSearchAllLibrariesEpisodeSort: %v", v)
}
}
// GetSearchAllLibrariesEnableCreditsMarkerGeneration - Setting that indicates if credits markers detection is enabled. (-1 = Library default, 0 = Disabled).
type GetSearchAllLibrariesEnableCreditsMarkerGeneration string
const (
GetSearchAllLibrariesEnableCreditsMarkerGenerationLibraryDefault GetSearchAllLibrariesEnableCreditsMarkerGeneration = "-1"
GetSearchAllLibrariesEnableCreditsMarkerGenerationDisabled GetSearchAllLibrariesEnableCreditsMarkerGeneration = "0"
)
func (e GetSearchAllLibrariesEnableCreditsMarkerGeneration) ToPointer() *GetSearchAllLibrariesEnableCreditsMarkerGeneration {
return &e
}
func (e *GetSearchAllLibrariesEnableCreditsMarkerGeneration) UnmarshalJSON(data []byte) error {
var v string
if err := json.Unmarshal(data, &v); err != nil {
return err
}
switch v {
case "-1":
fallthrough
case "0":
*e = GetSearchAllLibrariesEnableCreditsMarkerGeneration(v)
return nil
default:
return fmt.Errorf("invalid value for GetSearchAllLibrariesEnableCreditsMarkerGeneration: %v", v)
}
}
// GetSearchAllLibrariesShowOrdering - Setting that indicates the episode ordering for the show.
// None = Library default, // None = Library default,
// tmdbAiring = The Movie Database (Aired), // tmdbAiring = The Movie Database (Aired),
// aired = TheTVDB (Aired), // aired = TheTVDB (Aired),
@@ -248,11 +297,11 @@ func (e *GetSearchAllLibrariesFlattenSeasons) UnmarshalJSON(data []byte) error {
type GetSearchAllLibrariesShowOrdering string type GetSearchAllLibrariesShowOrdering string
const ( const (
GetSearchAllLibrariesShowOrderingNone GetSearchAllLibrariesShowOrdering = "None" GetSearchAllLibrariesShowOrderingNone GetSearchAllLibrariesShowOrdering = "None"
GetSearchAllLibrariesShowOrderingTmdbAiring GetSearchAllLibrariesShowOrdering = "tmdbAiring" GetSearchAllLibrariesShowOrderingTmdbAiring GetSearchAllLibrariesShowOrdering = "tmdbAiring"
GetSearchAllLibrariesShowOrderingAired GetSearchAllLibrariesShowOrdering = "aired" GetSearchAllLibrariesShowOrderingTvdbAired GetSearchAllLibrariesShowOrdering = "aired"
GetSearchAllLibrariesShowOrderingDvd GetSearchAllLibrariesShowOrdering = "dvd" GetSearchAllLibrariesShowOrderingTvdbDvd GetSearchAllLibrariesShowOrdering = "dvd"
GetSearchAllLibrariesShowOrderingAbsolute GetSearchAllLibrariesShowOrdering = "absolute" GetSearchAllLibrariesShowOrderingTvdbAbsolute GetSearchAllLibrariesShowOrdering = "absolute"
) )
func (e GetSearchAllLibrariesShowOrdering) ToPointer() *GetSearchAllLibrariesShowOrdering { func (e GetSearchAllLibrariesShowOrdering) ToPointer() *GetSearchAllLibrariesShowOrdering {
@@ -1226,18 +1275,23 @@ type GetSearchAllLibrariesMetadata struct {
LibrarySectionKey *string `json:"librarySectionKey,omitempty"` LibrarySectionKey *string `json:"librarySectionKey,omitempty"`
// The type of media content // The type of media content
// //
Type GetSearchAllLibrariesType `json:"type"` Type GetSearchAllLibrariesType `json:"type"`
Title string `json:"title"` Title string `json:"title"`
Slug *string `json:"slug,omitempty"` Slug *string `json:"slug,omitempty"`
ContentRating *string `json:"contentRating,omitempty"` ContentRating *string `json:"contentRating,omitempty"`
Summary string `json:"summary"` Summary string `json:"summary"`
Rating *float64 `json:"rating,omitempty"` Rating *float64 `json:"rating,omitempty"`
AudienceRating *float64 `json:"audienceRating,omitempty"` AudienceRating *float64 `json:"audienceRating,omitempty"`
Year *int `json:"year,omitempty"` Year *int `json:"year,omitempty"`
SeasonCount *int `json:"seasonCount,omitempty"` SeasonCount *int `json:"seasonCount,omitempty"`
Tagline *string `json:"tagline,omitempty"` Tagline *string `json:"tagline,omitempty"`
FlattenSeasons *GetSearchAllLibrariesFlattenSeasons `default:"0" json:"flattenSeasons"` // Setting that indicates if seasons are set to hidden for the show. (-1 = Library default, 0 = Hide, 1 = Show).
// Setting that indicates the episode ordering for the show FlattenSeasons *GetSearchAllLibrariesFlattenSeasons `json:"flattenSeasons,omitempty"`
// Setting that indicates how episodes are sorted for the show. (-1 = Library default, 0 = Oldest first, 1 = Newest first).
EpisodeSort *GetSearchAllLibrariesEpisodeSort `json:"episodeSort,omitempty"`
// Setting that indicates if credits markers detection is enabled. (-1 = Library default, 0 = Disabled).
EnableCreditsMarkerGeneration *GetSearchAllLibrariesEnableCreditsMarkerGeneration `json:"enableCreditsMarkerGeneration,omitempty"`
// Setting that indicates the episode ordering for the show.
// None = Library default, // None = Library default,
// tmdbAiring = The Movie Database (Aired), // tmdbAiring = The Movie Database (Aired),
// aired = TheTVDB (Aired), // aired = TheTVDB (Aired),
@@ -1453,6 +1507,20 @@ func (o *GetSearchAllLibrariesMetadata) GetFlattenSeasons() *GetSearchAllLibrari
return o.FlattenSeasons return o.FlattenSeasons
} }
func (o *GetSearchAllLibrariesMetadata) GetEpisodeSort() *GetSearchAllLibrariesEpisodeSort {
if o == nil {
return nil
}
return o.EpisodeSort
}
func (o *GetSearchAllLibrariesMetadata) GetEnableCreditsMarkerGeneration() *GetSearchAllLibrariesEnableCreditsMarkerGeneration {
if o == nil {
return nil
}
return o.EnableCreditsMarkerGeneration
}
func (o *GetSearchAllLibrariesMetadata) GetShowOrdering() *GetSearchAllLibrariesShowOrdering { func (o *GetSearchAllLibrariesMetadata) GetShowOrdering() *GetSearchAllLibrariesShowOrdering {
if o == nil { if o == nil {
return nil return nil

View File

@@ -21,6 +21,9 @@ const (
GetSearchLibraryQueryParamTypeTvShow GetSearchLibraryQueryParamType = 2 GetSearchLibraryQueryParamTypeTvShow GetSearchLibraryQueryParamType = 2
GetSearchLibraryQueryParamTypeSeason GetSearchLibraryQueryParamType = 3 GetSearchLibraryQueryParamTypeSeason GetSearchLibraryQueryParamType = 3
GetSearchLibraryQueryParamTypeEpisode GetSearchLibraryQueryParamType = 4 GetSearchLibraryQueryParamTypeEpisode GetSearchLibraryQueryParamType = 4
GetSearchLibraryQueryParamTypeAudio GetSearchLibraryQueryParamType = 8
GetSearchLibraryQueryParamTypeAlbum GetSearchLibraryQueryParamType = 9
GetSearchLibraryQueryParamTypeTrack GetSearchLibraryQueryParamType = 10
) )
func (e GetSearchLibraryQueryParamType) ToPointer() *GetSearchLibraryQueryParamType { func (e GetSearchLibraryQueryParamType) ToPointer() *GetSearchLibraryQueryParamType {
@@ -39,6 +42,12 @@ func (e *GetSearchLibraryQueryParamType) UnmarshalJSON(data []byte) error {
case 3: case 3:
fallthrough fallthrough
case 4: case 4:
fallthrough
case 8:
fallthrough
case 9:
fallthrough
case 10:
*e = GetSearchLibraryQueryParamType(v) *e = GetSearchLibraryQueryParamType(v)
return nil return nil
default: default:

View File

@@ -14,18 +14,6 @@ var GetServerResourcesServerList = []string{
"https://plex.tv/api/v2", "https://plex.tv/api/v2",
} }
type GetServerResourcesGlobals struct {
// An opaque identifier unique to the client (UUID, serial number, or other unique device ID)
ClientID *string `header:"style=simple,explode=false,name=X-Plex-Client-Identifier"`
}
func (o *GetServerResourcesGlobals) GetClientID() *string {
if o == nil {
return nil
}
return o.ClientID
}
// IncludeHTTPS - Include Https entries in the results // IncludeHTTPS - Include Https entries in the results
type IncludeHTTPS int type IncludeHTTPS int
@@ -118,7 +106,7 @@ type GetServerResourcesRequest struct {
// Include IPv6 entries in the results // Include IPv6 entries in the results
IncludeIPv6 *IncludeIPv6 `default:"0" queryParam:"style=form,explode=true,name=includeIPv6"` IncludeIPv6 *IncludeIPv6 `default:"0" queryParam:"style=form,explode=true,name=includeIPv6"`
// An opaque identifier unique to the client (UUID, serial number, or other unique device ID) // An opaque identifier unique to the client (UUID, serial number, or other unique device ID)
ClientID *string `header:"style=simple,explode=false,name=X-Plex-Client-Identifier"` ClientID string `header:"style=simple,explode=false,name=X-Plex-Client-Identifier"`
} }
func (g GetServerResourcesRequest) MarshalJSON() ([]byte, error) { func (g GetServerResourcesRequest) MarshalJSON() ([]byte, error) {
@@ -153,9 +141,9 @@ func (o *GetServerResourcesRequest) GetIncludeIPv6() *IncludeIPv6 {
return o.IncludeIPv6 return o.IncludeIPv6
} }
func (o *GetServerResourcesRequest) GetClientID() *string { func (o *GetServerResourcesRequest) GetClientID() string {
if o == nil { if o == nil {
return nil return ""
} }
return o.ClientID return o.ClientID
} }

View File

@@ -497,43 +497,45 @@ func (o *Session) GetLocation() *string {
} }
type GetSessionsMetadata struct { type GetSessionsMetadata struct {
AddedAt *int `json:"addedAt,omitempty"` AddedAt *int `json:"addedAt,omitempty"`
Art *string `json:"art,omitempty"` Art *string `json:"art,omitempty"`
Duration *int `json:"duration,omitempty"` Duration *int `json:"duration,omitempty"`
GrandparentArt *string `json:"grandparentArt,omitempty"` GrandparentArt *string `json:"grandparentArt,omitempty"`
GrandparentGUID *string `json:"grandparentGuid,omitempty"` GrandparentGUID *string `json:"grandparentGuid,omitempty"`
GrandparentKey *string `json:"grandparentKey,omitempty"` GrandparentKey *string `json:"grandparentKey,omitempty"`
GrandparentRatingKey *string `json:"grandparentRatingKey,omitempty"` GrandparentRatingKey *string `json:"grandparentRatingKey,omitempty"`
GrandparentThumb *string `json:"grandparentThumb,omitempty"` GrandparentThumb *string `json:"grandparentThumb,omitempty"`
GrandparentTitle *string `json:"grandparentTitle,omitempty"` GrandparentTitle *string `json:"grandparentTitle,omitempty"`
GUID *string `json:"guid,omitempty"` GUID *string `json:"guid,omitempty"`
Index *int `json:"index,omitempty"` Index *int `json:"index,omitempty"`
Key *string `json:"key,omitempty"` Key *string `json:"key,omitempty"`
LibrarySectionID *string `json:"librarySectionID,omitempty"` LibrarySectionID *string `json:"librarySectionID,omitempty"`
LibrarySectionKey *string `json:"librarySectionKey,omitempty"` LibrarySectionKey *string `json:"librarySectionKey,omitempty"`
LibrarySectionTitle *string `json:"librarySectionTitle,omitempty"` LibrarySectionTitle *string `json:"librarySectionTitle,omitempty"`
MusicAnalysisVersion *string `json:"musicAnalysisVersion,omitempty"` MusicAnalysisVersion *string `json:"musicAnalysisVersion,omitempty"`
ParentGUID *string `json:"parentGuid,omitempty"` // The original untranslated name of the media item when non-english, or the track artist if an audio Item has an album artist
ParentIndex *int `json:"parentIndex,omitempty"` OriginalTitle *string `json:"originalTitle,omitempty"`
ParentKey *string `json:"parentKey,omitempty"` ParentGUID *string `json:"parentGuid,omitempty"`
ParentRatingKey *string `json:"parentRatingKey,omitempty"` ParentIndex *int `json:"parentIndex,omitempty"`
ParentStudio *string `json:"parentStudio,omitempty"` ParentKey *string `json:"parentKey,omitempty"`
ParentThumb *string `json:"parentThumb,omitempty"` ParentRatingKey *string `json:"parentRatingKey,omitempty"`
ParentTitle *string `json:"parentTitle,omitempty"` ParentStudio *string `json:"parentStudio,omitempty"`
ParentYear *int `json:"parentYear,omitempty"` ParentThumb *string `json:"parentThumb,omitempty"`
RatingCount *int `json:"ratingCount,omitempty"` ParentTitle *string `json:"parentTitle,omitempty"`
RatingKey *string `json:"ratingKey,omitempty"` ParentYear *int `json:"parentYear,omitempty"`
SessionKey *string `json:"sessionKey,omitempty"` RatingCount *int `json:"ratingCount,omitempty"`
Thumb *string `json:"thumb,omitempty"` RatingKey *string `json:"ratingKey,omitempty"`
Title *string `json:"title,omitempty"` SessionKey *string `json:"sessionKey,omitempty"`
TitleSort *string `json:"titleSort,omitempty"` Thumb *string `json:"thumb,omitempty"`
Type *string `json:"type,omitempty"` Title *string `json:"title,omitempty"`
UpdatedAt *int `json:"updatedAt,omitempty"` TitleSort *string `json:"titleSort,omitempty"`
ViewOffset *int `json:"viewOffset,omitempty"` Type *string `json:"type,omitempty"`
Media []GetSessionsMedia `json:"Media,omitempty"` UpdatedAt *int `json:"updatedAt,omitempty"`
User *GetSessionsUser `json:"User,omitempty"` ViewOffset *int `json:"viewOffset,omitempty"`
Player *Player `json:"Player,omitempty"` Media []GetSessionsMedia `json:"Media,omitempty"`
Session *Session `json:"Session,omitempty"` User *GetSessionsUser `json:"User,omitempty"`
Player *Player `json:"Player,omitempty"`
Session *Session `json:"Session,omitempty"`
} }
func (o *GetSessionsMetadata) GetAddedAt() *int { func (o *GetSessionsMetadata) GetAddedAt() *int {
@@ -648,6 +650,13 @@ func (o *GetSessionsMetadata) GetMusicAnalysisVersion() *string {
return o.MusicAnalysisVersion return o.MusicAnalysisVersion
} }
func (o *GetSessionsMetadata) GetOriginalTitle() *string {
if o == nil {
return nil
}
return o.OriginalTitle
}
func (o *GetSessionsMetadata) GetParentGUID() *string { func (o *GetSessionsMetadata) GetParentGUID() *string {
if o == nil { if o == nil {
return nil return nil

View File

@@ -10,7 +10,7 @@ type GetStatisticsRequest struct {
// The timespan to retrieve statistics for // The timespan to retrieve statistics for
// the exact meaning of this parameter is not known // the exact meaning of this parameter is not known
// //
Timespan *int64 `queryParam:"style=form,explode=true,name=Timespan"` Timespan *int64 `queryParam:"style=form,explode=true,name=timespan"`
} }
func (o *GetStatisticsRequest) GetTimespan() *int64 { func (o *GetStatisticsRequest) GetTimespan() *int64 {

View File

@@ -12,59 +12,11 @@ var GetTokenByPinIDServerList = []string{
"https://plex.tv/api/v2", "https://plex.tv/api/v2",
} }
type GetTokenByPinIDGlobals struct {
// An opaque identifier unique to the client (UUID, serial number, or other unique device ID)
ClientID *string `header:"style=simple,explode=false,name=X-Plex-Client-Identifier"`
// The name of the client application. (Plex Web, Plex Media Server, etc.)
ClientName *string `header:"style=simple,explode=false,name=X-Plex-Product"`
// A relatively friendly name for the client device
DeviceNickname *string `header:"style=simple,explode=false,name=X-Plex-Device"`
// The version of the client application.
ClientVersion *string `header:"style=simple,explode=false,name=X-Plex-Version"`
// The platform of the client application.
Platform *string `header:"style=simple,explode=false,name=X-Plex-Platform"`
}
func (o *GetTokenByPinIDGlobals) GetClientID() *string {
if o == nil {
return nil
}
return o.ClientID
}
func (o *GetTokenByPinIDGlobals) GetClientName() *string {
if o == nil {
return nil
}
return o.ClientName
}
func (o *GetTokenByPinIDGlobals) GetDeviceNickname() *string {
if o == nil {
return nil
}
return o.DeviceNickname
}
func (o *GetTokenByPinIDGlobals) GetClientVersion() *string {
if o == nil {
return nil
}
return o.ClientVersion
}
func (o *GetTokenByPinIDGlobals) GetPlatform() *string {
if o == nil {
return nil
}
return o.Platform
}
type GetTokenByPinIDRequest struct { type GetTokenByPinIDRequest struct {
// The PinID to retrieve an access token for // The PinID to retrieve an access token for
PinID int64 `pathParam:"style=simple,explode=false,name=pinID"` PinID int64 `pathParam:"style=simple,explode=false,name=pinID"`
// An opaque identifier unique to the client (UUID, serial number, or other unique device ID) // An opaque identifier unique to the client (UUID, serial number, or other unique device ID)
ClientID *string `header:"style=simple,explode=false,name=X-Plex-Client-Identifier"` ClientID string `header:"style=simple,explode=false,name=X-Plex-Client-Identifier"`
// The name of the client application. (Plex Web, Plex Media Server, etc.) // The name of the client application. (Plex Web, Plex Media Server, etc.)
ClientName *string `header:"style=simple,explode=false,name=X-Plex-Product"` ClientName *string `header:"style=simple,explode=false,name=X-Plex-Product"`
// A relatively friendly name for the client device // A relatively friendly name for the client device
@@ -82,9 +34,9 @@ func (o *GetTokenByPinIDRequest) GetPinID() int64 {
return o.PinID return o.PinID
} }
func (o *GetTokenByPinIDRequest) GetClientID() *string { func (o *GetTokenByPinIDRequest) GetClientID() string {
if o == nil { if o == nil {
return nil return ""
} }
return o.ClientID return o.ClientID
} }

View File

@@ -544,7 +544,7 @@ type GetTokenDetailsUserPlexAccount struct {
MaxHomeSize int `json:"maxHomeSize"` MaxHomeSize int `json:"maxHomeSize"`
// [Might be removed] The hashed Plex Home PIN // [Might be removed] The hashed Plex Home PIN
// //
// Deprecated field: This will be removed in a future release, please migrate away from it as soon as possible. // Deprecated: This will be removed in a future release, please migrate away from it as soon as possible.
Pin *string `json:"pin,omitempty"` Pin *string `json:"pin,omitempty"`
Profile UserProfile `json:"profile"` Profile UserProfile `json:"profile"`
// If the account has a Plex Home PIN enabled // If the account has a Plex Home PIN enabled

View File

@@ -23,6 +23,9 @@ const (
GetTopWatchedContentQueryParamTypeTvShow GetTopWatchedContentQueryParamType = 2 GetTopWatchedContentQueryParamTypeTvShow GetTopWatchedContentQueryParamType = 2
GetTopWatchedContentQueryParamTypeSeason GetTopWatchedContentQueryParamType = 3 GetTopWatchedContentQueryParamTypeSeason GetTopWatchedContentQueryParamType = 3
GetTopWatchedContentQueryParamTypeEpisode GetTopWatchedContentQueryParamType = 4 GetTopWatchedContentQueryParamTypeEpisode GetTopWatchedContentQueryParamType = 4
GetTopWatchedContentQueryParamTypeAudio GetTopWatchedContentQueryParamType = 8
GetTopWatchedContentQueryParamTypeAlbum GetTopWatchedContentQueryParamType = 9
GetTopWatchedContentQueryParamTypeTrack GetTopWatchedContentQueryParamType = 10
) )
func (e GetTopWatchedContentQueryParamType) ToPointer() *GetTopWatchedContentQueryParamType { func (e GetTopWatchedContentQueryParamType) ToPointer() *GetTopWatchedContentQueryParamType {
@@ -41,6 +44,12 @@ func (e *GetTopWatchedContentQueryParamType) UnmarshalJSON(data []byte) error {
case 3: case 3:
fallthrough fallthrough
case 4: case 4:
fallthrough
case 8:
fallthrough
case 9:
fallthrough
case 10:
*e = GetTopWatchedContentQueryParamType(v) *e = GetTopWatchedContentQueryParamType(v)
return nil return nil
default: default:

View File

@@ -12,7 +12,6 @@ import (
var ErrUnsupportedOption = errors.New("unsupported option") var ErrUnsupportedOption = errors.New("unsupported option")
const ( const (
SupportedOptionServerURL = "serverURL"
SupportedOptionRetries = "retries" SupportedOptionRetries = "retries"
SupportedOptionTimeout = "timeout" SupportedOptionTimeout = "timeout"
SupportedOptionAcceptHeaderOverride = "acceptHeaderOverride" SupportedOptionAcceptHeaderOverride = "acceptHeaderOverride"
@@ -36,6 +35,7 @@ type Options struct {
Timeout *time.Duration Timeout *time.Duration
AcceptHeaderOverride *AcceptHeaderEnum AcceptHeaderOverride *AcceptHeaderEnum
URLOverride *string URLOverride *string
SetHeaders map[string]string
} }
type Option func(*Options, ...string) error type Option func(*Options, ...string) error
@@ -43,10 +43,6 @@ type Option func(*Options, ...string) error
// WithServerURL allows providing an alternative server URL. // WithServerURL allows providing an alternative server URL.
func WithServerURL(serverURL string) Option { func WithServerURL(serverURL string) Option {
return func(opts *Options, supportedOptions ...string) error { return func(opts *Options, supportedOptions ...string) error {
if !utils.Contains(supportedOptions, SupportedOptionServerURL) {
return ErrUnsupportedOption
}
opts.ServerURL = &serverURL opts.ServerURL = &serverURL
return nil return nil
} }
@@ -55,10 +51,6 @@ func WithServerURL(serverURL string) Option {
// WithTemplatedServerURL allows providing an alternative server URL with templated parameters. // WithTemplatedServerURL allows providing an alternative server URL with templated parameters.
func WithTemplatedServerURL(serverURL string, params map[string]string) Option { func WithTemplatedServerURL(serverURL string, params map[string]string) Option {
return func(opts *Options, supportedOptions ...string) error { return func(opts *Options, supportedOptions ...string) error {
if !utils.Contains(supportedOptions, SupportedOptionServerURL) {
return ErrUnsupportedOption
}
if params != nil { if params != nil {
serverURL = utils.ReplaceParameters(serverURL, params) serverURL = utils.ReplaceParameters(serverURL, params)
} }
@@ -114,3 +106,12 @@ func WithURLOverride(urlOverride string) Option {
return nil return nil
} }
} }
// WithSetHeaders takes a map of headers that will applied to a request. If the
// request contains headers that are in the map then they will be overwritten.
func WithSetHeaders(hdrs map[string]string) Option {
return func(opts *Options, supportedOptions ...string) error {
opts.SetHeaders = hdrs
return nil
}
}

View File

@@ -13,54 +13,6 @@ var PostUsersSignInDataServerList = []string{
"https://plex.tv/api/v2", "https://plex.tv/api/v2",
} }
type PostUsersSignInDataGlobals struct {
// An opaque identifier unique to the client (UUID, serial number, or other unique device ID)
ClientID *string `header:"style=simple,explode=false,name=X-Plex-Client-Identifier"`
// The name of the client application. (Plex Web, Plex Media Server, etc.)
ClientName *string `header:"style=simple,explode=false,name=X-Plex-Product"`
// A relatively friendly name for the client device
DeviceNickname *string `header:"style=simple,explode=false,name=X-Plex-Device"`
// The version of the client application.
ClientVersion *string `header:"style=simple,explode=false,name=X-Plex-Version"`
// The platform of the client application.
Platform *string `header:"style=simple,explode=false,name=X-Plex-Platform"`
}
func (o *PostUsersSignInDataGlobals) GetClientID() *string {
if o == nil {
return nil
}
return o.ClientID
}
func (o *PostUsersSignInDataGlobals) GetClientName() *string {
if o == nil {
return nil
}
return o.ClientName
}
func (o *PostUsersSignInDataGlobals) GetDeviceNickname() *string {
if o == nil {
return nil
}
return o.DeviceNickname
}
func (o *PostUsersSignInDataGlobals) GetClientVersion() *string {
if o == nil {
return nil
}
return o.ClientVersion
}
func (o *PostUsersSignInDataGlobals) GetPlatform() *string {
if o == nil {
return nil
}
return o.Platform
}
// PostUsersSignInDataRequestBody - Login credentials // PostUsersSignInDataRequestBody - Login credentials
type PostUsersSignInDataRequestBody struct { type PostUsersSignInDataRequestBody struct {
Login string `form:"name=login"` Login string `form:"name=login"`
@@ -110,7 +62,7 @@ func (o *PostUsersSignInDataRequestBody) GetVerificationCode() *string {
type PostUsersSignInDataRequest struct { type PostUsersSignInDataRequest struct {
// An opaque identifier unique to the client (UUID, serial number, or other unique device ID) // An opaque identifier unique to the client (UUID, serial number, or other unique device ID)
ClientID *string `header:"style=simple,explode=false,name=X-Plex-Client-Identifier"` ClientID string `header:"style=simple,explode=false,name=X-Plex-Client-Identifier"`
// The name of the client application. (Plex Web, Plex Media Server, etc.) // The name of the client application. (Plex Web, Plex Media Server, etc.)
ClientName *string `header:"style=simple,explode=false,name=X-Plex-Product"` ClientName *string `header:"style=simple,explode=false,name=X-Plex-Product"`
// A relatively friendly name for the client device // A relatively friendly name for the client device
@@ -123,9 +75,9 @@ type PostUsersSignInDataRequest struct {
RequestBody *PostUsersSignInDataRequestBody `request:"mediaType=application/x-www-form-urlencoded"` RequestBody *PostUsersSignInDataRequestBody `request:"mediaType=application/x-www-form-urlencoded"`
} }
func (o *PostUsersSignInDataRequest) GetClientID() *string { func (o *PostUsersSignInDataRequest) GetClientID() string {
if o == nil { if o == nil {
return nil return ""
} }
return o.ClientID return o.ClientID
} }
@@ -878,7 +830,7 @@ type PostUsersSignInDataUserPlexAccount struct {
MaxHomeSize int `json:"maxHomeSize"` MaxHomeSize int `json:"maxHomeSize"`
// [Might be removed] The hashed Plex Home PIN // [Might be removed] The hashed Plex Home PIN
// //
// Deprecated field: This will be removed in a future release, please migrate away from it as soon as possible. // Deprecated: This will be removed in a future release, please migrate away from it as soon as possible.
Pin *string `json:"pin,omitempty"` Pin *string `json:"pin,omitempty"`
Profile PostUsersSignInDataUserProfile `json:"profile"` Profile PostUsersSignInDataUserProfile `json:"profile"`
// If the account has a Plex Home PIN enabled // If the account has a Plex Home PIN enabled

File diff suppressed because it is too large Load Diff

388
plex.go
View File

@@ -10,8 +10,7 @@ import (
"github.com/LukeHagar/plexgo/internal/utils" "github.com/LukeHagar/plexgo/internal/utils"
"github.com/LukeHagar/plexgo/models/operations" "github.com/LukeHagar/plexgo/models/operations"
"github.com/LukeHagar/plexgo/models/sdkerrors" "github.com/LukeHagar/plexgo/models/sdkerrors"
"github.com/cenkalti/backoff/v4" "github.com/LukeHagar/plexgo/retry"
"io"
"net/http" "net/http"
"net/url" "net/url"
) )
@@ -39,7 +38,6 @@ func (s *Plex) GetCompanionsData(ctx context.Context, opts ...operations.Option)
o := operations.Options{} o := operations.Options{}
supportedOptions := []string{ supportedOptions := []string{
operations.SupportedOptionServerURL,
operations.SupportedOptionRetries, operations.SupportedOptionRetries,
operations.SupportedOptionTimeout, operations.SupportedOptionTimeout,
} }
@@ -82,6 +80,10 @@ func (s *Plex) GetCompanionsData(ctx context.Context, opts ...operations.Option)
return nil, err return nil, err
} }
for k, v := range o.SetHeaders {
req.Header.Set(k, v)
}
globalRetryConfig := s.sdkConfiguration.RetryConfig globalRetryConfig := s.sdkConfiguration.RetryConfig
retryConfig := o.Retries retryConfig := o.Retries
if retryConfig == nil { if retryConfig == nil {
@@ -112,7 +114,11 @@ func (s *Plex) GetCompanionsData(ctx context.Context, opts ...operations.Option)
req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req)
if err != nil { if err != nil {
return nil, backoff.Permanent(err) if retry.IsPermanentError(err) || retry.IsTemporaryError(err) {
return nil, err
}
return nil, retry.Permanent(err)
} }
httpRes, err := s.sdkConfiguration.Client.Do(req) httpRes, err := s.sdkConfiguration.Client.Do(req)
@@ -173,21 +179,11 @@ func (s *Plex) GetCompanionsData(ctx context.Context, opts ...operations.Option)
RawResponse: httpRes, RawResponse: httpRes,
} }
getRawBody := func() ([]byte, error) {
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))
return rawBody, nil
}
switch { switch {
case httpRes.StatusCode == 200: case httpRes.StatusCode == 200:
switch { switch {
case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -199,17 +195,16 @@ func (s *Plex) GetCompanionsData(ctx context.Context, opts ...operations.Option)
res.ResponseBodies = out res.ResponseBodies = out
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
} }
case httpRes.StatusCode == 400: case httpRes.StatusCode == 400:
switch { switch {
case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -222,17 +217,16 @@ func (s *Plex) GetCompanionsData(ctx context.Context, opts ...operations.Option)
out.RawResponse = httpRes out.RawResponse = httpRes
return nil, &out return nil, &out
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
} }
case httpRes.StatusCode == 401: case httpRes.StatusCode == 401:
switch { switch {
case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -245,28 +239,29 @@ func (s *Plex) GetCompanionsData(ctx context.Context, opts ...operations.Option)
out.RawResponse = httpRes out.RawResponse = httpRes
return nil, &out return nil, &out
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
} }
case httpRes.StatusCode >= 400 && httpRes.StatusCode < 500: case httpRes.StatusCode >= 400 && httpRes.StatusCode < 500:
fallthrough rawBody, err := utils.ConsumeRawBody(httpRes)
case httpRes.StatusCode >= 500 && httpRes.StatusCode < 600: if err != nil {
rawBody, err := getRawBody() return nil, err
}
return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes)
case httpRes.StatusCode >= 500 && httpRes.StatusCode < 600:
rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes)
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError("unknown status code returned", httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError("unknown status code returned", httpRes.StatusCode, string(rawBody), httpRes)
} }
@@ -286,7 +281,6 @@ func (s *Plex) GetUserFriends(ctx context.Context, opts ...operations.Option) (*
o := operations.Options{} o := operations.Options{}
supportedOptions := []string{ supportedOptions := []string{
operations.SupportedOptionServerURL,
operations.SupportedOptionRetries, operations.SupportedOptionRetries,
operations.SupportedOptionTimeout, operations.SupportedOptionTimeout,
} }
@@ -329,6 +323,10 @@ func (s *Plex) GetUserFriends(ctx context.Context, opts ...operations.Option) (*
return nil, err return nil, err
} }
for k, v := range o.SetHeaders {
req.Header.Set(k, v)
}
globalRetryConfig := s.sdkConfiguration.RetryConfig globalRetryConfig := s.sdkConfiguration.RetryConfig
retryConfig := o.Retries retryConfig := o.Retries
if retryConfig == nil { if retryConfig == nil {
@@ -359,7 +357,11 @@ func (s *Plex) GetUserFriends(ctx context.Context, opts ...operations.Option) (*
req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req)
if err != nil { if err != nil {
return nil, backoff.Permanent(err) if retry.IsPermanentError(err) || retry.IsTemporaryError(err) {
return nil, err
}
return nil, retry.Permanent(err)
} }
httpRes, err := s.sdkConfiguration.Client.Do(req) httpRes, err := s.sdkConfiguration.Client.Do(req)
@@ -420,21 +422,11 @@ func (s *Plex) GetUserFriends(ctx context.Context, opts ...operations.Option) (*
RawResponse: httpRes, RawResponse: httpRes,
} }
getRawBody := func() ([]byte, error) {
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))
return rawBody, nil
}
switch { switch {
case httpRes.StatusCode == 200: case httpRes.StatusCode == 200:
switch { switch {
case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -446,17 +438,16 @@ func (s *Plex) GetUserFriends(ctx context.Context, opts ...operations.Option) (*
res.Friends = out res.Friends = out
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
} }
case httpRes.StatusCode == 400: case httpRes.StatusCode == 400:
switch { switch {
case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -469,17 +460,16 @@ func (s *Plex) GetUserFriends(ctx context.Context, opts ...operations.Option) (*
out.RawResponse = httpRes out.RawResponse = httpRes
return nil, &out return nil, &out
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
} }
case httpRes.StatusCode == 401: case httpRes.StatusCode == 401:
switch { switch {
case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -492,28 +482,29 @@ func (s *Plex) GetUserFriends(ctx context.Context, opts ...operations.Option) (*
out.RawResponse = httpRes out.RawResponse = httpRes
return nil, &out return nil, &out
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
} }
case httpRes.StatusCode >= 400 && httpRes.StatusCode < 500: case httpRes.StatusCode >= 400 && httpRes.StatusCode < 500:
fallthrough rawBody, err := utils.ConsumeRawBody(httpRes)
case httpRes.StatusCode >= 500 && httpRes.StatusCode < 600: if err != nil {
rawBody, err := getRawBody() return nil, err
}
return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes)
case httpRes.StatusCode >= 500 && httpRes.StatusCode < 600:
rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes)
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError("unknown status code returned", httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError("unknown status code returned", httpRes.StatusCode, string(rawBody), httpRes)
} }
@@ -533,7 +524,6 @@ func (s *Plex) GetGeoData(ctx context.Context, opts ...operations.Option) (*oper
o := operations.Options{} o := operations.Options{}
supportedOptions := []string{ supportedOptions := []string{
operations.SupportedOptionServerURL,
operations.SupportedOptionRetries, operations.SupportedOptionRetries,
operations.SupportedOptionTimeout, operations.SupportedOptionTimeout,
} }
@@ -572,6 +562,10 @@ func (s *Plex) GetGeoData(ctx context.Context, opts ...operations.Option) (*oper
req.Header.Set("Accept", "application/json") req.Header.Set("Accept", "application/json")
req.Header.Set("User-Agent", s.sdkConfiguration.UserAgent) req.Header.Set("User-Agent", s.sdkConfiguration.UserAgent)
for k, v := range o.SetHeaders {
req.Header.Set(k, v)
}
globalRetryConfig := s.sdkConfiguration.RetryConfig globalRetryConfig := s.sdkConfiguration.RetryConfig
retryConfig := o.Retries retryConfig := o.Retries
if retryConfig == nil { if retryConfig == nil {
@@ -602,7 +596,11 @@ func (s *Plex) GetGeoData(ctx context.Context, opts ...operations.Option) (*oper
req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req)
if err != nil { if err != nil {
return nil, backoff.Permanent(err) if retry.IsPermanentError(err) || retry.IsTemporaryError(err) {
return nil, err
}
return nil, retry.Permanent(err)
} }
httpRes, err := s.sdkConfiguration.Client.Do(req) httpRes, err := s.sdkConfiguration.Client.Do(req)
@@ -663,21 +661,11 @@ func (s *Plex) GetGeoData(ctx context.Context, opts ...operations.Option) (*oper
RawResponse: httpRes, RawResponse: httpRes,
} }
getRawBody := func() ([]byte, error) {
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))
return rawBody, nil
}
switch { switch {
case httpRes.StatusCode == 200: case httpRes.StatusCode == 200:
switch { switch {
case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -689,17 +677,16 @@ func (s *Plex) GetGeoData(ctx context.Context, opts ...operations.Option) (*oper
res.GeoData = &out res.GeoData = &out
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
} }
case httpRes.StatusCode == 400: case httpRes.StatusCode == 400:
switch { switch {
case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -712,17 +699,16 @@ func (s *Plex) GetGeoData(ctx context.Context, opts ...operations.Option) (*oper
out.RawResponse = httpRes out.RawResponse = httpRes
return nil, &out return nil, &out
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
} }
case httpRes.StatusCode == 401: case httpRes.StatusCode == 401:
switch { switch {
case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -735,28 +721,29 @@ func (s *Plex) GetGeoData(ctx context.Context, opts ...operations.Option) (*oper
out.RawResponse = httpRes out.RawResponse = httpRes
return nil, &out return nil, &out
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
} }
case httpRes.StatusCode >= 400 && httpRes.StatusCode < 500: case httpRes.StatusCode >= 400 && httpRes.StatusCode < 500:
fallthrough rawBody, err := utils.ConsumeRawBody(httpRes)
case httpRes.StatusCode >= 500 && httpRes.StatusCode < 600: if err != nil {
rawBody, err := getRawBody() return nil, err
}
return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes)
case httpRes.StatusCode >= 500 && httpRes.StatusCode < 600:
rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes)
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError("unknown status code returned", httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError("unknown status code returned", httpRes.StatusCode, string(rawBody), httpRes)
} }
@@ -786,7 +773,12 @@ func (s *Plex) GetHomeData(ctx context.Context, opts ...operations.Option) (*ope
} }
} }
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) var baseURL string
if o.ServerURL == nil {
baseURL = utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
} else {
baseURL = *o.ServerURL
}
opURL, err := url.JoinPath(baseURL, "/home") opURL, err := url.JoinPath(baseURL, "/home")
if err != nil { if err != nil {
return nil, fmt.Errorf("error generating URL: %w", err) return nil, fmt.Errorf("error generating URL: %w", err)
@@ -814,6 +806,10 @@ func (s *Plex) GetHomeData(ctx context.Context, opts ...operations.Option) (*ope
return nil, err return nil, err
} }
for k, v := range o.SetHeaders {
req.Header.Set(k, v)
}
globalRetryConfig := s.sdkConfiguration.RetryConfig globalRetryConfig := s.sdkConfiguration.RetryConfig
retryConfig := o.Retries retryConfig := o.Retries
if retryConfig == nil { if retryConfig == nil {
@@ -844,7 +840,11 @@ func (s *Plex) GetHomeData(ctx context.Context, opts ...operations.Option) (*ope
req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req)
if err != nil { if err != nil {
return nil, backoff.Permanent(err) if retry.IsPermanentError(err) || retry.IsTemporaryError(err) {
return nil, err
}
return nil, retry.Permanent(err)
} }
httpRes, err := s.sdkConfiguration.Client.Do(req) httpRes, err := s.sdkConfiguration.Client.Do(req)
@@ -905,21 +905,11 @@ func (s *Plex) GetHomeData(ctx context.Context, opts ...operations.Option) (*ope
RawResponse: httpRes, RawResponse: httpRes,
} }
getRawBody := func() ([]byte, error) {
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))
return rawBody, nil
}
switch { switch {
case httpRes.StatusCode == 200: case httpRes.StatusCode == 200:
switch { switch {
case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -931,17 +921,16 @@ func (s *Plex) GetHomeData(ctx context.Context, opts ...operations.Option) (*ope
res.Object = &out res.Object = &out
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
} }
case httpRes.StatusCode == 400: case httpRes.StatusCode == 400:
switch { switch {
case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -954,17 +943,16 @@ func (s *Plex) GetHomeData(ctx context.Context, opts ...operations.Option) (*ope
out.RawResponse = httpRes out.RawResponse = httpRes
return nil, &out return nil, &out
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
} }
case httpRes.StatusCode == 401: case httpRes.StatusCode == 401:
switch { switch {
case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -977,28 +965,29 @@ func (s *Plex) GetHomeData(ctx context.Context, opts ...operations.Option) (*ope
out.RawResponse = httpRes out.RawResponse = httpRes
return nil, &out return nil, &out
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
} }
case httpRes.StatusCode >= 400 && httpRes.StatusCode < 500: case httpRes.StatusCode >= 400 && httpRes.StatusCode < 500:
fallthrough rawBody, err := utils.ConsumeRawBody(httpRes)
case httpRes.StatusCode >= 500 && httpRes.StatusCode < 600: if err != nil {
rawBody, err := getRawBody() return nil, err
}
return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes)
case httpRes.StatusCode >= 500 && httpRes.StatusCode < 600:
rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes)
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError("unknown status code returned", httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError("unknown status code returned", httpRes.StatusCode, string(rawBody), httpRes)
} }
@@ -1008,7 +997,7 @@ func (s *Plex) GetHomeData(ctx context.Context, opts ...operations.Option) (*ope
// GetServerResources - Get Server Resources // GetServerResources - Get Server Resources
// Get Plex server access tokens and server connections // Get Plex server access tokens and server connections
func (s *Plex) GetServerResources(ctx context.Context, includeHTTPS *operations.IncludeHTTPS, includeRelay *operations.IncludeRelay, includeIPv6 *operations.IncludeIPv6, clientID *string, opts ...operations.Option) (*operations.GetServerResourcesResponse, error) { func (s *Plex) GetServerResources(ctx context.Context, clientID string, includeHTTPS *operations.IncludeHTTPS, includeRelay *operations.IncludeRelay, includeIPv6 *operations.IncludeIPv6, opts ...operations.Option) (*operations.GetServerResourcesResponse, error) {
hookCtx := hooks.HookContext{ hookCtx := hooks.HookContext{
Context: ctx, Context: ctx,
OperationID: "get-server-resources", OperationID: "get-server-resources",
@@ -1023,13 +1012,8 @@ func (s *Plex) GetServerResources(ctx context.Context, includeHTTPS *operations.
ClientID: clientID, ClientID: clientID,
} }
globals := operations.GetServerResourcesGlobals{
ClientID: s.sdkConfiguration.Globals.ClientID,
}
o := operations.Options{} o := operations.Options{}
supportedOptions := []string{ supportedOptions := []string{
operations.SupportedOptionServerURL,
operations.SupportedOptionRetries, operations.SupportedOptionRetries,
operations.SupportedOptionTimeout, operations.SupportedOptionTimeout,
} }
@@ -1068,9 +1052,9 @@ func (s *Plex) GetServerResources(ctx context.Context, includeHTTPS *operations.
req.Header.Set("Accept", "application/json") req.Header.Set("Accept", "application/json")
req.Header.Set("User-Agent", s.sdkConfiguration.UserAgent) req.Header.Set("User-Agent", s.sdkConfiguration.UserAgent)
utils.PopulateHeaders(ctx, req, request, globals) utils.PopulateHeaders(ctx, req, request, nil)
if err := utils.PopulateQueryParams(ctx, req, request, globals); err != nil { if err := utils.PopulateQueryParams(ctx, req, request, nil); err != nil {
return nil, fmt.Errorf("error populating query params: %w", err) return nil, fmt.Errorf("error populating query params: %w", err)
} }
@@ -1078,6 +1062,10 @@ func (s *Plex) GetServerResources(ctx context.Context, includeHTTPS *operations.
return nil, err return nil, err
} }
for k, v := range o.SetHeaders {
req.Header.Set(k, v)
}
globalRetryConfig := s.sdkConfiguration.RetryConfig globalRetryConfig := s.sdkConfiguration.RetryConfig
retryConfig := o.Retries retryConfig := o.Retries
if retryConfig == nil { if retryConfig == nil {
@@ -1108,7 +1096,11 @@ func (s *Plex) GetServerResources(ctx context.Context, includeHTTPS *operations.
req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req)
if err != nil { if err != nil {
return nil, backoff.Permanent(err) if retry.IsPermanentError(err) || retry.IsTemporaryError(err) {
return nil, err
}
return nil, retry.Permanent(err)
} }
httpRes, err := s.sdkConfiguration.Client.Do(req) httpRes, err := s.sdkConfiguration.Client.Do(req)
@@ -1169,21 +1161,11 @@ func (s *Plex) GetServerResources(ctx context.Context, includeHTTPS *operations.
RawResponse: httpRes, RawResponse: httpRes,
} }
getRawBody := func() ([]byte, error) {
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))
return rawBody, nil
}
switch { switch {
case httpRes.StatusCode == 200: case httpRes.StatusCode == 200:
switch { switch {
case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -1195,17 +1177,16 @@ func (s *Plex) GetServerResources(ctx context.Context, includeHTTPS *operations.
res.PlexDevices = out res.PlexDevices = out
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
} }
case httpRes.StatusCode == 400: case httpRes.StatusCode == 400:
switch { switch {
case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -1218,17 +1199,16 @@ func (s *Plex) GetServerResources(ctx context.Context, includeHTTPS *operations.
out.RawResponse = httpRes out.RawResponse = httpRes
return nil, &out return nil, &out
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
} }
case httpRes.StatusCode == 401: case httpRes.StatusCode == 401:
switch { switch {
case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -1241,28 +1221,29 @@ func (s *Plex) GetServerResources(ctx context.Context, includeHTTPS *operations.
out.RawResponse = httpRes out.RawResponse = httpRes
return nil, &out return nil, &out
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
} }
case httpRes.StatusCode >= 400 && httpRes.StatusCode < 500: case httpRes.StatusCode >= 400 && httpRes.StatusCode < 500:
fallthrough rawBody, err := utils.ConsumeRawBody(httpRes)
case httpRes.StatusCode >= 500 && httpRes.StatusCode < 600: if err != nil {
rawBody, err := getRawBody() return nil, err
}
return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes)
case httpRes.StatusCode >= 500 && httpRes.StatusCode < 600:
rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes)
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError("unknown status code returned", httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError("unknown status code returned", httpRes.StatusCode, string(rawBody), httpRes)
} }
@@ -1280,17 +1261,8 @@ func (s *Plex) GetPin(ctx context.Context, request operations.GetPinRequest, opt
SecuritySource: nil, SecuritySource: nil,
} }
globals := operations.GetPinGlobals{
ClientID: s.sdkConfiguration.Globals.ClientID,
ClientName: s.sdkConfiguration.Globals.ClientName,
DeviceNickname: s.sdkConfiguration.Globals.DeviceNickname,
ClientVersion: s.sdkConfiguration.Globals.ClientVersion,
Platform: s.sdkConfiguration.Globals.Platform,
}
o := operations.Options{} o := operations.Options{}
supportedOptions := []string{ supportedOptions := []string{
operations.SupportedOptionServerURL,
operations.SupportedOptionRetries, operations.SupportedOptionRetries,
operations.SupportedOptionTimeout, operations.SupportedOptionTimeout,
} }
@@ -1329,12 +1301,16 @@ func (s *Plex) GetPin(ctx context.Context, request operations.GetPinRequest, opt
req.Header.Set("Accept", "application/json") req.Header.Set("Accept", "application/json")
req.Header.Set("User-Agent", s.sdkConfiguration.UserAgent) req.Header.Set("User-Agent", s.sdkConfiguration.UserAgent)
utils.PopulateHeaders(ctx, req, request, globals) utils.PopulateHeaders(ctx, req, request, nil)
if err := utils.PopulateQueryParams(ctx, req, request, globals); err != nil { if err := utils.PopulateQueryParams(ctx, req, request, nil); err != nil {
return nil, fmt.Errorf("error populating query params: %w", err) return nil, fmt.Errorf("error populating query params: %w", err)
} }
for k, v := range o.SetHeaders {
req.Header.Set(k, v)
}
globalRetryConfig := s.sdkConfiguration.RetryConfig globalRetryConfig := s.sdkConfiguration.RetryConfig
retryConfig := o.Retries retryConfig := o.Retries
if retryConfig == nil { if retryConfig == nil {
@@ -1365,7 +1341,11 @@ func (s *Plex) GetPin(ctx context.Context, request operations.GetPinRequest, opt
req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req)
if err != nil { if err != nil {
return nil, backoff.Permanent(err) if retry.IsPermanentError(err) || retry.IsTemporaryError(err) {
return nil, err
}
return nil, retry.Permanent(err)
} }
httpRes, err := s.sdkConfiguration.Client.Do(req) httpRes, err := s.sdkConfiguration.Client.Do(req)
@@ -1426,21 +1406,11 @@ func (s *Plex) GetPin(ctx context.Context, request operations.GetPinRequest, opt
RawResponse: httpRes, RawResponse: httpRes,
} }
getRawBody := func() ([]byte, error) {
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))
return rawBody, nil
}
switch { switch {
case httpRes.StatusCode == 201: case httpRes.StatusCode == 201:
switch { switch {
case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -1452,17 +1422,16 @@ func (s *Plex) GetPin(ctx context.Context, request operations.GetPinRequest, opt
res.AuthPinContainer = &out res.AuthPinContainer = &out
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
} }
case httpRes.StatusCode == 400: case httpRes.StatusCode == 400:
switch { switch {
case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -1475,28 +1444,29 @@ func (s *Plex) GetPin(ctx context.Context, request operations.GetPinRequest, opt
out.RawResponse = httpRes out.RawResponse = httpRes
return nil, &out return nil, &out
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
} }
case httpRes.StatusCode >= 400 && httpRes.StatusCode < 500: case httpRes.StatusCode >= 400 && httpRes.StatusCode < 500:
fallthrough rawBody, err := utils.ConsumeRawBody(httpRes)
case httpRes.StatusCode >= 500 && httpRes.StatusCode < 600: if err != nil {
rawBody, err := getRawBody() return nil, err
}
return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes)
case httpRes.StatusCode >= 500 && httpRes.StatusCode < 600:
rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes)
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError("unknown status code returned", httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError("unknown status code returned", httpRes.StatusCode, string(rawBody), httpRes)
} }
@@ -1514,17 +1484,8 @@ func (s *Plex) GetTokenByPinID(ctx context.Context, request operations.GetTokenB
SecuritySource: nil, SecuritySource: nil,
} }
globals := operations.GetTokenByPinIDGlobals{
ClientID: s.sdkConfiguration.Globals.ClientID,
ClientName: s.sdkConfiguration.Globals.ClientName,
DeviceNickname: s.sdkConfiguration.Globals.DeviceNickname,
ClientVersion: s.sdkConfiguration.Globals.ClientVersion,
Platform: s.sdkConfiguration.Globals.Platform,
}
o := operations.Options{} o := operations.Options{}
supportedOptions := []string{ supportedOptions := []string{
operations.SupportedOptionServerURL,
operations.SupportedOptionRetries, operations.SupportedOptionRetries,
operations.SupportedOptionTimeout, operations.SupportedOptionTimeout,
} }
@@ -1540,7 +1501,7 @@ func (s *Plex) GetTokenByPinID(ctx context.Context, request operations.GetTokenB
baseURL = *o.ServerURL baseURL = *o.ServerURL
} }
opURL, err := utils.GenerateURL(ctx, baseURL, "/pins/{pinID}", request, globals) opURL, err := utils.GenerateURL(ctx, baseURL, "/pins/{pinID}", request, nil)
if err != nil { if err != nil {
return nil, fmt.Errorf("error generating URL: %w", err) return nil, fmt.Errorf("error generating URL: %w", err)
} }
@@ -1563,7 +1524,11 @@ func (s *Plex) GetTokenByPinID(ctx context.Context, request operations.GetTokenB
req.Header.Set("Accept", "application/json") req.Header.Set("Accept", "application/json")
req.Header.Set("User-Agent", s.sdkConfiguration.UserAgent) req.Header.Set("User-Agent", s.sdkConfiguration.UserAgent)
utils.PopulateHeaders(ctx, req, request, globals) utils.PopulateHeaders(ctx, req, request, nil)
for k, v := range o.SetHeaders {
req.Header.Set(k, v)
}
globalRetryConfig := s.sdkConfiguration.RetryConfig globalRetryConfig := s.sdkConfiguration.RetryConfig
retryConfig := o.Retries retryConfig := o.Retries
@@ -1595,7 +1560,11 @@ func (s *Plex) GetTokenByPinID(ctx context.Context, request operations.GetTokenB
req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req)
if err != nil { if err != nil {
return nil, backoff.Permanent(err) if retry.IsPermanentError(err) || retry.IsTemporaryError(err) {
return nil, err
}
return nil, retry.Permanent(err)
} }
httpRes, err := s.sdkConfiguration.Client.Do(req) httpRes, err := s.sdkConfiguration.Client.Do(req)
@@ -1656,21 +1625,11 @@ func (s *Plex) GetTokenByPinID(ctx context.Context, request operations.GetTokenB
RawResponse: httpRes, RawResponse: httpRes,
} }
getRawBody := func() ([]byte, error) {
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))
return rawBody, nil
}
switch { switch {
case httpRes.StatusCode == 200: case httpRes.StatusCode == 200:
switch { switch {
case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -1682,17 +1641,16 @@ func (s *Plex) GetTokenByPinID(ctx context.Context, request operations.GetTokenB
res.AuthPinContainer = &out res.AuthPinContainer = &out
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
} }
case httpRes.StatusCode == 400: case httpRes.StatusCode == 400:
switch { switch {
case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -1705,17 +1663,16 @@ func (s *Plex) GetTokenByPinID(ctx context.Context, request operations.GetTokenB
out.RawResponse = httpRes out.RawResponse = httpRes
return nil, &out return nil, &out
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
} }
case httpRes.StatusCode == 404: case httpRes.StatusCode == 404:
switch { switch {
case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -1728,28 +1685,29 @@ func (s *Plex) GetTokenByPinID(ctx context.Context, request operations.GetTokenB
out.RawResponse = httpRes out.RawResponse = httpRes
return nil, &out return nil, &out
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
} }
case httpRes.StatusCode >= 400 && httpRes.StatusCode < 500: case httpRes.StatusCode >= 400 && httpRes.StatusCode < 500:
fallthrough rawBody, err := utils.ConsumeRawBody(httpRes)
case httpRes.StatusCode >= 500 && httpRes.StatusCode < 600: if err != nil {
rawBody, err := getRawBody() return nil, err
}
return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes)
case httpRes.StatusCode >= 500 && httpRes.StatusCode < 600:
rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes)
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError("unknown status code returned", httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError("unknown status code returned", httpRes.StatusCode, string(rawBody), httpRes)
} }

View File

@@ -6,7 +6,6 @@ import (
"context" "context"
"encoding/json" "encoding/json"
"fmt" "fmt"
"github.com/LukeHagar/plexgo/internal/globals"
"github.com/LukeHagar/plexgo/internal/hooks" "github.com/LukeHagar/plexgo/internal/hooks"
"github.com/LukeHagar/plexgo/internal/utils" "github.com/LukeHagar/plexgo/internal/utils"
"github.com/LukeHagar/plexgo/models/components" "github.com/LukeHagar/plexgo/models/components"
@@ -58,7 +57,6 @@ type sdkConfiguration struct {
SDKVersion string SDKVersion string
GenVersion string GenVersion string
UserAgent string UserAgent string
Globals globals.Globals
RetryConfig *retry.Config RetryConfig *retry.Config
Hooks *hooks.Hooks Hooks *hooks.Hooks
Timeout *time.Duration Timeout *time.Duration
@@ -281,41 +279,6 @@ func WithSecuritySource(security func(context.Context) (components.Security, err
} }
} }
// WithClientID allows setting the ClientID parameter for all supported operations
func WithClientID(clientID string) SDKOption {
return func(sdk *PlexAPI) {
sdk.sdkConfiguration.Globals.ClientID = &clientID
}
}
// WithClientName allows setting the ClientName parameter for all supported operations
func WithClientName(clientName string) SDKOption {
return func(sdk *PlexAPI) {
sdk.sdkConfiguration.Globals.ClientName = &clientName
}
}
// WithClientVersion allows setting the ClientVersion parameter for all supported operations
func WithClientVersion(clientVersion string) SDKOption {
return func(sdk *PlexAPI) {
sdk.sdkConfiguration.Globals.ClientVersion = &clientVersion
}
}
// WithPlatform allows setting the Platform parameter for all supported operations
func WithPlatform(platform string) SDKOption {
return func(sdk *PlexAPI) {
sdk.sdkConfiguration.Globals.Platform = &platform
}
}
// WithDeviceNickname allows setting the DeviceNickname parameter for all supported operations
func WithDeviceNickname(deviceNickname string) SDKOption {
return func(sdk *PlexAPI) {
sdk.sdkConfiguration.Globals.DeviceNickname = &deviceNickname
}
}
func WithRetryConfig(retryConfig retry.Config) SDKOption { func WithRetryConfig(retryConfig retry.Config) SDKOption {
return func(sdk *PlexAPI) { return func(sdk *PlexAPI) {
sdk.sdkConfiguration.RetryConfig = &retryConfig sdk.sdkConfiguration.RetryConfig = &retryConfig
@@ -335,10 +298,9 @@ func New(opts ...SDKOption) *PlexAPI {
sdkConfiguration: sdkConfiguration{ sdkConfiguration: sdkConfiguration{
Language: "go", Language: "go",
OpenAPIDocVersion: "0.0.3", OpenAPIDocVersion: "0.0.3",
SDKVersion: "0.15.1", SDKVersion: "0.17.3",
GenVersion: "2.429.0", GenVersion: "2.495.1",
UserAgent: "speakeasy-sdk/go 0.15.1 2.429.0 0.0.3 github.com/LukeHagar/plexgo", UserAgent: "speakeasy-sdk/go 0.17.3 2.495.1 0.0.3 github.com/LukeHagar/plexgo",
Globals: globals.Globals{},
ServerDefaults: []map[string]string{ ServerDefaults: []map[string]string{
{ {
"protocol": "https", "protocol": "https",

View File

@@ -2,6 +2,15 @@
package retry package retry
import (
"errors"
"net/http"
"strconv"
"time"
)
// BackoffStrategy defines the parameters for exponential backoff. This can be
// used to drive a retry loop for example.
type BackoffStrategy struct { type BackoffStrategy struct {
InitialInterval int InitialInterval int
MaxInterval int MaxInterval int
@@ -9,8 +18,131 @@ type BackoffStrategy struct {
MaxElapsedTime int MaxElapsedTime int
} }
// Config configures a retry policy.
type Config struct { type Config struct {
// Strategy sets the algorithm to use for a retry loop. It can be one of:
// - "backoff": retry with exponential backoff and random jitter.
// - "none" or "": disables retries.
Strategy string Strategy string
Backoff *BackoffStrategy Backoff *BackoffStrategy
RetryConnectionErrors bool RetryConnectionErrors bool
} }
// PermanentError is an error that signals that some operation has terminally
// failed and should not be retried.
type PermanentError struct {
cause error
}
// Permanent creates a PermanentError that signals to a retry loop that it
// should stop retrying an operation and return the underlying error.
func Permanent(cause error) error {
if IsPermanentError(cause) {
return cause
}
return &PermanentError{
cause: cause,
}
}
func (e *PermanentError) Error() string {
return e.cause.Error()
}
func (e *PermanentError) Unwrap() error {
return e.cause
}
// TemporaryError represents a retryable error and signals to a retry loop that
// an operation may be retried with an optional wait interval.
type TemporaryError struct {
wait time.Duration
message string
}
// Temporary creates a TemporaryError that signals to a retry loop that an
// operation can be retried. The error may also carry details about how long to
// wait before retrying. This wait interval may be used to override the retry
// policy in use.
func Temporary(message string) error {
return &TemporaryError{
message: message,
}
}
// TemporaryFromResponse creates a TemporaryError similar to Temporary but
// additionally parses the Retry-After header from a response to determine the
// wait interval before the next retry attempt.
func TemporaryFromResponse(message string, res *http.Response) error {
return &TemporaryError{
wait: retryIntervalFromResponse(res),
message: message,
}
}
func (e *TemporaryError) Error() string {
return e.message
}
// RetryAfter returns the time to wait before retrying the request. The zero
// value should be interpreted by retry loops to mean they should fallback on
// their default policy whether expenonential, constant backoff or something
// else. It does not mean that an operation should be retried immediately.
func (e *TemporaryError) RetryAfter() time.Duration {
return e.wait
}
func retryIntervalFromResponse(res *http.Response) time.Duration {
if res == nil {
return 0
}
retryVal := res.Header.Get("retry-after")
if retryVal == "" {
return 0
}
parsedNumber, err := strconv.ParseInt(retryVal, 10, 64)
if err == nil {
if parsedNumber < 0 {
return 0
} else {
return time.Duration(parsedNumber) * time.Second
}
}
parsedDate, err := time.Parse(time.RFC1123, retryVal)
if err == nil {
delta := parsedDate.Sub(time.Now())
if delta < 0 {
return 0
} else {
return delta
}
}
return 0
}
// IsPermanentError returns true if an error value is or contains a
// PermanentError in its chain of errors.
func IsPermanentError(err error) bool {
if err == nil {
return false
}
var pe *PermanentError
return errors.As(err, &pe)
}
// IsTemporaryError returns true if an error value is or contains a
// TemporaryError in its chain of errors.
func IsTemporaryError(err error) bool {
if err == nil {
return false
}
var pe *TemporaryError
return errors.As(err, &pe)
}

161
search.go
View File

@@ -10,8 +10,7 @@ import (
"github.com/LukeHagar/plexgo/internal/utils" "github.com/LukeHagar/plexgo/internal/utils"
"github.com/LukeHagar/plexgo/models/operations" "github.com/LukeHagar/plexgo/models/operations"
"github.com/LukeHagar/plexgo/models/sdkerrors" "github.com/LukeHagar/plexgo/models/sdkerrors"
"github.com/cenkalti/backoff/v4" "github.com/LukeHagar/plexgo/retry"
"io"
"net/http" "net/http"
"net/url" "net/url"
) )
@@ -67,7 +66,12 @@ func (s *Search) PerformSearch(ctx context.Context, query string, sectionID *flo
} }
} }
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) var baseURL string
if o.ServerURL == nil {
baseURL = utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
} else {
baseURL = *o.ServerURL
}
opURL, err := url.JoinPath(baseURL, "/hubs/search") opURL, err := url.JoinPath(baseURL, "/hubs/search")
if err != nil { if err != nil {
return nil, fmt.Errorf("error generating URL: %w", err) return nil, fmt.Errorf("error generating URL: %w", err)
@@ -99,6 +103,10 @@ func (s *Search) PerformSearch(ctx context.Context, query string, sectionID *flo
return nil, err return nil, err
} }
for k, v := range o.SetHeaders {
req.Header.Set(k, v)
}
globalRetryConfig := s.sdkConfiguration.RetryConfig globalRetryConfig := s.sdkConfiguration.RetryConfig
retryConfig := o.Retries retryConfig := o.Retries
if retryConfig == nil { if retryConfig == nil {
@@ -129,7 +137,11 @@ func (s *Search) PerformSearch(ctx context.Context, query string, sectionID *flo
req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req)
if err != nil { if err != nil {
return nil, backoff.Permanent(err) if retry.IsPermanentError(err) || retry.IsTemporaryError(err) {
return nil, err
}
return nil, retry.Permanent(err)
} }
httpRes, err := s.sdkConfiguration.Client.Do(req) httpRes, err := s.sdkConfiguration.Client.Do(req)
@@ -190,22 +202,12 @@ func (s *Search) PerformSearch(ctx context.Context, query string, sectionID *flo
RawResponse: httpRes, RawResponse: httpRes,
} }
getRawBody := func() ([]byte, error) {
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))
return rawBody, nil
}
switch { switch {
case httpRes.StatusCode == 200: case httpRes.StatusCode == 200:
case httpRes.StatusCode == 400: case httpRes.StatusCode == 400:
switch { switch {
case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -218,17 +220,16 @@ func (s *Search) PerformSearch(ctx context.Context, query string, sectionID *flo
out.RawResponse = httpRes out.RawResponse = httpRes
return nil, &out return nil, &out
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
} }
case httpRes.StatusCode == 401: case httpRes.StatusCode == 401:
switch { switch {
case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -241,28 +242,29 @@ func (s *Search) PerformSearch(ctx context.Context, query string, sectionID *flo
out.RawResponse = httpRes out.RawResponse = httpRes
return nil, &out return nil, &out
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
} }
case httpRes.StatusCode >= 400 && httpRes.StatusCode < 500: case httpRes.StatusCode >= 400 && httpRes.StatusCode < 500:
fallthrough rawBody, err := utils.ConsumeRawBody(httpRes)
case httpRes.StatusCode >= 500 && httpRes.StatusCode < 600: if err != nil {
rawBody, err := getRawBody() return nil, err
}
return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes)
case httpRes.StatusCode >= 500 && httpRes.StatusCode < 600:
rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes)
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError("unknown status code returned", httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError("unknown status code returned", httpRes.StatusCode, string(rawBody), httpRes)
} }
@@ -301,7 +303,12 @@ func (s *Search) PerformVoiceSearch(ctx context.Context, query string, sectionID
} }
} }
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) var baseURL string
if o.ServerURL == nil {
baseURL = utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
} else {
baseURL = *o.ServerURL
}
opURL, err := url.JoinPath(baseURL, "/hubs/search/voice") opURL, err := url.JoinPath(baseURL, "/hubs/search/voice")
if err != nil { if err != nil {
return nil, fmt.Errorf("error generating URL: %w", err) return nil, fmt.Errorf("error generating URL: %w", err)
@@ -333,6 +340,10 @@ func (s *Search) PerformVoiceSearch(ctx context.Context, query string, sectionID
return nil, err return nil, err
} }
for k, v := range o.SetHeaders {
req.Header.Set(k, v)
}
globalRetryConfig := s.sdkConfiguration.RetryConfig globalRetryConfig := s.sdkConfiguration.RetryConfig
retryConfig := o.Retries retryConfig := o.Retries
if retryConfig == nil { if retryConfig == nil {
@@ -363,7 +374,11 @@ func (s *Search) PerformVoiceSearch(ctx context.Context, query string, sectionID
req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req)
if err != nil { if err != nil {
return nil, backoff.Permanent(err) if retry.IsPermanentError(err) || retry.IsTemporaryError(err) {
return nil, err
}
return nil, retry.Permanent(err)
} }
httpRes, err := s.sdkConfiguration.Client.Do(req) httpRes, err := s.sdkConfiguration.Client.Do(req)
@@ -424,22 +439,12 @@ func (s *Search) PerformVoiceSearch(ctx context.Context, query string, sectionID
RawResponse: httpRes, RawResponse: httpRes,
} }
getRawBody := func() ([]byte, error) {
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))
return rawBody, nil
}
switch { switch {
case httpRes.StatusCode == 200: case httpRes.StatusCode == 200:
case httpRes.StatusCode == 400: case httpRes.StatusCode == 400:
switch { switch {
case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -452,17 +457,16 @@ func (s *Search) PerformVoiceSearch(ctx context.Context, query string, sectionID
out.RawResponse = httpRes out.RawResponse = httpRes
return nil, &out return nil, &out
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
} }
case httpRes.StatusCode == 401: case httpRes.StatusCode == 401:
switch { switch {
case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -475,28 +479,29 @@ func (s *Search) PerformVoiceSearch(ctx context.Context, query string, sectionID
out.RawResponse = httpRes out.RawResponse = httpRes
return nil, &out return nil, &out
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
} }
case httpRes.StatusCode >= 400 && httpRes.StatusCode < 500: case httpRes.StatusCode >= 400 && httpRes.StatusCode < 500:
fallthrough rawBody, err := utils.ConsumeRawBody(httpRes)
case httpRes.StatusCode >= 500 && httpRes.StatusCode < 600: if err != nil {
rawBody, err := getRawBody() return nil, err
}
return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes)
case httpRes.StatusCode >= 500 && httpRes.StatusCode < 600:
rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes)
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError("unknown status code returned", httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError("unknown status code returned", httpRes.StatusCode, string(rawBody), httpRes)
} }
@@ -530,7 +535,12 @@ func (s *Search) GetSearchResults(ctx context.Context, query string, opts ...ope
} }
} }
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) var baseURL string
if o.ServerURL == nil {
baseURL = utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
} else {
baseURL = *o.ServerURL
}
opURL, err := url.JoinPath(baseURL, "/search") opURL, err := url.JoinPath(baseURL, "/search")
if err != nil { if err != nil {
return nil, fmt.Errorf("error generating URL: %w", err) return nil, fmt.Errorf("error generating URL: %w", err)
@@ -562,6 +572,10 @@ func (s *Search) GetSearchResults(ctx context.Context, query string, opts ...ope
return nil, err return nil, err
} }
for k, v := range o.SetHeaders {
req.Header.Set(k, v)
}
globalRetryConfig := s.sdkConfiguration.RetryConfig globalRetryConfig := s.sdkConfiguration.RetryConfig
retryConfig := o.Retries retryConfig := o.Retries
if retryConfig == nil { if retryConfig == nil {
@@ -592,7 +606,11 @@ func (s *Search) GetSearchResults(ctx context.Context, query string, opts ...ope
req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req)
if err != nil { if err != nil {
return nil, backoff.Permanent(err) if retry.IsPermanentError(err) || retry.IsTemporaryError(err) {
return nil, err
}
return nil, retry.Permanent(err)
} }
httpRes, err := s.sdkConfiguration.Client.Do(req) httpRes, err := s.sdkConfiguration.Client.Do(req)
@@ -653,21 +671,11 @@ func (s *Search) GetSearchResults(ctx context.Context, query string, opts ...ope
RawResponse: httpRes, RawResponse: httpRes,
} }
getRawBody := func() ([]byte, error) {
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))
return rawBody, nil
}
switch { switch {
case httpRes.StatusCode == 200: case httpRes.StatusCode == 200:
switch { switch {
case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -679,17 +687,16 @@ func (s *Search) GetSearchResults(ctx context.Context, query string, opts ...ope
res.Object = &out res.Object = &out
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
} }
case httpRes.StatusCode == 400: case httpRes.StatusCode == 400:
switch { switch {
case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -702,17 +709,16 @@ func (s *Search) GetSearchResults(ctx context.Context, query string, opts ...ope
out.RawResponse = httpRes out.RawResponse = httpRes
return nil, &out return nil, &out
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
} }
case httpRes.StatusCode == 401: case httpRes.StatusCode == 401:
switch { switch {
case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -725,28 +731,29 @@ func (s *Search) GetSearchResults(ctx context.Context, query string, opts ...ope
out.RawResponse = httpRes out.RawResponse = httpRes
return nil, &out return nil, &out
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
} }
case httpRes.StatusCode >= 400 && httpRes.StatusCode < 500: case httpRes.StatusCode >= 400 && httpRes.StatusCode < 500:
fallthrough rawBody, err := utils.ConsumeRawBody(httpRes)
case httpRes.StatusCode >= 500 && httpRes.StatusCode < 600: if err != nil {
rawBody, err := getRawBody() return nil, err
}
return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes)
case httpRes.StatusCode >= 500 && httpRes.StatusCode < 600:
rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes)
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError("unknown status code returned", httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError("unknown status code returned", httpRes.StatusCode, string(rawBody), httpRes)
} }

497
server.go

File diff suppressed because it is too large Load Diff

View File

@@ -10,8 +10,7 @@ import (
"github.com/LukeHagar/plexgo/internal/utils" "github.com/LukeHagar/plexgo/internal/utils"
"github.com/LukeHagar/plexgo/models/operations" "github.com/LukeHagar/plexgo/models/operations"
"github.com/LukeHagar/plexgo/models/sdkerrors" "github.com/LukeHagar/plexgo/models/sdkerrors"
"github.com/cenkalti/backoff/v4" "github.com/LukeHagar/plexgo/retry"
"io"
"net/http" "net/http"
"net/url" "net/url"
) )
@@ -49,7 +48,12 @@ func (s *Sessions) GetSessions(ctx context.Context, opts ...operations.Option) (
} }
} }
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) var baseURL string
if o.ServerURL == nil {
baseURL = utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
} else {
baseURL = *o.ServerURL
}
opURL, err := url.JoinPath(baseURL, "/status/sessions") opURL, err := url.JoinPath(baseURL, "/status/sessions")
if err != nil { if err != nil {
return nil, fmt.Errorf("error generating URL: %w", err) return nil, fmt.Errorf("error generating URL: %w", err)
@@ -77,6 +81,10 @@ func (s *Sessions) GetSessions(ctx context.Context, opts ...operations.Option) (
return nil, err return nil, err
} }
for k, v := range o.SetHeaders {
req.Header.Set(k, v)
}
globalRetryConfig := s.sdkConfiguration.RetryConfig globalRetryConfig := s.sdkConfiguration.RetryConfig
retryConfig := o.Retries retryConfig := o.Retries
if retryConfig == nil { if retryConfig == nil {
@@ -107,7 +115,11 @@ func (s *Sessions) GetSessions(ctx context.Context, opts ...operations.Option) (
req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req)
if err != nil { if err != nil {
return nil, backoff.Permanent(err) if retry.IsPermanentError(err) || retry.IsTemporaryError(err) {
return nil, err
}
return nil, retry.Permanent(err)
} }
httpRes, err := s.sdkConfiguration.Client.Do(req) httpRes, err := s.sdkConfiguration.Client.Do(req)
@@ -168,21 +180,11 @@ func (s *Sessions) GetSessions(ctx context.Context, opts ...operations.Option) (
RawResponse: httpRes, RawResponse: httpRes,
} }
getRawBody := func() ([]byte, error) {
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))
return rawBody, nil
}
switch { switch {
case httpRes.StatusCode == 200: case httpRes.StatusCode == 200:
switch { switch {
case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -194,17 +196,16 @@ func (s *Sessions) GetSessions(ctx context.Context, opts ...operations.Option) (
res.Object = &out res.Object = &out
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
} }
case httpRes.StatusCode == 400: case httpRes.StatusCode == 400:
switch { switch {
case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -217,17 +218,16 @@ func (s *Sessions) GetSessions(ctx context.Context, opts ...operations.Option) (
out.RawResponse = httpRes out.RawResponse = httpRes
return nil, &out return nil, &out
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
} }
case httpRes.StatusCode == 401: case httpRes.StatusCode == 401:
switch { switch {
case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -240,28 +240,29 @@ func (s *Sessions) GetSessions(ctx context.Context, opts ...operations.Option) (
out.RawResponse = httpRes out.RawResponse = httpRes
return nil, &out return nil, &out
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
} }
case httpRes.StatusCode >= 400 && httpRes.StatusCode < 500: case httpRes.StatusCode >= 400 && httpRes.StatusCode < 500:
fallthrough rawBody, err := utils.ConsumeRawBody(httpRes)
case httpRes.StatusCode >= 500 && httpRes.StatusCode < 600: if err != nil {
rawBody, err := getRawBody() return nil, err
}
return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes)
case httpRes.StatusCode >= 500 && httpRes.StatusCode < 600:
rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes)
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError("unknown status code returned", httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError("unknown status code returned", httpRes.StatusCode, string(rawBody), httpRes)
} }
@@ -298,7 +299,12 @@ func (s *Sessions) GetSessionHistory(ctx context.Context, sort *string, accountI
} }
} }
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) var baseURL string
if o.ServerURL == nil {
baseURL = utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
} else {
baseURL = *o.ServerURL
}
opURL, err := url.JoinPath(baseURL, "/status/sessions/history/all") opURL, err := url.JoinPath(baseURL, "/status/sessions/history/all")
if err != nil { if err != nil {
return nil, fmt.Errorf("error generating URL: %w", err) return nil, fmt.Errorf("error generating URL: %w", err)
@@ -330,6 +336,10 @@ func (s *Sessions) GetSessionHistory(ctx context.Context, sort *string, accountI
return nil, err return nil, err
} }
for k, v := range o.SetHeaders {
req.Header.Set(k, v)
}
globalRetryConfig := s.sdkConfiguration.RetryConfig globalRetryConfig := s.sdkConfiguration.RetryConfig
retryConfig := o.Retries retryConfig := o.Retries
if retryConfig == nil { if retryConfig == nil {
@@ -360,7 +370,11 @@ func (s *Sessions) GetSessionHistory(ctx context.Context, sort *string, accountI
req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req)
if err != nil { if err != nil {
return nil, backoff.Permanent(err) if retry.IsPermanentError(err) || retry.IsTemporaryError(err) {
return nil, err
}
return nil, retry.Permanent(err)
} }
httpRes, err := s.sdkConfiguration.Client.Do(req) httpRes, err := s.sdkConfiguration.Client.Do(req)
@@ -421,21 +435,11 @@ func (s *Sessions) GetSessionHistory(ctx context.Context, sort *string, accountI
RawResponse: httpRes, RawResponse: httpRes,
} }
getRawBody := func() ([]byte, error) {
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))
return rawBody, nil
}
switch { switch {
case httpRes.StatusCode == 200: case httpRes.StatusCode == 200:
switch { switch {
case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -447,17 +451,16 @@ func (s *Sessions) GetSessionHistory(ctx context.Context, sort *string, accountI
res.Object = &out res.Object = &out
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
} }
case httpRes.StatusCode == 400: case httpRes.StatusCode == 400:
switch { switch {
case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -470,17 +473,16 @@ func (s *Sessions) GetSessionHistory(ctx context.Context, sort *string, accountI
out.RawResponse = httpRes out.RawResponse = httpRes
return nil, &out return nil, &out
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
} }
case httpRes.StatusCode == 401: case httpRes.StatusCode == 401:
switch { switch {
case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -493,28 +495,29 @@ func (s *Sessions) GetSessionHistory(ctx context.Context, sort *string, accountI
out.RawResponse = httpRes out.RawResponse = httpRes
return nil, &out return nil, &out
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
} }
case httpRes.StatusCode >= 400 && httpRes.StatusCode < 500: case httpRes.StatusCode >= 400 && httpRes.StatusCode < 500:
fallthrough rawBody, err := utils.ConsumeRawBody(httpRes)
case httpRes.StatusCode >= 500 && httpRes.StatusCode < 600: if err != nil {
rawBody, err := getRawBody() return nil, err
}
return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes)
case httpRes.StatusCode >= 500 && httpRes.StatusCode < 600:
rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes)
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError("unknown status code returned", httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError("unknown status code returned", httpRes.StatusCode, string(rawBody), httpRes)
} }
@@ -544,7 +547,12 @@ func (s *Sessions) GetTranscodeSessions(ctx context.Context, opts ...operations.
} }
} }
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) var baseURL string
if o.ServerURL == nil {
baseURL = utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
} else {
baseURL = *o.ServerURL
}
opURL, err := url.JoinPath(baseURL, "/transcode/sessions") opURL, err := url.JoinPath(baseURL, "/transcode/sessions")
if err != nil { if err != nil {
return nil, fmt.Errorf("error generating URL: %w", err) return nil, fmt.Errorf("error generating URL: %w", err)
@@ -572,6 +580,10 @@ func (s *Sessions) GetTranscodeSessions(ctx context.Context, opts ...operations.
return nil, err return nil, err
} }
for k, v := range o.SetHeaders {
req.Header.Set(k, v)
}
globalRetryConfig := s.sdkConfiguration.RetryConfig globalRetryConfig := s.sdkConfiguration.RetryConfig
retryConfig := o.Retries retryConfig := o.Retries
if retryConfig == nil { if retryConfig == nil {
@@ -602,7 +614,11 @@ func (s *Sessions) GetTranscodeSessions(ctx context.Context, opts ...operations.
req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req)
if err != nil { if err != nil {
return nil, backoff.Permanent(err) if retry.IsPermanentError(err) || retry.IsTemporaryError(err) {
return nil, err
}
return nil, retry.Permanent(err)
} }
httpRes, err := s.sdkConfiguration.Client.Do(req) httpRes, err := s.sdkConfiguration.Client.Do(req)
@@ -663,21 +679,11 @@ func (s *Sessions) GetTranscodeSessions(ctx context.Context, opts ...operations.
RawResponse: httpRes, RawResponse: httpRes,
} }
getRawBody := func() ([]byte, error) {
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))
return rawBody, nil
}
switch { switch {
case httpRes.StatusCode == 200: case httpRes.StatusCode == 200:
switch { switch {
case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -689,17 +695,16 @@ func (s *Sessions) GetTranscodeSessions(ctx context.Context, opts ...operations.
res.Object = &out res.Object = &out
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
} }
case httpRes.StatusCode == 400: case httpRes.StatusCode == 400:
switch { switch {
case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -712,17 +717,16 @@ func (s *Sessions) GetTranscodeSessions(ctx context.Context, opts ...operations.
out.RawResponse = httpRes out.RawResponse = httpRes
return nil, &out return nil, &out
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
} }
case httpRes.StatusCode == 401: case httpRes.StatusCode == 401:
switch { switch {
case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -735,28 +739,29 @@ func (s *Sessions) GetTranscodeSessions(ctx context.Context, opts ...operations.
out.RawResponse = httpRes out.RawResponse = httpRes
return nil, &out return nil, &out
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
} }
case httpRes.StatusCode >= 400 && httpRes.StatusCode < 500: case httpRes.StatusCode >= 400 && httpRes.StatusCode < 500:
fallthrough rawBody, err := utils.ConsumeRawBody(httpRes)
case httpRes.StatusCode >= 500 && httpRes.StatusCode < 600: if err != nil {
rawBody, err := getRawBody() return nil, err
}
return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes)
case httpRes.StatusCode >= 500 && httpRes.StatusCode < 600:
rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes)
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError("unknown status code returned", httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError("unknown status code returned", httpRes.StatusCode, string(rawBody), httpRes)
} }
@@ -790,7 +795,12 @@ func (s *Sessions) StopTranscodeSession(ctx context.Context, sessionKey string,
} }
} }
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) var baseURL string
if o.ServerURL == nil {
baseURL = utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
} else {
baseURL = *o.ServerURL
}
opURL, err := utils.GenerateURL(ctx, baseURL, "/transcode/sessions/{sessionKey}", request, nil) opURL, err := utils.GenerateURL(ctx, baseURL, "/transcode/sessions/{sessionKey}", request, nil)
if err != nil { if err != nil {
return nil, fmt.Errorf("error generating URL: %w", err) return nil, fmt.Errorf("error generating URL: %w", err)
@@ -818,6 +828,10 @@ func (s *Sessions) StopTranscodeSession(ctx context.Context, sessionKey string,
return nil, err return nil, err
} }
for k, v := range o.SetHeaders {
req.Header.Set(k, v)
}
globalRetryConfig := s.sdkConfiguration.RetryConfig globalRetryConfig := s.sdkConfiguration.RetryConfig
retryConfig := o.Retries retryConfig := o.Retries
if retryConfig == nil { if retryConfig == nil {
@@ -848,7 +862,11 @@ func (s *Sessions) StopTranscodeSession(ctx context.Context, sessionKey string,
req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req)
if err != nil { if err != nil {
return nil, backoff.Permanent(err) if retry.IsPermanentError(err) || retry.IsTemporaryError(err) {
return nil, err
}
return nil, retry.Permanent(err)
} }
httpRes, err := s.sdkConfiguration.Client.Do(req) httpRes, err := s.sdkConfiguration.Client.Do(req)
@@ -909,22 +927,12 @@ func (s *Sessions) StopTranscodeSession(ctx context.Context, sessionKey string,
RawResponse: httpRes, RawResponse: httpRes,
} }
getRawBody := func() ([]byte, error) {
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))
return rawBody, nil
}
switch { switch {
case httpRes.StatusCode == 204: case httpRes.StatusCode == 204:
case httpRes.StatusCode == 400: case httpRes.StatusCode == 400:
switch { switch {
case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -937,17 +945,16 @@ func (s *Sessions) StopTranscodeSession(ctx context.Context, sessionKey string,
out.RawResponse = httpRes out.RawResponse = httpRes
return nil, &out return nil, &out
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
} }
case httpRes.StatusCode == 401: case httpRes.StatusCode == 401:
switch { switch {
case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -960,28 +967,29 @@ func (s *Sessions) StopTranscodeSession(ctx context.Context, sessionKey string,
out.RawResponse = httpRes out.RawResponse = httpRes
return nil, &out return nil, &out
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
} }
case httpRes.StatusCode >= 400 && httpRes.StatusCode < 500: case httpRes.StatusCode >= 400 && httpRes.StatusCode < 500:
fallthrough rawBody, err := utils.ConsumeRawBody(httpRes)
case httpRes.StatusCode >= 500 && httpRes.StatusCode < 600: if err != nil {
rawBody, err := getRawBody() return nil, err
}
return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes)
case httpRes.StatusCode >= 500 && httpRes.StatusCode < 600:
rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes)
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError("unknown status code returned", httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError("unknown status code returned", httpRes.StatusCode, string(rawBody), httpRes)
} }

View File

@@ -10,8 +10,7 @@ import (
"github.com/LukeHagar/plexgo/internal/utils" "github.com/LukeHagar/plexgo/internal/utils"
"github.com/LukeHagar/plexgo/models/operations" "github.com/LukeHagar/plexgo/models/operations"
"github.com/LukeHagar/plexgo/models/sdkerrors" "github.com/LukeHagar/plexgo/models/sdkerrors"
"github.com/cenkalti/backoff/v4" "github.com/LukeHagar/plexgo/retry"
"io"
"net/http" "net/http"
"net/url" "net/url"
) )
@@ -53,7 +52,12 @@ func (s *Statistics) GetStatistics(ctx context.Context, timespan *int64, opts ..
} }
} }
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) var baseURL string
if o.ServerURL == nil {
baseURL = utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
} else {
baseURL = *o.ServerURL
}
opURL, err := url.JoinPath(baseURL, "/statistics/media") opURL, err := url.JoinPath(baseURL, "/statistics/media")
if err != nil { if err != nil {
return nil, fmt.Errorf("error generating URL: %w", err) return nil, fmt.Errorf("error generating URL: %w", err)
@@ -85,6 +89,10 @@ func (s *Statistics) GetStatistics(ctx context.Context, timespan *int64, opts ..
return nil, err return nil, err
} }
for k, v := range o.SetHeaders {
req.Header.Set(k, v)
}
globalRetryConfig := s.sdkConfiguration.RetryConfig globalRetryConfig := s.sdkConfiguration.RetryConfig
retryConfig := o.Retries retryConfig := o.Retries
if retryConfig == nil { if retryConfig == nil {
@@ -115,7 +123,11 @@ func (s *Statistics) GetStatistics(ctx context.Context, timespan *int64, opts ..
req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req)
if err != nil { if err != nil {
return nil, backoff.Permanent(err) if retry.IsPermanentError(err) || retry.IsTemporaryError(err) {
return nil, err
}
return nil, retry.Permanent(err)
} }
httpRes, err := s.sdkConfiguration.Client.Do(req) httpRes, err := s.sdkConfiguration.Client.Do(req)
@@ -176,21 +188,11 @@ func (s *Statistics) GetStatistics(ctx context.Context, timespan *int64, opts ..
RawResponse: httpRes, RawResponse: httpRes,
} }
getRawBody := func() ([]byte, error) {
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))
return rawBody, nil
}
switch { switch {
case httpRes.StatusCode == 200: case httpRes.StatusCode == 200:
switch { switch {
case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -202,17 +204,16 @@ func (s *Statistics) GetStatistics(ctx context.Context, timespan *int64, opts ..
res.Object = &out res.Object = &out
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
} }
case httpRes.StatusCode == 400: case httpRes.StatusCode == 400:
switch { switch {
case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -225,17 +226,16 @@ func (s *Statistics) GetStatistics(ctx context.Context, timespan *int64, opts ..
out.RawResponse = httpRes out.RawResponse = httpRes
return nil, &out return nil, &out
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
} }
case httpRes.StatusCode == 401: case httpRes.StatusCode == 401:
switch { switch {
case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -248,28 +248,29 @@ func (s *Statistics) GetStatistics(ctx context.Context, timespan *int64, opts ..
out.RawResponse = httpRes out.RawResponse = httpRes
return nil, &out return nil, &out
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
} }
case httpRes.StatusCode >= 400 && httpRes.StatusCode < 500: case httpRes.StatusCode >= 400 && httpRes.StatusCode < 500:
fallthrough rawBody, err := utils.ConsumeRawBody(httpRes)
case httpRes.StatusCode >= 500 && httpRes.StatusCode < 600: if err != nil {
rawBody, err := getRawBody() return nil, err
}
return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes)
case httpRes.StatusCode >= 500 && httpRes.StatusCode < 600:
rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes)
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError("unknown status code returned", httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError("unknown status code returned", httpRes.StatusCode, string(rawBody), httpRes)
} }
@@ -303,7 +304,12 @@ func (s *Statistics) GetResourcesStatistics(ctx context.Context, timespan *int64
} }
} }
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) var baseURL string
if o.ServerURL == nil {
baseURL = utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
} else {
baseURL = *o.ServerURL
}
opURL, err := url.JoinPath(baseURL, "/statistics/resources") opURL, err := url.JoinPath(baseURL, "/statistics/resources")
if err != nil { if err != nil {
return nil, fmt.Errorf("error generating URL: %w", err) return nil, fmt.Errorf("error generating URL: %w", err)
@@ -335,6 +341,10 @@ func (s *Statistics) GetResourcesStatistics(ctx context.Context, timespan *int64
return nil, err return nil, err
} }
for k, v := range o.SetHeaders {
req.Header.Set(k, v)
}
globalRetryConfig := s.sdkConfiguration.RetryConfig globalRetryConfig := s.sdkConfiguration.RetryConfig
retryConfig := o.Retries retryConfig := o.Retries
if retryConfig == nil { if retryConfig == nil {
@@ -365,7 +375,11 @@ func (s *Statistics) GetResourcesStatistics(ctx context.Context, timespan *int64
req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req)
if err != nil { if err != nil {
return nil, backoff.Permanent(err) if retry.IsPermanentError(err) || retry.IsTemporaryError(err) {
return nil, err
}
return nil, retry.Permanent(err)
} }
httpRes, err := s.sdkConfiguration.Client.Do(req) httpRes, err := s.sdkConfiguration.Client.Do(req)
@@ -426,21 +440,11 @@ func (s *Statistics) GetResourcesStatistics(ctx context.Context, timespan *int64
RawResponse: httpRes, RawResponse: httpRes,
} }
getRawBody := func() ([]byte, error) {
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))
return rawBody, nil
}
switch { switch {
case httpRes.StatusCode == 200: case httpRes.StatusCode == 200:
switch { switch {
case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -452,17 +456,16 @@ func (s *Statistics) GetResourcesStatistics(ctx context.Context, timespan *int64
res.Object = &out res.Object = &out
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
} }
case httpRes.StatusCode == 400: case httpRes.StatusCode == 400:
switch { switch {
case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -475,17 +478,16 @@ func (s *Statistics) GetResourcesStatistics(ctx context.Context, timespan *int64
out.RawResponse = httpRes out.RawResponse = httpRes
return nil, &out return nil, &out
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
} }
case httpRes.StatusCode == 401: case httpRes.StatusCode == 401:
switch { switch {
case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -498,28 +500,29 @@ func (s *Statistics) GetResourcesStatistics(ctx context.Context, timespan *int64
out.RawResponse = httpRes out.RawResponse = httpRes
return nil, &out return nil, &out
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
} }
case httpRes.StatusCode >= 400 && httpRes.StatusCode < 500: case httpRes.StatusCode >= 400 && httpRes.StatusCode < 500:
fallthrough rawBody, err := utils.ConsumeRawBody(httpRes)
case httpRes.StatusCode >= 500 && httpRes.StatusCode < 600: if err != nil {
rawBody, err := getRawBody() return nil, err
}
return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes)
case httpRes.StatusCode >= 500 && httpRes.StatusCode < 600:
rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes)
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError("unknown status code returned", httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError("unknown status code returned", httpRes.StatusCode, string(rawBody), httpRes)
} }
@@ -553,7 +556,12 @@ func (s *Statistics) GetBandwidthStatistics(ctx context.Context, timespan *int64
} }
} }
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) var baseURL string
if o.ServerURL == nil {
baseURL = utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
} else {
baseURL = *o.ServerURL
}
opURL, err := url.JoinPath(baseURL, "/statistics/bandwidth") opURL, err := url.JoinPath(baseURL, "/statistics/bandwidth")
if err != nil { if err != nil {
return nil, fmt.Errorf("error generating URL: %w", err) return nil, fmt.Errorf("error generating URL: %w", err)
@@ -585,6 +593,10 @@ func (s *Statistics) GetBandwidthStatistics(ctx context.Context, timespan *int64
return nil, err return nil, err
} }
for k, v := range o.SetHeaders {
req.Header.Set(k, v)
}
globalRetryConfig := s.sdkConfiguration.RetryConfig globalRetryConfig := s.sdkConfiguration.RetryConfig
retryConfig := o.Retries retryConfig := o.Retries
if retryConfig == nil { if retryConfig == nil {
@@ -615,7 +627,11 @@ func (s *Statistics) GetBandwidthStatistics(ctx context.Context, timespan *int64
req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req)
if err != nil { if err != nil {
return nil, backoff.Permanent(err) if retry.IsPermanentError(err) || retry.IsTemporaryError(err) {
return nil, err
}
return nil, retry.Permanent(err)
} }
httpRes, err := s.sdkConfiguration.Client.Do(req) httpRes, err := s.sdkConfiguration.Client.Do(req)
@@ -676,21 +692,11 @@ func (s *Statistics) GetBandwidthStatistics(ctx context.Context, timespan *int64
RawResponse: httpRes, RawResponse: httpRes,
} }
getRawBody := func() ([]byte, error) {
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))
return rawBody, nil
}
switch { switch {
case httpRes.StatusCode == 200: case httpRes.StatusCode == 200:
switch { switch {
case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -702,17 +708,16 @@ func (s *Statistics) GetBandwidthStatistics(ctx context.Context, timespan *int64
res.Object = &out res.Object = &out
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
} }
case httpRes.StatusCode == 400: case httpRes.StatusCode == 400:
switch { switch {
case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -725,17 +730,16 @@ func (s *Statistics) GetBandwidthStatistics(ctx context.Context, timespan *int64
out.RawResponse = httpRes out.RawResponse = httpRes
return nil, &out return nil, &out
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
} }
case httpRes.StatusCode == 401: case httpRes.StatusCode == 401:
switch { switch {
case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -748,28 +752,29 @@ func (s *Statistics) GetBandwidthStatistics(ctx context.Context, timespan *int64
out.RawResponse = httpRes out.RawResponse = httpRes
return nil, &out return nil, &out
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
} }
case httpRes.StatusCode >= 400 && httpRes.StatusCode < 500: case httpRes.StatusCode >= 400 && httpRes.StatusCode < 500:
fallthrough rawBody, err := utils.ConsumeRawBody(httpRes)
case httpRes.StatusCode >= 500 && httpRes.StatusCode < 600: if err != nil {
rawBody, err := getRawBody() return nil, err
}
return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes)
case httpRes.StatusCode >= 500 && httpRes.StatusCode < 600:
rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes)
default: default:
rawBody, err := getRawBody() rawBody, err := utils.ConsumeRawBody(httpRes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, sdkerrors.NewSDKError("unknown status code returned", httpRes.StatusCode, string(rawBody), httpRes) return nil, sdkerrors.NewSDKError("unknown status code returned", httpRes.StatusCode, string(rawBody), httpRes)
} }

Some files were not shown because too many files have changed in this diff Show More