ci: regenerated with OpenAPI Doc 0.0.3, Speakeasy CLI 1.158.0

This commit is contained in:
speakeasybot
2024-01-31 15:06:37 +00:00
parent d13b68791f
commit 493f095bf8
13 changed files with 766 additions and 39 deletions

View File

@@ -1,21 +1,22 @@
lockVersion: 2.0.0 lockVersion: 2.0.0
id: e742591b-391d-4f4e-8484-d01a093b32ec id: e742591b-391d-4f4e-8484-d01a093b32ec
management: management:
docChecksum: 95d4ac4070b7f9db42126fc81b258e02 docChecksum: 94439465ae5d544f0e52b00719af05ee
docVersion: 0.0.3 docVersion: 0.0.3
speakeasyVersion: internal speakeasyVersion: internal
generationVersion: 2.237.3 generationVersion: 2.239.4
releaseVersion: 0.3.3 releaseVersion: 0.4.0
configChecksum: 9e5cb1e3ab2e0be2fce9e48e71feacda configChecksum: b244e39f31dda4bc1f3428b5e4025f10
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.8.4 core: 3.9.2
globalSecurity: 2.81.3 globalSecurity: 2.81.3
globalServerURLs: 2.82.1 globalServerURLs: 2.82.1
methodServerURLs: 2.82.1
nameOverrides: 2.81.1 nameOverrides: 2.81.1
unions: 2.81.7 unions: 2.81.7
generatedFiles: generatedFiles:
@@ -27,6 +28,8 @@ 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/playlists.go - internal/sdk/playlists.go
- internal/sdk/security.go - internal/sdk/security.go
- internal/sdk/sessions.go - internal/sdk/sessions.go
@@ -130,6 +133,8 @@ generatedFiles:
- internal/sdk/pkg/models/operations/logline.go - internal/sdk/pkg/models/operations/logline.go
- internal/sdk/pkg/models/operations/logmultiline.go - internal/sdk/pkg/models/operations/logmultiline.go
- internal/sdk/pkg/models/operations/enablepapertrail.go - internal/sdk/pkg/models/operations/enablepapertrail.go
- internal/sdk/pkg/models/operations/getpin.go
- internal/sdk/pkg/models/operations/gettoken.go
- internal/sdk/pkg/models/operations/createplaylist.go - internal/sdk/pkg/models/operations/createplaylist.go
- internal/sdk/pkg/models/operations/getplaylists.go - internal/sdk/pkg/models/operations/getplaylists.go
- internal/sdk/pkg/models/operations/getplaylist.go - internal/sdk/pkg/models/operations/getplaylist.go
@@ -154,4 +159,5 @@ generatedFiles:
- USAGE.md - USAGE.md
- internal/provider/provider.go - internal/provider/provider.go
- examples/provider/provider.tf - examples/provider/provider.tf
- internal/sdk/pkg/models/operations/options.go
- .gitattributes - .gitattributes

View File

@@ -61,7 +61,7 @@ terraform {
required_providers { required_providers {
PlexAPI = { PlexAPI = {
source = "LukeHagar/PlexAPI" source = "LukeHagar/PlexAPI"
version = "0.3.3" version = "0.4.0"
} }
} }
} }

View File

@@ -95,3 +95,11 @@ Based on:
- Speakeasy CLI 1.150.0 (2.237.3) https://github.com/speakeasy-api/speakeasy - Speakeasy CLI 1.150.0 (2.237.3) https://github.com/speakeasy-api/speakeasy
### Generated ### Generated
- [terraform v0.3.3] . - [terraform v0.3.3] .
## 2024-01-31 15:06:03
### Changes
Based on:
- OpenAPI Doc 0.0.3
- Speakeasy CLI 1.158.0 (2.239.4) https://github.com/speakeasy-api/speakeasy
### Generated
- [terraform v0.4.0] .

View File

@@ -17,7 +17,7 @@ terraform {
required_providers { required_providers {
PlexAPI = { PlexAPI = {
source = "LukeHagar/PlexAPI" source = "LukeHagar/PlexAPI"
version = "0.3.3" version = "0.4.0"
} }
} }
} }

View File

@@ -2,7 +2,7 @@ terraform {
required_providers { required_providers {
PlexAPI = { PlexAPI = {
source = "LukeHagar/PlexAPI" source = "LukeHagar/PlexAPI"
version = "0.3.3" version = "0.4.0"
} }
} }
} }

View File

@@ -8,7 +8,7 @@ generation:
fixes: fixes:
nameResolutionDec2023: false nameResolutionDec2023: false
terraform: terraform:
version: 0.3.3 version: 0.4.0
author: LukeHagar author: LukeHagar
imports: imports:
option: openapi option: openapi

View File

@@ -45,19 +45,19 @@ func (o *GetLibrariesLibraryResponseBody) GetErrors() []GetLibrariesErrors {
return o.Errors return o.Errors
} }
type Location struct { type GetLibrariesLocation struct {
ID *int `json:"id,omitempty"` ID *int `json:"id,omitempty"`
Path *string `json:"path,omitempty"` Path *string `json:"path,omitempty"`
} }
func (o *Location) GetID() *int { func (o *GetLibrariesLocation) GetID() *int {
if o == nil { if o == nil {
return nil return nil
} }
return o.ID return o.ID
} }
func (o *Location) GetPath() *string { func (o *GetLibrariesLocation) GetPath() *string {
if o == nil { if o == nil {
return nil return nil
} }
@@ -65,27 +65,27 @@ func (o *Location) GetPath() *string {
} }
type GetLibrariesDirectory struct { type GetLibrariesDirectory struct {
AllowSync *bool `json:"allowSync,omitempty"` AllowSync *bool `json:"allowSync,omitempty"`
Art *string `json:"art,omitempty"` Art *string `json:"art,omitempty"`
Composite *string `json:"composite,omitempty"` Composite *string `json:"composite,omitempty"`
Filters *bool `json:"filters,omitempty"` Filters *bool `json:"filters,omitempty"`
Refreshing *bool `json:"refreshing,omitempty"` Refreshing *bool `json:"refreshing,omitempty"`
Thumb *string `json:"thumb,omitempty"` Thumb *string `json:"thumb,omitempty"`
Key *string `json:"key,omitempty"` Key *string `json:"key,omitempty"`
Type *string `json:"type,omitempty"` Type *string `json:"type,omitempty"`
Title *string `json:"title,omitempty"` Title *string `json:"title,omitempty"`
Agent *string `json:"agent,omitempty"` Agent *string `json:"agent,omitempty"`
Scanner *string `json:"scanner,omitempty"` Scanner *string `json:"scanner,omitempty"`
Language *string `json:"language,omitempty"` Language *string `json:"language,omitempty"`
UUID *string `json:"uuid,omitempty"` UUID *string `json:"uuid,omitempty"`
UpdatedAt *int `json:"updatedAt,omitempty"` UpdatedAt *int `json:"updatedAt,omitempty"`
CreatedAt *int `json:"createdAt,omitempty"` CreatedAt *int `json:"createdAt,omitempty"`
ScannedAt *int `json:"scannedAt,omitempty"` ScannedAt *int `json:"scannedAt,omitempty"`
Content *bool `json:"content,omitempty"` Content *bool `json:"content,omitempty"`
Directory *bool `json:"directory,omitempty"` Directory *bool `json:"directory,omitempty"`
ContentChangedAt *int `json:"contentChangedAt,omitempty"` ContentChangedAt *int `json:"contentChangedAt,omitempty"`
Hidden *int `json:"hidden,omitempty"` Hidden *int `json:"hidden,omitempty"`
Location []Location `json:"Location,omitempty"` Location []GetLibrariesLocation `json:"Location,omitempty"`
} }
func (o *GetLibrariesDirectory) GetAllowSync() *bool { func (o *GetLibrariesDirectory) GetAllowSync() *bool {
@@ -228,7 +228,7 @@ func (o *GetLibrariesDirectory) GetHidden() *int {
return o.Hidden return o.Hidden
} }
func (o *GetLibrariesDirectory) GetLocation() []Location { func (o *GetLibrariesDirectory) GetLocation() []GetLibrariesLocation {
if o == nil { if o == nil {
return nil return nil
} }

View File

@@ -0,0 +1,334 @@
// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT.
package operations
import (
"github.com/LukeHagar/terraform-provider-PlexAPI/internal/sdk/pkg/utils"
"net/http"
"time"
)
var GetPinServerList = []string{
"https://plex.tv/api/v2",
}
type GetPinRequest struct {
// 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`
//
Strong *bool `default:"false" queryParam:"style=form,explode=true,name=strong"`
// Plex Authentication Token
XPlexClientIdentifier string `header:"style=simple,explode=false,name=X-Plex-Client-Identifier"`
}
func (g GetPinRequest) MarshalJSON() ([]byte, error) {
return utils.MarshalJSON(g, "", false)
}
func (g *GetPinRequest) UnmarshalJSON(data []byte) error {
if err := utils.UnmarshalJSON(data, &g, "", false, false); err != nil {
return err
}
return nil
}
func (o *GetPinRequest) GetStrong() *bool {
if o == nil {
return nil
}
return o.Strong
}
func (o *GetPinRequest) GetXPlexClientIdentifier() string {
if o == nil {
return ""
}
return o.XPlexClientIdentifier
}
type GetPinErrors struct {
Code *float64 `json:"code,omitempty"`
Message *string `json:"message,omitempty"`
Status *float64 `json:"status,omitempty"`
}
func (o *GetPinErrors) GetCode() *float64 {
if o == nil {
return nil
}
return o.Code
}
func (o *GetPinErrors) GetMessage() *string {
if o == nil {
return nil
}
return o.Message
}
func (o *GetPinErrors) GetStatus() *float64 {
if o == nil {
return nil
}
return o.Status
}
// GetPinPlexTvResponseBody - X-Plex-Client-Identifier is missing
type GetPinPlexTvResponseBody struct {
Errors []GetPinErrors `json:"errors,omitempty"`
}
func (o *GetPinPlexTvResponseBody) GetErrors() []GetPinErrors {
if o == nil {
return nil
}
return o.Errors
}
type Location struct {
Code *string `json:"code,omitempty"`
EuropeanUnionMember *bool `json:"european_union_member,omitempty"`
ContinentCode *string `json:"continent_code,omitempty"`
Country *string `json:"country,omitempty"`
City *string `json:"city,omitempty"`
TimeZone *string `json:"time_zone,omitempty"`
PostalCode *float64 `json:"postal_code,omitempty"`
InPrivacyRestrictedCountry *bool `json:"in_privacy_restricted_country,omitempty"`
Subdivisions *string `json:"subdivisions,omitempty"`
Coordinates *string `json:"coordinates,omitempty"`
}
func (o *Location) GetCode() *string {
if o == nil {
return nil
}
return o.Code
}
func (o *Location) GetEuropeanUnionMember() *bool {
if o == nil {
return nil
}
return o.EuropeanUnionMember
}
func (o *Location) GetContinentCode() *string {
if o == nil {
return nil
}
return o.ContinentCode
}
func (o *Location) GetCountry() *string {
if o == nil {
return nil
}
return o.Country
}
func (o *Location) GetCity() *string {
if o == nil {
return nil
}
return o.City
}
func (o *Location) GetTimeZone() *string {
if o == nil {
return nil
}
return o.TimeZone
}
func (o *Location) GetPostalCode() *float64 {
if o == nil {
return nil
}
return o.PostalCode
}
func (o *Location) GetInPrivacyRestrictedCountry() *bool {
if o == nil {
return nil
}
return o.InPrivacyRestrictedCountry
}
func (o *Location) GetSubdivisions() *string {
if o == nil {
return nil
}
return o.Subdivisions
}
func (o *Location) GetCoordinates() *string {
if o == nil {
return nil
}
return o.Coordinates
}
// GetPinResponseBody - The Pin
type GetPinResponseBody struct {
// PinID for use with authentication
ID *float64 `json:"id,omitempty"`
Code *string `json:"code,omitempty"`
Product *string `json:"product,omitempty"`
Trusted *bool `json:"trusted,omitempty"`
// a link to a QR code hosted on plex.tv
// The QR code redirects to the relevant `plex.tv/link` authentication page
// Which then prompts the user for the 4 Digit Link Pin
//
Qr *string `json:"qr,omitempty"`
ClientIdentifier *string `json:"clientIdentifier,omitempty"`
Location *Location `json:"location,omitempty"`
ExpiresIn *float64 `json:"expiresIn,omitempty"`
CreatedAt *time.Time `json:"createdAt,omitempty"`
ExpiresAt *time.Time `json:"expiresAt,omitempty"`
AuthToken *string `json:"authToken,omitempty"`
NewRegistration *string `json:"newRegistration,omitempty"`
}
func (g GetPinResponseBody) MarshalJSON() ([]byte, error) {
return utils.MarshalJSON(g, "", false)
}
func (g *GetPinResponseBody) UnmarshalJSON(data []byte) error {
if err := utils.UnmarshalJSON(data, &g, "", false, false); err != nil {
return err
}
return nil
}
func (o *GetPinResponseBody) GetID() *float64 {
if o == nil {
return nil
}
return o.ID
}
func (o *GetPinResponseBody) GetCode() *string {
if o == nil {
return nil
}
return o.Code
}
func (o *GetPinResponseBody) GetProduct() *string {
if o == nil {
return nil
}
return o.Product
}
func (o *GetPinResponseBody) GetTrusted() *bool {
if o == nil {
return nil
}
return o.Trusted
}
func (o *GetPinResponseBody) GetQr() *string {
if o == nil {
return nil
}
return o.Qr
}
func (o *GetPinResponseBody) GetClientIdentifier() *string {
if o == nil {
return nil
}
return o.ClientIdentifier
}
func (o *GetPinResponseBody) GetLocation() *Location {
if o == nil {
return nil
}
return o.Location
}
func (o *GetPinResponseBody) GetExpiresIn() *float64 {
if o == nil {
return nil
}
return o.ExpiresIn
}
func (o *GetPinResponseBody) GetCreatedAt() *time.Time {
if o == nil {
return nil
}
return o.CreatedAt
}
func (o *GetPinResponseBody) GetExpiresAt() *time.Time {
if o == nil {
return nil
}
return o.ExpiresAt
}
func (o *GetPinResponseBody) GetAuthToken() *string {
if o == nil {
return nil
}
return o.AuthToken
}
func (o *GetPinResponseBody) GetNewRegistration() *string {
if o == nil {
return nil
}
return o.NewRegistration
}
type GetPinResponse struct {
// HTTP response content type for this operation
ContentType string
// HTTP response status code for this operation
StatusCode int
// Raw HTTP response; suitable for custom response parsing
RawResponse *http.Response
// The Pin
TwoHundredApplicationJSONObject *GetPinResponseBody
// X-Plex-Client-Identifier is missing
FourHundredApplicationJSONObject *GetPinPlexTvResponseBody
}
func (o *GetPinResponse) GetContentType() string {
if o == nil {
return ""
}
return o.ContentType
}
func (o *GetPinResponse) GetStatusCode() int {
if o == nil {
return 0
}
return o.StatusCode
}
func (o *GetPinResponse) GetRawResponse() *http.Response {
if o == nil {
return nil
}
return o.RawResponse
}
func (o *GetPinResponse) GetTwoHundredApplicationJSONObject() *GetPinResponseBody {
if o == nil {
return nil
}
return o.TwoHundredApplicationJSONObject
}
func (o *GetPinResponse) GetFourHundredApplicationJSONObject() *GetPinPlexTvResponseBody {
if o == nil {
return nil
}
return o.FourHundredApplicationJSONObject
}

View File

@@ -0,0 +1,110 @@
// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT.
package operations
import (
"net/http"
)
var GetTokenServerList = []string{
"https://plex.tv/api/v2",
}
type GetTokenRequest struct {
// The PinID to retrieve an access token for
PinID string `pathParam:"style=simple,explode=false,name=pinID"`
// Plex Authentication Token
XPlexClientIdentifier string `header:"style=simple,explode=false,name=X-Plex-Client-Identifier"`
}
func (o *GetTokenRequest) GetPinID() string {
if o == nil {
return ""
}
return o.PinID
}
func (o *GetTokenRequest) GetXPlexClientIdentifier() string {
if o == nil {
return ""
}
return o.XPlexClientIdentifier
}
type GetTokenErrors struct {
Code *float64 `json:"code,omitempty"`
Message *string `json:"message,omitempty"`
Status *float64 `json:"status,omitempty"`
}
func (o *GetTokenErrors) GetCode() *float64 {
if o == nil {
return nil
}
return o.Code
}
func (o *GetTokenErrors) GetMessage() *string {
if o == nil {
return nil
}
return o.Message
}
func (o *GetTokenErrors) GetStatus() *float64 {
if o == nil {
return nil
}
return o.Status
}
// GetTokenResponseBody - X-Plex-Client-Identifier is missing
type GetTokenResponseBody struct {
Errors []GetTokenErrors `json:"errors,omitempty"`
}
func (o *GetTokenResponseBody) GetErrors() []GetTokenErrors {
if o == nil {
return nil
}
return o.Errors
}
type GetTokenResponse struct {
// HTTP response content type for this operation
ContentType string
// HTTP response status code for this operation
StatusCode int
// Raw HTTP response; suitable for custom response parsing
RawResponse *http.Response
// X-Plex-Client-Identifier is missing
Object *GetTokenResponseBody
}
func (o *GetTokenResponse) GetContentType() string {
if o == nil {
return ""
}
return o.ContentType
}
func (o *GetTokenResponse) GetStatusCode() int {
if o == nil {
return 0
}
return o.StatusCode
}
func (o *GetTokenResponse) GetRawResponse() *http.Response {
if o == nil {
return nil
}
return o.RawResponse
}
func (o *GetTokenResponse) GetObject() *GetTokenResponseBody {
if o == nil {
return nil
}
return o.Object
}

View File

@@ -0,0 +1,63 @@
// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT.
package operations
import (
"errors"
"github.com/LukeHagar/terraform-provider-PlexAPI/internal/sdk/pkg/utils"
)
var ErrUnsupportedOption = errors.New("unsupported option")
const (
SupportedOptionServerURL = "serverURL"
SupportedOptionRetries = "retries"
SupportedOptionAcceptHeaderOverride = "acceptHeaderOverride"
)
type Options struct {
ServerURL *string
Retries *utils.RetryConfig
}
type Option func(*Options, ...string) error
// WithServerURL allows providing an alternative server URL.
func WithServerURL(serverURL string) Option {
return func(opts *Options, supportedOptions ...string) error {
if !utils.Contains(supportedOptions, SupportedOptionServerURL) {
return ErrUnsupportedOption
}
opts.ServerURL = &serverURL
return nil
}
}
// WithTemplatedServerURL allows providing an alternative server URL with templated parameters.
func WithTemplatedServerURL(serverURL string, params map[string]string) Option {
return func(opts *Options, supportedOptions ...string) error {
if !utils.Contains(supportedOptions, SupportedOptionServerURL) {
return ErrUnsupportedOption
}
if params != nil {
serverURL = utils.ReplaceParameters(serverURL, params)
}
opts.ServerURL = &serverURL
return nil
}
}
// WithRetries allows customizing the default retry configuration.
func WithRetries(config utils.RetryConfig) Option {
return func(opts *Options, supportedOptions ...string) error {
if !utils.Contains(supportedOptions, SupportedOptionRetries) {
return ErrUnsupportedOption
}
opts.Retries = &config
return nil
}
}

16
internal/sdk/plex.go Normal file
View File

@@ -0,0 +1,16 @@
// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT.
package sdk
type Plex struct {
Tv *Tv
sdkConfiguration sdkConfiguration
}
func newPlex(sdkConfig sdkConfiguration) *Plex {
return &Plex{
sdkConfiguration: sdkConfig,
Tv: newTv(sdkConfig),
}
}

View File

@@ -96,7 +96,8 @@ 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
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.
// Retrieving a playlist, or its items, will trigger a refresh of its metadata. // Retrieving a playlist, or its items, will trigger a refresh of its metadata.
@@ -259,9 +260,9 @@ func New(opts ...SDKOption) *PlexAPI {
sdkConfiguration: sdkConfiguration{ sdkConfiguration: sdkConfiguration{
Language: "go", Language: "go",
OpenAPIDocVersion: "0.0.3", OpenAPIDocVersion: "0.0.3",
SDKVersion: "0.3.3", SDKVersion: "0.4.0",
GenVersion: "2.237.3", GenVersion: "2.239.4",
UserAgent: "speakeasy-sdk/go 0.3.3 2.237.3 0.0.3 PlexAPI", UserAgent: "speakeasy-sdk/go 0.4.0 2.239.4 0.0.3 PlexAPI",
ServerDefaults: []map[string]string{ ServerDefaults: []map[string]string{
{ {
"protocol": "http", "protocol": "http",
@@ -303,6 +304,8 @@ func New(opts ...SDKOption) *PlexAPI {
sdk.Log = newLog(sdk.sdkConfiguration) sdk.Log = newLog(sdk.sdkConfiguration)
sdk.Plex = newPlex(sdk.sdkConfiguration)
sdk.Playlists = newPlaylists(sdk.sdkConfiguration) sdk.Playlists = newPlaylists(sdk.sdkConfiguration)
sdk.Security = newSecurity(sdk.sdkConfiguration) sdk.Security = newSecurity(sdk.sdkConfiguration)

187
internal/sdk/tv.go Normal file
View File

@@ -0,0 +1,187 @@
// 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
}