mirror of
https://github.com/LukeHagar/plexterraform.git
synced 2025-12-09 20:47:45 +00:00
ci: regenerated with OpenAPI Doc 0.0.3, Speakeasy CLI 1.166.1
This commit is contained in:
@@ -1,19 +1,19 @@
|
|||||||
lockVersion: 2.0.0
|
lockVersion: 2.0.0
|
||||||
id: e742591b-391d-4f4e-8484-d01a093b32ec
|
id: e742591b-391d-4f4e-8484-d01a093b32ec
|
||||||
management:
|
management:
|
||||||
docChecksum: 94439465ae5d544f0e52b00719af05ee
|
docChecksum: 099fc5bbb987ae7e391f7f07b4212860
|
||||||
docVersion: 0.0.3
|
docVersion: 0.0.3
|
||||||
speakeasyVersion: internal
|
speakeasyVersion: internal
|
||||||
generationVersion: 2.239.4
|
generationVersion: 2.249.1
|
||||||
releaseVersion: 0.4.0
|
releaseVersion: 0.5.0
|
||||||
configChecksum: b244e39f31dda4bc1f3428b5e4025f10
|
configChecksum: 1c7e54baac47fdd8c7da2254b5ada2fd
|
||||||
repoURL: https://github.com/LukeHagar/plexterraform.git
|
repoURL: https://github.com/LukeHagar/plexterraform.git
|
||||||
repoSubDirectory: .
|
repoSubDirectory: .
|
||||||
published: true
|
published: true
|
||||||
features:
|
features:
|
||||||
terraform:
|
terraform:
|
||||||
constsAndDefaults: 0.1.2
|
constsAndDefaults: 0.1.2
|
||||||
core: 3.9.2
|
core: 3.9.4
|
||||||
globalSecurity: 2.81.3
|
globalSecurity: 2.81.3
|
||||||
globalServerURLs: 2.82.1
|
globalServerURLs: 2.82.1
|
||||||
methodServerURLs: 2.82.1
|
methodServerURLs: 2.82.1
|
||||||
@@ -28,7 +28,6 @@ generatedFiles:
|
|||||||
- internal/sdk/search.go
|
- internal/sdk/search.go
|
||||||
- internal/sdk/library.go
|
- internal/sdk/library.go
|
||||||
- internal/sdk/log.go
|
- internal/sdk/log.go
|
||||||
- internal/sdk/tv.go
|
|
||||||
- internal/sdk/plex.go
|
- internal/sdk/plex.go
|
||||||
- internal/sdk/playlists.go
|
- internal/sdk/playlists.go
|
||||||
- internal/sdk/security.go
|
- internal/sdk/security.go
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ terraform {
|
|||||||
required_providers {
|
required_providers {
|
||||||
PlexAPI = {
|
PlexAPI = {
|
||||||
source = "LukeHagar/PlexAPI"
|
source = "LukeHagar/PlexAPI"
|
||||||
version = "0.4.0"
|
version = "0.5.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
10
RELEASES.md
10
RELEASES.md
@@ -102,4 +102,12 @@ Based on:
|
|||||||
- OpenAPI Doc 0.0.3
|
- OpenAPI Doc 0.0.3
|
||||||
- Speakeasy CLI 1.158.0 (2.239.4) https://github.com/speakeasy-api/speakeasy
|
- Speakeasy CLI 1.158.0 (2.239.4) https://github.com/speakeasy-api/speakeasy
|
||||||
### Generated
|
### Generated
|
||||||
- [terraform v0.4.0] .
|
- [terraform v0.4.0] .
|
||||||
|
|
||||||
|
## 2024-02-05 14:23:47
|
||||||
|
### Changes
|
||||||
|
Based on:
|
||||||
|
- OpenAPI Doc 0.0.3
|
||||||
|
- Speakeasy CLI 1.166.1 (2.249.1) https://github.com/speakeasy-api/speakeasy
|
||||||
|
### Generated
|
||||||
|
- [terraform v0.5.0] .
|
||||||
@@ -17,7 +17,7 @@ terraform {
|
|||||||
required_providers {
|
required_providers {
|
||||||
PlexAPI = {
|
PlexAPI = {
|
||||||
source = "LukeHagar/PlexAPI"
|
source = "LukeHagar/PlexAPI"
|
||||||
version = "0.4.0"
|
version = "0.5.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ terraform {
|
|||||||
required_providers {
|
required_providers {
|
||||||
PlexAPI = {
|
PlexAPI = {
|
||||||
source = "LukeHagar/PlexAPI"
|
source = "LukeHagar/PlexAPI"
|
||||||
version = "0.4.0"
|
version = "0.5.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
3
gen.yaml
3
gen.yaml
@@ -7,8 +7,9 @@ generation:
|
|||||||
useClassNamesForArrayFields: true
|
useClassNamesForArrayFields: true
|
||||||
fixes:
|
fixes:
|
||||||
nameResolutionDec2023: false
|
nameResolutionDec2023: false
|
||||||
|
parameterOrderingFeb2024: false
|
||||||
terraform:
|
terraform:
|
||||||
version: 0.4.0
|
version: 0.5.0
|
||||||
author: LukeHagar
|
author: LukeHagar
|
||||||
imports:
|
imports:
|
||||||
option: openapi
|
option: openapi
|
||||||
|
|||||||
@@ -18,7 +18,10 @@ type GetPinRequest struct {
|
|||||||
// Non-Strong codes are used for `Plex.tv/link`
|
// Non-Strong codes are used for `Plex.tv/link`
|
||||||
//
|
//
|
||||||
Strong *bool `default:"false" queryParam:"style=form,explode=true,name=strong"`
|
Strong *bool `default:"false" queryParam:"style=form,explode=true,name=strong"`
|
||||||
// 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"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -74,12 +77,12 @@ func (o *GetPinErrors) GetStatus() *float64 {
|
|||||||
return o.Status
|
return o.Status
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetPinPlexTvResponseBody - X-Plex-Client-Identifier is missing
|
// GetPinPlexResponseBody - X-Plex-Client-Identifier is missing
|
||||||
type GetPinPlexTvResponseBody struct {
|
type GetPinPlexResponseBody struct {
|
||||||
Errors []GetPinErrors `json:"errors,omitempty"`
|
Errors []GetPinErrors `json:"errors,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *GetPinPlexTvResponseBody) GetErrors() []GetPinErrors {
|
func (o *GetPinPlexResponseBody) GetErrors() []GetPinErrors {
|
||||||
if o == nil {
|
if o == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -295,7 +298,7 @@ type GetPinResponse struct {
|
|||||||
// The Pin
|
// The Pin
|
||||||
TwoHundredApplicationJSONObject *GetPinResponseBody
|
TwoHundredApplicationJSONObject *GetPinResponseBody
|
||||||
// X-Plex-Client-Identifier is missing
|
// X-Plex-Client-Identifier is missing
|
||||||
FourHundredApplicationJSONObject *GetPinPlexTvResponseBody
|
FourHundredApplicationJSONObject *GetPinPlexResponseBody
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *GetPinResponse) GetContentType() string {
|
func (o *GetPinResponse) GetContentType() string {
|
||||||
@@ -326,7 +329,7 @@ func (o *GetPinResponse) GetTwoHundredApplicationJSONObject() *GetPinResponseBod
|
|||||||
return o.TwoHundredApplicationJSONObject
|
return o.TwoHundredApplicationJSONObject
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *GetPinResponse) GetFourHundredApplicationJSONObject() *GetPinPlexTvResponseBody {
|
func (o *GetPinResponse) GetFourHundredApplicationJSONObject() *GetPinPlexResponseBody {
|
||||||
if o == nil {
|
if o == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,15 +2,187 @@
|
|||||||
|
|
||||||
package sdk
|
package sdk
|
||||||
|
|
||||||
type Plex struct {
|
import (
|
||||||
Tv *Tv
|
"bytes"
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"github.com/LukeHagar/terraform-provider-PlexAPI/internal/sdk/pkg/models/operations"
|
||||||
|
"github.com/LukeHagar/terraform-provider-PlexAPI/internal/sdk/pkg/models/sdkerrors"
|
||||||
|
"github.com/LukeHagar/terraform-provider-PlexAPI/internal/sdk/pkg/utils"
|
||||||
|
"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, request operations.GetPinRequest, opts ...operations.Option) (*operations.GetPinResponse, error) {
|
||||||
|
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")
|
||||||
|
}
|
||||||
|
|
||||||
|
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))
|
||||||
|
|
||||||
|
contentType := httpRes.Header.Get("Content-Type")
|
||||||
|
|
||||||
|
res := &operations.GetPinResponse{
|
||||||
|
StatusCode: httpRes.StatusCode,
|
||||||
|
ContentType: contentType,
|
||||||
|
RawResponse: httpRes,
|
||||||
|
}
|
||||||
|
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.TwoHundredApplicationJSONObject = &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 operations.GetPinPlexResponseBody
|
||||||
|
if err := utils.UnmarshalJsonFromResponseBody(bytes.NewBuffer(rawBody), &out, ""); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
res.FourHundredApplicationJSONObject = &out
|
||||||
|
default:
|
||||||
|
return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", contentType), 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, request operations.GetTokenRequest, opts ...operations.Option) (*operations.GetTokenResponse, error) {
|
||||||
|
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")
|
||||||
|
}
|
||||||
|
|
||||||
|
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))
|
||||||
|
|
||||||
|
contentType := httpRes.Header.Get("Content-Type")
|
||||||
|
|
||||||
|
res := &operations.GetTokenResponse{
|
||||||
|
StatusCode: httpRes.StatusCode,
|
||||||
|
ContentType: contentType,
|
||||||
|
RawResponse: httpRes,
|
||||||
|
}
|
||||||
|
switch {
|
||||||
|
case httpRes.StatusCode == 200:
|
||||||
|
case httpRes.StatusCode == 400:
|
||||||
|
switch {
|
||||||
|
case utils.MatchContentType(contentType, `application/json`):
|
||||||
|
var out operations.GetTokenResponseBody
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return res, nil
|
||||||
|
}
|
||||||
|
|||||||
@@ -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.
|
||||||
@@ -260,9 +262,9 @@ func New(opts ...SDKOption) *PlexAPI {
|
|||||||
sdkConfiguration: sdkConfiguration{
|
sdkConfiguration: sdkConfiguration{
|
||||||
Language: "go",
|
Language: "go",
|
||||||
OpenAPIDocVersion: "0.0.3",
|
OpenAPIDocVersion: "0.0.3",
|
||||||
SDKVersion: "0.4.0",
|
SDKVersion: "0.5.0",
|
||||||
GenVersion: "2.239.4",
|
GenVersion: "2.249.1",
|
||||||
UserAgent: "speakeasy-sdk/go 0.4.0 2.239.4 0.0.3 PlexAPI",
|
UserAgent: "speakeasy-sdk/go 0.5.0 2.249.1 0.0.3 PlexAPI",
|
||||||
ServerDefaults: []map[string]string{
|
ServerDefaults: []map[string]string{
|
||||||
{
|
{
|
||||||
"protocol": "http",
|
"protocol": "http",
|
||||||
|
|||||||
@@ -1,187 +0,0 @@
|
|||||||
// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT.
|
|
||||||
|
|
||||||
package sdk
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes"
|
|
||||||
"context"
|
|
||||||
"fmt"
|
|
||||||
"github.com/LukeHagar/terraform-provider-PlexAPI/internal/sdk/pkg/models/operations"
|
|
||||||
"github.com/LukeHagar/terraform-provider-PlexAPI/internal/sdk/pkg/models/sdkerrors"
|
|
||||||
"github.com/LukeHagar/terraform-provider-PlexAPI/internal/sdk/pkg/utils"
|
|
||||||
"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, request operations.GetPinRequest, opts ...operations.Option) (*operations.GetPinResponse, error) {
|
|
||||||
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")
|
|
||||||
}
|
|
||||||
|
|
||||||
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))
|
|
||||||
|
|
||||||
contentType := httpRes.Header.Get("Content-Type")
|
|
||||||
|
|
||||||
res := &operations.GetPinResponse{
|
|
||||||
StatusCode: httpRes.StatusCode,
|
|
||||||
ContentType: contentType,
|
|
||||||
RawResponse: httpRes,
|
|
||||||
}
|
|
||||||
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.TwoHundredApplicationJSONObject = &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 operations.GetPinPlexTvResponseBody
|
|
||||||
if err := utils.UnmarshalJsonFromResponseBody(bytes.NewBuffer(rawBody), &out, ""); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
res.FourHundredApplicationJSONObject = &out
|
|
||||||
default:
|
|
||||||
return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", contentType), 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, request operations.GetTokenRequest, opts ...operations.Option) (*operations.GetTokenResponse, error) {
|
|
||||||
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")
|
|
||||||
}
|
|
||||||
|
|
||||||
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))
|
|
||||||
|
|
||||||
contentType := httpRes.Header.Get("Content-Type")
|
|
||||||
|
|
||||||
res := &operations.GetTokenResponse{
|
|
||||||
StatusCode: httpRes.StatusCode,
|
|
||||||
ContentType: contentType,
|
|
||||||
RawResponse: httpRes,
|
|
||||||
}
|
|
||||||
switch {
|
|
||||||
case httpRes.StatusCode == 200:
|
|
||||||
case httpRes.StatusCode == 400:
|
|
||||||
switch {
|
|
||||||
case utils.MatchContentType(contentType, `application/json`):
|
|
||||||
var out operations.GetTokenResponseBody
|
|
||||||
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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return res, nil
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user