diff --git a/.speakeasy/gen.lock b/.speakeasy/gen.lock
index dd66991..e62b6f3 100755
--- a/.speakeasy/gen.lock
+++ b/.speakeasy/gen.lock
@@ -1,12 +1,12 @@
lockVersion: 2.0.0
id: dfa99515-01c0-42eb-9be5-ee212fd03eb3
management:
- docChecksum: 94439465ae5d544f0e52b00719af05ee
+ docChecksum: 099fc5bbb987ae7e391f7f07b4212860
docVersion: 0.0.3
speakeasyVersion: internal
- generationVersion: 2.245.1
- releaseVersion: 0.2.1
- configChecksum: 0c6f5f0bce6af6f3bd99f99ce9584d7e
+ generationVersion: 2.249.1
+ releaseVersion: 0.3.0
+ configChecksum: ae48b3df080bde21a30ed099e1ffc0d8
repoURL: https://github.com/LukeHagar/plexgo.git
repoSubDirectory: .
installationURL: https://github.com/LukeHagar/plexgo
@@ -14,9 +14,9 @@ management:
features:
go:
constsAndDefaults: 0.1.2
- core: 3.3.1
+ core: 3.3.2
flattening: 2.81.1
- globalSecurity: 2.82.5
+ globalSecurity: 2.82.6
globalServerURLs: 2.82.1
methodServerURLs: 2.82.1
nameOverrides: 2.81.1
@@ -30,7 +30,6 @@ generatedFiles:
- search.go
- library.go
- log.go
- - tv.go
- plex.go
- playlists.go
- security.go
@@ -574,9 +573,8 @@ generatedFiles:
- docs/sdks/search/README.md
- docs/sdks/library/README.md
- docs/sdks/log/README.md
- - docs/sdks/plex/README.md
- docs/models/operations/option.md
- - docs/sdks/tv/README.md
+ - docs/sdks/plex/README.md
- docs/sdks/playlists/README.md
- docs/sdks/security/README.md
- docs/sdks/sessions/README.md
diff --git a/README.md b/README.md
index c96049e..eae7ccb 100644
--- a/README.md
+++ b/README.md
@@ -113,11 +113,10 @@ func main() {
* [LogMultiLine](docs/sdks/log/README.md#logmultiline) - Logging a multi-line message
* [EnablePaperTrail](docs/sdks/log/README.md#enablepapertrail) - Enabling Papertrail
+### [Plex](docs/sdks/plex/README.md)
-### [Plex.Tv](docs/sdks/tv/README.md)
-
-* [GetPin](docs/sdks/tv/README.md#getpin) - Get a Pin
-* [GetToken](docs/sdks/tv/README.md#gettoken) - Get Access Token
+* [GetPin](docs/sdks/plex/README.md#getpin) - Get a Pin
+* [GetToken](docs/sdks/plex/README.md#gettoken) - Get Access Token
### [Playlists](docs/sdks/playlists/README.md)
@@ -309,7 +308,7 @@ func main() {
var strong *bool = false
ctx := context.Background()
- res, err := s.Plex.Tv.GetPin(ctx, operations.WithServerURL("https://plex.tv/api/v2"), xPlexClientIdentifier, strong)
+ res, err := s.Plex.GetPin(ctx, operations.WithServerURL("https://plex.tv/api/v2"), xPlexClientIdentifier, strong)
if err != nil {
log.Fatal(err)
}
diff --git a/RELEASES.md b/RELEASES.md
index 6610f2a..ac28bb8 100644
--- a/RELEASES.md
+++ b/RELEASES.md
@@ -108,4 +108,14 @@ Based on:
### Generated
- [go v0.2.1] .
### Releases
-- [Go v0.2.1] https://github.com/LukeHagar/plexgo/releases/tag/v0.2.1 - .
\ No newline at end of file
+- [Go v0.2.1] https://github.com/LukeHagar/plexgo/releases/tag/v0.2.1 - .
+
+## 2024-02-05 14:23:54
+### Changes
+Based on:
+- OpenAPI Doc 0.0.3
+- Speakeasy CLI 1.166.1 (2.249.1) https://github.com/speakeasy-api/speakeasy
+### Generated
+- [go v0.3.0] .
+### Releases
+- [Go v0.3.0] https://github.com/LukeHagar/plexgo/releases/tag/v0.3.0 - .
\ No newline at end of file
diff --git a/docs/models/operations/getpinrequest.md b/docs/models/operations/getpinrequest.md
index 7ef996f..7c30038 100644
--- a/docs/models/operations/getpinrequest.md
+++ b/docs/models/operations/getpinrequest.md
@@ -3,7 +3,7 @@
## Fields
-| Field | Type | Required | Description |
-| ----------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- |
-| `XPlexClientIdentifier` | *string* | :heavy_check_mark: | Plex Authentication Token |
-| `Strong` | **bool* | :heavy_minus_sign: | Determines the kind of code returned by the API call
Strong codes are used for Pin authentication flows
Non-Strong codes are used for `Plex.tv/link`
|
\ No newline at end of file
+| Field | Type | Required | Description |
+| --------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
+| `XPlexClientIdentifier` | *string* | :heavy_check_mark: | The unique identifier for the client application
This is used to track the client application and its usage
(UUID, serial number, or other number unique per device)
|
+| `Strong` | **bool* | :heavy_minus_sign: | Determines the kind of code returned by the API call
Strong codes are used for Pin authentication flows
Non-Strong codes are used for `Plex.tv/link`
|
\ No newline at end of file
diff --git a/docs/models/operations/gettokenrequest.md b/docs/models/operations/gettokenrequest.md
index 64bbfbe..d4d7a73 100644
--- a/docs/models/operations/gettokenrequest.md
+++ b/docs/models/operations/gettokenrequest.md
@@ -3,7 +3,7 @@
## Fields
-| Field | Type | Required | Description |
-| ----------------------------------------- | ----------------------------------------- | ----------------------------------------- | ----------------------------------------- |
-| `PinID` | *string* | :heavy_check_mark: | The PinID to retrieve an access token for |
-| `XPlexClientIdentifier` | *string* | :heavy_check_mark: | Plex Authentication Token |
\ No newline at end of file
+| Field | Type | Required | Description |
+| --------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
+| `PinID` | *string* | :heavy_check_mark: | The PinID to retrieve an access token for |
+| `XPlexClientIdentifier` | *string* | :heavy_check_mark: | The unique identifier for the client application
This is used to track the client application and its usage
(UUID, serial number, or other number unique per device)
|
\ No newline at end of file
diff --git a/docs/sdks/plex/README.md b/docs/sdks/plex/README.md
index 6e7dad8..237d67f 100644
--- a/docs/sdks/plex/README.md
+++ b/docs/sdks/plex/README.md
@@ -1,5 +1,125 @@
# Plex
(*Plex*)
+## Overview
+
+API Calls that perform operations directly against https://Plex.tv
+
+
### Available Operations
+* [GetPin](#getpin) - Get a Pin
+* [GetToken](#gettoken) - Get Access Token
+
+## GetPin
+
+Retrieve a Pin from Plex.tv for authentication flows
+
+### Example Usage
+
+```go
+package main
+
+import(
+ "github.com/LukeHagar/plexgo/models/components"
+ "github.com/LukeHagar/plexgo"
+ "context"
+ "log"
+)
+
+func main() {
+ s := plexgo.New(
+ plexgo.WithSecurity(""),
+ )
+
+
+ var xPlexClientIdentifier string = "string"
+
+ var strong *bool = false
+
+ ctx := context.Background()
+ res, err := s.Plex.GetPin(ctx, xPlexClientIdentifier, strong)
+ if err != nil {
+ log.Fatal(err)
+ }
+
+ if res.Object != nil {
+ // handle response
+ }
+}
+```
+
+### Parameters
+
+| Parameter | Type | Required | Description |
+| --------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
+| `ctx` | [context.Context](https://pkg.go.dev/context#Context) | :heavy_check_mark: | The context to use for the request. |
+| `xPlexClientIdentifier` | *string* | :heavy_check_mark: | The unique identifier for the client application
This is used to track the client application and its usage
(UUID, serial number, or other number unique per device)
|
+| `strong` | **bool* | :heavy_minus_sign: | Determines the kind of code returned by the API call
Strong codes are used for Pin authentication flows
Non-Strong codes are used for `Plex.tv/link`
|
+| `opts` | [][operations.Option](../../models/operations/option.md) | :heavy_minus_sign: | The options for this request. |
+
+
+### Response
+
+**[*operations.GetPinResponse](../../models/operations/getpinresponse.md), error**
+| Error Object | Status Code | Content Type |
+| ---------------------------- | ---------------------------- | ---------------------------- |
+| sdkerrors.GetPinResponseBody | 400 | application/json |
+| sdkerrors.SDKError | 4xx-5xx | */* |
+
+## GetToken
+
+Retrieve an Access Token from Plex.tv after the Pin has already been authenticated
+
+### Example Usage
+
+```go
+package main
+
+import(
+ "github.com/LukeHagar/plexgo/models/components"
+ "github.com/LukeHagar/plexgo"
+ "context"
+ "log"
+ "net/http"
+)
+
+func main() {
+ s := plexgo.New(
+ plexgo.WithSecurity(""),
+ )
+
+
+ var pinID string = "string"
+
+ var xPlexClientIdentifier string = "string"
+
+ ctx := context.Background()
+ res, err := s.Plex.GetToken(ctx, pinID, xPlexClientIdentifier)
+ if err != nil {
+ log.Fatal(err)
+ }
+
+ if res.StatusCode == http.StatusOK {
+ // handle response
+ }
+}
+```
+
+### Parameters
+
+| Parameter | Type | Required | Description |
+| --------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
+| `ctx` | [context.Context](https://pkg.go.dev/context#Context) | :heavy_check_mark: | The context to use for the request. |
+| `pinID` | *string* | :heavy_check_mark: | The PinID to retrieve an access token for |
+| `xPlexClientIdentifier` | *string* | :heavy_check_mark: | The unique identifier for the client application
This is used to track the client application and its usage
(UUID, serial number, or other number unique per device)
|
+| `opts` | [][operations.Option](../../models/operations/option.md) | :heavy_minus_sign: | The options for this request. |
+
+
+### Response
+
+**[*operations.GetTokenResponse](../../models/operations/gettokenresponse.md), error**
+| Error Object | Status Code | Content Type |
+| ------------------------------ | ------------------------------ | ------------------------------ |
+| sdkerrors.GetTokenResponseBody | 400 | application/json |
+| sdkerrors.SDKError | 4xx-5xx | */* |
diff --git a/docs/sdks/tv/README.md b/docs/sdks/tv/README.md
deleted file mode 100644
index 02ca724..0000000
--- a/docs/sdks/tv/README.md
+++ /dev/null
@@ -1,120 +0,0 @@
-# Tv
-(*Plex.Tv*)
-
-### Available Operations
-
-* [GetPin](#getpin) - Get a Pin
-* [GetToken](#gettoken) - Get Access Token
-
-## GetPin
-
-Retrieve a Pin from Plex.tv for authentication flows
-
-### Example Usage
-
-```go
-package main
-
-import(
- "github.com/LukeHagar/plexgo/models/components"
- "github.com/LukeHagar/plexgo"
- "context"
- "log"
-)
-
-func main() {
- s := plexgo.New(
- plexgo.WithSecurity(""),
- )
-
-
- var xPlexClientIdentifier string = "string"
-
- var strong *bool = false
-
- ctx := context.Background()
- res, err := s.Plex.Tv.GetPin(ctx, xPlexClientIdentifier, strong)
- if err != nil {
- log.Fatal(err)
- }
-
- if res.Object != nil {
- // handle response
- }
-}
-```
-
-### Parameters
-
-| Parameter | Type | Required | Description |
-| ----------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- |
-| `ctx` | [context.Context](https://pkg.go.dev/context#Context) | :heavy_check_mark: | The context to use for the request. |
-| `xPlexClientIdentifier` | *string* | :heavy_check_mark: | Plex Authentication Token |
-| `strong` | **bool* | :heavy_minus_sign: | Determines the kind of code returned by the API call
Strong codes are used for Pin authentication flows
Non-Strong codes are used for `Plex.tv/link`
|
-| `opts` | [][operations.Option](../../models/operations/option.md) | :heavy_minus_sign: | The options for this request. |
-
-
-### Response
-
-**[*operations.GetPinResponse](../../models/operations/getpinresponse.md), error**
-| Error Object | Status Code | Content Type |
-| ---------------------------- | ---------------------------- | ---------------------------- |
-| sdkerrors.GetPinResponseBody | 400 | application/json |
-| sdkerrors.SDKError | 4xx-5xx | */* |
-
-## GetToken
-
-Retrieve an Access Token from Plex.tv after the Pin has already been authenticated
-
-### Example Usage
-
-```go
-package main
-
-import(
- "github.com/LukeHagar/plexgo/models/components"
- "github.com/LukeHagar/plexgo"
- "context"
- "log"
- "net/http"
-)
-
-func main() {
- s := plexgo.New(
- plexgo.WithSecurity(""),
- )
-
-
- var pinID string = "string"
-
- var xPlexClientIdentifier string = "string"
-
- ctx := context.Background()
- res, err := s.Plex.Tv.GetToken(ctx, pinID, xPlexClientIdentifier)
- if err != nil {
- log.Fatal(err)
- }
-
- if res.StatusCode == http.StatusOK {
- // handle response
- }
-}
-```
-
-### Parameters
-
-| Parameter | Type | Required | Description |
-| -------------------------------------------------------- | -------------------------------------------------------- | -------------------------------------------------------- | -------------------------------------------------------- |
-| `ctx` | [context.Context](https://pkg.go.dev/context#Context) | :heavy_check_mark: | The context to use for the request. |
-| `pinID` | *string* | :heavy_check_mark: | The PinID to retrieve an access token for |
-| `xPlexClientIdentifier` | *string* | :heavy_check_mark: | Plex Authentication Token |
-| `opts` | [][operations.Option](../../models/operations/option.md) | :heavy_minus_sign: | The options for this request. |
-
-
-### Response
-
-**[*operations.GetTokenResponse](../../models/operations/gettokenresponse.md), error**
-| Error Object | Status Code | Content Type |
-| ------------------------------ | ------------------------------ | ------------------------------ |
-| sdkerrors.GetTokenResponseBody | 400 | application/json |
-| sdkerrors.SDKError | 4xx-5xx | */* |
diff --git a/gen.yaml b/gen.yaml
index 791e8a5..4b35bcb 100644
--- a/gen.yaml
+++ b/gen.yaml
@@ -7,8 +7,9 @@ generation:
useClassNamesForArrayFields: true
fixes:
nameResolutionDec2023: false
+ parameterOrderingFeb2024: false
go:
- version: 0.2.1
+ version: 0.3.0
clientServerStatusCodesAsErrors: true
flattenGlobalSecurity: true
imports:
diff --git a/models/operations/getpin.go b/models/operations/getpin.go
index 4620c2d..8a2abc9 100644
--- a/models/operations/getpin.go
+++ b/models/operations/getpin.go
@@ -13,7 +13,10 @@ var GetPinServerList = []string{
}
type GetPinRequest struct {
- // Plex Authentication Token
+ // The unique identifier for the client application
+ // This is used to track the client application and its usage
+ // (UUID, serial number, or other number unique per device)
+ //
XPlexClientIdentifier string `header:"style=simple,explode=false,name=X-Plex-Client-Identifier"`
// Determines the kind of code returned by the API call
// Strong codes are used for Pin authentication flows
diff --git a/models/operations/gettoken.go b/models/operations/gettoken.go
index 5686648..f9d5c34 100644
--- a/models/operations/gettoken.go
+++ b/models/operations/gettoken.go
@@ -13,7 +13,10 @@ var GetTokenServerList = []string{
type GetTokenRequest struct {
// The PinID to retrieve an access token for
PinID string `pathParam:"style=simple,explode=false,name=pinID"`
- // Plex Authentication Token
+ // The unique identifier for the client application
+ // This is used to track the client application and its usage
+ // (UUID, serial number, or other number unique per device)
+ //
XPlexClientIdentifier string `header:"style=simple,explode=false,name=X-Plex-Client-Identifier"`
}
diff --git a/plex.go b/plex.go
index 3bb616f..3f3f9a3 100644
--- a/plex.go
+++ b/plex.go
@@ -2,15 +2,207 @@
package plexgo
-type Plex struct {
- Tv *Tv
+import (
+ "bytes"
+ "context"
+ "fmt"
+ "github.com/LukeHagar/plexgo/internal/utils"
+ "github.com/LukeHagar/plexgo/models/operations"
+ "github.com/LukeHagar/plexgo/models/sdkerrors"
+ "io"
+ "net/http"
+ "strings"
+)
+// Plex - API Calls that perform operations directly against https://Plex.tv
+type Plex struct {
sdkConfiguration sdkConfiguration
}
func newPlex(sdkConfig sdkConfiguration) *Plex {
return &Plex{
sdkConfiguration: sdkConfig,
- Tv: newTv(sdkConfig),
}
}
+
+// GetPin - Get a Pin
+// Retrieve a Pin from Plex.tv for authentication flows
+func (s *Plex) GetPin(ctx context.Context, xPlexClientIdentifier string, strong *bool, opts ...operations.Option) (*operations.GetPinResponse, error) {
+ request := operations.GetPinRequest{
+ XPlexClientIdentifier: xPlexClientIdentifier,
+ Strong: strong,
+ }
+
+ o := operations.Options{}
+ supportedOptions := []string{
+ operations.SupportedOptionServerURL,
+ }
+
+ for _, opt := range opts {
+ if err := opt(&o, supportedOptions...); err != nil {
+ return nil, fmt.Errorf("error applying option: %w", err)
+ }
+ }
+ baseURL := utils.ReplaceParameters(operations.GetPinServerList[0], map[string]string{})
+ if o.ServerURL != nil {
+ baseURL = *o.ServerURL
+ }
+
+ url := strings.TrimSuffix(baseURL, "/") + "/pins"
+
+ req, err := http.NewRequestWithContext(ctx, "POST", url, nil)
+ if err != nil {
+ return nil, fmt.Errorf("error creating request: %w", err)
+ }
+ req.Header.Set("Accept", "application/json")
+ req.Header.Set("user-agent", s.sdkConfiguration.UserAgent)
+
+ utils.PopulateHeaders(ctx, req, request)
+
+ if err := utils.PopulateQueryParams(ctx, req, request, nil); err != nil {
+ return nil, fmt.Errorf("error populating query params: %w", err)
+ }
+
+ client := s.sdkConfiguration.SecurityClient
+
+ httpRes, err := client.Do(req)
+ if err != nil {
+ return nil, fmt.Errorf("error sending request: %w", err)
+ }
+ if httpRes == nil {
+ return nil, fmt.Errorf("error sending request: no response")
+ }
+
+ contentType := httpRes.Header.Get("Content-Type")
+
+ res := &operations.GetPinResponse{
+ StatusCode: httpRes.StatusCode,
+ ContentType: contentType,
+ RawResponse: httpRes,
+ }
+
+ rawBody, err := io.ReadAll(httpRes.Body)
+ if err != nil {
+ return nil, fmt.Errorf("error reading response body: %w", err)
+ }
+ httpRes.Body.Close()
+ httpRes.Body = io.NopCloser(bytes.NewBuffer(rawBody))
+ switch {
+ case httpRes.StatusCode == 200:
+ switch {
+ case utils.MatchContentType(contentType, `application/json`):
+ var out operations.GetPinResponseBody
+ if err := utils.UnmarshalJsonFromResponseBody(bytes.NewBuffer(rawBody), &out, ""); err != nil {
+ return nil, err
+ }
+
+ res.Object = &out
+ default:
+ return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", contentType), httpRes.StatusCode, string(rawBody), httpRes)
+ }
+ case httpRes.StatusCode == 400:
+ switch {
+ case utils.MatchContentType(contentType, `application/json`):
+ var out sdkerrors.GetPinResponseBody
+ if err := utils.UnmarshalJsonFromResponseBody(bytes.NewBuffer(rawBody), &out, ""); err != nil {
+ return nil, err
+ }
+ out.RawResponse = httpRes
+
+ return nil, &out
+ default:
+ return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", contentType), httpRes.StatusCode, string(rawBody), httpRes)
+ }
+ case httpRes.StatusCode >= 400 && httpRes.StatusCode < 500:
+ fallthrough
+ case httpRes.StatusCode >= 500 && httpRes.StatusCode < 600:
+ return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes)
+ }
+
+ return res, nil
+}
+
+// GetToken - Get Access Token
+// Retrieve an Access Token from Plex.tv after the Pin has already been authenticated
+func (s *Plex) GetToken(ctx context.Context, pinID string, xPlexClientIdentifier string, opts ...operations.Option) (*operations.GetTokenResponse, error) {
+ request := operations.GetTokenRequest{
+ PinID: pinID,
+ XPlexClientIdentifier: xPlexClientIdentifier,
+ }
+
+ o := operations.Options{}
+ supportedOptions := []string{
+ operations.SupportedOptionServerURL,
+ }
+
+ for _, opt := range opts {
+ if err := opt(&o, supportedOptions...); err != nil {
+ return nil, fmt.Errorf("error applying option: %w", err)
+ }
+ }
+ baseURL := utils.ReplaceParameters(operations.GetTokenServerList[0], map[string]string{})
+ if o.ServerURL != nil {
+ baseURL = *o.ServerURL
+ }
+
+ url, err := utils.GenerateURL(ctx, baseURL, "/pins/{pinID}", request, nil)
+ if err != nil {
+ return nil, fmt.Errorf("error generating URL: %w", err)
+ }
+
+ req, err := http.NewRequestWithContext(ctx, "GET", url, nil)
+ if err != nil {
+ return nil, fmt.Errorf("error creating request: %w", err)
+ }
+ req.Header.Set("Accept", "application/json")
+ req.Header.Set("user-agent", s.sdkConfiguration.UserAgent)
+
+ utils.PopulateHeaders(ctx, req, request)
+
+ client := s.sdkConfiguration.SecurityClient
+
+ httpRes, err := client.Do(req)
+ if err != nil {
+ return nil, fmt.Errorf("error sending request: %w", err)
+ }
+ if httpRes == nil {
+ return nil, fmt.Errorf("error sending request: no response")
+ }
+
+ contentType := httpRes.Header.Get("Content-Type")
+
+ res := &operations.GetTokenResponse{
+ StatusCode: httpRes.StatusCode,
+ ContentType: contentType,
+ RawResponse: httpRes,
+ }
+
+ rawBody, err := io.ReadAll(httpRes.Body)
+ if err != nil {
+ return nil, fmt.Errorf("error reading response body: %w", err)
+ }
+ httpRes.Body.Close()
+ httpRes.Body = io.NopCloser(bytes.NewBuffer(rawBody))
+ switch {
+ case httpRes.StatusCode == 200:
+ case httpRes.StatusCode == 400:
+ switch {
+ case utils.MatchContentType(contentType, `application/json`):
+ var out sdkerrors.GetTokenResponseBody
+ if err := utils.UnmarshalJsonFromResponseBody(bytes.NewBuffer(rawBody), &out, ""); err != nil {
+ return nil, err
+ }
+ out.RawResponse = httpRes
+
+ return nil, &out
+ default:
+ return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", contentType), httpRes.StatusCode, string(rawBody), httpRes)
+ }
+ case httpRes.StatusCode >= 400 && httpRes.StatusCode < 500:
+ fallthrough
+ case httpRes.StatusCode >= 500 && httpRes.StatusCode < 600:
+ return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes)
+ }
+
+ return res, nil
+}
diff --git a/plexapi.go b/plexapi.go
index acc4abd..53bf840 100644
--- a/plexapi.go
+++ b/plexapi.go
@@ -96,7 +96,9 @@ type PlexAPI struct {
Library *Library
// Submit logs to the Log Handler for Plex Media Server
//
- Log *Log
+ Log *Log
+ // API Calls that perform operations directly against https://Plex.tv
+ //
Plex *Plex
// Playlists are ordered collections of media. They can be dumb (just a list of media) or smart (based on a media query, such as "all albums from 2017").
// They can be organized in (optionally nesting) folders.
@@ -261,9 +263,9 @@ func New(opts ...SDKOption) *PlexAPI {
sdkConfiguration: sdkConfiguration{
Language: "go",
OpenAPIDocVersion: "0.0.3",
- SDKVersion: "0.2.1",
- GenVersion: "2.245.1",
- UserAgent: "speakeasy-sdk/go 0.2.1 2.245.1 0.0.3 github.com/LukeHagar/plexgo",
+ SDKVersion: "0.3.0",
+ GenVersion: "2.249.1",
+ UserAgent: "speakeasy-sdk/go 0.3.0 2.249.1 0.0.3 github.com/LukeHagar/plexgo",
ServerDefaults: []map[string]string{
{
"protocol": "http",
diff --git a/tv.go b/tv.go
deleted file mode 100644
index 8dc9aab..0000000
--- a/tv.go
+++ /dev/null
@@ -1,207 +0,0 @@
-// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT.
-
-package plexgo
-
-import (
- "bytes"
- "context"
- "fmt"
- "github.com/LukeHagar/plexgo/internal/utils"
- "github.com/LukeHagar/plexgo/models/operations"
- "github.com/LukeHagar/plexgo/models/sdkerrors"
- "io"
- "net/http"
- "strings"
-)
-
-type Tv struct {
- sdkConfiguration sdkConfiguration
-}
-
-func newTv(sdkConfig sdkConfiguration) *Tv {
- return &Tv{
- sdkConfiguration: sdkConfig,
- }
-}
-
-// GetPin - Get a Pin
-// Retrieve a Pin from Plex.tv for authentication flows
-func (s *Tv) GetPin(ctx context.Context, xPlexClientIdentifier string, strong *bool, opts ...operations.Option) (*operations.GetPinResponse, error) {
- request := operations.GetPinRequest{
- XPlexClientIdentifier: xPlexClientIdentifier,
- Strong: strong,
- }
-
- o := operations.Options{}
- supportedOptions := []string{
- operations.SupportedOptionServerURL,
- }
-
- for _, opt := range opts {
- if err := opt(&o, supportedOptions...); err != nil {
- return nil, fmt.Errorf("error applying option: %w", err)
- }
- }
- baseURL := utils.ReplaceParameters(operations.GetPinServerList[0], map[string]string{})
- if o.ServerURL != nil {
- baseURL = *o.ServerURL
- }
-
- url := strings.TrimSuffix(baseURL, "/") + "/pins"
-
- req, err := http.NewRequestWithContext(ctx, "POST", url, nil)
- if err != nil {
- return nil, fmt.Errorf("error creating request: %w", err)
- }
- req.Header.Set("Accept", "application/json")
- req.Header.Set("user-agent", s.sdkConfiguration.UserAgent)
-
- utils.PopulateHeaders(ctx, req, request)
-
- if err := utils.PopulateQueryParams(ctx, req, request, nil); err != nil {
- return nil, fmt.Errorf("error populating query params: %w", err)
- }
-
- client := s.sdkConfiguration.SecurityClient
-
- httpRes, err := client.Do(req)
- if err != nil {
- return nil, fmt.Errorf("error sending request: %w", err)
- }
- if httpRes == nil {
- return nil, fmt.Errorf("error sending request: no response")
- }
-
- contentType := httpRes.Header.Get("Content-Type")
-
- res := &operations.GetPinResponse{
- StatusCode: httpRes.StatusCode,
- ContentType: contentType,
- RawResponse: httpRes,
- }
-
- rawBody, err := io.ReadAll(httpRes.Body)
- if err != nil {
- return nil, fmt.Errorf("error reading response body: %w", err)
- }
- httpRes.Body.Close()
- httpRes.Body = io.NopCloser(bytes.NewBuffer(rawBody))
- switch {
- case httpRes.StatusCode == 200:
- switch {
- case utils.MatchContentType(contentType, `application/json`):
- var out operations.GetPinResponseBody
- if err := utils.UnmarshalJsonFromResponseBody(bytes.NewBuffer(rawBody), &out, ""); err != nil {
- return nil, err
- }
-
- res.Object = &out
- default:
- return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", contentType), httpRes.StatusCode, string(rawBody), httpRes)
- }
- case httpRes.StatusCode == 400:
- switch {
- case utils.MatchContentType(contentType, `application/json`):
- var out sdkerrors.GetPinResponseBody
- if err := utils.UnmarshalJsonFromResponseBody(bytes.NewBuffer(rawBody), &out, ""); err != nil {
- return nil, err
- }
- out.RawResponse = httpRes
-
- return nil, &out
- default:
- return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", contentType), httpRes.StatusCode, string(rawBody), httpRes)
- }
- case httpRes.StatusCode >= 400 && httpRes.StatusCode < 500:
- fallthrough
- case httpRes.StatusCode >= 500 && httpRes.StatusCode < 600:
- return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes)
- }
-
- return res, nil
-}
-
-// GetToken - Get Access Token
-// Retrieve an Access Token from Plex.tv after the Pin has already been authenticated
-func (s *Tv) GetToken(ctx context.Context, pinID string, xPlexClientIdentifier string, opts ...operations.Option) (*operations.GetTokenResponse, error) {
- request := operations.GetTokenRequest{
- PinID: pinID,
- XPlexClientIdentifier: xPlexClientIdentifier,
- }
-
- o := operations.Options{}
- supportedOptions := []string{
- operations.SupportedOptionServerURL,
- }
-
- for _, opt := range opts {
- if err := opt(&o, supportedOptions...); err != nil {
- return nil, fmt.Errorf("error applying option: %w", err)
- }
- }
- baseURL := utils.ReplaceParameters(operations.GetTokenServerList[0], map[string]string{})
- if o.ServerURL != nil {
- baseURL = *o.ServerURL
- }
-
- url, err := utils.GenerateURL(ctx, baseURL, "/pins/{pinID}", request, nil)
- if err != nil {
- return nil, fmt.Errorf("error generating URL: %w", err)
- }
-
- req, err := http.NewRequestWithContext(ctx, "GET", url, nil)
- if err != nil {
- return nil, fmt.Errorf("error creating request: %w", err)
- }
- req.Header.Set("Accept", "application/json")
- req.Header.Set("user-agent", s.sdkConfiguration.UserAgent)
-
- utils.PopulateHeaders(ctx, req, request)
-
- client := s.sdkConfiguration.SecurityClient
-
- httpRes, err := client.Do(req)
- if err != nil {
- return nil, fmt.Errorf("error sending request: %w", err)
- }
- if httpRes == nil {
- return nil, fmt.Errorf("error sending request: no response")
- }
-
- contentType := httpRes.Header.Get("Content-Type")
-
- res := &operations.GetTokenResponse{
- StatusCode: httpRes.StatusCode,
- ContentType: contentType,
- RawResponse: httpRes,
- }
-
- rawBody, err := io.ReadAll(httpRes.Body)
- if err != nil {
- return nil, fmt.Errorf("error reading response body: %w", err)
- }
- httpRes.Body.Close()
- httpRes.Body = io.NopCloser(bytes.NewBuffer(rawBody))
- switch {
- case httpRes.StatusCode == 200:
- case httpRes.StatusCode == 400:
- switch {
- case utils.MatchContentType(contentType, `application/json`):
- var out sdkerrors.GetTokenResponseBody
- if err := utils.UnmarshalJsonFromResponseBody(bytes.NewBuffer(rawBody), &out, ""); err != nil {
- return nil, err
- }
- out.RawResponse = httpRes
-
- return nil, &out
- default:
- return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", contentType), httpRes.StatusCode, string(rawBody), httpRes)
- }
- case httpRes.StatusCode >= 400 && httpRes.StatusCode < 500:
- fallthrough
- case httpRes.StatusCode >= 500 && httpRes.StatusCode < 600:
- return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes)
- }
-
- return res, nil
-}