Compare commits

...

4 Commits

Author SHA1 Message Date
speakeasybot
2b4d612003 ci: regenerated with OpenAPI Doc 0.0.3, Speakeasy CLI 1.166.1 2024-02-05 14:24:08 +00:00
speakeasy-bot
853bfe69d5 🐝 Add license. 2024-02-01 16:30:13 +00:00
speakeasy-bot
81cfd47570 🐝 Update gen.yaml 2024-02-01 16:30:13 +00:00
speakeasy-bot
44e551a11d 🐝 Update workflow file 2024-02-01 16:30:12 +00:00
13 changed files with 361 additions and 360 deletions

View File

@@ -1,12 +1,12 @@
lockVersion: 2.0.0 lockVersion: 2.0.0
id: dfa99515-01c0-42eb-9be5-ee212fd03eb3 id: dfa99515-01c0-42eb-9be5-ee212fd03eb3
management: management:
docChecksum: 94439465ae5d544f0e52b00719af05ee docChecksum: 099fc5bbb987ae7e391f7f07b4212860
docVersion: 0.0.3 docVersion: 0.0.3
speakeasyVersion: internal speakeasyVersion: internal
generationVersion: 2.245.1 generationVersion: 2.249.1
releaseVersion: 0.2.1 releaseVersion: 0.3.0
configChecksum: 0c6f5f0bce6af6f3bd99f99ce9584d7e configChecksum: ae48b3df080bde21a30ed099e1ffc0d8
repoURL: https://github.com/LukeHagar/plexgo.git repoURL: https://github.com/LukeHagar/plexgo.git
repoSubDirectory: . repoSubDirectory: .
installationURL: https://github.com/LukeHagar/plexgo installationURL: https://github.com/LukeHagar/plexgo
@@ -14,9 +14,9 @@ management:
features: features:
go: go:
constsAndDefaults: 0.1.2 constsAndDefaults: 0.1.2
core: 3.3.1 core: 3.3.2
flattening: 2.81.1 flattening: 2.81.1
globalSecurity: 2.82.5 globalSecurity: 2.82.6
globalServerURLs: 2.82.1 globalServerURLs: 2.82.1
methodServerURLs: 2.82.1 methodServerURLs: 2.82.1
nameOverrides: 2.81.1 nameOverrides: 2.81.1
@@ -30,7 +30,6 @@ generatedFiles:
- search.go - search.go
- library.go - library.go
- log.go - log.go
- tv.go
- plex.go - plex.go
- playlists.go - playlists.go
- security.go - security.go
@@ -574,9 +573,8 @@ generatedFiles:
- docs/sdks/search/README.md - docs/sdks/search/README.md
- docs/sdks/library/README.md - docs/sdks/library/README.md
- docs/sdks/log/README.md - docs/sdks/log/README.md
- docs/sdks/plex/README.md
- docs/models/operations/option.md - docs/models/operations/option.md
- docs/sdks/tv/README.md - docs/sdks/plex/README.md
- docs/sdks/playlists/README.md - docs/sdks/playlists/README.md
- docs/sdks/security/README.md - docs/sdks/security/README.md
- docs/sdks/sessions/README.md - docs/sdks/sessions/README.md

View File

@@ -113,11 +113,10 @@ func main() {
* [LogMultiLine](docs/sdks/log/README.md#logmultiline) - Logging a multi-line message * [LogMultiLine](docs/sdks/log/README.md#logmultiline) - Logging a multi-line message
* [EnablePaperTrail](docs/sdks/log/README.md#enablepapertrail) - Enabling Papertrail * [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/plex/README.md#getpin) - Get a Pin
* [GetToken](docs/sdks/plex/README.md#gettoken) - Get Access Token
* [GetPin](docs/sdks/tv/README.md#getpin) - Get a Pin
* [GetToken](docs/sdks/tv/README.md#gettoken) - Get Access Token
### [Playlists](docs/sdks/playlists/README.md) ### [Playlists](docs/sdks/playlists/README.md)
@@ -309,7 +308,7 @@ func main() {
var strong *bool = false var strong *bool = false
ctx := context.Background() 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 { if err != nil {
log.Fatal(err) log.Fatal(err)
} }

View File

@@ -108,4 +108,14 @@ Based on:
### Generated ### Generated
- [go v0.2.1] . - [go v0.2.1] .
### Releases ### Releases
- [Go v0.2.1] https://github.com/LukeHagar/plexgo/releases/tag/v0.2.1 - . - [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 - .

View File

@@ -3,7 +3,7 @@
## Fields ## Fields
| Field | Type | Required | Description | | Field | Type | Required | Description |
| ----------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `XPlexClientIdentifier` | *string* | :heavy_check_mark: | Plex Authentication Token | | `XPlexClientIdentifier` | *string* | :heavy_check_mark: | The unique identifier for the client application<br/>This is used to track the client application and its usage<br/>(UUID, serial number, or other number unique per device)<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/> | | `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/> |

View File

@@ -3,7 +3,7 @@
## Fields ## Fields
| Field | Type | Required | Description | | Field | Type | Required | Description |
| ----------------------------------------- | ----------------------------------------- | ----------------------------------------- | ----------------------------------------- | | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `PinID` | *string* | :heavy_check_mark: | The PinID to retrieve an access token for | | `PinID` | *string* | :heavy_check_mark: | The PinID to retrieve an access token for |
| `XPlexClientIdentifier` | *string* | :heavy_check_mark: | Plex Authentication Token | | `XPlexClientIdentifier` | *string* | :heavy_check_mark: | The unique identifier for the client application<br/>This is used to track the client application and its usage<br/>(UUID, serial number, or other number unique per device)<br/> |

View File

@@ -1,5 +1,125 @@
# Plex # Plex
(*Plex*) (*Plex*)
## Overview
API Calls that perform operations directly against https://Plex.tv
### Available Operations ### 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("<YOUR_API_KEY_HERE>"),
)
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<br/>This is used to track the client application and its usage<br/>(UUID, serial number, or other number unique per device)<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/> |
| `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("<YOUR_API_KEY_HERE>"),
)
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<br/>This is used to track the client application and its usage<br/>(UUID, serial number, or other number unique per device)<br/> |
| `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 | */* |

View File

@@ -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("<YOUR_API_KEY_HERE>"),
)
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<br/>Strong codes are used for Pin authentication flows<br/>Non-Strong codes are used for `Plex.tv/link`<br/> |
| `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("<YOUR_API_KEY_HERE>"),
)
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 | */* |

View File

@@ -7,8 +7,9 @@ generation:
useClassNamesForArrayFields: true useClassNamesForArrayFields: true
fixes: fixes:
nameResolutionDec2023: false nameResolutionDec2023: false
parameterOrderingFeb2024: false
go: go:
version: 0.2.1 version: 0.3.0
clientServerStatusCodesAsErrors: true clientServerStatusCodesAsErrors: true
flattenGlobalSecurity: true flattenGlobalSecurity: true
imports: imports:

View File

@@ -13,7 +13,10 @@ var GetPinServerList = []string{
} }
type GetPinRequest struct { 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"` XPlexClientIdentifier string `header:"style=simple,explode=false,name=X-Plex-Client-Identifier"`
// 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

View File

@@ -13,7 +13,10 @@ var GetTokenServerList = []string{
type GetTokenRequest struct { type GetTokenRequest struct {
// The PinID to retrieve an access token for // The PinID to retrieve an access token for
PinID string `pathParam:"style=simple,explode=false,name=pinID"` 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"` XPlexClientIdentifier string `header:"style=simple,explode=false,name=X-Plex-Client-Identifier"`
} }

198
plex.go
View File

@@ -2,15 +2,207 @@
package plexgo package plexgo
type Plex struct { import (
Tv *Tv "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 sdkConfiguration sdkConfiguration
} }
func newPlex(sdkConfig sdkConfiguration) *Plex { func newPlex(sdkConfig sdkConfiguration) *Plex {
return &Plex{ return &Plex{
sdkConfiguration: sdkConfig, 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
}

View File

@@ -96,7 +96,9 @@ type PlexAPI struct {
Library *Library Library *Library
// Submit logs to the Log Handler for Plex Media Server // 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 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"). // 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. // They can be organized in (optionally nesting) folders.
@@ -261,9 +263,9 @@ func New(opts ...SDKOption) *PlexAPI {
sdkConfiguration: sdkConfiguration{ sdkConfiguration: sdkConfiguration{
Language: "go", Language: "go",
OpenAPIDocVersion: "0.0.3", OpenAPIDocVersion: "0.0.3",
SDKVersion: "0.2.1", SDKVersion: "0.3.0",
GenVersion: "2.245.1", GenVersion: "2.249.1",
UserAgent: "speakeasy-sdk/go 0.2.1 2.245.1 0.0.3 github.com/LukeHagar/plexgo", UserAgent: "speakeasy-sdk/go 0.3.0 2.249.1 0.0.3 github.com/LukeHagar/plexgo",
ServerDefaults: []map[string]string{ ServerDefaults: []map[string]string{
{ {
"protocol": "http", "protocol": "http",

207
tv.go
View File

@@ -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
}