mirror of
https://github.com/LukeHagar/plexgo.git
synced 2025-12-06 12:37:46 +00:00
Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2cfb7aefac | ||
|
|
41ce744f6d | ||
|
|
2b4d612003 | ||
|
|
853bfe69d5 | ||
|
|
81cfd47570 | ||
|
|
44e551a11d | ||
|
|
264d228db7 | ||
|
|
c1bc2419c8 | ||
|
|
471d850f17 | ||
|
|
b3ac2d0c2e |
@@ -1,42 +1,43 @@
|
||||
lockVersion: 2.0.0
|
||||
id: dfa99515-01c0-42eb-9be5-ee212fd03eb3
|
||||
management:
|
||||
docChecksum: 7aba498c024534142941d65a7c2e649c
|
||||
docChecksum: 278d186496d83d5830ba4870f8cad39d
|
||||
docVersion: 0.0.3
|
||||
speakeasyVersion: internal
|
||||
generationVersion: 2.237.3
|
||||
releaseVersion: 0.1.1
|
||||
configChecksum: 75ea35f7a212ecc077e24de582ed767e
|
||||
generationVersion: 2.269.0
|
||||
releaseVersion: 0.4.0
|
||||
configChecksum: 319de8bf53c668d84b706d9496459b7c
|
||||
repoURL: https://github.com/LukeHagar/plexgo.git
|
||||
repoSubDirectory: .
|
||||
installationURL: https://github.com/LukeHagar/plexgo
|
||||
published: true
|
||||
features:
|
||||
go:
|
||||
constsAndDefaults: 0.1.2
|
||||
core: 3.3.1
|
||||
constsAndDefaults: 0.1.3
|
||||
core: 3.4.1
|
||||
flattening: 2.81.1
|
||||
globalSecurity: 2.82.4
|
||||
globalSecurity: 2.82.6
|
||||
globalServerURLs: 2.82.1
|
||||
methodServerURLs: 2.82.1
|
||||
nameOverrides: 2.81.1
|
||||
unions: 2.85.2
|
||||
generatedFiles:
|
||||
- server.go
|
||||
- media.go
|
||||
- video.go
|
||||
- activities.go
|
||||
- butler.go
|
||||
- hubs.go
|
||||
- search.go
|
||||
- library.go
|
||||
- log.go
|
||||
- plex.go
|
||||
- playlists.go
|
||||
- security.go
|
||||
- statistics.go
|
||||
- sessions.go
|
||||
- updater.go
|
||||
- video.go
|
||||
- plexapi.go
|
||||
- go.mod
|
||||
- go.sum
|
||||
- models/sdkerrors/sdkerror.go
|
||||
- types/bigint.go
|
||||
- types/date.go
|
||||
@@ -64,6 +65,8 @@ generatedFiles:
|
||||
- /models/operations/markplayed.go
|
||||
- /models/operations/markunplayed.go
|
||||
- /models/operations/updateplayprogress.go
|
||||
- /models/operations/gettimeline.go
|
||||
- /models/operations/startuniversaltranscode.go
|
||||
- /models/operations/getserveractivities.go
|
||||
- /models/operations/cancelserveractivities.go
|
||||
- /models/operations/getbutlertasks.go
|
||||
@@ -83,12 +86,15 @@ generatedFiles:
|
||||
- /models/operations/deletelibrary.go
|
||||
- /models/operations/getlibraryitems.go
|
||||
- /models/operations/refreshlibrary.go
|
||||
- /models/operations/searchlibrary.go
|
||||
- /models/operations/getmetadata.go
|
||||
- /models/operations/getmetadatachildren.go
|
||||
- /models/operations/getondeck.go
|
||||
- /models/operations/logline.go
|
||||
- /models/operations/logmultiline.go
|
||||
- /models/operations/enablepapertrail.go
|
||||
- /models/operations/getpin.go
|
||||
- /models/operations/gettoken.go
|
||||
- /models/operations/createplaylist.go
|
||||
- /models/operations/getplaylists.go
|
||||
- /models/operations/getplaylist.go
|
||||
@@ -100,6 +106,7 @@ generatedFiles:
|
||||
- /models/operations/uploadplaylist.go
|
||||
- /models/operations/gettransienttoken.go
|
||||
- /models/operations/getsourceconnectioninformation.go
|
||||
- /models/operations/getstatistics.go
|
||||
- /models/operations/getsessions.go
|
||||
- /models/operations/getsessionhistory.go
|
||||
- /models/operations/gettranscodesessions.go
|
||||
@@ -107,8 +114,6 @@ generatedFiles:
|
||||
- /models/operations/getupdatestatus.go
|
||||
- /models/operations/checkforupdates.go
|
||||
- /models/operations/applyupdates.go
|
||||
- /models/operations/startuniversaltranscode.go
|
||||
- /models/operations/gettimeline.go
|
||||
- /models/sdkerrors/getservercapabilities.go
|
||||
- /models/sdkerrors/getserverpreferences.go
|
||||
- /models/sdkerrors/getavailableclients.go
|
||||
@@ -120,6 +125,8 @@ generatedFiles:
|
||||
- /models/sdkerrors/markplayed.go
|
||||
- /models/sdkerrors/markunplayed.go
|
||||
- /models/sdkerrors/updateplayprogress.go
|
||||
- /models/sdkerrors/gettimeline.go
|
||||
- /models/sdkerrors/startuniversaltranscode.go
|
||||
- /models/sdkerrors/getserveractivities.go
|
||||
- /models/sdkerrors/cancelserveractivities.go
|
||||
- /models/sdkerrors/getbutlertasks.go
|
||||
@@ -144,6 +151,8 @@ generatedFiles:
|
||||
- /models/sdkerrors/logline.go
|
||||
- /models/sdkerrors/logmultiline.go
|
||||
- /models/sdkerrors/enablepapertrail.go
|
||||
- /models/sdkerrors/getpin.go
|
||||
- /models/sdkerrors/gettoken.go
|
||||
- /models/sdkerrors/createplaylist.go
|
||||
- /models/sdkerrors/getplaylists.go
|
||||
- /models/sdkerrors/getplaylist.go
|
||||
@@ -155,6 +164,7 @@ generatedFiles:
|
||||
- /models/sdkerrors/uploadplaylist.go
|
||||
- /models/sdkerrors/gettransienttoken.go
|
||||
- /models/sdkerrors/getsourceconnectioninformation.go
|
||||
- /models/sdkerrors/getstatistics.go
|
||||
- /models/sdkerrors/getsessions.go
|
||||
- /models/sdkerrors/getsessionhistory.go
|
||||
- /models/sdkerrors/gettranscodesessions.go
|
||||
@@ -162,15 +172,11 @@ generatedFiles:
|
||||
- /models/sdkerrors/getupdatestatus.go
|
||||
- /models/sdkerrors/checkforupdates.go
|
||||
- /models/sdkerrors/applyupdates.go
|
||||
- /models/sdkerrors/startuniversaltranscode.go
|
||||
- /models/sdkerrors/gettimeline.go
|
||||
- /models/components/security.go
|
||||
- docs/models/operations/directory.md
|
||||
- docs/models/operations/mediacontainer.md
|
||||
- docs/models/operations/getservercapabilitiesresponsebody.md
|
||||
- docs/models/operations/getservercapabilitiesresponse.md
|
||||
- docs/models/operations/two.md
|
||||
- docs/models/operations/one.md
|
||||
- docs/models/operations/setting.md
|
||||
- docs/models/operations/getserverpreferencesmediacontainer.md
|
||||
- docs/models/operations/getserverpreferencesresponsebody.md
|
||||
@@ -203,6 +209,11 @@ generatedFiles:
|
||||
- docs/models/operations/markunplayedresponse.md
|
||||
- docs/models/operations/updateplayprogressrequest.md
|
||||
- docs/models/operations/updateplayprogressresponse.md
|
||||
- docs/models/operations/state.md
|
||||
- docs/models/operations/gettimelinerequest.md
|
||||
- docs/models/operations/gettimelineresponse.md
|
||||
- docs/models/operations/startuniversaltranscoderequest.md
|
||||
- docs/models/operations/startuniversaltranscoderesponse.md
|
||||
- docs/models/operations/context.md
|
||||
- docs/models/operations/activity.md
|
||||
- docs/models/operations/getserveractivitiesmediacontainer.md
|
||||
@@ -274,7 +285,7 @@ generatedFiles:
|
||||
- docs/models/operations/getrecentlyaddedmediacontainer.md
|
||||
- docs/models/operations/getrecentlyaddedresponsebody.md
|
||||
- docs/models/operations/getrecentlyaddedresponse.md
|
||||
- docs/models/operations/location.md
|
||||
- docs/models/operations/getlibrarieslocation.md
|
||||
- docs/models/operations/getlibrariesdirectory.md
|
||||
- docs/models/operations/getlibrariesmediacontainer.md
|
||||
- docs/models/operations/getlibrariesresponsebody.md
|
||||
@@ -308,6 +319,12 @@ generatedFiles:
|
||||
- docs/models/operations/getlibraryitemsresponse.md
|
||||
- docs/models/operations/refreshlibraryrequest.md
|
||||
- docs/models/operations/refreshlibraryresponse.md
|
||||
- docs/models/operations/type.md
|
||||
- docs/models/operations/searchlibraryrequest.md
|
||||
- docs/models/operations/searchlibrarymetadata.md
|
||||
- docs/models/operations/searchlibrarymediacontainer.md
|
||||
- docs/models/operations/searchlibraryresponsebody.md
|
||||
- docs/models/operations/searchlibraryresponse.md
|
||||
- docs/models/operations/getmetadatarequest.md
|
||||
- docs/models/operations/stream.md
|
||||
- docs/models/operations/getmetadatapart.md
|
||||
@@ -343,7 +360,13 @@ generatedFiles:
|
||||
- docs/models/operations/loglineresponse.md
|
||||
- docs/models/operations/logmultilineresponse.md
|
||||
- docs/models/operations/enablepapertrailresponse.md
|
||||
- docs/models/operations/type.md
|
||||
- docs/models/operations/getpinrequest.md
|
||||
- docs/models/operations/location.md
|
||||
- docs/models/operations/getpinresponsebody.md
|
||||
- docs/models/operations/getpinresponse.md
|
||||
- docs/models/operations/gettokenrequest.md
|
||||
- docs/models/operations/gettokenresponse.md
|
||||
- docs/models/operations/queryparamtype.md
|
||||
- docs/models/operations/smart.md
|
||||
- docs/models/operations/createplaylistrequest.md
|
||||
- docs/models/operations/createplaylistmetadata.md
|
||||
@@ -388,12 +411,19 @@ generatedFiles:
|
||||
- docs/models/operations/force.md
|
||||
- docs/models/operations/uploadplaylistrequest.md
|
||||
- docs/models/operations/uploadplaylistresponse.md
|
||||
- docs/models/operations/queryparamtype.md
|
||||
- docs/models/operations/gettransienttokenqueryparamtype.md
|
||||
- docs/models/operations/scope.md
|
||||
- docs/models/operations/gettransienttokenrequest.md
|
||||
- docs/models/operations/gettransienttokenresponse.md
|
||||
- docs/models/operations/getsourceconnectioninformationrequest.md
|
||||
- docs/models/operations/getsourceconnectioninformationresponse.md
|
||||
- docs/models/operations/getstatisticsrequest.md
|
||||
- docs/models/operations/getstatisticsdevice.md
|
||||
- docs/models/operations/account.md
|
||||
- docs/models/operations/statisticsmedia.md
|
||||
- docs/models/operations/getstatisticsmediacontainer.md
|
||||
- docs/models/operations/getstatisticsresponsebody.md
|
||||
- docs/models/operations/getstatisticsresponse.md
|
||||
- docs/models/operations/getsessionsstream.md
|
||||
- docs/models/operations/getsessionspart.md
|
||||
- docs/models/operations/getsessionsmedia.md
|
||||
@@ -425,11 +455,6 @@ generatedFiles:
|
||||
- docs/models/operations/skip.md
|
||||
- docs/models/operations/applyupdatesrequest.md
|
||||
- docs/models/operations/applyupdatesresponse.md
|
||||
- docs/models/operations/startuniversaltranscoderequest.md
|
||||
- docs/models/operations/startuniversaltranscoderesponse.md
|
||||
- docs/models/operations/state.md
|
||||
- docs/models/operations/gettimelinerequest.md
|
||||
- docs/models/operations/gettimelineresponse.md
|
||||
- docs/models/sdkerrors/errors.md
|
||||
- docs/models/sdkerrors/getservercapabilitiesresponsebody.md
|
||||
- docs/models/sdkerrors/getserverpreferenceserrors.md
|
||||
@@ -452,6 +477,10 @@ generatedFiles:
|
||||
- docs/models/sdkerrors/markunplayedresponsebody.md
|
||||
- docs/models/sdkerrors/updateplayprogresserrors.md
|
||||
- docs/models/sdkerrors/updateplayprogressresponsebody.md
|
||||
- docs/models/sdkerrors/gettimelineerrors.md
|
||||
- docs/models/sdkerrors/gettimelineresponsebody.md
|
||||
- docs/models/sdkerrors/startuniversaltranscodeerrors.md
|
||||
- docs/models/sdkerrors/startuniversaltranscoderesponsebody.md
|
||||
- docs/models/sdkerrors/getserveractivitieserrors.md
|
||||
- docs/models/sdkerrors/getserveractivitiesresponsebody.md
|
||||
- docs/models/sdkerrors/cancelserveractivitieserrors.md
|
||||
@@ -500,6 +529,10 @@ generatedFiles:
|
||||
- docs/models/sdkerrors/logmultilineresponsebody.md
|
||||
- docs/models/sdkerrors/enablepapertrailerrors.md
|
||||
- docs/models/sdkerrors/enablepapertrailresponsebody.md
|
||||
- docs/models/sdkerrors/getpinerrors.md
|
||||
- docs/models/sdkerrors/getpinresponsebody.md
|
||||
- docs/models/sdkerrors/gettokenerrors.md
|
||||
- docs/models/sdkerrors/gettokenresponsebody.md
|
||||
- docs/models/sdkerrors/createplaylisterrors.md
|
||||
- docs/models/sdkerrors/createplaylistresponsebody.md
|
||||
- docs/models/sdkerrors/getplaylistserrors.md
|
||||
@@ -522,6 +555,8 @@ generatedFiles:
|
||||
- docs/models/sdkerrors/gettransienttokenresponsebody.md
|
||||
- docs/models/sdkerrors/getsourceconnectioninformationerrors.md
|
||||
- docs/models/sdkerrors/getsourceconnectioninformationresponsebody.md
|
||||
- docs/models/sdkerrors/getstatisticserrors.md
|
||||
- docs/models/sdkerrors/getstatisticsresponsebody.md
|
||||
- docs/models/sdkerrors/getsessionserrors.md
|
||||
- docs/models/sdkerrors/getsessionsresponsebody.md
|
||||
- docs/models/sdkerrors/getsessionhistoryerrors.md
|
||||
@@ -536,24 +571,25 @@ generatedFiles:
|
||||
- docs/models/sdkerrors/checkforupdatesresponsebody.md
|
||||
- docs/models/sdkerrors/applyupdateserrors.md
|
||||
- docs/models/sdkerrors/applyupdatesresponsebody.md
|
||||
- docs/models/sdkerrors/startuniversaltranscodeerrors.md
|
||||
- docs/models/sdkerrors/startuniversaltranscoderesponsebody.md
|
||||
- docs/models/sdkerrors/gettimelineerrors.md
|
||||
- docs/models/sdkerrors/gettimelineresponsebody.md
|
||||
- docs/models/components/security.md
|
||||
- docs/sdks/plexapi/README.md
|
||||
- docs/sdks/server/README.md
|
||||
- docs/sdks/media/README.md
|
||||
- docs/sdks/video/README.md
|
||||
- docs/sdks/activities/README.md
|
||||
- docs/sdks/butler/README.md
|
||||
- docs/sdks/hubs/README.md
|
||||
- docs/sdks/search/README.md
|
||||
- docs/sdks/library/README.md
|
||||
- docs/sdks/log/README.md
|
||||
- docs/models/operations/option.md
|
||||
- docs/sdks/plex/README.md
|
||||
- docs/sdks/playlists/README.md
|
||||
- docs/sdks/security/README.md
|
||||
- docs/sdks/statistics/README.md
|
||||
- docs/sdks/sessions/README.md
|
||||
- docs/sdks/updater/README.md
|
||||
- docs/sdks/video/README.md
|
||||
- USAGE.md
|
||||
- models/operations/options.go
|
||||
- .gitattributes
|
||||
- internal/hooks/hooks.go
|
||||
|
||||
55
README.md
55
README.md
@@ -69,6 +69,11 @@ func main() {
|
||||
* [MarkUnplayed](docs/sdks/media/README.md#markunplayed) - Mark Media Unplayed
|
||||
* [UpdatePlayProgress](docs/sdks/media/README.md#updateplayprogress) - Update Media Play Progress
|
||||
|
||||
### [Video](docs/sdks/video/README.md)
|
||||
|
||||
* [GetTimeline](docs/sdks/video/README.md#gettimeline) - Get the timeline for a media item
|
||||
* [StartUniversalTranscode](docs/sdks/video/README.md#startuniversaltranscode) - Start Universal Transcode
|
||||
|
||||
### [Activities](docs/sdks/activities/README.md)
|
||||
|
||||
* [GetServerActivities](docs/sdks/activities/README.md#getserveractivities) - Get Server Activities
|
||||
@@ -102,6 +107,7 @@ func main() {
|
||||
* [DeleteLibrary](docs/sdks/library/README.md#deletelibrary) - Delete Library Section
|
||||
* [GetLibraryItems](docs/sdks/library/README.md#getlibraryitems) - Get Library Items
|
||||
* [RefreshLibrary](docs/sdks/library/README.md#refreshlibrary) - Refresh Library
|
||||
* [SearchLibrary](docs/sdks/library/README.md#searchlibrary) - Search Library
|
||||
* [GetMetadata](docs/sdks/library/README.md#getmetadata) - Get Items Metadata
|
||||
* [GetMetadataChildren](docs/sdks/library/README.md#getmetadatachildren) - Get Items Children
|
||||
* [GetOnDeck](docs/sdks/library/README.md#getondeck) - Get On Deck
|
||||
@@ -112,6 +118,11 @@ 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)
|
||||
|
||||
* [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)
|
||||
|
||||
* [CreatePlaylist](docs/sdks/playlists/README.md#createplaylist) - Create a Playlist
|
||||
@@ -129,6 +140,10 @@ func main() {
|
||||
* [GetTransientToken](docs/sdks/security/README.md#gettransienttoken) - Get a Transient Token.
|
||||
* [GetSourceConnectionInformation](docs/sdks/security/README.md#getsourceconnectioninformation) - Get Source Connection Information
|
||||
|
||||
### [Statistics](docs/sdks/statistics/README.md)
|
||||
|
||||
* [GetStatistics](docs/sdks/statistics/README.md#getstatistics) - Get Media Statistics
|
||||
|
||||
### [Sessions](docs/sdks/sessions/README.md)
|
||||
|
||||
* [GetSessions](docs/sdks/sessions/README.md#getsessions) - Get Active Sessions
|
||||
@@ -141,11 +156,6 @@ func main() {
|
||||
* [GetUpdateStatus](docs/sdks/updater/README.md#getupdatestatus) - Querying status of updates
|
||||
* [CheckForUpdates](docs/sdks/updater/README.md#checkforupdates) - Checking for updates
|
||||
* [ApplyUpdates](docs/sdks/updater/README.md#applyupdates) - Apply Updates
|
||||
|
||||
### [Video](docs/sdks/video/README.md)
|
||||
|
||||
* [StartUniversalTranscode](docs/sdks/video/README.md#startuniversaltranscode) - Start Universal Transcode
|
||||
* [GetTimeline](docs/sdks/video/README.md#gettimeline) - Get the timeline for a media item
|
||||
<!-- End Available Resources and Operations [operations] -->
|
||||
|
||||
<!-- Start Error Handling [errors] -->
|
||||
@@ -277,6 +287,41 @@ func main() {
|
||||
}
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
### Override Server URL Per-Operation
|
||||
|
||||
The server URL can also be overridden on a per-operation basis, provided a server list was specified for the operation. For example:
|
||||
```go
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/LukeHagar/plexgo"
|
||||
"github.com/LukeHagar/plexgo/models/components"
|
||||
"log"
|
||||
)
|
||||
|
||||
func main() {
|
||||
s := plexgo.New(
|
||||
plexgo.WithSecurity("<YOUR_API_KEY_HERE>"),
|
||||
)
|
||||
|
||||
var xPlexClientIdentifier string = "<value>"
|
||||
|
||||
var strong *bool = plexgo.Bool(false)
|
||||
|
||||
ctx := context.Background()
|
||||
res, err := s.Plex.GetPin(ctx, operations.WithServerURL("https://plex.tv/api/v2"), xPlexClientIdentifier, strong)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
if res.Object != nil {
|
||||
// handle response
|
||||
}
|
||||
}
|
||||
|
||||
```
|
||||
<!-- End Server Selection [server] -->
|
||||
|
||||
|
||||
62
RELEASES.md
62
RELEASES.md
@@ -68,4 +68,64 @@ Based on:
|
||||
### Generated
|
||||
- [go v0.1.1] .
|
||||
### Releases
|
||||
- [Go v0.1.1] https://github.com/LukeHagar/plexgo/releases/tag/v0.1.1 - .
|
||||
- [Go v0.1.1] https://github.com/LukeHagar/plexgo/releases/tag/v0.1.1 - .
|
||||
|
||||
## 2024-01-23 20:47:20
|
||||
### Changes
|
||||
Based on:
|
||||
- OpenAPI Doc 0.0.3
|
||||
- Speakeasy CLI 1.150.0 (2.237.3) https://github.com/speakeasy-api/speakeasy
|
||||
### Generated
|
||||
- [go v0.1.2] .
|
||||
### Releases
|
||||
- [Go v0.1.2] https://github.com/LukeHagar/plexgo/releases/tag/v0.1.2 - .
|
||||
|
||||
## 2024-01-23 21:56:10
|
||||
### Changes
|
||||
Based on:
|
||||
- OpenAPI Doc 0.0.3
|
||||
- Speakeasy CLI 1.150.0 (2.237.3) https://github.com/speakeasy-api/speakeasy
|
||||
### Generated
|
||||
- [go v0.1.3] .
|
||||
### Releases
|
||||
- [Go v0.1.3] https://github.com/LukeHagar/plexgo/releases/tag/v0.1.3 - .
|
||||
|
||||
## 2024-01-31 15:05:54
|
||||
### Changes
|
||||
Based on:
|
||||
- OpenAPI Doc 0.0.3
|
||||
- Speakeasy CLI 1.158.0 (2.239.4) https://github.com/speakeasy-api/speakeasy
|
||||
### Generated
|
||||
- [go v0.2.0] .
|
||||
### Releases
|
||||
- [Go v0.2.0] https://github.com/LukeHagar/plexgo/releases/tag/v0.2.0 - .
|
||||
|
||||
## 2024-02-01 00:46:46
|
||||
### Changes
|
||||
Based on:
|
||||
- OpenAPI Doc 0.0.3
|
||||
- Speakeasy CLI 1.161.0 (2.245.1) https://github.com/speakeasy-api/speakeasy
|
||||
### Generated
|
||||
- [go v0.2.1] .
|
||||
### Releases
|
||||
- [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 - .
|
||||
|
||||
## 2024-02-23 14:46:30
|
||||
### Changes
|
||||
Based on:
|
||||
- OpenAPI Doc 0.0.3
|
||||
- Speakeasy CLI 1.193.0 (2.269.0) https://github.com/speakeasy-api/speakeasy
|
||||
### Generated
|
||||
- [go v0.4.0] .
|
||||
### Releases
|
||||
- [Go v0.4.0] https://github.com/LukeHagar/plexgo/releases/tag/v0.4.0 - .
|
||||
@@ -6,12 +6,13 @@ import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/LukeHagar/plexgo/internal/hooks"
|
||||
"github.com/LukeHagar/plexgo/internal/utils"
|
||||
"github.com/LukeHagar/plexgo/models/operations"
|
||||
"github.com/LukeHagar/plexgo/models/sdkerrors"
|
||||
"io"
|
||||
"net/http"
|
||||
"strings"
|
||||
"net/url"
|
||||
)
|
||||
|
||||
// Activities are awesome. They provide a way to monitor and control asynchronous operations on the server. In order to receive real-time updates for activities, a client would normally subscribe via either EventSource or Websocket endpoints.
|
||||
@@ -34,26 +35,49 @@ func newActivities(sdkConfig sdkConfiguration) *Activities {
|
||||
// GetServerActivities - Get Server Activities
|
||||
// Get Server Activities
|
||||
func (s *Activities) GetServerActivities(ctx context.Context) (*operations.GetServerActivitiesResponse, error) {
|
||||
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
|
||||
url := strings.TrimSuffix(baseURL, "/") + "/activities"
|
||||
hookCtx := hooks.HookContext{OperationID: "getServerActivities"}
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", url, nil)
|
||||
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
|
||||
opURL, err := url.JoinPath(baseURL, "/activities")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error generating URL: %w", err)
|
||||
}
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", opURL, 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)
|
||||
req.Header.Set("User-Agent", s.sdkConfiguration.UserAgent)
|
||||
|
||||
req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{hookCtx}, req)
|
||||
if err != nil {
|
||||
return nil, 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")
|
||||
}
|
||||
if err != nil || httpRes == nil {
|
||||
if err != nil {
|
||||
err = fmt.Errorf("error sending request: %w", err)
|
||||
} else {
|
||||
err = fmt.Errorf("error sending request: no response")
|
||||
}
|
||||
|
||||
_, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{hookCtx}, nil, err)
|
||||
return nil, err
|
||||
} else if utils.MatchStatusCodes([]string{"400", "401", "4XX", "5XX"}, httpRes.StatusCode) {
|
||||
httpRes, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{hookCtx}, httpRes, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{hookCtx}, httpRes)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
contentType := httpRes.Header.Get("Content-Type")
|
||||
|
||||
res := &operations.GetServerActivitiesResponse{
|
||||
@@ -68,6 +92,7 @@ func (s *Activities) GetServerActivities(ctx context.Context) (*operations.GetSe
|
||||
}
|
||||
httpRes.Body.Close()
|
||||
httpRes.Body = io.NopCloser(bytes.NewBuffer(rawBody))
|
||||
|
||||
switch {
|
||||
case httpRes.StatusCode == 200:
|
||||
switch {
|
||||
@@ -108,33 +133,53 @@ func (s *Activities) GetServerActivities(ctx context.Context) (*operations.GetSe
|
||||
// CancelServerActivities - Cancel Server Activities
|
||||
// Cancel Server Activities
|
||||
func (s *Activities) CancelServerActivities(ctx context.Context, activityUUID string) (*operations.CancelServerActivitiesResponse, error) {
|
||||
hookCtx := hooks.HookContext{OperationID: "cancelServerActivities"}
|
||||
|
||||
request := operations.CancelServerActivitiesRequest{
|
||||
ActivityUUID: activityUUID,
|
||||
}
|
||||
|
||||
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
|
||||
url, err := utils.GenerateURL(ctx, baseURL, "/activities/{activityUUID}", request, nil)
|
||||
opURL, err := utils.GenerateURL(ctx, baseURL, "/activities/{activityUUID}", request, nil)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error generating URL: %w", err)
|
||||
}
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, "DELETE", url, nil)
|
||||
req, err := http.NewRequestWithContext(ctx, "DELETE", opURL, 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)
|
||||
req.Header.Set("User-Agent", s.sdkConfiguration.UserAgent)
|
||||
|
||||
req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{hookCtx}, req)
|
||||
if err != nil {
|
||||
return nil, 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")
|
||||
}
|
||||
if err != nil || httpRes == nil {
|
||||
if err != nil {
|
||||
err = fmt.Errorf("error sending request: %w", err)
|
||||
} else {
|
||||
err = fmt.Errorf("error sending request: no response")
|
||||
}
|
||||
|
||||
_, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{hookCtx}, nil, err)
|
||||
return nil, err
|
||||
} else if utils.MatchStatusCodes([]string{"400", "401", "4XX", "5XX"}, httpRes.StatusCode) {
|
||||
httpRes, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{hookCtx}, httpRes, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{hookCtx}, httpRes)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
contentType := httpRes.Header.Get("Content-Type")
|
||||
|
||||
res := &operations.CancelServerActivitiesResponse{
|
||||
@@ -149,6 +194,7 @@ func (s *Activities) CancelServerActivities(ctx context.Context, activityUUID st
|
||||
}
|
||||
httpRes.Body.Close()
|
||||
httpRes.Body = io.NopCloser(bytes.NewBuffer(rawBody))
|
||||
|
||||
switch {
|
||||
case httpRes.StatusCode == 200:
|
||||
case httpRes.StatusCode == 400:
|
||||
|
||||
213
butler.go
213
butler.go
@@ -6,12 +6,13 @@ import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/LukeHagar/plexgo/internal/hooks"
|
||||
"github.com/LukeHagar/plexgo/internal/utils"
|
||||
"github.com/LukeHagar/plexgo/models/operations"
|
||||
"github.com/LukeHagar/plexgo/models/sdkerrors"
|
||||
"io"
|
||||
"net/http"
|
||||
"strings"
|
||||
"net/url"
|
||||
)
|
||||
|
||||
// Butler is the task manager of the Plex Media Server Ecosystem.
|
||||
@@ -28,26 +29,49 @@ func newButler(sdkConfig sdkConfiguration) *Butler {
|
||||
// GetButlerTasks - Get Butler tasks
|
||||
// Returns a list of butler tasks
|
||||
func (s *Butler) GetButlerTasks(ctx context.Context) (*operations.GetButlerTasksResponse, error) {
|
||||
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
|
||||
url := strings.TrimSuffix(baseURL, "/") + "/butler"
|
||||
hookCtx := hooks.HookContext{OperationID: "getButlerTasks"}
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", url, nil)
|
||||
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
|
||||
opURL, err := url.JoinPath(baseURL, "/butler")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error generating URL: %w", err)
|
||||
}
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", opURL, 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)
|
||||
req.Header.Set("User-Agent", s.sdkConfiguration.UserAgent)
|
||||
|
||||
req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{hookCtx}, req)
|
||||
if err != nil {
|
||||
return nil, 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")
|
||||
}
|
||||
if err != nil || httpRes == nil {
|
||||
if err != nil {
|
||||
err = fmt.Errorf("error sending request: %w", err)
|
||||
} else {
|
||||
err = fmt.Errorf("error sending request: no response")
|
||||
}
|
||||
|
||||
_, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{hookCtx}, nil, err)
|
||||
return nil, err
|
||||
} else if utils.MatchStatusCodes([]string{"400", "401", "4XX", "5XX"}, httpRes.StatusCode) {
|
||||
httpRes, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{hookCtx}, httpRes, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{hookCtx}, httpRes)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
contentType := httpRes.Header.Get("Content-Type")
|
||||
|
||||
res := &operations.GetButlerTasksResponse{
|
||||
@@ -62,6 +86,7 @@ func (s *Butler) GetButlerTasks(ctx context.Context) (*operations.GetButlerTasks
|
||||
}
|
||||
httpRes.Body.Close()
|
||||
httpRes.Body = io.NopCloser(bytes.NewBuffer(rawBody))
|
||||
|
||||
switch {
|
||||
case httpRes.StatusCode == 200:
|
||||
switch {
|
||||
@@ -106,26 +131,49 @@ func (s *Butler) GetButlerTasks(ctx context.Context) (*operations.GetButlerTasks
|
||||
// 3. If a task is configured to run at a random time during the configured window and we are within that window, the task will be scheduled at a random time within the window.
|
||||
// 4. If we are outside the configured window, the task will start immediately.
|
||||
func (s *Butler) StartAllTasks(ctx context.Context) (*operations.StartAllTasksResponse, error) {
|
||||
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
|
||||
url := strings.TrimSuffix(baseURL, "/") + "/butler"
|
||||
hookCtx := hooks.HookContext{OperationID: "startAllTasks"}
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, "POST", url, nil)
|
||||
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
|
||||
opURL, err := url.JoinPath(baseURL, "/butler")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error generating URL: %w", err)
|
||||
}
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, "POST", opURL, 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)
|
||||
req.Header.Set("User-Agent", s.sdkConfiguration.UserAgent)
|
||||
|
||||
req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{hookCtx}, req)
|
||||
if err != nil {
|
||||
return nil, 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")
|
||||
}
|
||||
if err != nil || httpRes == nil {
|
||||
if err != nil {
|
||||
err = fmt.Errorf("error sending request: %w", err)
|
||||
} else {
|
||||
err = fmt.Errorf("error sending request: no response")
|
||||
}
|
||||
|
||||
_, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{hookCtx}, nil, err)
|
||||
return nil, err
|
||||
} else if utils.MatchStatusCodes([]string{"400", "401", "4XX", "5XX"}, httpRes.StatusCode) {
|
||||
httpRes, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{hookCtx}, httpRes, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{hookCtx}, httpRes)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
contentType := httpRes.Header.Get("Content-Type")
|
||||
|
||||
res := &operations.StartAllTasksResponse{
|
||||
@@ -140,6 +188,7 @@ func (s *Butler) StartAllTasks(ctx context.Context) (*operations.StartAllTasksRe
|
||||
}
|
||||
httpRes.Body.Close()
|
||||
httpRes.Body = io.NopCloser(bytes.NewBuffer(rawBody))
|
||||
|
||||
switch {
|
||||
case httpRes.StatusCode == 200:
|
||||
case httpRes.StatusCode == 400:
|
||||
@@ -169,26 +218,49 @@ func (s *Butler) StartAllTasks(ctx context.Context) (*operations.StartAllTasksRe
|
||||
// StopAllTasks - Stop all Butler tasks
|
||||
// This endpoint will stop all currently running tasks and remove any scheduled tasks from the queue.
|
||||
func (s *Butler) StopAllTasks(ctx context.Context) (*operations.StopAllTasksResponse, error) {
|
||||
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
|
||||
url := strings.TrimSuffix(baseURL, "/") + "/butler"
|
||||
hookCtx := hooks.HookContext{OperationID: "stopAllTasks"}
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, "DELETE", url, nil)
|
||||
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
|
||||
opURL, err := url.JoinPath(baseURL, "/butler")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error generating URL: %w", err)
|
||||
}
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, "DELETE", opURL, 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)
|
||||
req.Header.Set("User-Agent", s.sdkConfiguration.UserAgent)
|
||||
|
||||
req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{hookCtx}, req)
|
||||
if err != nil {
|
||||
return nil, 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")
|
||||
}
|
||||
if err != nil || httpRes == nil {
|
||||
if err != nil {
|
||||
err = fmt.Errorf("error sending request: %w", err)
|
||||
} else {
|
||||
err = fmt.Errorf("error sending request: no response")
|
||||
}
|
||||
|
||||
_, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{hookCtx}, nil, err)
|
||||
return nil, err
|
||||
} else if utils.MatchStatusCodes([]string{"400", "401", "4XX", "5XX"}, httpRes.StatusCode) {
|
||||
httpRes, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{hookCtx}, httpRes, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{hookCtx}, httpRes)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
contentType := httpRes.Header.Get("Content-Type")
|
||||
|
||||
res := &operations.StopAllTasksResponse{
|
||||
@@ -203,6 +275,7 @@ func (s *Butler) StopAllTasks(ctx context.Context) (*operations.StopAllTasksResp
|
||||
}
|
||||
httpRes.Body.Close()
|
||||
httpRes.Body = io.NopCloser(bytes.NewBuffer(rawBody))
|
||||
|
||||
switch {
|
||||
case httpRes.StatusCode == 200:
|
||||
case httpRes.StatusCode == 400:
|
||||
@@ -236,33 +309,53 @@ func (s *Butler) StopAllTasks(ctx context.Context) (*operations.StopAllTasksResp
|
||||
// 3. If a task is configured to run at a random time during the configured window and we are within that window, the task will be scheduled at a random time within the window.
|
||||
// 4. If we are outside the configured window, the task will start immediately.
|
||||
func (s *Butler) StartTask(ctx context.Context, taskName operations.TaskName) (*operations.StartTaskResponse, error) {
|
||||
hookCtx := hooks.HookContext{OperationID: "startTask"}
|
||||
|
||||
request := operations.StartTaskRequest{
|
||||
TaskName: taskName,
|
||||
}
|
||||
|
||||
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
|
||||
url, err := utils.GenerateURL(ctx, baseURL, "/butler/{taskName}", request, nil)
|
||||
opURL, err := utils.GenerateURL(ctx, baseURL, "/butler/{taskName}", request, nil)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error generating URL: %w", err)
|
||||
}
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, "POST", url, nil)
|
||||
req, err := http.NewRequestWithContext(ctx, "POST", opURL, 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)
|
||||
req.Header.Set("User-Agent", s.sdkConfiguration.UserAgent)
|
||||
|
||||
req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{hookCtx}, req)
|
||||
if err != nil {
|
||||
return nil, 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")
|
||||
}
|
||||
if err != nil || httpRes == nil {
|
||||
if err != nil {
|
||||
err = fmt.Errorf("error sending request: %w", err)
|
||||
} else {
|
||||
err = fmt.Errorf("error sending request: no response")
|
||||
}
|
||||
|
||||
_, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{hookCtx}, nil, err)
|
||||
return nil, err
|
||||
} else if utils.MatchStatusCodes([]string{"400", "401", "4XX", "5XX"}, httpRes.StatusCode) {
|
||||
httpRes, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{hookCtx}, httpRes, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{hookCtx}, httpRes)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
contentType := httpRes.Header.Get("Content-Type")
|
||||
|
||||
res := &operations.StartTaskResponse{
|
||||
@@ -277,6 +370,7 @@ func (s *Butler) StartTask(ctx context.Context, taskName operations.TaskName) (*
|
||||
}
|
||||
httpRes.Body.Close()
|
||||
httpRes.Body = io.NopCloser(bytes.NewBuffer(rawBody))
|
||||
|
||||
switch {
|
||||
case httpRes.StatusCode == 200:
|
||||
fallthrough
|
||||
@@ -308,33 +402,53 @@ func (s *Butler) StartTask(ctx context.Context, taskName operations.TaskName) (*
|
||||
// StopTask - Stop a single Butler task
|
||||
// This endpoint will stop a currently running task by name, or remove it from the list of scheduled tasks if it exists. See the section above for a list of task names for this endpoint.
|
||||
func (s *Butler) StopTask(ctx context.Context, taskName operations.PathParamTaskName) (*operations.StopTaskResponse, error) {
|
||||
hookCtx := hooks.HookContext{OperationID: "stopTask"}
|
||||
|
||||
request := operations.StopTaskRequest{
|
||||
TaskName: taskName,
|
||||
}
|
||||
|
||||
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
|
||||
url, err := utils.GenerateURL(ctx, baseURL, "/butler/{taskName}", request, nil)
|
||||
opURL, err := utils.GenerateURL(ctx, baseURL, "/butler/{taskName}", request, nil)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error generating URL: %w", err)
|
||||
}
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, "DELETE", url, nil)
|
||||
req, err := http.NewRequestWithContext(ctx, "DELETE", opURL, 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)
|
||||
req.Header.Set("User-Agent", s.sdkConfiguration.UserAgent)
|
||||
|
||||
req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{hookCtx}, req)
|
||||
if err != nil {
|
||||
return nil, 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")
|
||||
}
|
||||
if err != nil || httpRes == nil {
|
||||
if err != nil {
|
||||
err = fmt.Errorf("error sending request: %w", err)
|
||||
} else {
|
||||
err = fmt.Errorf("error sending request: no response")
|
||||
}
|
||||
|
||||
_, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{hookCtx}, nil, err)
|
||||
return nil, err
|
||||
} else if utils.MatchStatusCodes([]string{"400", "401", "404", "4XX", "5XX"}, httpRes.StatusCode) {
|
||||
httpRes, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{hookCtx}, httpRes, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{hookCtx}, httpRes)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
contentType := httpRes.Header.Get("Content-Type")
|
||||
|
||||
res := &operations.StopTaskResponse{
|
||||
@@ -349,6 +463,7 @@ func (s *Butler) StopTask(ctx context.Context, taskName operations.PathParamTask
|
||||
}
|
||||
httpRes.Body.Close()
|
||||
httpRes.Body = io.NopCloser(bytes.NewBuffer(rawBody))
|
||||
|
||||
switch {
|
||||
case httpRes.StatusCode == 200:
|
||||
case httpRes.StatusCode == 400:
|
||||
|
||||
15
docs/models/operations/account.md
Normal file
15
docs/models/operations/account.md
Normal file
@@ -0,0 +1,15 @@
|
||||
# Account
|
||||
|
||||
|
||||
## Fields
|
||||
|
||||
| Field | Type | Required | Description | Example |
|
||||
| ---------------------------------------------------------- | ---------------------------------------------------------- | ---------------------------------------------------------- | ---------------------------------------------------------- | ---------------------------------------------------------- |
|
||||
| `ID` | **int* | :heavy_minus_sign: | N/A | 238960586 |
|
||||
| `Key` | **string* | :heavy_minus_sign: | N/A | /accounts/238960586 |
|
||||
| `Name` | **string* | :heavy_minus_sign: | N/A | Diane |
|
||||
| `DefaultAudioLanguage` | **string* | :heavy_minus_sign: | N/A | en |
|
||||
| `AutoSelectAudio` | **bool* | :heavy_minus_sign: | N/A | true |
|
||||
| `DefaultSubtitleLanguage` | **string* | :heavy_minus_sign: | N/A | en |
|
||||
| `SubtitleMode` | **int* | :heavy_minus_sign: | N/A | 1 |
|
||||
| `Thumb` | **string* | :heavy_minus_sign: | N/A | https://plex.tv/users/50d83634246da1de/avatar?c=1707110967 |
|
||||
@@ -3,10 +3,10 @@
|
||||
|
||||
## Fields
|
||||
|
||||
| Field | Type | Required | Description |
|
||||
| ---------------------------------------------------- | ---------------------------------------------------- | ---------------------------------------------------- | ---------------------------------------------------- |
|
||||
| `Title` | *string* | :heavy_check_mark: | name of the playlist |
|
||||
| `Type` | [operations.Type](../../models/operations/type.md) | :heavy_check_mark: | type of playlist to create |
|
||||
| `Smart` | [operations.Smart](../../models/operations/smart.md) | :heavy_check_mark: | whether the playlist is smart or not |
|
||||
| `URI` | *string* | :heavy_check_mark: | the content URI for the playlist |
|
||||
| `PlayQueueID` | **float64* | :heavy_minus_sign: | the play queue to copy to a playlist |
|
||||
| Field | Type | Required | Description |
|
||||
| ---------------------------------------------------------------------- | ---------------------------------------------------------------------- | ---------------------------------------------------------------------- | ---------------------------------------------------------------------- |
|
||||
| `Title` | *string* | :heavy_check_mark: | name of the playlist |
|
||||
| `Type` | [operations.QueryParamType](../../models/operations/queryparamtype.md) | :heavy_check_mark: | type of playlist to create |
|
||||
| `Smart` | [operations.Smart](../../models/operations/smart.md) | :heavy_check_mark: | whether the playlist is smart or not |
|
||||
| `URI` | *string* | :heavy_check_mark: | the content URI for the playlist |
|
||||
| `PlayQueueID` | **float64* | :heavy_minus_sign: | the play queue to copy to a playlist |
|
||||
@@ -3,26 +3,26 @@
|
||||
|
||||
## Fields
|
||||
|
||||
| Field | Type | Required | Description | Example |
|
||||
| ------------------------------------------------------------ | ------------------------------------------------------------ | ------------------------------------------------------------ | ------------------------------------------------------------ | ------------------------------------------------------------ |
|
||||
| `AllowSync` | **bool* | :heavy_minus_sign: | N/A | true |
|
||||
| `Art` | **string* | :heavy_minus_sign: | N/A | /:/resources/movie-fanart.jpg |
|
||||
| `Composite` | **string* | :heavy_minus_sign: | N/A | /library/sections/1/composite/1705615584 |
|
||||
| `Filters` | **bool* | :heavy_minus_sign: | N/A | true |
|
||||
| `Refreshing` | **bool* | :heavy_minus_sign: | N/A | false |
|
||||
| `Thumb` | **string* | :heavy_minus_sign: | N/A | /:/resources/movie.png |
|
||||
| `Key` | **string* | :heavy_minus_sign: | N/A | 1 |
|
||||
| `Type` | **string* | :heavy_minus_sign: | N/A | movie |
|
||||
| `Title` | **string* | :heavy_minus_sign: | N/A | Movies |
|
||||
| `Agent` | **string* | :heavy_minus_sign: | N/A | tv.plex.agents.movie |
|
||||
| `Scanner` | **string* | :heavy_minus_sign: | N/A | Plex Movie |
|
||||
| `Language` | **string* | :heavy_minus_sign: | N/A | en-US |
|
||||
| `UUID` | **string* | :heavy_minus_sign: | N/A | 322a231a-b7f7-49f5-920f-14c61199cd30 |
|
||||
| `UpdatedAt` | **int* | :heavy_minus_sign: | N/A | 1705615634 |
|
||||
| `CreatedAt` | **int* | :heavy_minus_sign: | N/A | 1654131312 |
|
||||
| `ScannedAt` | **int* | :heavy_minus_sign: | N/A | 1705615584 |
|
||||
| `Content` | **bool* | :heavy_minus_sign: | N/A | true |
|
||||
| `Directory` | **bool* | :heavy_minus_sign: | N/A | true |
|
||||
| `ContentChangedAt` | **int* | :heavy_minus_sign: | N/A | 3192854 |
|
||||
| `Hidden` | **int* | :heavy_minus_sign: | N/A | 0 |
|
||||
| `Location` | [][operations.Location](../../models/operations/location.md) | :heavy_minus_sign: | N/A | [{"id":1,"path":"/movies"}] |
|
||||
| Field | Type | Required | Description | Example |
|
||||
| ------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------ |
|
||||
| `AllowSync` | **bool* | :heavy_minus_sign: | N/A | true |
|
||||
| `Art` | **string* | :heavy_minus_sign: | N/A | /:/resources/movie-fanart.jpg |
|
||||
| `Composite` | **string* | :heavy_minus_sign: | N/A | /library/sections/1/composite/1705615584 |
|
||||
| `Filters` | **bool* | :heavy_minus_sign: | N/A | true |
|
||||
| `Refreshing` | **bool* | :heavy_minus_sign: | N/A | false |
|
||||
| `Thumb` | **string* | :heavy_minus_sign: | N/A | /:/resources/movie.png |
|
||||
| `Key` | **string* | :heavy_minus_sign: | N/A | 1 |
|
||||
| `Type` | **string* | :heavy_minus_sign: | N/A | movie |
|
||||
| `Title` | **string* | :heavy_minus_sign: | N/A | Movies |
|
||||
| `Agent` | **string* | :heavy_minus_sign: | N/A | tv.plex.agents.movie |
|
||||
| `Scanner` | **string* | :heavy_minus_sign: | N/A | Plex Movie |
|
||||
| `Language` | **string* | :heavy_minus_sign: | N/A | en-US |
|
||||
| `UUID` | **string* | :heavy_minus_sign: | N/A | 322a231a-b7f7-49f5-920f-14c61199cd30 |
|
||||
| `UpdatedAt` | **int* | :heavy_minus_sign: | N/A | 1705615634 |
|
||||
| `CreatedAt` | **int* | :heavy_minus_sign: | N/A | 1654131312 |
|
||||
| `ScannedAt` | **int* | :heavy_minus_sign: | N/A | 1705615584 |
|
||||
| `Content` | **bool* | :heavy_minus_sign: | N/A | true |
|
||||
| `Directory` | **bool* | :heavy_minus_sign: | N/A | true |
|
||||
| `ContentChangedAt` | **int* | :heavy_minus_sign: | N/A | 3192854 |
|
||||
| `Hidden` | **int* | :heavy_minus_sign: | N/A | 0 |
|
||||
| `Location` | [][operations.GetLibrariesLocation](../../models/operations/getlibrarieslocation.md) | :heavy_minus_sign: | N/A | [{"id":1,"path":"/movies"}] |
|
||||
9
docs/models/operations/getlibrarieslocation.md
Normal file
9
docs/models/operations/getlibrarieslocation.md
Normal file
@@ -0,0 +1,9 @@
|
||||
# GetLibrariesLocation
|
||||
|
||||
|
||||
## Fields
|
||||
|
||||
| Field | Type | Required | Description | Example |
|
||||
| ------------------ | ------------------ | ------------------ | ------------------ | ------------------ |
|
||||
| `ID` | **int* | :heavy_minus_sign: | N/A | 1 |
|
||||
| `Path` | **string* | :heavy_minus_sign: | N/A | /movies |
|
||||
File diff suppressed because one or more lines are too long
@@ -27,6 +27,13 @@
|
||||
| `ChapterSource` | **string* | :heavy_minus_sign: | N/A | media |
|
||||
| `PrimaryExtraKey` | **string* | :heavy_minus_sign: | N/A | /library/metadata/58684 |
|
||||
| `RatingImage` | **string* | :heavy_minus_sign: | N/A | rottentomatoes://image.rating.ripe |
|
||||
| `GrandparentRatingKey` | **string* | :heavy_minus_sign: | N/A | 66 |
|
||||
| `GrandparentGUID` | **string* | :heavy_minus_sign: | N/A | plex://show/5d9c081b170e24001f2a7be4 |
|
||||
| `GrandparentKey` | **string* | :heavy_minus_sign: | N/A | /library/metadata/66 |
|
||||
| `GrandparentTitle` | **string* | :heavy_minus_sign: | N/A | Caprica |
|
||||
| `GrandparentThumb` | **string* | :heavy_minus_sign: | N/A | /library/metadata/66/thumb/1705716261 |
|
||||
| `GrandparentArt` | **string* | :heavy_minus_sign: | N/A | /library/metadata/66/art/1705716261 |
|
||||
| `GrandparentTheme` | **string* | :heavy_minus_sign: | N/A | /library/metadata/66/theme/1705716261 |
|
||||
| `Media` | [][operations.GetLibraryItemsMedia](../../models/operations/getlibraryitemsmedia.md) | :heavy_minus_sign: | N/A | [{"Part":[{"container":"mkv","duration":11558112,"file":"/movies/Avatar The Way of Water (2022)/Avatar.The.Way.of.Water.2022.2160p.WEB-DL.DDP5.1.Atmos.DV.HDR10.HEVC-CMRG.mkv","id":119542,"key":"/library/parts/119542/1680457526/file.mkv","size":36158371307,"videoProfile":"main 10"}],"aspectRatio":1.85,"audioChannels":6,"audioCodec":"eac3","bitrate":25025,"container":"mkv","duration":11558112,"height":2072,"id":119534,"videoCodec":"hevc","videoFrameRate":"24p","videoProfile":"main 10","videoResolution":"4k","width":3840}] |
|
||||
| `Genre` | [][operations.GetLibraryItemsGenre](../../models/operations/getlibraryitemsgenre.md) | :heavy_minus_sign: | N/A | [{"tag":"Adventure"}] |
|
||||
| `Country` | [][operations.GetLibraryItemsCountry](../../models/operations/getlibraryitemscountry.md) | :heavy_minus_sign: | N/A | [{"tag":"United States of America"}] |
|
||||
@@ -38,4 +45,20 @@
|
||||
| `LastViewedAt` | **int* | :heavy_minus_sign: | N/A | 1682752242 |
|
||||
| `OriginalTitle` | **string* | :heavy_minus_sign: | N/A | 映画 ブラッククローバー 魔法帝の剣 |
|
||||
| `ViewOffset` | **int* | :heavy_minus_sign: | N/A | 5222500 |
|
||||
| `SkipCount` | **int* | :heavy_minus_sign: | N/A | 1 |
|
||||
| `SkipCount` | **int* | :heavy_minus_sign: | N/A | 1 |
|
||||
| `Index` | **int* | :heavy_minus_sign: | N/A | 1 |
|
||||
| `Theme` | **string* | :heavy_minus_sign: | N/A | /library/metadata/1/theme/1705636920 |
|
||||
| `LeafCount` | **int* | :heavy_minus_sign: | N/A | 14 |
|
||||
| `ViewedLeafCount` | **int* | :heavy_minus_sign: | N/A | 0 |
|
||||
| `ChildCount` | **int* | :heavy_minus_sign: | N/A | 1 |
|
||||
| `HasPremiumExtras` | **string* | :heavy_minus_sign: | N/A | 1 |
|
||||
| `HasPremiumPrimaryExtra` | **string* | :heavy_minus_sign: | N/A | 1 |
|
||||
| `ParentRatingKey` | **string* | :heavy_minus_sign: | N/A | 66 |
|
||||
| `ParentGUID` | **string* | :heavy_minus_sign: | N/A | plex://show/5d9c081b170e24001f2a7be4 |
|
||||
| `ParentStudio` | **string* | :heavy_minus_sign: | N/A | UCP |
|
||||
| `ParentKey` | **string* | :heavy_minus_sign: | N/A | /library/metadata/66 |
|
||||
| `ParentTitle` | **string* | :heavy_minus_sign: | N/A | Caprica |
|
||||
| `ParentIndex` | **int* | :heavy_minus_sign: | N/A | 1 |
|
||||
| `ParentYear` | **int* | :heavy_minus_sign: | N/A | 2010 |
|
||||
| `ParentThumb` | **string* | :heavy_minus_sign: | N/A | /library/metadata/66/thumb/1705716261 |
|
||||
| `ParentTheme` | **string* | :heavy_minus_sign: | N/A | /library/metadata/66/theme/1705716261 |
|
||||
9
docs/models/operations/getpinrequest.md
Normal file
9
docs/models/operations/getpinrequest.md
Normal file
@@ -0,0 +1,9 @@
|
||||
# GetPinRequest
|
||||
|
||||
|
||||
## Fields
|
||||
|
||||
| Field | Type | Required | Description |
|
||||
| --------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| `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/> |
|
||||
11
docs/models/operations/getpinresponse.md
Normal file
11
docs/models/operations/getpinresponse.md
Normal file
@@ -0,0 +1,11 @@
|
||||
# GetPinResponse
|
||||
|
||||
|
||||
## Fields
|
||||
|
||||
| Field | Type | Required | Description |
|
||||
| ------------------------------------------------------------------------------- | ------------------------------------------------------------------------------- | ------------------------------------------------------------------------------- | ------------------------------------------------------------------------------- |
|
||||
| `ContentType` | *string* | :heavy_check_mark: | HTTP response content type for this operation |
|
||||
| `StatusCode` | *int* | :heavy_check_mark: | HTTP response status code for this operation |
|
||||
| `RawResponse` | [*http.Response](https://pkg.go.dev/net/http#Response) | :heavy_check_mark: | Raw HTTP response; suitable for custom response parsing |
|
||||
| `Object` | [*operations.GetPinResponseBody](../../models/operations/getpinresponsebody.md) | :heavy_minus_sign: | The Pin |
|
||||
21
docs/models/operations/getpinresponsebody.md
Normal file
21
docs/models/operations/getpinresponsebody.md
Normal file
@@ -0,0 +1,21 @@
|
||||
# GetPinResponseBody
|
||||
|
||||
The Pin
|
||||
|
||||
|
||||
## Fields
|
||||
|
||||
| Field | Type | Required | Description | Example |
|
||||
| --------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| `ID` | **float64* | :heavy_minus_sign: | PinID for use with authentication | 1272322473 |
|
||||
| `Code` | **string* | :heavy_minus_sign: | N/A | 3patfx1a78ukcbr7x0n9bl26t |
|
||||
| `Product` | **string* | :heavy_minus_sign: | N/A | Plex Web |
|
||||
| `Trusted` | **bool* | :heavy_minus_sign: | N/A | |
|
||||
| `Qr` | **string* | :heavy_minus_sign: | a link to a QR code hosted on plex.tv <br/>The QR code redirects to the relevant `plex.tv/link` authentication page<br/>Which then prompts the user for the 4 Digit Link Pin<br/> | https://plex.tv/api/v2/pins/qr/3patfx1a78ukcbr7x0n9bl26t |
|
||||
| `ClientIdentifier` | **string* | :heavy_minus_sign: | N/A | Postman |
|
||||
| `Location` | [*operations.Location](../../models/operations/location.md) | :heavy_minus_sign: | N/A | |
|
||||
| `ExpiresIn` | **float64* | :heavy_minus_sign: | N/A | 1800 |
|
||||
| `CreatedAt` | [*time.Time](https://pkg.go.dev/time#Time) | :heavy_minus_sign: | N/A | 2023-04-12 17:00:03 +0000 UTC |
|
||||
| `ExpiresAt` | [*time.Time](https://pkg.go.dev/time#Time) | :heavy_minus_sign: | N/A | 2023-04-12 17:30:03 +0000 UTC |
|
||||
| `AuthToken` | **string* | :heavy_minus_sign: | N/A | |
|
||||
| `NewRegistration` | **string* | :heavy_minus_sign: | N/A | |
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
## Fields
|
||||
|
||||
| Field | Type | Required | Description | Example |
|
||||
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
||||
| `Size` | **int* | :heavy_minus_sign: | N/A | 161 |
|
||||
| `Setting` | [][operations.Setting](../../models/operations/setting.md) | :heavy_minus_sign: | N/A | [{"advanced":false,"default":"","group":"general","hidden":false,"id":"FriendlyName","label":"Friendly name","summary":"This name will be used to identify this media server to other computers on your network. If you leave it blank, your computer's name will be used instead.","type":"text","value":"Hera"},{"advanced":false,"default":3600,"enumValues":"900:every 15 minutes\|1800:every 30 minutes\|3600:hourly\|7200:every 2 hours\|21600:every 6 hours\|43200:every 12 hours\|86400:daily","group":"library","hidden":false,"id":"ScheduledLibraryUpdateInterval","label":"Library scan interval","summary":"","type":"int","value":3600}] |
|
||||
| Field | Type | Required | Description | Example |
|
||||
| ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| `Size` | **int* | :heavy_minus_sign: | N/A | 161 |
|
||||
| `Setting` | [][operations.Setting](../../models/operations/setting.md) | :heavy_minus_sign: | N/A | [{"advanced":false,"default":false,"enumValues":"1:admin only\|2:everyone","group":"","hidden":true,"id":"EnableDatabaseTrace","label":"","summary":"","type":"bool","value":false}] |
|
||||
12
docs/models/operations/getstatisticsdevice.md
Normal file
12
docs/models/operations/getstatisticsdevice.md
Normal file
@@ -0,0 +1,12 @@
|
||||
# GetStatisticsDevice
|
||||
|
||||
|
||||
## Fields
|
||||
|
||||
| Field | Type | Required | Description | Example |
|
||||
| -------------------------------- | -------------------------------- | -------------------------------- | -------------------------------- | -------------------------------- |
|
||||
| `ID` | **int* | :heavy_minus_sign: | N/A | 208 |
|
||||
| `Name` | **string* | :heavy_minus_sign: | N/A | Roku Express |
|
||||
| `Platform` | **string* | :heavy_minus_sign: | N/A | Roku |
|
||||
| `ClientIdentifier` | **string* | :heavy_minus_sign: | N/A | 793095d235660625108ef785cc7646e9 |
|
||||
| `CreatedAt` | **int* | :heavy_minus_sign: | N/A | 1706470556 |
|
||||
@@ -1,17 +1,11 @@
|
||||
# Two
|
||||
# GetStatisticsMediaContainer
|
||||
|
||||
|
||||
## Fields
|
||||
|
||||
| Field | Type | Required | Description | Example |
|
||||
| ------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------ |
|
||||
| `ID` | **string* | :heavy_minus_sign: | N/A | ScheduledLibraryUpdateInterval |
|
||||
| `Label` | **string* | :heavy_minus_sign: | N/A | Library scan interval |
|
||||
| `Summary` | **string* | :heavy_minus_sign: | N/A | |
|
||||
| `Type` | **string* | :heavy_minus_sign: | N/A | int |
|
||||
| `Default` | **int* | :heavy_minus_sign: | N/A | 3600 |
|
||||
| `Value` | **int* | :heavy_minus_sign: | N/A | 3600 |
|
||||
| `Hidden` | **bool* | :heavy_minus_sign: | N/A | false |
|
||||
| `Advanced` | **bool* | :heavy_minus_sign: | N/A | false |
|
||||
| `Group` | **string* | :heavy_minus_sign: | N/A | library |
|
||||
| `EnumValues` | **string* | :heavy_minus_sign: | N/A | 900:every 15 minutes\|1800:every 30 minutes\|3600:hourly\|7200:every 2 hours\|21600:every 6 hours\|43200:every 12 hours\|86400:daily |
|
||||
| Field | Type | Required | Description | Example |
|
||||
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| `Size` | **int* | :heavy_minus_sign: | N/A | 5497 |
|
||||
| `Device` | [][operations.GetStatisticsDevice](../../models/operations/getstatisticsdevice.md) | :heavy_minus_sign: | N/A | [{"clientIdentifier":"793095d235660625108ef785cc7646e9","createdAt":1706470556,"id":208,"name":"Roku Express","platform":"Roku"}] |
|
||||
| `Account` | [][operations.Account](../../models/operations/account.md) | :heavy_minus_sign: | N/A | [{"autoSelectAudio":true,"defaultAudioLanguage":"en","defaultSubtitleLanguage":"en","id":238960586,"key":"/accounts/238960586","name":"Diane","subtitleMode":1,"thumb":"https://plex.tv/users/50d83634246da1de/avatar?c=1707110967"}] |
|
||||
| `StatisticsMedia` | [][operations.StatisticsMedia](../../models/operations/statisticsmedia.md) | :heavy_minus_sign: | N/A | [{"accountID":1,"at":1707141600,"count":1,"deviceID":13,"duration":1555,"metadataType":4,"timespan":4}] |
|
||||
8
docs/models/operations/getstatisticsrequest.md
Normal file
8
docs/models/operations/getstatisticsrequest.md
Normal file
@@ -0,0 +1,8 @@
|
||||
# GetStatisticsRequest
|
||||
|
||||
|
||||
## Fields
|
||||
|
||||
| Field | Type | Required | Description |
|
||||
| ----------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------- |
|
||||
| `Timespan` | **int64* | :heavy_minus_sign: | The timespan to retrieve statistics for<br/>the exact meaning of this parameter is not known<br/> |
|
||||
11
docs/models/operations/getstatisticsresponse.md
Normal file
11
docs/models/operations/getstatisticsresponse.md
Normal file
@@ -0,0 +1,11 @@
|
||||
# GetStatisticsResponse
|
||||
|
||||
|
||||
## Fields
|
||||
|
||||
| Field | Type | Required | Description |
|
||||
| --------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------- |
|
||||
| `ContentType` | *string* | :heavy_check_mark: | HTTP response content type for this operation |
|
||||
| `StatusCode` | *int* | :heavy_check_mark: | HTTP response status code for this operation |
|
||||
| `RawResponse` | [*http.Response](https://pkg.go.dev/net/http#Response) | :heavy_check_mark: | Raw HTTP response; suitable for custom response parsing |
|
||||
| `Object` | [*operations.GetStatisticsResponseBody](../../models/operations/getstatisticsresponsebody.md) | :heavy_minus_sign: | Media Statistics |
|
||||
10
docs/models/operations/getstatisticsresponsebody.md
Normal file
10
docs/models/operations/getstatisticsresponsebody.md
Normal file
@@ -0,0 +1,10 @@
|
||||
# GetStatisticsResponseBody
|
||||
|
||||
Media Statistics
|
||||
|
||||
|
||||
## Fields
|
||||
|
||||
| Field | Type | Required | Description |
|
||||
| ------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------- |
|
||||
| `MediaContainer` | [*operations.GetStatisticsMediaContainer](../../models/operations/getstatisticsmediacontainer.md) | :heavy_minus_sign: | N/A |
|
||||
9
docs/models/operations/gettokenrequest.md
Normal file
9
docs/models/operations/gettokenrequest.md
Normal file
@@ -0,0 +1,9 @@
|
||||
# GetTokenRequest
|
||||
|
||||
|
||||
## Fields
|
||||
|
||||
| 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<br/>This is used to track the client application and its usage<br/>(UUID, serial number, or other number unique per device)<br/> |
|
||||
10
docs/models/operations/gettokenresponse.md
Normal file
10
docs/models/operations/gettokenresponse.md
Normal file
@@ -0,0 +1,10 @@
|
||||
# GetTokenResponse
|
||||
|
||||
|
||||
## Fields
|
||||
|
||||
| Field | Type | Required | Description |
|
||||
| ------------------------------------------------------- | ------------------------------------------------------- | ------------------------------------------------------- | ------------------------------------------------------- |
|
||||
| `ContentType` | *string* | :heavy_check_mark: | HTTP response content type for this operation |
|
||||
| `StatusCode` | *int* | :heavy_check_mark: | HTTP response status code for this operation |
|
||||
| `RawResponse` | [*http.Response](https://pkg.go.dev/net/http#Response) | :heavy_check_mark: | Raw HTTP response; suitable for custom response parsing |
|
||||
10
docs/models/operations/gettransienttokenqueryparamtype.md
Normal file
10
docs/models/operations/gettransienttokenqueryparamtype.md
Normal file
@@ -0,0 +1,10 @@
|
||||
# GetTransientTokenQueryParamType
|
||||
|
||||
`delegation` - This is the only supported `type` parameter.
|
||||
|
||||
|
||||
## Values
|
||||
|
||||
| Name | Value |
|
||||
| ------------------------------------------- | ------------------------------------------- |
|
||||
| `GetTransientTokenQueryParamTypeDelegation` | delegation |
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
## Fields
|
||||
|
||||
| Field | Type | Required | Description |
|
||||
| ---------------------------------------------------------------------- | ---------------------------------------------------------------------- | ---------------------------------------------------------------------- | ---------------------------------------------------------------------- |
|
||||
| `Type` | [operations.QueryParamType](../../models/operations/queryparamtype.md) | :heavy_check_mark: | `delegation` - This is the only supported `type` parameter. |
|
||||
| `Scope` | [operations.Scope](../../models/operations/scope.md) | :heavy_check_mark: | `all` - This is the only supported `scope` parameter. |
|
||||
| Field | Type | Required | Description |
|
||||
| -------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------- |
|
||||
| `Type` | [operations.GetTransientTokenQueryParamType](../../models/operations/gettransienttokenqueryparamtype.md) | :heavy_check_mark: | `delegation` - This is the only supported `type` parameter. |
|
||||
| `Scope` | [operations.Scope](../../models/operations/scope.md) | :heavy_check_mark: | `all` - This is the only supported `scope` parameter. |
|
||||
@@ -3,7 +3,15 @@
|
||||
|
||||
## Fields
|
||||
|
||||
| Field | Type | Required | Description | Example |
|
||||
| ------------------ | ------------------ | ------------------ | ------------------ | ------------------ |
|
||||
| `ID` | **int* | :heavy_minus_sign: | N/A | 1 |
|
||||
| `Path` | **string* | :heavy_minus_sign: | N/A | /movies |
|
||||
| Field | Type | Required | Description | Example |
|
||||
| ---------------------------- | ---------------------------- | ---------------------------- | ---------------------------- | ---------------------------- |
|
||||
| `Code` | **string* | :heavy_minus_sign: | N/A | US |
|
||||
| `EuropeanUnionMember` | **bool* | :heavy_minus_sign: | N/A | |
|
||||
| `ContinentCode` | **string* | :heavy_minus_sign: | N/A | NA |
|
||||
| `Country` | **string* | :heavy_minus_sign: | N/A | United States |
|
||||
| `City` | **string* | :heavy_minus_sign: | N/A | Austin |
|
||||
| `TimeZone` | **string* | :heavy_minus_sign: | N/A | America/Chicago |
|
||||
| `PostalCode` | **float64* | :heavy_minus_sign: | N/A | 78732 |
|
||||
| `InPrivacyRestrictedCountry` | **bool* | :heavy_minus_sign: | N/A | |
|
||||
| `Subdivisions` | **string* | :heavy_minus_sign: | N/A | Texas |
|
||||
| `Coordinates` | **string* | :heavy_minus_sign: | N/A | 30.3768 -97.8935 |
|
||||
@@ -1,16 +0,0 @@
|
||||
# One
|
||||
|
||||
|
||||
## Fields
|
||||
|
||||
| Field | Type | Required | Description | Example |
|
||||
| ---------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| `ID` | **string* | :heavy_minus_sign: | N/A | FriendlyName |
|
||||
| `Label` | **string* | :heavy_minus_sign: | N/A | Friendly name |
|
||||
| `Summary` | **string* | :heavy_minus_sign: | N/A | This name will be used to identify this media server to other computers on your network. If you leave it blank, your computer's name will be used instead. |
|
||||
| `Type` | **string* | :heavy_minus_sign: | N/A | text |
|
||||
| `Default` | **string* | :heavy_minus_sign: | N/A | |
|
||||
| `Value` | **string* | :heavy_minus_sign: | N/A | Hera |
|
||||
| `Hidden` | **bool* | :heavy_minus_sign: | N/A | false |
|
||||
| `Advanced` | **bool* | :heavy_minus_sign: | N/A | false |
|
||||
| `Group` | **string* | :heavy_minus_sign: | N/A | general |
|
||||
37
docs/models/operations/option.md
Normal file
37
docs/models/operations/option.md
Normal file
@@ -0,0 +1,37 @@
|
||||
## Options
|
||||
|
||||
### WithServerURL
|
||||
|
||||
WithServerURL allows providing an alternative server URL.
|
||||
|
||||
```go
|
||||
operations.WithServerURL("http://api.example.com")
|
||||
```
|
||||
|
||||
## WithTemplatedServerURL
|
||||
|
||||
WithTemplatedServerURL allows providing an alternative server URL with templated parameters.
|
||||
|
||||
```go
|
||||
operations.WithTemplatedServerURL("http://{host}:{port}", map[string]string{
|
||||
"host": "api.example.com",
|
||||
"port": "8080",
|
||||
})
|
||||
```
|
||||
|
||||
### WithRetries
|
||||
|
||||
WithRetries allows customizing the default retry configuration. Only usable with methods that mention they support retries.
|
||||
|
||||
```go
|
||||
operations.WithRetries(utils.RetryConfig{
|
||||
Strategy: "backoff",
|
||||
Backoff: utils.BackoffStrategy{
|
||||
InitialInterval: 500 * time.Millisecond,
|
||||
MaxInterval: 60 * time.Second,
|
||||
Exponent: 1.5,
|
||||
MaxElapsedTime: 5 * time.Minute,
|
||||
},
|
||||
RetryConnectionErrors: true,
|
||||
})
|
||||
```
|
||||
@@ -1,10 +1,12 @@
|
||||
# QueryParamType
|
||||
|
||||
`delegation` - This is the only supported `type` parameter.
|
||||
type of playlist to create
|
||||
|
||||
|
||||
## Values
|
||||
|
||||
| Name | Value |
|
||||
| -------------------------- | -------------------------- |
|
||||
| `QueryParamTypeDelegation` | delegation |
|
||||
| Name | Value |
|
||||
| --------------------- | --------------------- |
|
||||
| `QueryParamTypeAudio` | audio |
|
||||
| `QueryParamTypeVideo` | video |
|
||||
| `QueryParamTypePhoto` | photo |
|
||||
20
docs/models/operations/searchlibrarymediacontainer.md
Normal file
20
docs/models/operations/searchlibrarymediacontainer.md
Normal file
File diff suppressed because one or more lines are too long
27
docs/models/operations/searchlibrarymetadata.md
Normal file
27
docs/models/operations/searchlibrarymetadata.md
Normal file
@@ -0,0 +1,27 @@
|
||||
# SearchLibraryMetadata
|
||||
|
||||
|
||||
## Fields
|
||||
|
||||
| Field | Type | Required | Description | Example |
|
||||
| -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| `RatingKey` | **string* | :heavy_minus_sign: | N/A | 2 |
|
||||
| `Key` | **string* | :heavy_minus_sign: | N/A | /library/metadata/2/children |
|
||||
| `ParentRatingKey` | **string* | :heavy_minus_sign: | N/A | 1 |
|
||||
| `GUID` | **string* | :heavy_minus_sign: | N/A | plex://season/602e67e766dfdb002c0a1b5b |
|
||||
| `ParentGUID` | **string* | :heavy_minus_sign: | N/A | plex://show/5d9c086c7d06d9001ffd27aa |
|
||||
| `ParentStudio` | **string* | :heavy_minus_sign: | N/A | Mutant Enemy Productions |
|
||||
| `Type` | **string* | :heavy_minus_sign: | N/A | season |
|
||||
| `Title` | **string* | :heavy_minus_sign: | N/A | Season 1 |
|
||||
| `ParentKey` | **string* | :heavy_minus_sign: | N/A | /library/metadata/1 |
|
||||
| `ParentTitle` | **string* | :heavy_minus_sign: | N/A | Firefly |
|
||||
| `Summary` | **string* | :heavy_minus_sign: | N/A | Captain Malcolm 'Mal' Reynolds is a former galactic war veteran who is the captain of the transport ship "Serenity". Mal and his crew, ensign Zoe Alleyne Washburne; Zoe's husband, pilot Hoban 'Wash' Washburne; muscular mercenary Jayne Cobb; young mechanic Kaylee Frye; former Alliance medical officer Simon Tam; his disturbed teenage sister River (both on the run from the interplanetary government "The Alliance"); the beautiful courtesan Inara Serra; and preacher Shepherd Book do any jobs, legal or illegal, they can find as the Serenity crew travels across the outskirts of outer space. |
|
||||
| `Index` | **int* | :heavy_minus_sign: | N/A | 1 |
|
||||
| `ParentIndex` | **int* | :heavy_minus_sign: | N/A | 1 |
|
||||
| `ParentYear` | **int* | :heavy_minus_sign: | N/A | 2002 |
|
||||
| `Thumb` | **string* | :heavy_minus_sign: | N/A | /library/metadata/2/thumb/1705636920 |
|
||||
| `Art` | **string* | :heavy_minus_sign: | N/A | /library/metadata/1/art/1705636920 |
|
||||
| `ParentThumb` | **string* | :heavy_minus_sign: | N/A | /library/metadata/1/thumb/1705636920 |
|
||||
| `ParentTheme` | **string* | :heavy_minus_sign: | N/A | /library/metadata/1/theme/1705636920 |
|
||||
| `AddedAt` | **int* | :heavy_minus_sign: | N/A | 1705636916 |
|
||||
| `UpdatedAt` | **int* | :heavy_minus_sign: | N/A | 1705636920 |
|
||||
9
docs/models/operations/searchlibraryrequest.md
Normal file
9
docs/models/operations/searchlibraryrequest.md
Normal file
@@ -0,0 +1,9 @@
|
||||
# SearchLibraryRequest
|
||||
|
||||
|
||||
## Fields
|
||||
|
||||
| Field | Type | Required | Description |
|
||||
| -------------------------------------------------- | -------------------------------------------------- | -------------------------------------------------- | -------------------------------------------------- |
|
||||
| `SectionID` | *int64* | :heavy_check_mark: | the Id of the library to query |
|
||||
| `Type` | [operations.Type](../../models/operations/type.md) | :heavy_check_mark: | Plex content type to search for |
|
||||
11
docs/models/operations/searchlibraryresponse.md
Normal file
11
docs/models/operations/searchlibraryresponse.md
Normal file
@@ -0,0 +1,11 @@
|
||||
# SearchLibraryResponse
|
||||
|
||||
|
||||
## Fields
|
||||
|
||||
| Field | Type | Required | Description |
|
||||
| --------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------- |
|
||||
| `ContentType` | *string* | :heavy_check_mark: | HTTP response content type for this operation |
|
||||
| `StatusCode` | *int* | :heavy_check_mark: | HTTP response status code for this operation |
|
||||
| `RawResponse` | [*http.Response](https://pkg.go.dev/net/http#Response) | :heavy_check_mark: | Raw HTTP response; suitable for custom response parsing |
|
||||
| `Object` | [*operations.SearchLibraryResponseBody](../../models/operations/searchlibraryresponsebody.md) | :heavy_minus_sign: | The contents of the library by section and type |
|
||||
10
docs/models/operations/searchlibraryresponsebody.md
Normal file
10
docs/models/operations/searchlibraryresponsebody.md
Normal file
@@ -0,0 +1,10 @@
|
||||
# SearchLibraryResponseBody
|
||||
|
||||
The contents of the library by section and type
|
||||
|
||||
|
||||
## Fields
|
||||
|
||||
| Field | Type | Required | Description |
|
||||
| ------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------- |
|
||||
| `MediaContainer` | [*operations.SearchLibraryMediaContainer](../../models/operations/searchlibrarymediacontainer.md) | :heavy_minus_sign: | N/A |
|
||||
@@ -1,17 +1,17 @@
|
||||
# Setting
|
||||
|
||||
|
||||
## Supported Types
|
||||
|
||||
### One
|
||||
|
||||
```go
|
||||
setting := operations.CreateSettingOne(operations.One{/* values here */})
|
||||
```
|
||||
|
||||
### Two
|
||||
|
||||
```go
|
||||
setting := operations.CreateSettingTwo(operations.Two{/* values here */})
|
||||
```
|
||||
## Fields
|
||||
|
||||
| Field | Type | Required | Description | Example |
|
||||
| ----------------------- | ----------------------- | ----------------------- | ----------------------- | ----------------------- |
|
||||
| `ID` | **string* | :heavy_minus_sign: | N/A | EnableDatabaseTrace |
|
||||
| `Label` | **string* | :heavy_minus_sign: | N/A | |
|
||||
| `Summary` | **string* | :heavy_minus_sign: | N/A | |
|
||||
| `Type` | **string* | :heavy_minus_sign: | N/A | bool |
|
||||
| `Default` | **bool* | :heavy_minus_sign: | N/A | false |
|
||||
| `Value` | **bool* | :heavy_minus_sign: | N/A | false |
|
||||
| `Hidden` | **bool* | :heavy_minus_sign: | N/A | true |
|
||||
| `Advanced` | **bool* | :heavy_minus_sign: | N/A | false |
|
||||
| `Group` | **string* | :heavy_minus_sign: | N/A | |
|
||||
| `EnumValues` | **string* | :heavy_minus_sign: | N/A | 1:admin only\|2:everyone |
|
||||
14
docs/models/operations/statisticsmedia.md
Normal file
14
docs/models/operations/statisticsmedia.md
Normal file
@@ -0,0 +1,14 @@
|
||||
# StatisticsMedia
|
||||
|
||||
|
||||
## Fields
|
||||
|
||||
| Field | Type | Required | Description | Example |
|
||||
| ------------------ | ------------------ | ------------------ | ------------------ | ------------------ |
|
||||
| `AccountID` | **int* | :heavy_minus_sign: | N/A | 1 |
|
||||
| `DeviceID` | **int* | :heavy_minus_sign: | N/A | 13 |
|
||||
| `Timespan` | **int* | :heavy_minus_sign: | N/A | 4 |
|
||||
| `At` | **int* | :heavy_minus_sign: | N/A | 1707141600 |
|
||||
| `MetadataType` | **int* | :heavy_minus_sign: | N/A | 4 |
|
||||
| `Count` | **int* | :heavy_minus_sign: | N/A | 1 |
|
||||
| `Duration` | **int* | :heavy_minus_sign: | N/A | 1555 |
|
||||
@@ -5,25 +5,24 @@ A key representing a specific tag within the section.
|
||||
|
||||
## Values
|
||||
|
||||
| Name | Value |
|
||||
| --------------------- | --------------------- |
|
||||
| `TagAll` | all |
|
||||
| `TagUnwatched` | unwatched |
|
||||
| `TagNewest` | newest |
|
||||
| `TagRecentlyAdded` | recentlyAdded |
|
||||
| `TagRecentlyViewed` | recentlyViewed |
|
||||
| `TagOnDeck` | onDeck |
|
||||
| `TagCollection` | collection |
|
||||
| `TagEdition` | edition |
|
||||
| `TagGenre` | genre |
|
||||
| `TagYear` | year |
|
||||
| `TagDecade` | decade |
|
||||
| `TagDirector` | director |
|
||||
| `TagActor` | actor |
|
||||
| `TagCountry` | country |
|
||||
| `TagContentRating` | contentRating |
|
||||
| `TagRating` | rating |
|
||||
| `TagResolution` | resolution |
|
||||
| `TagFirstCharacter` | firstCharacter |
|
||||
| `TagFolder` | folder |
|
||||
| `TagSearchTypeEqual1` | search?type=1 |
|
||||
| Name | Value |
|
||||
| ------------------- | ------------------- |
|
||||
| `TagAll` | all |
|
||||
| `TagUnwatched` | unwatched |
|
||||
| `TagNewest` | newest |
|
||||
| `TagRecentlyAdded` | recentlyAdded |
|
||||
| `TagRecentlyViewed` | recentlyViewed |
|
||||
| `TagOnDeck` | onDeck |
|
||||
| `TagCollection` | collection |
|
||||
| `TagEdition` | edition |
|
||||
| `TagGenre` | genre |
|
||||
| `TagYear` | year |
|
||||
| `TagDecade` | decade |
|
||||
| `TagDirector` | director |
|
||||
| `TagActor` | actor |
|
||||
| `TagCountry` | country |
|
||||
| `TagContentRating` | contentRating |
|
||||
| `TagRating` | rating |
|
||||
| `TagResolution` | resolution |
|
||||
| `TagFirstCharacter` | firstCharacter |
|
||||
| `TagFolder` | folder |
|
||||
@@ -1,12 +1,13 @@
|
||||
# Type
|
||||
|
||||
type of playlist to create
|
||||
Plex content type to search for
|
||||
|
||||
|
||||
## Values
|
||||
|
||||
| Name | Value |
|
||||
| ----------- | ----------- |
|
||||
| `TypeAudio` | audio |
|
||||
| `TypeVideo` | video |
|
||||
| `TypePhoto` | photo |
|
||||
| `TypeOne` | 1 |
|
||||
| `TypeTwo` | 2 |
|
||||
| `TypeThree` | 3 |
|
||||
| `TypeFour` | 4 |
|
||||
10
docs/models/sdkerrors/getpinerrors.md
Normal file
10
docs/models/sdkerrors/getpinerrors.md
Normal file
@@ -0,0 +1,10 @@
|
||||
# GetPinErrors
|
||||
|
||||
|
||||
## Fields
|
||||
|
||||
| Field | Type | Required | Description | Example |
|
||||
| ----------------------------------- | ----------------------------------- | ----------------------------------- | ----------------------------------- | ----------------------------------- |
|
||||
| `Code` | **float64* | :heavy_minus_sign: | N/A | 1000 |
|
||||
| `Message` | **string* | :heavy_minus_sign: | N/A | X-Plex-Client-Identifier is missing |
|
||||
| `Status` | **float64* | :heavy_minus_sign: | N/A | 400 |
|
||||
11
docs/models/sdkerrors/getpinresponsebody.md
Normal file
11
docs/models/sdkerrors/getpinresponsebody.md
Normal file
@@ -0,0 +1,11 @@
|
||||
# GetPinResponseBody
|
||||
|
||||
X-Plex-Client-Identifier is missing
|
||||
|
||||
|
||||
## Fields
|
||||
|
||||
| Field | Type | Required | Description |
|
||||
| ------------------------------------------------------------------ | ------------------------------------------------------------------ | ------------------------------------------------------------------ | ------------------------------------------------------------------ |
|
||||
| `Errors` | [][sdkerrors.GetPinErrors](../../models/sdkerrors/getpinerrors.md) | :heavy_minus_sign: | N/A |
|
||||
| `RawResponse` | [*http.Response](https://pkg.go.dev/net/http#Response) | :heavy_minus_sign: | Raw HTTP response; suitable for custom response parsing |
|
||||
10
docs/models/sdkerrors/getstatisticserrors.md
Normal file
10
docs/models/sdkerrors/getstatisticserrors.md
Normal file
@@ -0,0 +1,10 @@
|
||||
# GetStatisticsErrors
|
||||
|
||||
|
||||
## Fields
|
||||
|
||||
| Field | Type | Required | Description | Example |
|
||||
| ------------------------------- | ------------------------------- | ------------------------------- | ------------------------------- | ------------------------------- |
|
||||
| `Code` | **float64* | :heavy_minus_sign: | N/A | 1001 |
|
||||
| `Message` | **string* | :heavy_minus_sign: | N/A | User could not be authenticated |
|
||||
| `Status` | **float64* | :heavy_minus_sign: | N/A | 401 |
|
||||
11
docs/models/sdkerrors/getstatisticsresponsebody.md
Normal file
11
docs/models/sdkerrors/getstatisticsresponsebody.md
Normal file
@@ -0,0 +1,11 @@
|
||||
# GetStatisticsResponseBody
|
||||
|
||||
Unauthorized - Returned if the X-Plex-Token is missing from the header or query.
|
||||
|
||||
|
||||
## Fields
|
||||
|
||||
| Field | Type | Required | Description |
|
||||
| -------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- |
|
||||
| `Errors` | [][sdkerrors.GetStatisticsErrors](../../models/sdkerrors/getstatisticserrors.md) | :heavy_minus_sign: | N/A |
|
||||
| `RawResponse` | [*http.Response](https://pkg.go.dev/net/http#Response) | :heavy_minus_sign: | Raw HTTP response; suitable for custom response parsing |
|
||||
10
docs/models/sdkerrors/gettokenerrors.md
Normal file
10
docs/models/sdkerrors/gettokenerrors.md
Normal file
@@ -0,0 +1,10 @@
|
||||
# GetTokenErrors
|
||||
|
||||
|
||||
## Fields
|
||||
|
||||
| Field | Type | Required | Description | Example |
|
||||
| ----------------------------------- | ----------------------------------- | ----------------------------------- | ----------------------------------- | ----------------------------------- |
|
||||
| `Code` | **float64* | :heavy_minus_sign: | N/A | 1000 |
|
||||
| `Message` | **string* | :heavy_minus_sign: | N/A | X-Plex-Client-Identifier is missing |
|
||||
| `Status` | **float64* | :heavy_minus_sign: | N/A | 400 |
|
||||
11
docs/models/sdkerrors/gettokenresponsebody.md
Normal file
11
docs/models/sdkerrors/gettokenresponsebody.md
Normal file
@@ -0,0 +1,11 @@
|
||||
# GetTokenResponseBody
|
||||
|
||||
X-Plex-Client-Identifier is missing
|
||||
|
||||
|
||||
## Fields
|
||||
|
||||
| Field | Type | Required | Description |
|
||||
| ---------------------------------------------------------------------- | ---------------------------------------------------------------------- | ---------------------------------------------------------------------- | ---------------------------------------------------------------------- |
|
||||
| `Errors` | [][sdkerrors.GetTokenErrors](../../models/sdkerrors/gettokenerrors.md) | :heavy_minus_sign: | N/A |
|
||||
| `RawResponse` | [*http.Response](https://pkg.go.dev/net/http#Response) | :heavy_minus_sign: | Raw HTTP response; suitable for custom response parsing |
|
||||
@@ -88,7 +88,7 @@ func main() {
|
||||
)
|
||||
|
||||
|
||||
var activityUUID string = "string"
|
||||
var activityUUID string = "<value>"
|
||||
|
||||
ctx := context.Background()
|
||||
res, err := s.Activities.CancelServerActivities(ctx, activityUUID)
|
||||
|
||||
@@ -34,9 +34,9 @@ func main() {
|
||||
)
|
||||
|
||||
|
||||
var count *float64 = 1262.49
|
||||
var count *float64 = plexgo.Float64(1262.49)
|
||||
|
||||
var onlyTransient *operations.OnlyTransient = operations.OnlyTransientOne
|
||||
var onlyTransient *operations.OnlyTransient = operations.OnlyTransientOne.ToPointer()
|
||||
|
||||
ctx := context.Background()
|
||||
res, err := s.Hubs.GetGlobalHubs(ctx, count, onlyTransient)
|
||||
@@ -93,9 +93,9 @@ func main() {
|
||||
|
||||
var sectionID float64 = 6728.76
|
||||
|
||||
var count *float64 = 9010.22
|
||||
var count *float64 = plexgo.Float64(9010.22)
|
||||
|
||||
var onlyTransient *operations.QueryParamOnlyTransient = operations.QueryParamOnlyTransientZero
|
||||
var onlyTransient *operations.QueryParamOnlyTransient = operations.QueryParamOnlyTransientZero.ToPointer()
|
||||
|
||||
ctx := context.Background()
|
||||
res, err := s.Hubs.GetLibraryHubs(ctx, sectionID, count, onlyTransient)
|
||||
|
||||
@@ -15,6 +15,7 @@ API Calls interacting with Plex Media Server Libraries
|
||||
* [DeleteLibrary](#deletelibrary) - Delete Library Section
|
||||
* [GetLibraryItems](#getlibraryitems) - Get Library Items
|
||||
* [RefreshLibrary](#refreshlibrary) - Refresh Library
|
||||
* [SearchLibrary](#searchlibrary) - Search Library
|
||||
* [GetMetadata](#getmetadata) - Get Items Metadata
|
||||
* [GetMetadataChildren](#getmetadatachildren) - Get Items Children
|
||||
* [GetOnDeck](#getondeck) - Get On Deck
|
||||
@@ -44,7 +45,7 @@ func main() {
|
||||
|
||||
var url_ string = "file://C:\Image.png&type=13"
|
||||
|
||||
var type_ *float64 = 4462.17
|
||||
var type_ *float64 = plexgo.Float64(4462.17)
|
||||
|
||||
ctx := context.Background()
|
||||
res, err := s.Library.GetFileHash(ctx, url_, type_)
|
||||
@@ -242,7 +243,7 @@ func main() {
|
||||
|
||||
var sectionID float64 = 1000
|
||||
|
||||
var includeDetails *operations.IncludeDetails = operations.IncludeDetailsZero
|
||||
var includeDetails *operations.IncludeDetails = operations.IncludeDetailsZero.ToPointer()
|
||||
|
||||
ctx := context.Background()
|
||||
res, err := s.Library.GetLibrary(ctx, sectionID, includeDetails)
|
||||
@@ -348,7 +349,6 @@ Fetches details from a specific section of the library identified by a section k
|
||||
- `resolution`: Items categorized by resolution.
|
||||
- `firstCharacter`: Items categorized by the first letter.
|
||||
- `folder`: Items categorized by folder.
|
||||
- `search?type=1`: Search functionality within the section.
|
||||
|
||||
|
||||
### Example Usage
|
||||
@@ -456,6 +456,79 @@ func main() {
|
||||
| sdkerrors.RefreshLibraryResponseBody | 401 | application/json |
|
||||
| sdkerrors.SDKError | 4xx-5xx | */* |
|
||||
|
||||
## SearchLibrary
|
||||
|
||||
Search for content within a specific section of the library.
|
||||
|
||||
### Types
|
||||
Each type in the library comes with a set of filters and sorts, aiding in building dynamic media controls:
|
||||
|
||||
- **Type Object Attributes**:
|
||||
- `type`: Metadata type (if standard Plex type).
|
||||
- `title`: Title for this content type (e.g., "Movies").
|
||||
|
||||
- **Filter Objects**:
|
||||
- Subset of the media query language.
|
||||
- Attributes include `filter` (name), `filterType` (data type), `key` (endpoint for value range), and `title`.
|
||||
|
||||
- **Sort Objects**:
|
||||
- Description of sort fields.
|
||||
- Attributes include `defaultDirection` (asc/desc), `descKey` and `key` (sort parameters), and `title`.
|
||||
|
||||
> **Note**: Filters and sorts are optional; without them, no filtering controls are rendered.
|
||||
|
||||
|
||||
### Example Usage
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
import(
|
||||
"github.com/LukeHagar/plexgo/models/components"
|
||||
"github.com/LukeHagar/plexgo"
|
||||
"github.com/LukeHagar/plexgo/models/operations"
|
||||
"context"
|
||||
"log"
|
||||
)
|
||||
|
||||
func main() {
|
||||
s := plexgo.New(
|
||||
plexgo.WithSecurity("<YOUR_API_KEY_HERE>"),
|
||||
)
|
||||
|
||||
|
||||
var sectionID int64 = 933505
|
||||
|
||||
var type_ operations.Type = operations.TypeFour
|
||||
|
||||
ctx := context.Background()
|
||||
res, err := s.Library.SearchLibrary(ctx, sectionID, type_)
|
||||
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. |
|
||||
| `sectionID` | *int64* | :heavy_check_mark: | the Id of the library to query |
|
||||
| `type_` | [operations.Type](../../models/operations/type.md) | :heavy_check_mark: | Plex content type to search for |
|
||||
|
||||
|
||||
### Response
|
||||
|
||||
**[*operations.SearchLibraryResponse](../../models/operations/searchlibraryresponse.md), error**
|
||||
| Error Object | Status Code | Content Type |
|
||||
| ------------------ | ------------------ | ------------------ |
|
||||
| sdkerrors.SDKError | 4xx-5xx | */* |
|
||||
|
||||
## GetMetadata
|
||||
|
||||
This endpoint will return the metadata of a library item specified with the ratingKey.
|
||||
|
||||
@@ -142,11 +142,11 @@ func main() {
|
||||
)
|
||||
|
||||
|
||||
var key string = "string"
|
||||
var key string = "<value>"
|
||||
|
||||
var time float64 = 6900.91
|
||||
|
||||
var state string = "string"
|
||||
var state string = "<value>"
|
||||
|
||||
ctx := context.Background()
|
||||
res, err := s.Media.UpdatePlayProgress(ctx, key, time, state)
|
||||
|
||||
@@ -48,8 +48,8 @@ func main() {
|
||||
|
||||
ctx := context.Background()
|
||||
res, err := s.Playlists.CreatePlaylist(ctx, operations.CreatePlaylistRequest{
|
||||
Title: "string",
|
||||
Type: operations.TypePhoto,
|
||||
Title: "<value>",
|
||||
Type: operations.QueryParamTypePhoto,
|
||||
Smart: operations.SmartOne,
|
||||
URI: "https://inborn-brochure.biz",
|
||||
})
|
||||
@@ -102,9 +102,9 @@ func main() {
|
||||
)
|
||||
|
||||
|
||||
var playlistType *operations.PlaylistType = operations.PlaylistTypeAudio
|
||||
var playlistType *operations.PlaylistType = operations.PlaylistTypeAudio.ToPointer()
|
||||
|
||||
var smart *operations.QueryParamSmart = operations.QueryParamSmartZero
|
||||
var smart *operations.QueryParamSmart = operations.QueryParamSmartZero.ToPointer()
|
||||
|
||||
ctx := context.Background()
|
||||
res, err := s.Playlists.GetPlaylists(ctx, playlistType, smart)
|
||||
@@ -269,9 +269,9 @@ func main() {
|
||||
|
||||
var playlistID float64 = 3915
|
||||
|
||||
var title *string = "string"
|
||||
var title *string = plexgo.String("<value>")
|
||||
|
||||
var summary *string = "string"
|
||||
var summary *string = plexgo.String("<value>")
|
||||
|
||||
ctx := context.Background()
|
||||
res, err := s.Playlists.UpdatePlaylist(ctx, playlistID, title, summary)
|
||||
@@ -444,7 +444,7 @@ func main() {
|
||||
|
||||
var uri string = "server://12345/com.plexapp.plugins.library/library/metadata/1"
|
||||
|
||||
var playQueueID *float64 = 123
|
||||
var playQueueID *float64 = plexgo.Float64(123)
|
||||
|
||||
ctx := context.Background()
|
||||
res, err := s.Playlists.AddPlaylistContents(ctx, playlistID, uri, playQueueID)
|
||||
|
||||
125
docs/sdks/plex/README.md
Normal file
125
docs/sdks/plex/README.md
Normal file
@@ -0,0 +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("<YOUR_API_KEY_HERE>"),
|
||||
)
|
||||
|
||||
|
||||
var xPlexClientIdentifier string = "<value>"
|
||||
|
||||
var strong *bool = plexgo.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 = "<value>"
|
||||
|
||||
var xPlexClientIdentifier string = "<value>"
|
||||
|
||||
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 | */* |
|
||||
@@ -49,9 +49,9 @@ func main() {
|
||||
|
||||
var query string = "dylan"
|
||||
|
||||
var sectionID *float64 = 1516.53
|
||||
var sectionID *float64 = plexgo.Float64(1516.53)
|
||||
|
||||
var limit *float64 = 5
|
||||
var limit *float64 = plexgo.Float64(5)
|
||||
|
||||
ctx := context.Background()
|
||||
res, err := s.Search.PerformSearch(ctx, query, sectionID, limit)
|
||||
@@ -112,9 +112,9 @@ func main() {
|
||||
|
||||
var query string = "dead+poop"
|
||||
|
||||
var sectionID *float64 = 4094.8
|
||||
var sectionID *float64 = plexgo.Float64(4094.8)
|
||||
|
||||
var limit *float64 = 5
|
||||
var limit *float64 = plexgo.Float64(5)
|
||||
|
||||
ctx := context.Background()
|
||||
res, err := s.Search.PerformVoiceSearch(ctx, query, sectionID, limit)
|
||||
|
||||
@@ -36,7 +36,7 @@ func main() {
|
||||
)
|
||||
|
||||
|
||||
var type_ operations.QueryParamType = operations.QueryParamTypeDelegation
|
||||
var type_ operations.GetTransientTokenQueryParamType = operations.GetTransientTokenQueryParamTypeDelegation
|
||||
|
||||
var scope operations.Scope = operations.ScopeAll
|
||||
|
||||
@@ -54,11 +54,11 @@ func main() {
|
||||
|
||||
### Parameters
|
||||
|
||||
| Parameter | Type | Required | Description |
|
||||
| ---------------------------------------------------------------------- | ---------------------------------------------------------------------- | ---------------------------------------------------------------------- | ---------------------------------------------------------------------- |
|
||||
| `ctx` | [context.Context](https://pkg.go.dev/context#Context) | :heavy_check_mark: | The context to use for the request. |
|
||||
| `type_` | [operations.QueryParamType](../../models/operations/queryparamtype.md) | :heavy_check_mark: | `delegation` - This is the only supported `type` parameter. |
|
||||
| `scope` | [operations.Scope](../../models/operations/scope.md) | :heavy_check_mark: | `all` - This is the only supported `scope` parameter. |
|
||||
| Parameter | Type | Required | Description |
|
||||
| -------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------- |
|
||||
| `ctx` | [context.Context](https://pkg.go.dev/context#Context) | :heavy_check_mark: | The context to use for the request. |
|
||||
| `type_` | [operations.GetTransientTokenQueryParamType](../../models/operations/gettransienttokenqueryparamtype.md) | :heavy_check_mark: | `delegation` - This is the only supported `type` parameter. |
|
||||
| `scope` | [operations.Scope](../../models/operations/scope.md) | :heavy_check_mark: | `all` - This is the only supported `scope` parameter. |
|
||||
|
||||
|
||||
### Response
|
||||
|
||||
63
docs/sdks/statistics/README.md
Normal file
63
docs/sdks/statistics/README.md
Normal file
@@ -0,0 +1,63 @@
|
||||
# Statistics
|
||||
(*Statistics*)
|
||||
|
||||
## Overview
|
||||
|
||||
API Calls that perform operations with Plex Media Server Statistics
|
||||
|
||||
|
||||
### Available Operations
|
||||
|
||||
* [GetStatistics](#getstatistics) - Get Media Statistics
|
||||
|
||||
## GetStatistics
|
||||
|
||||
This will return the media statistics for the server
|
||||
|
||||
### 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 timespan *int64 = plexgo.Int64(411769)
|
||||
|
||||
ctx := context.Background()
|
||||
res, err := s.Statistics.GetStatistics(ctx, timespan)
|
||||
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. |
|
||||
| `timespan` | **int64* | :heavy_minus_sign: | The timespan to retrieve statistics for<br/>the exact meaning of this parameter is not known<br/> |
|
||||
|
||||
|
||||
### Response
|
||||
|
||||
**[*operations.GetStatisticsResponse](../../models/operations/getstatisticsresponse.md), error**
|
||||
| Error Object | Status Code | Content Type |
|
||||
| ----------------------------------- | ----------------------------------- | ----------------------------------- |
|
||||
| sdkerrors.GetStatisticsResponseBody | 401 | application/json |
|
||||
| sdkerrors.SDKError | 4xx-5xx | */* |
|
||||
@@ -85,7 +85,7 @@ func main() {
|
||||
)
|
||||
|
||||
|
||||
var download *operations.Download = operations.DownloadOne
|
||||
var download *operations.Download = operations.DownloadOne.ToPointer()
|
||||
|
||||
ctx := context.Background()
|
||||
res, err := s.Updater.CheckForUpdates(ctx, download)
|
||||
@@ -140,9 +140,9 @@ func main() {
|
||||
)
|
||||
|
||||
|
||||
var tonight *operations.Tonight = operations.TonightOne
|
||||
var tonight *operations.Tonight = operations.TonightOne.ToPointer()
|
||||
|
||||
var skip *operations.Skip = operations.SkipZero
|
||||
var skip *operations.Skip = operations.SkipZero.ToPointer()
|
||||
|
||||
ctx := context.Background()
|
||||
res, err := s.Updater.ApplyUpdates(ctx, tonight, skip)
|
||||
|
||||
@@ -8,65 +8,8 @@ API Calls that perform operations with Plex Media Server Videos
|
||||
|
||||
### Available Operations
|
||||
|
||||
* [StartUniversalTranscode](#startuniversaltranscode) - Start Universal Transcode
|
||||
* [GetTimeline](#gettimeline) - Get the timeline for a media item
|
||||
|
||||
## StartUniversalTranscode
|
||||
|
||||
Begin a Universal Transcode Session
|
||||
|
||||
### Example Usage
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
import(
|
||||
"github.com/LukeHagar/plexgo/models/components"
|
||||
"github.com/LukeHagar/plexgo"
|
||||
"context"
|
||||
"github.com/LukeHagar/plexgo/models/operations"
|
||||
"log"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func main() {
|
||||
s := plexgo.New(
|
||||
plexgo.WithSecurity("<YOUR_API_KEY_HERE>"),
|
||||
)
|
||||
|
||||
ctx := context.Background()
|
||||
res, err := s.Video.StartUniversalTranscode(ctx, operations.StartUniversalTranscodeRequest{
|
||||
HasMDE: 8924.99,
|
||||
Path: "/etc/mail",
|
||||
MediaIndex: 9962.95,
|
||||
PartIndex: 1232.82,
|
||||
Protocol: "string",
|
||||
})
|
||||
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. |
|
||||
| `request` | [operations.StartUniversalTranscodeRequest](../../models/operations/startuniversaltranscoderequest.md) | :heavy_check_mark: | The request object to use for the request. |
|
||||
|
||||
|
||||
### Response
|
||||
|
||||
**[*operations.StartUniversalTranscodeResponse](../../models/operations/startuniversaltranscoderesponse.md), error**
|
||||
| Error Object | Status Code | Content Type |
|
||||
| --------------------------------------------- | --------------------------------------------- | --------------------------------------------- |
|
||||
| sdkerrors.StartUniversalTranscodeResponseBody | 401 | application/json |
|
||||
| sdkerrors.SDKError | 4xx-5xx | */* |
|
||||
* [StartUniversalTranscode](#startuniversaltranscode) - Start Universal Transcode
|
||||
|
||||
## GetTimeline
|
||||
|
||||
@@ -99,7 +42,7 @@ func main() {
|
||||
HasMDE: 7574.33,
|
||||
Time: 3327.51,
|
||||
Duration: 7585.39,
|
||||
Context: "string",
|
||||
Context: "<value>",
|
||||
PlayQueueItemID: 1406.21,
|
||||
PlayBackTime: 2699.34,
|
||||
Row: 3536.42,
|
||||
@@ -129,3 +72,60 @@ func main() {
|
||||
| --------------------------------- | --------------------------------- | --------------------------------- |
|
||||
| sdkerrors.GetTimelineResponseBody | 401 | application/json |
|
||||
| sdkerrors.SDKError | 4xx-5xx | */* |
|
||||
|
||||
## StartUniversalTranscode
|
||||
|
||||
Begin a Universal Transcode Session
|
||||
|
||||
### Example Usage
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
import(
|
||||
"github.com/LukeHagar/plexgo/models/components"
|
||||
"github.com/LukeHagar/plexgo"
|
||||
"context"
|
||||
"github.com/LukeHagar/plexgo/models/operations"
|
||||
"log"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func main() {
|
||||
s := plexgo.New(
|
||||
plexgo.WithSecurity("<YOUR_API_KEY_HERE>"),
|
||||
)
|
||||
|
||||
ctx := context.Background()
|
||||
res, err := s.Video.StartUniversalTranscode(ctx, operations.StartUniversalTranscodeRequest{
|
||||
HasMDE: 8924.99,
|
||||
Path: "/etc/mail",
|
||||
MediaIndex: 9962.95,
|
||||
PartIndex: 1232.82,
|
||||
Protocol: "<value>",
|
||||
})
|
||||
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. |
|
||||
| `request` | [operations.StartUniversalTranscodeRequest](../../models/operations/startuniversaltranscoderequest.md) | :heavy_check_mark: | The request object to use for the request. |
|
||||
|
||||
|
||||
### Response
|
||||
|
||||
**[*operations.StartUniversalTranscodeResponse](../../models/operations/startuniversaltranscoderesponse.md), error**
|
||||
| Error Object | Status Code | Content Type |
|
||||
| --------------------------------------------- | --------------------------------------------- | --------------------------------------------- |
|
||||
| sdkerrors.StartUniversalTranscodeResponseBody | 401 | application/json |
|
||||
| sdkerrors.SDKError | 4xx-5xx | */* |
|
||||
|
||||
5
gen.yaml
5
gen.yaml
@@ -7,8 +7,11 @@ generation:
|
||||
useClassNamesForArrayFields: true
|
||||
fixes:
|
||||
nameResolutionDec2023: false
|
||||
parameterOrderingFeb2024: false
|
||||
requestResponseComponentNamesFeb2024: false
|
||||
go:
|
||||
version: 0.1.1
|
||||
version: 0.4.0
|
||||
additionalDependencies: {}
|
||||
clientServerStatusCodesAsErrors: true
|
||||
flattenGlobalSecurity: true
|
||||
imports:
|
||||
|
||||
2
go.mod
2
go.mod
@@ -5,6 +5,4 @@ go 1.20
|
||||
require (
|
||||
github.com/cenkalti/backoff/v4 v4.2.0
|
||||
github.com/ericlagergren/decimal v0.0.0-20221120152707-495c53812d05
|
||||
github.com/mitchellh/mapstructure v1.5.0
|
||||
github.com/spyzhov/ajson v0.8.0
|
||||
)
|
||||
|
||||
4
go.sum
4
go.sum
@@ -2,7 +2,3 @@ github.com/cenkalti/backoff/v4 v4.2.0 h1:HN5dHm3WBOgndBH6E8V0q2jIYIR3s9yglV8k/+M
|
||||
github.com/cenkalti/backoff/v4 v4.2.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=
|
||||
github.com/ericlagergren/decimal v0.0.0-20221120152707-495c53812d05 h1:S92OBrGuLLZsyM5ybUzgc/mPjIYk2AZqufieooe98uw=
|
||||
github.com/ericlagergren/decimal v0.0.0-20221120152707-495c53812d05/go.mod h1:M9R1FoZ3y//hwwnJtO51ypFGwm8ZfpxPT/ZLtO1mcgQ=
|
||||
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
|
||||
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
|
||||
github.com/spyzhov/ajson v0.8.0 h1:sFXyMbi4Y/BKjrsfkUZHSjA2JM1184enheSjjoT/zCc=
|
||||
github.com/spyzhov/ajson v0.8.0/go.mod h1:63V+CGM6f1Bu/p4nLIN8885ojBdt88TbLoSFzyqMuVA=
|
||||
|
||||
84
hubs.go
84
hubs.go
@@ -6,12 +6,13 @@ import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/LukeHagar/plexgo/internal/hooks"
|
||||
"github.com/LukeHagar/plexgo/internal/utils"
|
||||
"github.com/LukeHagar/plexgo/models/operations"
|
||||
"github.com/LukeHagar/plexgo/models/sdkerrors"
|
||||
"io"
|
||||
"net/http"
|
||||
"strings"
|
||||
"net/url"
|
||||
)
|
||||
|
||||
// Hubs are a structured two-dimensional container for media, generally represented by multiple horizontal rows.
|
||||
@@ -28,35 +29,58 @@ func newHubs(sdkConfig sdkConfiguration) *Hubs {
|
||||
// GetGlobalHubs - Get Global Hubs
|
||||
// Get Global Hubs filtered by the parameters provided.
|
||||
func (s *Hubs) GetGlobalHubs(ctx context.Context, count *float64, onlyTransient *operations.OnlyTransient) (*operations.GetGlobalHubsResponse, error) {
|
||||
hookCtx := hooks.HookContext{OperationID: "getGlobalHubs"}
|
||||
|
||||
request := operations.GetGlobalHubsRequest{
|
||||
Count: count,
|
||||
OnlyTransient: onlyTransient,
|
||||
}
|
||||
|
||||
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
|
||||
url := strings.TrimSuffix(baseURL, "/") + "/hubs"
|
||||
opURL, err := url.JoinPath(baseURL, "/hubs")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error generating URL: %w", err)
|
||||
}
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", url, nil)
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", opURL, 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)
|
||||
req.Header.Set("User-Agent", s.sdkConfiguration.UserAgent)
|
||||
|
||||
if err := utils.PopulateQueryParams(ctx, req, request, nil); err != nil {
|
||||
return nil, fmt.Errorf("error populating query params: %w", err)
|
||||
}
|
||||
|
||||
req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{hookCtx}, req)
|
||||
if err != nil {
|
||||
return nil, 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")
|
||||
}
|
||||
if err != nil || httpRes == nil {
|
||||
if err != nil {
|
||||
err = fmt.Errorf("error sending request: %w", err)
|
||||
} else {
|
||||
err = fmt.Errorf("error sending request: no response")
|
||||
}
|
||||
|
||||
_, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{hookCtx}, nil, err)
|
||||
return nil, err
|
||||
} else if utils.MatchStatusCodes([]string{"400", "401", "4XX", "5XX"}, httpRes.StatusCode) {
|
||||
httpRes, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{hookCtx}, httpRes, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{hookCtx}, httpRes)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
contentType := httpRes.Header.Get("Content-Type")
|
||||
|
||||
res := &operations.GetGlobalHubsResponse{
|
||||
@@ -71,6 +95,7 @@ func (s *Hubs) GetGlobalHubs(ctx context.Context, count *float64, onlyTransient
|
||||
}
|
||||
httpRes.Body.Close()
|
||||
httpRes.Body = io.NopCloser(bytes.NewBuffer(rawBody))
|
||||
|
||||
switch {
|
||||
case httpRes.StatusCode == 200:
|
||||
switch {
|
||||
@@ -111,6 +136,8 @@ func (s *Hubs) GetGlobalHubs(ctx context.Context, count *float64, onlyTransient
|
||||
// GetLibraryHubs - Get library specific hubs
|
||||
// This endpoint will return a list of library specific hubs
|
||||
func (s *Hubs) GetLibraryHubs(ctx context.Context, sectionID float64, count *float64, onlyTransient *operations.QueryParamOnlyTransient) (*operations.GetLibraryHubsResponse, error) {
|
||||
hookCtx := hooks.HookContext{OperationID: "getLibraryHubs"}
|
||||
|
||||
request := operations.GetLibraryHubsRequest{
|
||||
SectionID: sectionID,
|
||||
Count: count,
|
||||
@@ -118,32 +145,50 @@ func (s *Hubs) GetLibraryHubs(ctx context.Context, sectionID float64, count *flo
|
||||
}
|
||||
|
||||
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
|
||||
url, err := utils.GenerateURL(ctx, baseURL, "/hubs/sections/{sectionId}", request, nil)
|
||||
opURL, err := utils.GenerateURL(ctx, baseURL, "/hubs/sections/{sectionId}", request, nil)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error generating URL: %w", err)
|
||||
}
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", url, nil)
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", opURL, 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)
|
||||
req.Header.Set("User-Agent", s.sdkConfiguration.UserAgent)
|
||||
|
||||
if err := utils.PopulateQueryParams(ctx, req, request, nil); err != nil {
|
||||
return nil, fmt.Errorf("error populating query params: %w", err)
|
||||
}
|
||||
|
||||
req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{hookCtx}, req)
|
||||
if err != nil {
|
||||
return nil, 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")
|
||||
}
|
||||
if err != nil || httpRes == nil {
|
||||
if err != nil {
|
||||
err = fmt.Errorf("error sending request: %w", err)
|
||||
} else {
|
||||
err = fmt.Errorf("error sending request: no response")
|
||||
}
|
||||
|
||||
_, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{hookCtx}, nil, err)
|
||||
return nil, err
|
||||
} else if utils.MatchStatusCodes([]string{"400", "401", "4XX", "5XX"}, httpRes.StatusCode) {
|
||||
httpRes, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{hookCtx}, httpRes, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{hookCtx}, httpRes)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
contentType := httpRes.Header.Get("Content-Type")
|
||||
|
||||
res := &operations.GetLibraryHubsResponse{
|
||||
@@ -158,6 +203,7 @@ func (s *Hubs) GetLibraryHubs(ctx context.Context, sectionID float64, count *flo
|
||||
}
|
||||
httpRes.Body.Close()
|
||||
httpRes.Body = io.NopCloser(bytes.NewBuffer(rawBody))
|
||||
|
||||
switch {
|
||||
case httpRes.StatusCode == 200:
|
||||
switch {
|
||||
|
||||
140
internal/hooks/hooks.go
Normal file
140
internal/hooks/hooks.go
Normal file
@@ -0,0 +1,140 @@
|
||||
// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT.
|
||||
|
||||
package hooks
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type FailEarly struct {
|
||||
Cause error
|
||||
}
|
||||
|
||||
var _ error = (*FailEarly)(nil)
|
||||
|
||||
func (f *FailEarly) Error() string {
|
||||
return f.Cause.Error()
|
||||
}
|
||||
|
||||
// HTTPClient provides an interface for supplying the SDK with a custom HTTP client
|
||||
type HTTPClient interface {
|
||||
Do(req *http.Request) (*http.Response, error)
|
||||
}
|
||||
|
||||
type HookContext struct {
|
||||
OperationID string
|
||||
}
|
||||
|
||||
type BeforeRequestContext struct {
|
||||
HookContext
|
||||
}
|
||||
|
||||
type AfterSuccessContext struct {
|
||||
HookContext
|
||||
}
|
||||
|
||||
type AfterErrorContext struct {
|
||||
HookContext
|
||||
}
|
||||
|
||||
// clientInitHook is called when the SDK is initializing the HTTP client. The hook can return a new HTTP client to be used by the SDK.
|
||||
type clientInitHook interface {
|
||||
ClientInit(client HTTPClient) HTTPClient
|
||||
}
|
||||
|
||||
// beforeRequestHook is called before the SDK sends a request. The hook can modify the request before it is sent or return an error to stop the request from being sent.
|
||||
type beforeRequestHook interface {
|
||||
BeforeRequest(hookCtx BeforeRequestContext, req *http.Request) (*http.Request, error)
|
||||
}
|
||||
|
||||
// afterSuccessHook is called after the SDK receives a response. The hook can modify the response before it is handled or return an error to stop the response from being handled.
|
||||
type afterSuccessHook interface {
|
||||
AfterSuccess(hookCtx AfterSuccessContext, res *http.Response) (*http.Response, error)
|
||||
}
|
||||
|
||||
// afterErrorHook is called after the SDK encounters an error, or a non-successful response. The hook can modify the response if available otherwise modify the error.
|
||||
// All afterErrorHook hooks are called and returning an error won't stop the other hooks from being called. But if you want to stop the other hooks from being called, you can return a FailEarly error wrapping your error.
|
||||
type afterErrorHook interface {
|
||||
AfterError(hookCtx AfterErrorContext, res *http.Response, err error) (*http.Response, error)
|
||||
}
|
||||
|
||||
type Hooks struct {
|
||||
clientInitHooks []clientInitHook
|
||||
beforeRequestHook []beforeRequestHook
|
||||
afterSuccessHook []afterSuccessHook
|
||||
afterErrorHook []afterErrorHook
|
||||
}
|
||||
|
||||
func New() *Hooks {
|
||||
h := &Hooks{
|
||||
clientInitHooks: []clientInitHook{},
|
||||
beforeRequestHook: []beforeRequestHook{},
|
||||
afterSuccessHook: []afterSuccessHook{},
|
||||
afterErrorHook: []afterErrorHook{},
|
||||
}
|
||||
|
||||
initHooks(h)
|
||||
|
||||
return h
|
||||
}
|
||||
|
||||
// registerClientInitHook registers a hook to be used by the SDK for the client initialization event.
|
||||
func (h *Hooks) registerClientInitHook(hook clientInitHook) {
|
||||
h.clientInitHooks = append(h.clientInitHooks, hook)
|
||||
}
|
||||
|
||||
// registerBeforeRequestHook registers a hook to be used by the SDK for the before request event.
|
||||
func (h *Hooks) registerBeforeRequestHook(hook beforeRequestHook) {
|
||||
h.beforeRequestHook = append(h.beforeRequestHook, hook)
|
||||
}
|
||||
|
||||
// registerAfterSuccessHook registers a hook to be used by the SDK for the after success event.
|
||||
func (h *Hooks) registerAfterSuccessHook(hook afterSuccessHook) {
|
||||
h.afterSuccessHook = append(h.afterSuccessHook, hook)
|
||||
}
|
||||
|
||||
// registerAfterErrorHook registers a hook to be used by the SDK for the after error event.
|
||||
func (h *Hooks) registerAfterErrorHook(hook afterErrorHook) {
|
||||
h.afterErrorHook = append(h.afterErrorHook, hook)
|
||||
}
|
||||
|
||||
func (h *Hooks) ClientInit(client HTTPClient) HTTPClient {
|
||||
for _, hook := range h.clientInitHooks {
|
||||
client = hook.ClientInit(client)
|
||||
}
|
||||
return client
|
||||
}
|
||||
|
||||
func (h *Hooks) BeforeRequest(hookCtx BeforeRequestContext, req *http.Request) (*http.Request, error) {
|
||||
for _, hook := range h.beforeRequestHook {
|
||||
var err error
|
||||
req, err = hook.BeforeRequest(hookCtx, req)
|
||||
if err != nil {
|
||||
return req, err
|
||||
}
|
||||
}
|
||||
return req, nil
|
||||
}
|
||||
|
||||
func (h *Hooks) AfterSuccess(hookCtx AfterSuccessContext, res *http.Response) (*http.Response, error) {
|
||||
for _, hook := range h.afterSuccessHook {
|
||||
var err error
|
||||
res, err = hook.AfterSuccess(hookCtx, res)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
}
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func (h *Hooks) AfterError(hookCtx AfterErrorContext, res *http.Response, err error) (*http.Response, error) {
|
||||
for _, hook := range h.afterErrorHook {
|
||||
res, err = hook.AfterError(hookCtx, res, err)
|
||||
var fe *FailEarly
|
||||
if errors.As(err, &fe) {
|
||||
return nil, fe.Cause
|
||||
}
|
||||
}
|
||||
return res, err
|
||||
}
|
||||
13
internal/hooks/registration.go
Normal file
13
internal/hooks/registration.go
Normal file
@@ -0,0 +1,13 @@
|
||||
package hooks
|
||||
|
||||
/*
|
||||
* This file is only ever generated once on the first generation and then is free to be modified.
|
||||
* Any hooks you wish to add should be registered in the InitHooks function. Feel free to define them
|
||||
* in this file or in separate files in the hooks package.
|
||||
*/
|
||||
|
||||
func initHooks(h *Hooks) {
|
||||
// Add hooks by calling h.register{ClientInit/BeforeRequest/AfterRequest/AfterError}Hook
|
||||
// with an instance of a hook that implements that specific Hook interface
|
||||
// Hooks are registered per SDK instance, and are valid for the lifetime of the SDK instance
|
||||
}
|
||||
@@ -358,7 +358,7 @@ func handleDefaultConstValue(tagValue string, val interface{}, tag reflect.Struc
|
||||
return []byte(fmt.Sprintf(`"%s"`, tagValue))
|
||||
default:
|
||||
if typ.Kind() == reflect.String {
|
||||
return []byte(fmt.Sprintf(`"%s"`, tagValue))
|
||||
return []byte(fmt.Sprintf("%q", tagValue))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -26,6 +26,19 @@ var (
|
||||
)
|
||||
|
||||
func SerializeRequestBody(ctx context.Context, request interface{}, nullable, optional bool, requestFieldName, serializationMethod, tag string) (io.Reader, string, error) {
|
||||
bodyReader, contentType, err := serializeRequestBody(ctx, request, nullable, optional, requestFieldName, serializationMethod, tag)
|
||||
if err != nil {
|
||||
return nil, "", fmt.Errorf("error serializing request body: %w", err)
|
||||
}
|
||||
|
||||
if bodyReader == nil && !optional {
|
||||
return nil, "", fmt.Errorf("request body is required")
|
||||
}
|
||||
|
||||
return bodyReader, contentType, nil
|
||||
}
|
||||
|
||||
func serializeRequestBody(ctx context.Context, request interface{}, nullable, optional bool, requestFieldName, serializationMethod, tag string) (io.Reader, string, error) {
|
||||
requestStructType := reflect.TypeOf(request)
|
||||
requestValType := reflect.ValueOf(request)
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"math/big"
|
||||
"reflect"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -63,6 +64,29 @@ func Contains(slice []string, item string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func MatchStatusCodes(expectedCodes []string, statusCode int) bool {
|
||||
for _, codeStr := range expectedCodes {
|
||||
code, err := strconv.Atoi(codeStr)
|
||||
if err == nil {
|
||||
if code == statusCode {
|
||||
return true
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
codeRange, err := strconv.Atoi(string(codeStr[0]))
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
if statusCode >= (codeRange*100) && statusCode < ((codeRange+1)*100) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func parseStructTag(tagKey string, field reflect.StructField) map[string]string {
|
||||
tag := field.Tag.Get(tagKey)
|
||||
if tag == "" {
|
||||
|
||||
521
library.go
521
library.go
@@ -6,12 +6,13 @@ import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/LukeHagar/plexgo/internal/hooks"
|
||||
"github.com/LukeHagar/plexgo/internal/utils"
|
||||
"github.com/LukeHagar/plexgo/models/operations"
|
||||
"github.com/LukeHagar/plexgo/models/sdkerrors"
|
||||
"io"
|
||||
"net/http"
|
||||
"strings"
|
||||
"net/url"
|
||||
)
|
||||
|
||||
// Library - API Calls interacting with Plex Media Server Libraries
|
||||
@@ -28,35 +29,58 @@ func newLibrary(sdkConfig sdkConfiguration) *Library {
|
||||
// GetFileHash - Get Hash Value
|
||||
// This resource returns hash values for local files
|
||||
func (s *Library) GetFileHash(ctx context.Context, url_ string, type_ *float64) (*operations.GetFileHashResponse, error) {
|
||||
hookCtx := hooks.HookContext{OperationID: "getFileHash"}
|
||||
|
||||
request := operations.GetFileHashRequest{
|
||||
URL: url_,
|
||||
Type: type_,
|
||||
}
|
||||
|
||||
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
|
||||
url := strings.TrimSuffix(baseURL, "/") + "/library/hashes"
|
||||
opURL, err := url.JoinPath(baseURL, "/library/hashes")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error generating URL: %w", err)
|
||||
}
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", url, nil)
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", opURL, 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)
|
||||
req.Header.Set("User-Agent", s.sdkConfiguration.UserAgent)
|
||||
|
||||
if err := utils.PopulateQueryParams(ctx, req, request, nil); err != nil {
|
||||
return nil, fmt.Errorf("error populating query params: %w", err)
|
||||
}
|
||||
|
||||
req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{hookCtx}, req)
|
||||
if err != nil {
|
||||
return nil, 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")
|
||||
}
|
||||
if err != nil || httpRes == nil {
|
||||
if err != nil {
|
||||
err = fmt.Errorf("error sending request: %w", err)
|
||||
} else {
|
||||
err = fmt.Errorf("error sending request: no response")
|
||||
}
|
||||
|
||||
_, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{hookCtx}, nil, err)
|
||||
return nil, err
|
||||
} else if utils.MatchStatusCodes([]string{"400", "401", "4XX", "5XX"}, httpRes.StatusCode) {
|
||||
httpRes, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{hookCtx}, httpRes, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{hookCtx}, httpRes)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
contentType := httpRes.Header.Get("Content-Type")
|
||||
|
||||
res := &operations.GetFileHashResponse{
|
||||
@@ -71,6 +95,7 @@ func (s *Library) GetFileHash(ctx context.Context, url_ string, type_ *float64)
|
||||
}
|
||||
httpRes.Body.Close()
|
||||
httpRes.Body = io.NopCloser(bytes.NewBuffer(rawBody))
|
||||
|
||||
switch {
|
||||
case httpRes.StatusCode == 200:
|
||||
case httpRes.StatusCode == 400:
|
||||
@@ -100,26 +125,49 @@ func (s *Library) GetFileHash(ctx context.Context, url_ string, type_ *float64)
|
||||
// GetRecentlyAdded - Get Recently Added
|
||||
// This endpoint will return the recently added content.
|
||||
func (s *Library) GetRecentlyAdded(ctx context.Context) (*operations.GetRecentlyAddedResponse, error) {
|
||||
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
|
||||
url := strings.TrimSuffix(baseURL, "/") + "/library/recentlyAdded"
|
||||
hookCtx := hooks.HookContext{OperationID: "getRecentlyAdded"}
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", url, nil)
|
||||
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
|
||||
opURL, err := url.JoinPath(baseURL, "/library/recentlyAdded")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error generating URL: %w", err)
|
||||
}
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", opURL, 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)
|
||||
req.Header.Set("User-Agent", s.sdkConfiguration.UserAgent)
|
||||
|
||||
req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{hookCtx}, req)
|
||||
if err != nil {
|
||||
return nil, 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")
|
||||
}
|
||||
if err != nil || httpRes == nil {
|
||||
if err != nil {
|
||||
err = fmt.Errorf("error sending request: %w", err)
|
||||
} else {
|
||||
err = fmt.Errorf("error sending request: no response")
|
||||
}
|
||||
|
||||
_, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{hookCtx}, nil, err)
|
||||
return nil, err
|
||||
} else if utils.MatchStatusCodes([]string{"400", "401", "4XX", "5XX"}, httpRes.StatusCode) {
|
||||
httpRes, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{hookCtx}, httpRes, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{hookCtx}, httpRes)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
contentType := httpRes.Header.Get("Content-Type")
|
||||
|
||||
res := &operations.GetRecentlyAddedResponse{
|
||||
@@ -134,6 +182,7 @@ func (s *Library) GetRecentlyAdded(ctx context.Context) (*operations.GetRecently
|
||||
}
|
||||
httpRes.Body.Close()
|
||||
httpRes.Body = io.NopCloser(bytes.NewBuffer(rawBody))
|
||||
|
||||
switch {
|
||||
case httpRes.StatusCode == 200:
|
||||
switch {
|
||||
@@ -179,26 +228,49 @@ func (s *Library) GetRecentlyAdded(ctx context.Context) (*operations.GetRecently
|
||||
// Libraries have features beyond just being a collection of media; for starters, they include information about supported types, filters and sorts.
|
||||
// This allows a client to provide a rich interface around the media (e.g. allow sorting movies by release year).
|
||||
func (s *Library) GetLibraries(ctx context.Context) (*operations.GetLibrariesResponse, error) {
|
||||
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
|
||||
url := strings.TrimSuffix(baseURL, "/") + "/library/sections"
|
||||
hookCtx := hooks.HookContext{OperationID: "getLibraries"}
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", url, nil)
|
||||
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
|
||||
opURL, err := url.JoinPath(baseURL, "/library/sections")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error generating URL: %w", err)
|
||||
}
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", opURL, 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)
|
||||
req.Header.Set("User-Agent", s.sdkConfiguration.UserAgent)
|
||||
|
||||
req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{hookCtx}, req)
|
||||
if err != nil {
|
||||
return nil, 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")
|
||||
}
|
||||
if err != nil || httpRes == nil {
|
||||
if err != nil {
|
||||
err = fmt.Errorf("error sending request: %w", err)
|
||||
} else {
|
||||
err = fmt.Errorf("error sending request: no response")
|
||||
}
|
||||
|
||||
_, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{hookCtx}, nil, err)
|
||||
return nil, err
|
||||
} else if utils.MatchStatusCodes([]string{"400", "401", "4XX", "5XX"}, httpRes.StatusCode) {
|
||||
httpRes, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{hookCtx}, httpRes, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{hookCtx}, httpRes)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
contentType := httpRes.Header.Get("Content-Type")
|
||||
|
||||
res := &operations.GetLibrariesResponse{
|
||||
@@ -213,6 +285,7 @@ func (s *Library) GetLibraries(ctx context.Context) (*operations.GetLibrariesRes
|
||||
}
|
||||
httpRes.Body.Close()
|
||||
httpRes.Body = io.NopCloser(bytes.NewBuffer(rawBody))
|
||||
|
||||
switch {
|
||||
case httpRes.StatusCode == 200:
|
||||
switch {
|
||||
@@ -291,38 +364,58 @@ func (s *Library) GetLibraries(ctx context.Context) (*operations.GetLibrariesRes
|
||||
//
|
||||
// > **Note**: Filters and sorts are optional; without them, no filtering controls are rendered.
|
||||
func (s *Library) GetLibrary(ctx context.Context, sectionID float64, includeDetails *operations.IncludeDetails) (*operations.GetLibraryResponse, error) {
|
||||
hookCtx := hooks.HookContext{OperationID: "getLibrary"}
|
||||
|
||||
request := operations.GetLibraryRequest{
|
||||
SectionID: sectionID,
|
||||
IncludeDetails: includeDetails,
|
||||
}
|
||||
|
||||
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
|
||||
url, err := utils.GenerateURL(ctx, baseURL, "/library/sections/{sectionId}", request, nil)
|
||||
opURL, err := utils.GenerateURL(ctx, baseURL, "/library/sections/{sectionId}", request, nil)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error generating URL: %w", err)
|
||||
}
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", url, nil)
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", opURL, 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)
|
||||
req.Header.Set("User-Agent", s.sdkConfiguration.UserAgent)
|
||||
|
||||
if err := utils.PopulateQueryParams(ctx, req, request, nil); err != nil {
|
||||
return nil, fmt.Errorf("error populating query params: %w", err)
|
||||
}
|
||||
|
||||
req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{hookCtx}, req)
|
||||
if err != nil {
|
||||
return nil, 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")
|
||||
}
|
||||
if err != nil || httpRes == nil {
|
||||
if err != nil {
|
||||
err = fmt.Errorf("error sending request: %w", err)
|
||||
} else {
|
||||
err = fmt.Errorf("error sending request: no response")
|
||||
}
|
||||
|
||||
_, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{hookCtx}, nil, err)
|
||||
return nil, err
|
||||
} else if utils.MatchStatusCodes([]string{"400", "401", "4XX", "5XX"}, httpRes.StatusCode) {
|
||||
httpRes, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{hookCtx}, httpRes, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{hookCtx}, httpRes)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
contentType := httpRes.Header.Get("Content-Type")
|
||||
|
||||
res := &operations.GetLibraryResponse{
|
||||
@@ -337,6 +430,7 @@ func (s *Library) GetLibrary(ctx context.Context, sectionID float64, includeDeta
|
||||
}
|
||||
httpRes.Body.Close()
|
||||
httpRes.Body = io.NopCloser(bytes.NewBuffer(rawBody))
|
||||
|
||||
switch {
|
||||
case httpRes.StatusCode == 200:
|
||||
switch {
|
||||
@@ -377,33 +471,53 @@ func (s *Library) GetLibrary(ctx context.Context, sectionID float64, includeDeta
|
||||
// DeleteLibrary - Delete Library Section
|
||||
// Delate a library using a specific section
|
||||
func (s *Library) DeleteLibrary(ctx context.Context, sectionID float64) (*operations.DeleteLibraryResponse, error) {
|
||||
hookCtx := hooks.HookContext{OperationID: "deleteLibrary"}
|
||||
|
||||
request := operations.DeleteLibraryRequest{
|
||||
SectionID: sectionID,
|
||||
}
|
||||
|
||||
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
|
||||
url, err := utils.GenerateURL(ctx, baseURL, "/library/sections/{sectionId}", request, nil)
|
||||
opURL, err := utils.GenerateURL(ctx, baseURL, "/library/sections/{sectionId}", request, nil)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error generating URL: %w", err)
|
||||
}
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, "DELETE", url, nil)
|
||||
req, err := http.NewRequestWithContext(ctx, "DELETE", opURL, 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)
|
||||
req.Header.Set("User-Agent", s.sdkConfiguration.UserAgent)
|
||||
|
||||
req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{hookCtx}, req)
|
||||
if err != nil {
|
||||
return nil, 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")
|
||||
}
|
||||
if err != nil || httpRes == nil {
|
||||
if err != nil {
|
||||
err = fmt.Errorf("error sending request: %w", err)
|
||||
} else {
|
||||
err = fmt.Errorf("error sending request: no response")
|
||||
}
|
||||
|
||||
_, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{hookCtx}, nil, err)
|
||||
return nil, err
|
||||
} else if utils.MatchStatusCodes([]string{"400", "401", "4XX", "5XX"}, httpRes.StatusCode) {
|
||||
httpRes, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{hookCtx}, httpRes, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{hookCtx}, httpRes)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
contentType := httpRes.Header.Get("Content-Type")
|
||||
|
||||
res := &operations.DeleteLibraryResponse{
|
||||
@@ -418,6 +532,7 @@ func (s *Library) DeleteLibrary(ctx context.Context, sectionID float64) (*operat
|
||||
}
|
||||
httpRes.Body.Close()
|
||||
httpRes.Body = io.NopCloser(bytes.NewBuffer(rawBody))
|
||||
|
||||
switch {
|
||||
case httpRes.StatusCode == 200:
|
||||
case httpRes.StatusCode == 400:
|
||||
@@ -465,36 +580,55 @@ func (s *Library) DeleteLibrary(ctx context.Context, sectionID float64) (*operat
|
||||
// - `resolution`: Items categorized by resolution.
|
||||
// - `firstCharacter`: Items categorized by the first letter.
|
||||
// - `folder`: Items categorized by folder.
|
||||
// - `search?type=1`: Search functionality within the section.
|
||||
func (s *Library) GetLibraryItems(ctx context.Context, sectionID int64, tag operations.Tag) (*operations.GetLibraryItemsResponse, error) {
|
||||
hookCtx := hooks.HookContext{OperationID: "getLibraryItems"}
|
||||
|
||||
request := operations.GetLibraryItemsRequest{
|
||||
SectionID: sectionID,
|
||||
Tag: tag,
|
||||
}
|
||||
|
||||
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
|
||||
url, err := utils.GenerateURL(ctx, baseURL, "/library/sections/{sectionId}/{tag}", request, nil)
|
||||
opURL, err := utils.GenerateURL(ctx, baseURL, "/library/sections/{sectionId}/{tag}", request, nil)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error generating URL: %w", err)
|
||||
}
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", url, nil)
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", opURL, 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)
|
||||
req.Header.Set("User-Agent", s.sdkConfiguration.UserAgent)
|
||||
|
||||
req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{hookCtx}, req)
|
||||
if err != nil {
|
||||
return nil, 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")
|
||||
}
|
||||
if err != nil || httpRes == nil {
|
||||
if err != nil {
|
||||
err = fmt.Errorf("error sending request: %w", err)
|
||||
} else {
|
||||
err = fmt.Errorf("error sending request: no response")
|
||||
}
|
||||
|
||||
_, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{hookCtx}, nil, err)
|
||||
return nil, err
|
||||
} else if utils.MatchStatusCodes([]string{"4XX", "5XX"}, httpRes.StatusCode) {
|
||||
httpRes, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{hookCtx}, httpRes, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{hookCtx}, httpRes)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
contentType := httpRes.Header.Get("Content-Type")
|
||||
|
||||
res := &operations.GetLibraryItemsResponse{
|
||||
@@ -509,6 +643,7 @@ func (s *Library) GetLibraryItems(ctx context.Context, sectionID int64, tag oper
|
||||
}
|
||||
httpRes.Body.Close()
|
||||
httpRes.Body = io.NopCloser(bytes.NewBuffer(rawBody))
|
||||
|
||||
switch {
|
||||
case httpRes.StatusCode == 200:
|
||||
switch {
|
||||
@@ -534,33 +669,53 @@ func (s *Library) GetLibraryItems(ctx context.Context, sectionID int64, tag oper
|
||||
// RefreshLibrary - Refresh Library
|
||||
// This endpoint Refreshes the library.
|
||||
func (s *Library) RefreshLibrary(ctx context.Context, sectionID float64) (*operations.RefreshLibraryResponse, error) {
|
||||
hookCtx := hooks.HookContext{OperationID: "refreshLibrary"}
|
||||
|
||||
request := operations.RefreshLibraryRequest{
|
||||
SectionID: sectionID,
|
||||
}
|
||||
|
||||
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
|
||||
url, err := utils.GenerateURL(ctx, baseURL, "/library/sections/{sectionId}/refresh", request, nil)
|
||||
opURL, err := utils.GenerateURL(ctx, baseURL, "/library/sections/{sectionId}/refresh", request, nil)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error generating URL: %w", err)
|
||||
}
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", url, nil)
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", opURL, 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)
|
||||
req.Header.Set("User-Agent", s.sdkConfiguration.UserAgent)
|
||||
|
||||
req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{hookCtx}, req)
|
||||
if err != nil {
|
||||
return nil, 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")
|
||||
}
|
||||
if err != nil || httpRes == nil {
|
||||
if err != nil {
|
||||
err = fmt.Errorf("error sending request: %w", err)
|
||||
} else {
|
||||
err = fmt.Errorf("error sending request: no response")
|
||||
}
|
||||
|
||||
_, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{hookCtx}, nil, err)
|
||||
return nil, err
|
||||
} else if utils.MatchStatusCodes([]string{"400", "401", "4XX", "5XX"}, httpRes.StatusCode) {
|
||||
httpRes, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{hookCtx}, httpRes, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{hookCtx}, httpRes)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
contentType := httpRes.Header.Get("Content-Type")
|
||||
|
||||
res := &operations.RefreshLibraryResponse{
|
||||
@@ -575,6 +730,7 @@ func (s *Library) RefreshLibrary(ctx context.Context, sectionID float64) (*opera
|
||||
}
|
||||
httpRes.Body.Close()
|
||||
httpRes.Body = io.NopCloser(bytes.NewBuffer(rawBody))
|
||||
|
||||
switch {
|
||||
case httpRes.StatusCode == 200:
|
||||
case httpRes.StatusCode == 400:
|
||||
@@ -601,36 +757,165 @@ func (s *Library) RefreshLibrary(ctx context.Context, sectionID float64) (*opera
|
||||
return res, nil
|
||||
}
|
||||
|
||||
// SearchLibrary - Search Library
|
||||
// Search for content within a specific section of the library.
|
||||
//
|
||||
// ### Types
|
||||
// Each type in the library comes with a set of filters and sorts, aiding in building dynamic media controls:
|
||||
//
|
||||
// - **Type Object Attributes**:
|
||||
// - `type`: Metadata type (if standard Plex type).
|
||||
// - `title`: Title for this content type (e.g., "Movies").
|
||||
//
|
||||
// - **Filter Objects**:
|
||||
// - Subset of the media query language.
|
||||
// - Attributes include `filter` (name), `filterType` (data type), `key` (endpoint for value range), and `title`.
|
||||
//
|
||||
// - **Sort Objects**:
|
||||
// - Description of sort fields.
|
||||
// - Attributes include `defaultDirection` (asc/desc), `descKey` and `key` (sort parameters), and `title`.
|
||||
//
|
||||
// > **Note**: Filters and sorts are optional; without them, no filtering controls are rendered.
|
||||
func (s *Library) SearchLibrary(ctx context.Context, sectionID int64, type_ operations.Type) (*operations.SearchLibraryResponse, error) {
|
||||
hookCtx := hooks.HookContext{OperationID: "searchLibrary"}
|
||||
|
||||
request := operations.SearchLibraryRequest{
|
||||
SectionID: sectionID,
|
||||
Type: type_,
|
||||
}
|
||||
|
||||
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
|
||||
opURL, err := utils.GenerateURL(ctx, baseURL, "/library/sections/{sectionId}/search", request, nil)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error generating URL: %w", err)
|
||||
}
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", opURL, 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)
|
||||
|
||||
if err := utils.PopulateQueryParams(ctx, req, request, nil); err != nil {
|
||||
return nil, fmt.Errorf("error populating query params: %w", err)
|
||||
}
|
||||
|
||||
req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{hookCtx}, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
client := s.sdkConfiguration.SecurityClient
|
||||
|
||||
httpRes, err := client.Do(req)
|
||||
if err != nil || httpRes == nil {
|
||||
if err != nil {
|
||||
err = fmt.Errorf("error sending request: %w", err)
|
||||
} else {
|
||||
err = fmt.Errorf("error sending request: no response")
|
||||
}
|
||||
|
||||
_, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{hookCtx}, nil, err)
|
||||
return nil, err
|
||||
} else if utils.MatchStatusCodes([]string{"4XX", "5XX"}, httpRes.StatusCode) {
|
||||
httpRes, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{hookCtx}, httpRes, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{hookCtx}, httpRes)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
contentType := httpRes.Header.Get("Content-Type")
|
||||
|
||||
res := &operations.SearchLibraryResponse{
|
||||
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.SearchLibraryResponseBody
|
||||
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 && 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
|
||||
}
|
||||
|
||||
// GetMetadata - Get Items Metadata
|
||||
// This endpoint will return the metadata of a library item specified with the ratingKey.
|
||||
func (s *Library) GetMetadata(ctx context.Context, ratingKey float64) (*operations.GetMetadataResponse, error) {
|
||||
hookCtx := hooks.HookContext{OperationID: "getMetadata"}
|
||||
|
||||
request := operations.GetMetadataRequest{
|
||||
RatingKey: ratingKey,
|
||||
}
|
||||
|
||||
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
|
||||
url, err := utils.GenerateURL(ctx, baseURL, "/library/metadata/{ratingKey}", request, nil)
|
||||
opURL, err := utils.GenerateURL(ctx, baseURL, "/library/metadata/{ratingKey}", request, nil)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error generating URL: %w", err)
|
||||
}
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", url, nil)
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", opURL, 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)
|
||||
req.Header.Set("User-Agent", s.sdkConfiguration.UserAgent)
|
||||
|
||||
req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{hookCtx}, req)
|
||||
if err != nil {
|
||||
return nil, 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")
|
||||
}
|
||||
if err != nil || httpRes == nil {
|
||||
if err != nil {
|
||||
err = fmt.Errorf("error sending request: %w", err)
|
||||
} else {
|
||||
err = fmt.Errorf("error sending request: no response")
|
||||
}
|
||||
|
||||
_, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{hookCtx}, nil, err)
|
||||
return nil, err
|
||||
} else if utils.MatchStatusCodes([]string{"400", "401", "4XX", "5XX"}, httpRes.StatusCode) {
|
||||
httpRes, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{hookCtx}, httpRes, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{hookCtx}, httpRes)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
contentType := httpRes.Header.Get("Content-Type")
|
||||
|
||||
res := &operations.GetMetadataResponse{
|
||||
@@ -645,6 +930,7 @@ func (s *Library) GetMetadata(ctx context.Context, ratingKey float64) (*operatio
|
||||
}
|
||||
httpRes.Body.Close()
|
||||
httpRes.Body = io.NopCloser(bytes.NewBuffer(rawBody))
|
||||
|
||||
switch {
|
||||
case httpRes.StatusCode == 200:
|
||||
switch {
|
||||
@@ -685,33 +971,53 @@ func (s *Library) GetMetadata(ctx context.Context, ratingKey float64) (*operatio
|
||||
// GetMetadataChildren - Get Items Children
|
||||
// This endpoint will return the children of of a library item specified with the ratingKey.
|
||||
func (s *Library) GetMetadataChildren(ctx context.Context, ratingKey float64) (*operations.GetMetadataChildrenResponse, error) {
|
||||
hookCtx := hooks.HookContext{OperationID: "getMetadataChildren"}
|
||||
|
||||
request := operations.GetMetadataChildrenRequest{
|
||||
RatingKey: ratingKey,
|
||||
}
|
||||
|
||||
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
|
||||
url, err := utils.GenerateURL(ctx, baseURL, "/library/metadata/{ratingKey}/children", request, nil)
|
||||
opURL, err := utils.GenerateURL(ctx, baseURL, "/library/metadata/{ratingKey}/children", request, nil)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error generating URL: %w", err)
|
||||
}
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", url, nil)
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", opURL, 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)
|
||||
req.Header.Set("User-Agent", s.sdkConfiguration.UserAgent)
|
||||
|
||||
req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{hookCtx}, req)
|
||||
if err != nil {
|
||||
return nil, 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")
|
||||
}
|
||||
if err != nil || httpRes == nil {
|
||||
if err != nil {
|
||||
err = fmt.Errorf("error sending request: %w", err)
|
||||
} else {
|
||||
err = fmt.Errorf("error sending request: no response")
|
||||
}
|
||||
|
||||
_, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{hookCtx}, nil, err)
|
||||
return nil, err
|
||||
} else if utils.MatchStatusCodes([]string{"400", "401", "4XX", "5XX"}, httpRes.StatusCode) {
|
||||
httpRes, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{hookCtx}, httpRes, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{hookCtx}, httpRes)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
contentType := httpRes.Header.Get("Content-Type")
|
||||
|
||||
res := &operations.GetMetadataChildrenResponse{
|
||||
@@ -726,6 +1032,7 @@ func (s *Library) GetMetadataChildren(ctx context.Context, ratingKey float64) (*
|
||||
}
|
||||
httpRes.Body.Close()
|
||||
httpRes.Body = io.NopCloser(bytes.NewBuffer(rawBody))
|
||||
|
||||
switch {
|
||||
case httpRes.StatusCode == 200:
|
||||
switch {
|
||||
@@ -766,26 +1073,49 @@ func (s *Library) GetMetadataChildren(ctx context.Context, ratingKey float64) (*
|
||||
// GetOnDeck - Get On Deck
|
||||
// This endpoint will return the on deck content.
|
||||
func (s *Library) GetOnDeck(ctx context.Context) (*operations.GetOnDeckResponse, error) {
|
||||
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
|
||||
url := strings.TrimSuffix(baseURL, "/") + "/library/onDeck"
|
||||
hookCtx := hooks.HookContext{OperationID: "getOnDeck"}
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", url, nil)
|
||||
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
|
||||
opURL, err := url.JoinPath(baseURL, "/library/onDeck")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error generating URL: %w", err)
|
||||
}
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", opURL, 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)
|
||||
req.Header.Set("User-Agent", s.sdkConfiguration.UserAgent)
|
||||
|
||||
req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{hookCtx}, req)
|
||||
if err != nil {
|
||||
return nil, 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")
|
||||
}
|
||||
if err != nil || httpRes == nil {
|
||||
if err != nil {
|
||||
err = fmt.Errorf("error sending request: %w", err)
|
||||
} else {
|
||||
err = fmt.Errorf("error sending request: no response")
|
||||
}
|
||||
|
||||
_, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{hookCtx}, nil, err)
|
||||
return nil, err
|
||||
} else if utils.MatchStatusCodes([]string{"400", "401", "4XX", "5XX"}, httpRes.StatusCode) {
|
||||
httpRes, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{hookCtx}, httpRes, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{hookCtx}, httpRes)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
contentType := httpRes.Header.Get("Content-Type")
|
||||
|
||||
res := &operations.GetOnDeckResponse{
|
||||
@@ -800,6 +1130,7 @@ func (s *Library) GetOnDeck(ctx context.Context) (*operations.GetOnDeckResponse,
|
||||
}
|
||||
httpRes.Body.Close()
|
||||
httpRes.Body = io.NopCloser(bytes.NewBuffer(rawBody))
|
||||
|
||||
switch {
|
||||
case httpRes.StatusCode == 200:
|
||||
switch {
|
||||
|
||||
137
log.go
137
log.go
@@ -6,12 +6,13 @@ import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/LukeHagar/plexgo/internal/hooks"
|
||||
"github.com/LukeHagar/plexgo/internal/utils"
|
||||
"github.com/LukeHagar/plexgo/models/operations"
|
||||
"github.com/LukeHagar/plexgo/models/sdkerrors"
|
||||
"io"
|
||||
"net/http"
|
||||
"strings"
|
||||
"net/url"
|
||||
)
|
||||
|
||||
// Log - Submit logs to the Log Handler for Plex Media Server
|
||||
@@ -28,6 +29,8 @@ func newLog(sdkConfig sdkConfiguration) *Log {
|
||||
// LogLine - Logging a single line message.
|
||||
// This endpoint will write a single-line log message, including a level and source to the main Plex Media Server log.
|
||||
func (s *Log) LogLine(ctx context.Context, level operations.Level, message string, source string) (*operations.LogLineResponse, error) {
|
||||
hookCtx := hooks.HookContext{OperationID: "logLine"}
|
||||
|
||||
request := operations.LogLineRequest{
|
||||
Level: level,
|
||||
Message: message,
|
||||
@@ -35,29 +38,50 @@ func (s *Log) LogLine(ctx context.Context, level operations.Level, message strin
|
||||
}
|
||||
|
||||
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
|
||||
url := strings.TrimSuffix(baseURL, "/") + "/log"
|
||||
opURL, err := url.JoinPath(baseURL, "/log")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error generating URL: %w", err)
|
||||
}
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", url, nil)
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", opURL, 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)
|
||||
req.Header.Set("User-Agent", s.sdkConfiguration.UserAgent)
|
||||
|
||||
if err := utils.PopulateQueryParams(ctx, req, request, nil); err != nil {
|
||||
return nil, fmt.Errorf("error populating query params: %w", err)
|
||||
}
|
||||
|
||||
req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{hookCtx}, req)
|
||||
if err != nil {
|
||||
return nil, 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")
|
||||
}
|
||||
if err != nil || httpRes == nil {
|
||||
if err != nil {
|
||||
err = fmt.Errorf("error sending request: %w", err)
|
||||
} else {
|
||||
err = fmt.Errorf("error sending request: no response")
|
||||
}
|
||||
|
||||
_, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{hookCtx}, nil, err)
|
||||
return nil, err
|
||||
} else if utils.MatchStatusCodes([]string{"400", "401", "4XX", "5XX"}, httpRes.StatusCode) {
|
||||
httpRes, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{hookCtx}, httpRes, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{hookCtx}, httpRes)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
contentType := httpRes.Header.Get("Content-Type")
|
||||
|
||||
res := &operations.LogLineResponse{
|
||||
@@ -72,6 +96,7 @@ func (s *Log) LogLine(ctx context.Context, level operations.Level, message strin
|
||||
}
|
||||
httpRes.Body.Close()
|
||||
httpRes.Body = io.NopCloser(bytes.NewBuffer(rawBody))
|
||||
|
||||
switch {
|
||||
case httpRes.StatusCode == 200:
|
||||
case httpRes.StatusCode == 400:
|
||||
@@ -121,36 +146,55 @@ func (s *Log) LogLine(ctx context.Context, level operations.Level, message strin
|
||||
//
|
||||
// Ensure each parameter is properly URL-encoded to avoid interpretation issues.
|
||||
func (s *Log) LogMultiLine(ctx context.Context, request string) (*operations.LogMultiLineResponse, error) {
|
||||
hookCtx := hooks.HookContext{OperationID: "logMultiLine"}
|
||||
|
||||
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
|
||||
url := strings.TrimSuffix(baseURL, "/") + "/log"
|
||||
opURL, err := url.JoinPath(baseURL, "/log")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error generating URL: %w", err)
|
||||
}
|
||||
|
||||
bodyReader, reqContentType, err := utils.SerializeRequestBody(ctx, request, false, false, "Request", "string", `request:"mediaType=text/plain"`)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error serializing request body: %w", err)
|
||||
}
|
||||
if bodyReader == nil {
|
||||
return nil, fmt.Errorf("request body is required")
|
||||
return nil, err
|
||||
}
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, "POST", url, bodyReader)
|
||||
req, err := http.NewRequestWithContext(ctx, "POST", opURL, bodyReader)
|
||||
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)
|
||||
|
||||
req.Header.Set("User-Agent", s.sdkConfiguration.UserAgent)
|
||||
req.Header.Set("Content-Type", reqContentType)
|
||||
|
||||
req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{hookCtx}, req)
|
||||
if err != nil {
|
||||
return nil, 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")
|
||||
}
|
||||
if err != nil || httpRes == nil {
|
||||
if err != nil {
|
||||
err = fmt.Errorf("error sending request: %w", err)
|
||||
} else {
|
||||
err = fmt.Errorf("error sending request: no response")
|
||||
}
|
||||
|
||||
_, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{hookCtx}, nil, err)
|
||||
return nil, err
|
||||
} else if utils.MatchStatusCodes([]string{"400", "401", "4XX", "5XX"}, httpRes.StatusCode) {
|
||||
httpRes, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{hookCtx}, httpRes, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{hookCtx}, httpRes)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
contentType := httpRes.Header.Get("Content-Type")
|
||||
|
||||
res := &operations.LogMultiLineResponse{
|
||||
@@ -165,6 +209,7 @@ func (s *Log) LogMultiLine(ctx context.Context, request string) (*operations.Log
|
||||
}
|
||||
httpRes.Body.Close()
|
||||
httpRes.Body = io.NopCloser(bytes.NewBuffer(rawBody))
|
||||
|
||||
switch {
|
||||
case httpRes.StatusCode == 200:
|
||||
case httpRes.StatusCode == 400:
|
||||
@@ -194,26 +239,49 @@ func (s *Log) LogMultiLine(ctx context.Context, request string) (*operations.Log
|
||||
// EnablePaperTrail - Enabling Papertrail
|
||||
// This endpoint will enable all Plex Media Serverlogs to be sent to the Papertrail networked logging site for a period of time.
|
||||
func (s *Log) EnablePaperTrail(ctx context.Context) (*operations.EnablePaperTrailResponse, error) {
|
||||
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
|
||||
url := strings.TrimSuffix(baseURL, "/") + "/log/networked"
|
||||
hookCtx := hooks.HookContext{OperationID: "enablePaperTrail"}
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", url, nil)
|
||||
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
|
||||
opURL, err := url.JoinPath(baseURL, "/log/networked")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error generating URL: %w", err)
|
||||
}
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", opURL, 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)
|
||||
req.Header.Set("User-Agent", s.sdkConfiguration.UserAgent)
|
||||
|
||||
req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{hookCtx}, req)
|
||||
if err != nil {
|
||||
return nil, 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")
|
||||
}
|
||||
if err != nil || httpRes == nil {
|
||||
if err != nil {
|
||||
err = fmt.Errorf("error sending request: %w", err)
|
||||
} else {
|
||||
err = fmt.Errorf("error sending request: no response")
|
||||
}
|
||||
|
||||
_, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{hookCtx}, nil, err)
|
||||
return nil, err
|
||||
} else if utils.MatchStatusCodes([]string{"400", "401", "403", "4XX", "5XX"}, httpRes.StatusCode) {
|
||||
httpRes, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{hookCtx}, httpRes, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{hookCtx}, httpRes)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
contentType := httpRes.Header.Get("Content-Type")
|
||||
|
||||
res := &operations.EnablePaperTrailResponse{
|
||||
@@ -228,6 +296,7 @@ func (s *Log) EnablePaperTrail(ctx context.Context) (*operations.EnablePaperTrai
|
||||
}
|
||||
httpRes.Body.Close()
|
||||
httpRes.Body = io.NopCloser(bytes.NewBuffer(rawBody))
|
||||
|
||||
switch {
|
||||
case httpRes.StatusCode == 200:
|
||||
case httpRes.StatusCode == 400:
|
||||
|
||||
129
media.go
129
media.go
@@ -6,12 +6,13 @@ import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/LukeHagar/plexgo/internal/hooks"
|
||||
"github.com/LukeHagar/plexgo/internal/utils"
|
||||
"github.com/LukeHagar/plexgo/models/operations"
|
||||
"github.com/LukeHagar/plexgo/models/sdkerrors"
|
||||
"io"
|
||||
"net/http"
|
||||
"strings"
|
||||
"net/url"
|
||||
)
|
||||
|
||||
// Media - API Calls interacting with Plex Media Server Media
|
||||
@@ -28,34 +29,57 @@ func newMedia(sdkConfig sdkConfiguration) *Media {
|
||||
// MarkPlayed - Mark Media Played
|
||||
// This will mark the provided media key as Played.
|
||||
func (s *Media) MarkPlayed(ctx context.Context, key float64) (*operations.MarkPlayedResponse, error) {
|
||||
hookCtx := hooks.HookContext{OperationID: "markPlayed"}
|
||||
|
||||
request := operations.MarkPlayedRequest{
|
||||
Key: key,
|
||||
}
|
||||
|
||||
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
|
||||
url := strings.TrimSuffix(baseURL, "/") + "/:/scrobble"
|
||||
opURL, err := url.JoinPath(baseURL, "/:/scrobble")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error generating URL: %w", err)
|
||||
}
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", url, nil)
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", opURL, 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)
|
||||
req.Header.Set("User-Agent", s.sdkConfiguration.UserAgent)
|
||||
|
||||
if err := utils.PopulateQueryParams(ctx, req, request, nil); err != nil {
|
||||
return nil, fmt.Errorf("error populating query params: %w", err)
|
||||
}
|
||||
|
||||
req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{hookCtx}, req)
|
||||
if err != nil {
|
||||
return nil, 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")
|
||||
}
|
||||
if err != nil || httpRes == nil {
|
||||
if err != nil {
|
||||
err = fmt.Errorf("error sending request: %w", err)
|
||||
} else {
|
||||
err = fmt.Errorf("error sending request: no response")
|
||||
}
|
||||
|
||||
_, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{hookCtx}, nil, err)
|
||||
return nil, err
|
||||
} else if utils.MatchStatusCodes([]string{"400", "401", "4XX", "5XX"}, httpRes.StatusCode) {
|
||||
httpRes, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{hookCtx}, httpRes, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{hookCtx}, httpRes)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
contentType := httpRes.Header.Get("Content-Type")
|
||||
|
||||
res := &operations.MarkPlayedResponse{
|
||||
@@ -70,6 +94,7 @@ func (s *Media) MarkPlayed(ctx context.Context, key float64) (*operations.MarkPl
|
||||
}
|
||||
httpRes.Body.Close()
|
||||
httpRes.Body = io.NopCloser(bytes.NewBuffer(rawBody))
|
||||
|
||||
switch {
|
||||
case httpRes.StatusCode == 200:
|
||||
case httpRes.StatusCode == 400:
|
||||
@@ -99,34 +124,57 @@ func (s *Media) MarkPlayed(ctx context.Context, key float64) (*operations.MarkPl
|
||||
// MarkUnplayed - Mark Media Unplayed
|
||||
// This will mark the provided media key as Unplayed.
|
||||
func (s *Media) MarkUnplayed(ctx context.Context, key float64) (*operations.MarkUnplayedResponse, error) {
|
||||
hookCtx := hooks.HookContext{OperationID: "markUnplayed"}
|
||||
|
||||
request := operations.MarkUnplayedRequest{
|
||||
Key: key,
|
||||
}
|
||||
|
||||
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
|
||||
url := strings.TrimSuffix(baseURL, "/") + "/:/unscrobble"
|
||||
opURL, err := url.JoinPath(baseURL, "/:/unscrobble")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error generating URL: %w", err)
|
||||
}
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", url, nil)
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", opURL, 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)
|
||||
req.Header.Set("User-Agent", s.sdkConfiguration.UserAgent)
|
||||
|
||||
if err := utils.PopulateQueryParams(ctx, req, request, nil); err != nil {
|
||||
return nil, fmt.Errorf("error populating query params: %w", err)
|
||||
}
|
||||
|
||||
req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{hookCtx}, req)
|
||||
if err != nil {
|
||||
return nil, 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")
|
||||
}
|
||||
if err != nil || httpRes == nil {
|
||||
if err != nil {
|
||||
err = fmt.Errorf("error sending request: %w", err)
|
||||
} else {
|
||||
err = fmt.Errorf("error sending request: no response")
|
||||
}
|
||||
|
||||
_, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{hookCtx}, nil, err)
|
||||
return nil, err
|
||||
} else if utils.MatchStatusCodes([]string{"400", "401", "4XX", "5XX"}, httpRes.StatusCode) {
|
||||
httpRes, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{hookCtx}, httpRes, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{hookCtx}, httpRes)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
contentType := httpRes.Header.Get("Content-Type")
|
||||
|
||||
res := &operations.MarkUnplayedResponse{
|
||||
@@ -141,6 +189,7 @@ func (s *Media) MarkUnplayed(ctx context.Context, key float64) (*operations.Mark
|
||||
}
|
||||
httpRes.Body.Close()
|
||||
httpRes.Body = io.NopCloser(bytes.NewBuffer(rawBody))
|
||||
|
||||
switch {
|
||||
case httpRes.StatusCode == 200:
|
||||
case httpRes.StatusCode == 400:
|
||||
@@ -170,6 +219,8 @@ func (s *Media) MarkUnplayed(ctx context.Context, key float64) (*operations.Mark
|
||||
// UpdatePlayProgress - Update Media Play Progress
|
||||
// This API command can be used to update the play progress of a media item.
|
||||
func (s *Media) UpdatePlayProgress(ctx context.Context, key string, time float64, state string) (*operations.UpdatePlayProgressResponse, error) {
|
||||
hookCtx := hooks.HookContext{OperationID: "updatePlayProgress"}
|
||||
|
||||
request := operations.UpdatePlayProgressRequest{
|
||||
Key: key,
|
||||
Time: time,
|
||||
@@ -177,29 +228,50 @@ func (s *Media) UpdatePlayProgress(ctx context.Context, key string, time float64
|
||||
}
|
||||
|
||||
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
|
||||
url := strings.TrimSuffix(baseURL, "/") + "/:/progress"
|
||||
opURL, err := url.JoinPath(baseURL, "/:/progress")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error generating URL: %w", err)
|
||||
}
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, "POST", url, nil)
|
||||
req, err := http.NewRequestWithContext(ctx, "POST", opURL, 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)
|
||||
req.Header.Set("User-Agent", s.sdkConfiguration.UserAgent)
|
||||
|
||||
if err := utils.PopulateQueryParams(ctx, req, request, nil); err != nil {
|
||||
return nil, fmt.Errorf("error populating query params: %w", err)
|
||||
}
|
||||
|
||||
req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{hookCtx}, req)
|
||||
if err != nil {
|
||||
return nil, 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")
|
||||
}
|
||||
if err != nil || httpRes == nil {
|
||||
if err != nil {
|
||||
err = fmt.Errorf("error sending request: %w", err)
|
||||
} else {
|
||||
err = fmt.Errorf("error sending request: no response")
|
||||
}
|
||||
|
||||
_, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{hookCtx}, nil, err)
|
||||
return nil, err
|
||||
} else if utils.MatchStatusCodes([]string{"400", "401", "4XX", "5XX"}, httpRes.StatusCode) {
|
||||
httpRes, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{hookCtx}, httpRes, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{hookCtx}, httpRes)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
contentType := httpRes.Header.Get("Content-Type")
|
||||
|
||||
res := &operations.UpdatePlayProgressResponse{
|
||||
@@ -214,6 +286,7 @@ func (s *Media) UpdatePlayProgress(ctx context.Context, key string, time float64
|
||||
}
|
||||
httpRes.Body.Close()
|
||||
httpRes.Body = io.NopCloser(bytes.NewBuffer(rawBody))
|
||||
|
||||
switch {
|
||||
case httpRes.StatusCode == 200:
|
||||
case httpRes.StatusCode == 400:
|
||||
|
||||
@@ -8,20 +8,20 @@ import (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// Type - type of playlist to create
|
||||
type Type string
|
||||
// QueryParamType - type of playlist to create
|
||||
type QueryParamType string
|
||||
|
||||
const (
|
||||
TypeAudio Type = "audio"
|
||||
TypeVideo Type = "video"
|
||||
TypePhoto Type = "photo"
|
||||
QueryParamTypeAudio QueryParamType = "audio"
|
||||
QueryParamTypeVideo QueryParamType = "video"
|
||||
QueryParamTypePhoto QueryParamType = "photo"
|
||||
)
|
||||
|
||||
func (e Type) ToPointer() *Type {
|
||||
func (e QueryParamType) ToPointer() *QueryParamType {
|
||||
return &e
|
||||
}
|
||||
|
||||
func (e *Type) UnmarshalJSON(data []byte) error {
|
||||
func (e *QueryParamType) UnmarshalJSON(data []byte) error {
|
||||
var v string
|
||||
if err := json.Unmarshal(data, &v); err != nil {
|
||||
return err
|
||||
@@ -32,10 +32,10 @@ func (e *Type) UnmarshalJSON(data []byte) error {
|
||||
case "video":
|
||||
fallthrough
|
||||
case "photo":
|
||||
*e = Type(v)
|
||||
*e = QueryParamType(v)
|
||||
return nil
|
||||
default:
|
||||
return fmt.Errorf("invalid value for Type: %v", v)
|
||||
return fmt.Errorf("invalid value for QueryParamType: %v", v)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@ type CreatePlaylistRequest struct {
|
||||
// name of the playlist
|
||||
Title string `queryParam:"style=form,explode=true,name=title"`
|
||||
// type of playlist to create
|
||||
Type Type `queryParam:"style=form,explode=true,name=type"`
|
||||
Type QueryParamType `queryParam:"style=form,explode=true,name=type"`
|
||||
// whether the playlist is smart or not
|
||||
Smart Smart `queryParam:"style=form,explode=true,name=smart"`
|
||||
// the content URI for the playlist
|
||||
@@ -87,9 +87,9 @@ func (o *CreatePlaylistRequest) GetTitle() string {
|
||||
return o.Title
|
||||
}
|
||||
|
||||
func (o *CreatePlaylistRequest) GetType() Type {
|
||||
func (o *CreatePlaylistRequest) GetType() QueryParamType {
|
||||
if o == nil {
|
||||
return Type("")
|
||||
return QueryParamType("")
|
||||
}
|
||||
return o.Type
|
||||
}
|
||||
|
||||
@@ -6,19 +6,19 @@ import (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type Location struct {
|
||||
type GetLibrariesLocation struct {
|
||||
ID *int `json:"id,omitempty"`
|
||||
Path *string `json:"path,omitempty"`
|
||||
}
|
||||
|
||||
func (o *Location) GetID() *int {
|
||||
func (o *GetLibrariesLocation) GetID() *int {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
return o.ID
|
||||
}
|
||||
|
||||
func (o *Location) GetPath() *string {
|
||||
func (o *GetLibrariesLocation) GetPath() *string {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
@@ -26,27 +26,27 @@ func (o *Location) GetPath() *string {
|
||||
}
|
||||
|
||||
type GetLibrariesDirectory struct {
|
||||
AllowSync *bool `json:"allowSync,omitempty"`
|
||||
Art *string `json:"art,omitempty"`
|
||||
Composite *string `json:"composite,omitempty"`
|
||||
Filters *bool `json:"filters,omitempty"`
|
||||
Refreshing *bool `json:"refreshing,omitempty"`
|
||||
Thumb *string `json:"thumb,omitempty"`
|
||||
Key *string `json:"key,omitempty"`
|
||||
Type *string `json:"type,omitempty"`
|
||||
Title *string `json:"title,omitempty"`
|
||||
Agent *string `json:"agent,omitempty"`
|
||||
Scanner *string `json:"scanner,omitempty"`
|
||||
Language *string `json:"language,omitempty"`
|
||||
UUID *string `json:"uuid,omitempty"`
|
||||
UpdatedAt *int `json:"updatedAt,omitempty"`
|
||||
CreatedAt *int `json:"createdAt,omitempty"`
|
||||
ScannedAt *int `json:"scannedAt,omitempty"`
|
||||
Content *bool `json:"content,omitempty"`
|
||||
Directory *bool `json:"directory,omitempty"`
|
||||
ContentChangedAt *int `json:"contentChangedAt,omitempty"`
|
||||
Hidden *int `json:"hidden,omitempty"`
|
||||
Location []Location `json:"Location,omitempty"`
|
||||
AllowSync *bool `json:"allowSync,omitempty"`
|
||||
Art *string `json:"art,omitempty"`
|
||||
Composite *string `json:"composite,omitempty"`
|
||||
Filters *bool `json:"filters,omitempty"`
|
||||
Refreshing *bool `json:"refreshing,omitempty"`
|
||||
Thumb *string `json:"thumb,omitempty"`
|
||||
Key *string `json:"key,omitempty"`
|
||||
Type *string `json:"type,omitempty"`
|
||||
Title *string `json:"title,omitempty"`
|
||||
Agent *string `json:"agent,omitempty"`
|
||||
Scanner *string `json:"scanner,omitempty"`
|
||||
Language *string `json:"language,omitempty"`
|
||||
UUID *string `json:"uuid,omitempty"`
|
||||
UpdatedAt *int `json:"updatedAt,omitempty"`
|
||||
CreatedAt *int `json:"createdAt,omitempty"`
|
||||
ScannedAt *int `json:"scannedAt,omitempty"`
|
||||
Content *bool `json:"content,omitempty"`
|
||||
Directory *bool `json:"directory,omitempty"`
|
||||
ContentChangedAt *int `json:"contentChangedAt,omitempty"`
|
||||
Hidden *int `json:"hidden,omitempty"`
|
||||
Location []GetLibrariesLocation `json:"Location,omitempty"`
|
||||
}
|
||||
|
||||
func (o *GetLibrariesDirectory) GetAllowSync() *bool {
|
||||
@@ -189,7 +189,7 @@ func (o *GetLibrariesDirectory) GetHidden() *int {
|
||||
return o.Hidden
|
||||
}
|
||||
|
||||
func (o *GetLibrariesDirectory) GetLocation() []Location {
|
||||
func (o *GetLibrariesDirectory) GetLocation() []GetLibrariesLocation {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -14,26 +14,25 @@ import (
|
||||
type Tag string
|
||||
|
||||
const (
|
||||
TagAll Tag = "all"
|
||||
TagUnwatched Tag = "unwatched"
|
||||
TagNewest Tag = "newest"
|
||||
TagRecentlyAdded Tag = "recentlyAdded"
|
||||
TagRecentlyViewed Tag = "recentlyViewed"
|
||||
TagOnDeck Tag = "onDeck"
|
||||
TagCollection Tag = "collection"
|
||||
TagEdition Tag = "edition"
|
||||
TagGenre Tag = "genre"
|
||||
TagYear Tag = "year"
|
||||
TagDecade Tag = "decade"
|
||||
TagDirector Tag = "director"
|
||||
TagActor Tag = "actor"
|
||||
TagCountry Tag = "country"
|
||||
TagContentRating Tag = "contentRating"
|
||||
TagRating Tag = "rating"
|
||||
TagResolution Tag = "resolution"
|
||||
TagFirstCharacter Tag = "firstCharacter"
|
||||
TagFolder Tag = "folder"
|
||||
TagSearchTypeEqual1 Tag = "search?type=1"
|
||||
TagAll Tag = "all"
|
||||
TagUnwatched Tag = "unwatched"
|
||||
TagNewest Tag = "newest"
|
||||
TagRecentlyAdded Tag = "recentlyAdded"
|
||||
TagRecentlyViewed Tag = "recentlyViewed"
|
||||
TagOnDeck Tag = "onDeck"
|
||||
TagCollection Tag = "collection"
|
||||
TagEdition Tag = "edition"
|
||||
TagGenre Tag = "genre"
|
||||
TagYear Tag = "year"
|
||||
TagDecade Tag = "decade"
|
||||
TagDirector Tag = "director"
|
||||
TagActor Tag = "actor"
|
||||
TagCountry Tag = "country"
|
||||
TagContentRating Tag = "contentRating"
|
||||
TagRating Tag = "rating"
|
||||
TagResolution Tag = "resolution"
|
||||
TagFirstCharacter Tag = "firstCharacter"
|
||||
TagFolder Tag = "folder"
|
||||
)
|
||||
|
||||
func (e Tag) ToPointer() *Tag {
|
||||
@@ -83,8 +82,6 @@ func (e *Tag) UnmarshalJSON(data []byte) error {
|
||||
case "firstCharacter":
|
||||
fallthrough
|
||||
case "folder":
|
||||
fallthrough
|
||||
case "search?type=1":
|
||||
*e = Tag(v)
|
||||
return nil
|
||||
default:
|
||||
@@ -343,40 +340,63 @@ func (o *GetLibraryItemsRole) GetTag() *string {
|
||||
}
|
||||
|
||||
type GetLibraryItemsMetadata struct {
|
||||
RatingKey *string `json:"ratingKey,omitempty"`
|
||||
Key *string `json:"key,omitempty"`
|
||||
GUID *string `json:"guid,omitempty"`
|
||||
Studio *string `json:"studio,omitempty"`
|
||||
Type *string `json:"type,omitempty"`
|
||||
Title *string `json:"title,omitempty"`
|
||||
ContentRating *string `json:"contentRating,omitempty"`
|
||||
Summary *string `json:"summary,omitempty"`
|
||||
Rating *float64 `json:"rating,omitempty"`
|
||||
AudienceRating *float64 `json:"audienceRating,omitempty"`
|
||||
Year *int `json:"year,omitempty"`
|
||||
Tagline *string `json:"tagline,omitempty"`
|
||||
Thumb *string `json:"thumb,omitempty"`
|
||||
Art *string `json:"art,omitempty"`
|
||||
Duration *int `json:"duration,omitempty"`
|
||||
OriginallyAvailableAt *types.Date `json:"originallyAvailableAt,omitempty"`
|
||||
AddedAt *int `json:"addedAt,omitempty"`
|
||||
UpdatedAt *int `json:"updatedAt,omitempty"`
|
||||
AudienceRatingImage *string `json:"audienceRatingImage,omitempty"`
|
||||
ChapterSource *string `json:"chapterSource,omitempty"`
|
||||
PrimaryExtraKey *string `json:"primaryExtraKey,omitempty"`
|
||||
RatingImage *string `json:"ratingImage,omitempty"`
|
||||
Media []GetLibraryItemsMedia `json:"Media,omitempty"`
|
||||
Genre []GetLibraryItemsGenre `json:"Genre,omitempty"`
|
||||
Country []GetLibraryItemsCountry `json:"Country,omitempty"`
|
||||
Director []GetLibraryItemsDirector `json:"Director,omitempty"`
|
||||
Writer []GetLibraryItemsWriter `json:"Writer,omitempty"`
|
||||
Role []GetLibraryItemsRole `json:"Role,omitempty"`
|
||||
TitleSort *string `json:"titleSort,omitempty"`
|
||||
ViewCount *int `json:"viewCount,omitempty"`
|
||||
LastViewedAt *int `json:"lastViewedAt,omitempty"`
|
||||
OriginalTitle *string `json:"originalTitle,omitempty"`
|
||||
ViewOffset *int `json:"viewOffset,omitempty"`
|
||||
SkipCount *int `json:"skipCount,omitempty"`
|
||||
RatingKey *string `json:"ratingKey,omitempty"`
|
||||
Key *string `json:"key,omitempty"`
|
||||
GUID *string `json:"guid,omitempty"`
|
||||
Studio *string `json:"studio,omitempty"`
|
||||
Type *string `json:"type,omitempty"`
|
||||
Title *string `json:"title,omitempty"`
|
||||
ContentRating *string `json:"contentRating,omitempty"`
|
||||
Summary *string `json:"summary,omitempty"`
|
||||
Rating *float64 `json:"rating,omitempty"`
|
||||
AudienceRating *float64 `json:"audienceRating,omitempty"`
|
||||
Year *int `json:"year,omitempty"`
|
||||
Tagline *string `json:"tagline,omitempty"`
|
||||
Thumb *string `json:"thumb,omitempty"`
|
||||
Art *string `json:"art,omitempty"`
|
||||
Duration *int `json:"duration,omitempty"`
|
||||
OriginallyAvailableAt *types.Date `json:"originallyAvailableAt,omitempty"`
|
||||
AddedAt *int `json:"addedAt,omitempty"`
|
||||
UpdatedAt *int `json:"updatedAt,omitempty"`
|
||||
AudienceRatingImage *string `json:"audienceRatingImage,omitempty"`
|
||||
ChapterSource *string `json:"chapterSource,omitempty"`
|
||||
PrimaryExtraKey *string `json:"primaryExtraKey,omitempty"`
|
||||
RatingImage *string `json:"ratingImage,omitempty"`
|
||||
GrandparentRatingKey *string `json:"grandparentRatingKey,omitempty"`
|
||||
GrandparentGUID *string `json:"grandparentGuid,omitempty"`
|
||||
GrandparentKey *string `json:"grandparentKey,omitempty"`
|
||||
GrandparentTitle *string `json:"grandparentTitle,omitempty"`
|
||||
GrandparentThumb *string `json:"grandparentThumb,omitempty"`
|
||||
GrandparentArt *string `json:"grandparentArt,omitempty"`
|
||||
GrandparentTheme *string `json:"grandparentTheme,omitempty"`
|
||||
Media []GetLibraryItemsMedia `json:"Media,omitempty"`
|
||||
Genre []GetLibraryItemsGenre `json:"Genre,omitempty"`
|
||||
Country []GetLibraryItemsCountry `json:"Country,omitempty"`
|
||||
Director []GetLibraryItemsDirector `json:"Director,omitempty"`
|
||||
Writer []GetLibraryItemsWriter `json:"Writer,omitempty"`
|
||||
Role []GetLibraryItemsRole `json:"Role,omitempty"`
|
||||
TitleSort *string `json:"titleSort,omitempty"`
|
||||
ViewCount *int `json:"viewCount,omitempty"`
|
||||
LastViewedAt *int `json:"lastViewedAt,omitempty"`
|
||||
OriginalTitle *string `json:"originalTitle,omitempty"`
|
||||
ViewOffset *int `json:"viewOffset,omitempty"`
|
||||
SkipCount *int `json:"skipCount,omitempty"`
|
||||
Index *int `json:"index,omitempty"`
|
||||
Theme *string `json:"theme,omitempty"`
|
||||
LeafCount *int `json:"leafCount,omitempty"`
|
||||
ViewedLeafCount *int `json:"viewedLeafCount,omitempty"`
|
||||
ChildCount *int `json:"childCount,omitempty"`
|
||||
HasPremiumExtras *string `json:"hasPremiumExtras,omitempty"`
|
||||
HasPremiumPrimaryExtra *string `json:"hasPremiumPrimaryExtra,omitempty"`
|
||||
ParentRatingKey *string `json:"parentRatingKey,omitempty"`
|
||||
ParentGUID *string `json:"parentGuid,omitempty"`
|
||||
ParentStudio *string `json:"parentStudio,omitempty"`
|
||||
ParentKey *string `json:"parentKey,omitempty"`
|
||||
ParentTitle *string `json:"parentTitle,omitempty"`
|
||||
ParentIndex *int `json:"parentIndex,omitempty"`
|
||||
ParentYear *int `json:"parentYear,omitempty"`
|
||||
ParentThumb *string `json:"parentThumb,omitempty"`
|
||||
ParentTheme *string `json:"parentTheme,omitempty"`
|
||||
}
|
||||
|
||||
func (g GetLibraryItemsMetadata) MarshalJSON() ([]byte, error) {
|
||||
@@ -544,6 +564,55 @@ func (o *GetLibraryItemsMetadata) GetRatingImage() *string {
|
||||
return o.RatingImage
|
||||
}
|
||||
|
||||
func (o *GetLibraryItemsMetadata) GetGrandparentRatingKey() *string {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
return o.GrandparentRatingKey
|
||||
}
|
||||
|
||||
func (o *GetLibraryItemsMetadata) GetGrandparentGUID() *string {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
return o.GrandparentGUID
|
||||
}
|
||||
|
||||
func (o *GetLibraryItemsMetadata) GetGrandparentKey() *string {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
return o.GrandparentKey
|
||||
}
|
||||
|
||||
func (o *GetLibraryItemsMetadata) GetGrandparentTitle() *string {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
return o.GrandparentTitle
|
||||
}
|
||||
|
||||
func (o *GetLibraryItemsMetadata) GetGrandparentThumb() *string {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
return o.GrandparentThumb
|
||||
}
|
||||
|
||||
func (o *GetLibraryItemsMetadata) GetGrandparentArt() *string {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
return o.GrandparentArt
|
||||
}
|
||||
|
||||
func (o *GetLibraryItemsMetadata) GetGrandparentTheme() *string {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
return o.GrandparentTheme
|
||||
}
|
||||
|
||||
func (o *GetLibraryItemsMetadata) GetMedia() []GetLibraryItemsMedia {
|
||||
if o == nil {
|
||||
return nil
|
||||
@@ -628,6 +697,118 @@ func (o *GetLibraryItemsMetadata) GetSkipCount() *int {
|
||||
return o.SkipCount
|
||||
}
|
||||
|
||||
func (o *GetLibraryItemsMetadata) GetIndex() *int {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
return o.Index
|
||||
}
|
||||
|
||||
func (o *GetLibraryItemsMetadata) GetTheme() *string {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
return o.Theme
|
||||
}
|
||||
|
||||
func (o *GetLibraryItemsMetadata) GetLeafCount() *int {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
return o.LeafCount
|
||||
}
|
||||
|
||||
func (o *GetLibraryItemsMetadata) GetViewedLeafCount() *int {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
return o.ViewedLeafCount
|
||||
}
|
||||
|
||||
func (o *GetLibraryItemsMetadata) GetChildCount() *int {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
return o.ChildCount
|
||||
}
|
||||
|
||||
func (o *GetLibraryItemsMetadata) GetHasPremiumExtras() *string {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
return o.HasPremiumExtras
|
||||
}
|
||||
|
||||
func (o *GetLibraryItemsMetadata) GetHasPremiumPrimaryExtra() *string {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
return o.HasPremiumPrimaryExtra
|
||||
}
|
||||
|
||||
func (o *GetLibraryItemsMetadata) GetParentRatingKey() *string {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
return o.ParentRatingKey
|
||||
}
|
||||
|
||||
func (o *GetLibraryItemsMetadata) GetParentGUID() *string {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
return o.ParentGUID
|
||||
}
|
||||
|
||||
func (o *GetLibraryItemsMetadata) GetParentStudio() *string {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
return o.ParentStudio
|
||||
}
|
||||
|
||||
func (o *GetLibraryItemsMetadata) GetParentKey() *string {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
return o.ParentKey
|
||||
}
|
||||
|
||||
func (o *GetLibraryItemsMetadata) GetParentTitle() *string {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
return o.ParentTitle
|
||||
}
|
||||
|
||||
func (o *GetLibraryItemsMetadata) GetParentIndex() *int {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
return o.ParentIndex
|
||||
}
|
||||
|
||||
func (o *GetLibraryItemsMetadata) GetParentYear() *int {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
return o.ParentYear
|
||||
}
|
||||
|
||||
func (o *GetLibraryItemsMetadata) GetParentThumb() *string {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
return o.ParentThumb
|
||||
}
|
||||
|
||||
func (o *GetLibraryItemsMetadata) GetParentTheme() *string {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
return o.ParentTheme
|
||||
}
|
||||
|
||||
type GetLibraryItemsMediaContainer struct {
|
||||
Size *int `json:"size,omitempty"`
|
||||
AllowSync *bool `json:"allowSync,omitempty"`
|
||||
@@ -643,6 +824,7 @@ type GetLibraryItemsMediaContainer struct {
|
||||
Title2 *string `json:"title2,omitempty"`
|
||||
ViewGroup *string `json:"viewGroup,omitempty"`
|
||||
ViewMode *int `json:"viewMode,omitempty"`
|
||||
MixedParents *bool `json:"mixedParents,omitempty"`
|
||||
Metadata []GetLibraryItemsMetadata `json:"Metadata,omitempty"`
|
||||
}
|
||||
|
||||
@@ -744,6 +926,13 @@ func (o *GetLibraryItemsMediaContainer) GetViewMode() *int {
|
||||
return o.ViewMode
|
||||
}
|
||||
|
||||
func (o *GetLibraryItemsMediaContainer) GetMixedParents() *bool {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
return o.MixedParents
|
||||
}
|
||||
|
||||
func (o *GetLibraryItemsMediaContainer) GetMetadata() []GetLibraryItemsMetadata {
|
||||
if o == nil {
|
||||
return nil
|
||||
|
||||
289
models/operations/getpin.go
Normal file
289
models/operations/getpin.go
Normal file
@@ -0,0 +1,289 @@
|
||||
// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT.
|
||||
|
||||
package operations
|
||||
|
||||
import (
|
||||
"github.com/LukeHagar/plexgo/internal/utils"
|
||||
"net/http"
|
||||
"time"
|
||||
)
|
||||
|
||||
var GetPinServerList = []string{
|
||||
"https://plex.tv/api/v2",
|
||||
}
|
||||
|
||||
type GetPinRequest struct {
|
||||
// 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
|
||||
// Non-Strong codes are used for `Plex.tv/link`
|
||||
//
|
||||
Strong *bool `default:"false" queryParam:"style=form,explode=true,name=strong"`
|
||||
}
|
||||
|
||||
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) GetXPlexClientIdentifier() string {
|
||||
if o == nil {
|
||||
return ""
|
||||
}
|
||||
return o.XPlexClientIdentifier
|
||||
}
|
||||
|
||||
func (o *GetPinRequest) GetStrong() *bool {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
return o.Strong
|
||||
}
|
||||
|
||||
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
|
||||
Object *GetPinResponseBody
|
||||
}
|
||||
|
||||
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) GetObject() *GetPinResponseBody {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
return o.Object
|
||||
}
|
||||
@@ -3,232 +3,92 @@
|
||||
package operations
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"github.com/LukeHagar/plexgo/internal/utils"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type Two struct {
|
||||
type Setting struct {
|
||||
ID *string `json:"id,omitempty"`
|
||||
Label *string `json:"label,omitempty"`
|
||||
Summary *string `json:"summary,omitempty"`
|
||||
Type *string `json:"type,omitempty"`
|
||||
Default *int `json:"default,omitempty"`
|
||||
Value *int `json:"value,omitempty"`
|
||||
Default *bool `json:"default,omitempty"`
|
||||
Value *bool `json:"value,omitempty"`
|
||||
Hidden *bool `json:"hidden,omitempty"`
|
||||
Advanced *bool `json:"advanced,omitempty"`
|
||||
Group *string `json:"group,omitempty"`
|
||||
EnumValues *string `json:"enumValues,omitempty"`
|
||||
}
|
||||
|
||||
func (o *Two) GetID() *string {
|
||||
func (o *Setting) GetID() *string {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
return o.ID
|
||||
}
|
||||
|
||||
func (o *Two) GetLabel() *string {
|
||||
func (o *Setting) GetLabel() *string {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
return o.Label
|
||||
}
|
||||
|
||||
func (o *Two) GetSummary() *string {
|
||||
func (o *Setting) GetSummary() *string {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
return o.Summary
|
||||
}
|
||||
|
||||
func (o *Two) GetType() *string {
|
||||
func (o *Setting) GetType() *string {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
return o.Type
|
||||
}
|
||||
|
||||
func (o *Two) GetDefault() *int {
|
||||
func (o *Setting) GetDefault() *bool {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
return o.Default
|
||||
}
|
||||
|
||||
func (o *Two) GetValue() *int {
|
||||
func (o *Setting) GetValue() *bool {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
return o.Value
|
||||
}
|
||||
|
||||
func (o *Two) GetHidden() *bool {
|
||||
func (o *Setting) GetHidden() *bool {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
return o.Hidden
|
||||
}
|
||||
|
||||
func (o *Two) GetAdvanced() *bool {
|
||||
func (o *Setting) GetAdvanced() *bool {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
return o.Advanced
|
||||
}
|
||||
|
||||
func (o *Two) GetGroup() *string {
|
||||
func (o *Setting) GetGroup() *string {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
return o.Group
|
||||
}
|
||||
|
||||
func (o *Two) GetEnumValues() *string {
|
||||
func (o *Setting) GetEnumValues() *string {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
return o.EnumValues
|
||||
}
|
||||
|
||||
type One struct {
|
||||
ID *string `json:"id,omitempty"`
|
||||
Label *string `json:"label,omitempty"`
|
||||
Summary *string `json:"summary,omitempty"`
|
||||
Type *string `json:"type,omitempty"`
|
||||
Default *string `json:"default,omitempty"`
|
||||
Value *string `json:"value,omitempty"`
|
||||
Hidden *bool `json:"hidden,omitempty"`
|
||||
Advanced *bool `json:"advanced,omitempty"`
|
||||
Group *string `json:"group,omitempty"`
|
||||
}
|
||||
|
||||
func (o *One) GetID() *string {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
return o.ID
|
||||
}
|
||||
|
||||
func (o *One) GetLabel() *string {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
return o.Label
|
||||
}
|
||||
|
||||
func (o *One) GetSummary() *string {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
return o.Summary
|
||||
}
|
||||
|
||||
func (o *One) GetType() *string {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
return o.Type
|
||||
}
|
||||
|
||||
func (o *One) GetDefault() *string {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
return o.Default
|
||||
}
|
||||
|
||||
func (o *One) GetValue() *string {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
return o.Value
|
||||
}
|
||||
|
||||
func (o *One) GetHidden() *bool {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
return o.Hidden
|
||||
}
|
||||
|
||||
func (o *One) GetAdvanced() *bool {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
return o.Advanced
|
||||
}
|
||||
|
||||
func (o *One) GetGroup() *string {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
return o.Group
|
||||
}
|
||||
|
||||
type SettingType string
|
||||
|
||||
const (
|
||||
SettingTypeOne SettingType = "1"
|
||||
SettingTypeTwo SettingType = "2"
|
||||
)
|
||||
|
||||
type Setting struct {
|
||||
One *One
|
||||
Two *Two
|
||||
|
||||
Type SettingType
|
||||
}
|
||||
|
||||
func CreateSettingOne(one One) Setting {
|
||||
typ := SettingTypeOne
|
||||
|
||||
return Setting{
|
||||
One: &one,
|
||||
Type: typ,
|
||||
}
|
||||
}
|
||||
|
||||
func CreateSettingTwo(two Two) Setting {
|
||||
typ := SettingTypeTwo
|
||||
|
||||
return Setting{
|
||||
Two: &two,
|
||||
Type: typ,
|
||||
}
|
||||
}
|
||||
|
||||
func (u *Setting) UnmarshalJSON(data []byte) error {
|
||||
|
||||
one := One{}
|
||||
if err := utils.UnmarshalJSON(data, &one, "", true, true); err == nil {
|
||||
u.One = &one
|
||||
u.Type = SettingTypeOne
|
||||
return nil
|
||||
}
|
||||
|
||||
two := Two{}
|
||||
if err := utils.UnmarshalJSON(data, &two, "", true, true); err == nil {
|
||||
u.Two = &two
|
||||
u.Type = SettingTypeTwo
|
||||
return nil
|
||||
}
|
||||
|
||||
return errors.New("could not unmarshal into supported union types")
|
||||
}
|
||||
|
||||
func (u Setting) MarshalJSON() ([]byte, error) {
|
||||
if u.One != nil {
|
||||
return utils.MarshalJSON(u.One, "", true)
|
||||
}
|
||||
|
||||
if u.Two != nil {
|
||||
return utils.MarshalJSON(u.Two, "", true)
|
||||
}
|
||||
|
||||
return nil, errors.New("could not marshal union type: all fields are null")
|
||||
}
|
||||
|
||||
type GetServerPreferencesMediaContainer struct {
|
||||
Size *int `json:"size,omitempty"`
|
||||
Setting []Setting `json:"Setting,omitempty"`
|
||||
|
||||
276
models/operations/getstatistics.go
Normal file
276
models/operations/getstatistics.go
Normal file
@@ -0,0 +1,276 @@
|
||||
// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT.
|
||||
|
||||
package operations
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type GetStatisticsRequest struct {
|
||||
// The timespan to retrieve statistics for
|
||||
// the exact meaning of this parameter is not known
|
||||
//
|
||||
Timespan *int64 `queryParam:"style=form,explode=true,name=Timespan"`
|
||||
}
|
||||
|
||||
func (o *GetStatisticsRequest) GetTimespan() *int64 {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
return o.Timespan
|
||||
}
|
||||
|
||||
type GetStatisticsDevice struct {
|
||||
ID *int `json:"id,omitempty"`
|
||||
Name *string `json:"name,omitempty"`
|
||||
Platform *string `json:"platform,omitempty"`
|
||||
ClientIdentifier *string `json:"clientIdentifier,omitempty"`
|
||||
CreatedAt *int `json:"createdAt,omitempty"`
|
||||
}
|
||||
|
||||
func (o *GetStatisticsDevice) GetID() *int {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
return o.ID
|
||||
}
|
||||
|
||||
func (o *GetStatisticsDevice) GetName() *string {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
return o.Name
|
||||
}
|
||||
|
||||
func (o *GetStatisticsDevice) GetPlatform() *string {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
return o.Platform
|
||||
}
|
||||
|
||||
func (o *GetStatisticsDevice) GetClientIdentifier() *string {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
return o.ClientIdentifier
|
||||
}
|
||||
|
||||
func (o *GetStatisticsDevice) GetCreatedAt() *int {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
return o.CreatedAt
|
||||
}
|
||||
|
||||
type Account struct {
|
||||
ID *int `json:"id,omitempty"`
|
||||
Key *string `json:"key,omitempty"`
|
||||
Name *string `json:"name,omitempty"`
|
||||
DefaultAudioLanguage *string `json:"defaultAudioLanguage,omitempty"`
|
||||
AutoSelectAudio *bool `json:"autoSelectAudio,omitempty"`
|
||||
DefaultSubtitleLanguage *string `json:"defaultSubtitleLanguage,omitempty"`
|
||||
SubtitleMode *int `json:"subtitleMode,omitempty"`
|
||||
Thumb *string `json:"thumb,omitempty"`
|
||||
}
|
||||
|
||||
func (o *Account) GetID() *int {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
return o.ID
|
||||
}
|
||||
|
||||
func (o *Account) GetKey() *string {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
return o.Key
|
||||
}
|
||||
|
||||
func (o *Account) GetName() *string {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
return o.Name
|
||||
}
|
||||
|
||||
func (o *Account) GetDefaultAudioLanguage() *string {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
return o.DefaultAudioLanguage
|
||||
}
|
||||
|
||||
func (o *Account) GetAutoSelectAudio() *bool {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
return o.AutoSelectAudio
|
||||
}
|
||||
|
||||
func (o *Account) GetDefaultSubtitleLanguage() *string {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
return o.DefaultSubtitleLanguage
|
||||
}
|
||||
|
||||
func (o *Account) GetSubtitleMode() *int {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
return o.SubtitleMode
|
||||
}
|
||||
|
||||
func (o *Account) GetThumb() *string {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
return o.Thumb
|
||||
}
|
||||
|
||||
type StatisticsMedia struct {
|
||||
AccountID *int `json:"accountID,omitempty"`
|
||||
DeviceID *int `json:"deviceID,omitempty"`
|
||||
Timespan *int `json:"timespan,omitempty"`
|
||||
At *int `json:"at,omitempty"`
|
||||
MetadataType *int `json:"metadataType,omitempty"`
|
||||
Count *int `json:"count,omitempty"`
|
||||
Duration *int `json:"duration,omitempty"`
|
||||
}
|
||||
|
||||
func (o *StatisticsMedia) GetAccountID() *int {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
return o.AccountID
|
||||
}
|
||||
|
||||
func (o *StatisticsMedia) GetDeviceID() *int {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
return o.DeviceID
|
||||
}
|
||||
|
||||
func (o *StatisticsMedia) GetTimespan() *int {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
return o.Timespan
|
||||
}
|
||||
|
||||
func (o *StatisticsMedia) GetAt() *int {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
return o.At
|
||||
}
|
||||
|
||||
func (o *StatisticsMedia) GetMetadataType() *int {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
return o.MetadataType
|
||||
}
|
||||
|
||||
func (o *StatisticsMedia) GetCount() *int {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
return o.Count
|
||||
}
|
||||
|
||||
func (o *StatisticsMedia) GetDuration() *int {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
return o.Duration
|
||||
}
|
||||
|
||||
type GetStatisticsMediaContainer struct {
|
||||
Size *int `json:"size,omitempty"`
|
||||
Device []GetStatisticsDevice `json:"Device,omitempty"`
|
||||
Account []Account `json:"Account,omitempty"`
|
||||
StatisticsMedia []StatisticsMedia `json:"StatisticsMedia,omitempty"`
|
||||
}
|
||||
|
||||
func (o *GetStatisticsMediaContainer) GetSize() *int {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
return o.Size
|
||||
}
|
||||
|
||||
func (o *GetStatisticsMediaContainer) GetDevice() []GetStatisticsDevice {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
return o.Device
|
||||
}
|
||||
|
||||
func (o *GetStatisticsMediaContainer) GetAccount() []Account {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
return o.Account
|
||||
}
|
||||
|
||||
func (o *GetStatisticsMediaContainer) GetStatisticsMedia() []StatisticsMedia {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
return o.StatisticsMedia
|
||||
}
|
||||
|
||||
// GetStatisticsResponseBody - Media Statistics
|
||||
type GetStatisticsResponseBody struct {
|
||||
MediaContainer *GetStatisticsMediaContainer `json:"MediaContainer,omitempty"`
|
||||
}
|
||||
|
||||
func (o *GetStatisticsResponseBody) GetMediaContainer() *GetStatisticsMediaContainer {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
return o.MediaContainer
|
||||
}
|
||||
|
||||
type GetStatisticsResponse 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
|
||||
// Media Statistics
|
||||
Object *GetStatisticsResponseBody
|
||||
}
|
||||
|
||||
func (o *GetStatisticsResponse) GetContentType() string {
|
||||
if o == nil {
|
||||
return ""
|
||||
}
|
||||
return o.ContentType
|
||||
}
|
||||
|
||||
func (o *GetStatisticsResponse) GetStatusCode() int {
|
||||
if o == nil {
|
||||
return 0
|
||||
}
|
||||
return o.StatusCode
|
||||
}
|
||||
|
||||
func (o *GetStatisticsResponse) GetRawResponse() *http.Response {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
return o.RawResponse
|
||||
}
|
||||
|
||||
func (o *GetStatisticsResponse) GetObject() *GetStatisticsResponseBody {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
return o.Object
|
||||
}
|
||||
65
models/operations/gettoken.go
Normal file
65
models/operations/gettoken.go
Normal file
@@ -0,0 +1,65 @@
|
||||
// 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"`
|
||||
// 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"`
|
||||
}
|
||||
|
||||
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 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
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
@@ -8,28 +8,28 @@ import (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// QueryParamType - `delegation` - This is the only supported `type` parameter.
|
||||
type QueryParamType string
|
||||
// GetTransientTokenQueryParamType - `delegation` - This is the only supported `type` parameter.
|
||||
type GetTransientTokenQueryParamType string
|
||||
|
||||
const (
|
||||
QueryParamTypeDelegation QueryParamType = "delegation"
|
||||
GetTransientTokenQueryParamTypeDelegation GetTransientTokenQueryParamType = "delegation"
|
||||
)
|
||||
|
||||
func (e QueryParamType) ToPointer() *QueryParamType {
|
||||
func (e GetTransientTokenQueryParamType) ToPointer() *GetTransientTokenQueryParamType {
|
||||
return &e
|
||||
}
|
||||
|
||||
func (e *QueryParamType) UnmarshalJSON(data []byte) error {
|
||||
func (e *GetTransientTokenQueryParamType) UnmarshalJSON(data []byte) error {
|
||||
var v string
|
||||
if err := json.Unmarshal(data, &v); err != nil {
|
||||
return err
|
||||
}
|
||||
switch v {
|
||||
case "delegation":
|
||||
*e = QueryParamType(v)
|
||||
*e = GetTransientTokenQueryParamType(v)
|
||||
return nil
|
||||
default:
|
||||
return fmt.Errorf("invalid value for QueryParamType: %v", v)
|
||||
return fmt.Errorf("invalid value for GetTransientTokenQueryParamType: %v", v)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,14 +60,14 @@ func (e *Scope) UnmarshalJSON(data []byte) error {
|
||||
|
||||
type GetTransientTokenRequest struct {
|
||||
// `delegation` - This is the only supported `type` parameter.
|
||||
Type QueryParamType `queryParam:"style=form,explode=true,name=type"`
|
||||
Type GetTransientTokenQueryParamType `queryParam:"style=form,explode=true,name=type"`
|
||||
// `all` - This is the only supported `scope` parameter.
|
||||
Scope Scope `queryParam:"style=form,explode=true,name=scope"`
|
||||
}
|
||||
|
||||
func (o *GetTransientTokenRequest) GetType() QueryParamType {
|
||||
func (o *GetTransientTokenRequest) GetType() GetTransientTokenQueryParamType {
|
||||
if o == nil {
|
||||
return QueryParamType("")
|
||||
return GetTransientTokenQueryParamType("")
|
||||
}
|
||||
return o.Type
|
||||
}
|
||||
|
||||
63
models/operations/options.go
Normal file
63
models/operations/options.go
Normal file
@@ -0,0 +1,63 @@
|
||||
// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT.
|
||||
|
||||
package operations
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"github.com/LukeHagar/plexgo/internal/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
|
||||
}
|
||||
}
|
||||
385
models/operations/searchlibrary.go
Normal file
385
models/operations/searchlibrary.go
Normal file
@@ -0,0 +1,385 @@
|
||||
// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT.
|
||||
|
||||
package operations
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// Type - Plex content type to search for
|
||||
type Type int64
|
||||
|
||||
const (
|
||||
TypeOne Type = 1
|
||||
TypeTwo Type = 2
|
||||
TypeThree Type = 3
|
||||
TypeFour Type = 4
|
||||
)
|
||||
|
||||
func (e Type) ToPointer() *Type {
|
||||
return &e
|
||||
}
|
||||
|
||||
func (e *Type) UnmarshalJSON(data []byte) error {
|
||||
var v int64
|
||||
if err := json.Unmarshal(data, &v); err != nil {
|
||||
return err
|
||||
}
|
||||
switch v {
|
||||
case 1:
|
||||
fallthrough
|
||||
case 2:
|
||||
fallthrough
|
||||
case 3:
|
||||
fallthrough
|
||||
case 4:
|
||||
*e = Type(v)
|
||||
return nil
|
||||
default:
|
||||
return fmt.Errorf("invalid value for Type: %v", v)
|
||||
}
|
||||
}
|
||||
|
||||
type SearchLibraryRequest struct {
|
||||
// the Id of the library to query
|
||||
SectionID int64 `pathParam:"style=simple,explode=false,name=sectionId"`
|
||||
// Plex content type to search for
|
||||
Type Type `queryParam:"style=form,explode=true,name=type"`
|
||||
}
|
||||
|
||||
func (o *SearchLibraryRequest) GetSectionID() int64 {
|
||||
if o == nil {
|
||||
return 0
|
||||
}
|
||||
return o.SectionID
|
||||
}
|
||||
|
||||
func (o *SearchLibraryRequest) GetType() Type {
|
||||
if o == nil {
|
||||
return Type(0)
|
||||
}
|
||||
return o.Type
|
||||
}
|
||||
|
||||
type SearchLibraryMetadata struct {
|
||||
RatingKey *string `json:"ratingKey,omitempty"`
|
||||
Key *string `json:"key,omitempty"`
|
||||
ParentRatingKey *string `json:"parentRatingKey,omitempty"`
|
||||
GUID *string `json:"guid,omitempty"`
|
||||
ParentGUID *string `json:"parentGuid,omitempty"`
|
||||
ParentStudio *string `json:"parentStudio,omitempty"`
|
||||
Type *string `json:"type,omitempty"`
|
||||
Title *string `json:"title,omitempty"`
|
||||
ParentKey *string `json:"parentKey,omitempty"`
|
||||
ParentTitle *string `json:"parentTitle,omitempty"`
|
||||
Summary *string `json:"summary,omitempty"`
|
||||
Index *int `json:"index,omitempty"`
|
||||
ParentIndex *int `json:"parentIndex,omitempty"`
|
||||
ParentYear *int `json:"parentYear,omitempty"`
|
||||
Thumb *string `json:"thumb,omitempty"`
|
||||
Art *string `json:"art,omitempty"`
|
||||
ParentThumb *string `json:"parentThumb,omitempty"`
|
||||
ParentTheme *string `json:"parentTheme,omitempty"`
|
||||
AddedAt *int `json:"addedAt,omitempty"`
|
||||
UpdatedAt *int `json:"updatedAt,omitempty"`
|
||||
}
|
||||
|
||||
func (o *SearchLibraryMetadata) GetRatingKey() *string {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
return o.RatingKey
|
||||
}
|
||||
|
||||
func (o *SearchLibraryMetadata) GetKey() *string {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
return o.Key
|
||||
}
|
||||
|
||||
func (o *SearchLibraryMetadata) GetParentRatingKey() *string {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
return o.ParentRatingKey
|
||||
}
|
||||
|
||||
func (o *SearchLibraryMetadata) GetGUID() *string {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
return o.GUID
|
||||
}
|
||||
|
||||
func (o *SearchLibraryMetadata) GetParentGUID() *string {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
return o.ParentGUID
|
||||
}
|
||||
|
||||
func (o *SearchLibraryMetadata) GetParentStudio() *string {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
return o.ParentStudio
|
||||
}
|
||||
|
||||
func (o *SearchLibraryMetadata) GetType() *string {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
return o.Type
|
||||
}
|
||||
|
||||
func (o *SearchLibraryMetadata) GetTitle() *string {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
return o.Title
|
||||
}
|
||||
|
||||
func (o *SearchLibraryMetadata) GetParentKey() *string {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
return o.ParentKey
|
||||
}
|
||||
|
||||
func (o *SearchLibraryMetadata) GetParentTitle() *string {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
return o.ParentTitle
|
||||
}
|
||||
|
||||
func (o *SearchLibraryMetadata) GetSummary() *string {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
return o.Summary
|
||||
}
|
||||
|
||||
func (o *SearchLibraryMetadata) GetIndex() *int {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
return o.Index
|
||||
}
|
||||
|
||||
func (o *SearchLibraryMetadata) GetParentIndex() *int {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
return o.ParentIndex
|
||||
}
|
||||
|
||||
func (o *SearchLibraryMetadata) GetParentYear() *int {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
return o.ParentYear
|
||||
}
|
||||
|
||||
func (o *SearchLibraryMetadata) GetThumb() *string {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
return o.Thumb
|
||||
}
|
||||
|
||||
func (o *SearchLibraryMetadata) GetArt() *string {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
return o.Art
|
||||
}
|
||||
|
||||
func (o *SearchLibraryMetadata) GetParentThumb() *string {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
return o.ParentThumb
|
||||
}
|
||||
|
||||
func (o *SearchLibraryMetadata) GetParentTheme() *string {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
return o.ParentTheme
|
||||
}
|
||||
|
||||
func (o *SearchLibraryMetadata) GetAddedAt() *int {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
return o.AddedAt
|
||||
}
|
||||
|
||||
func (o *SearchLibraryMetadata) GetUpdatedAt() *int {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
return o.UpdatedAt
|
||||
}
|
||||
|
||||
type SearchLibraryMediaContainer struct {
|
||||
Size *int `json:"size,omitempty"`
|
||||
AllowSync *bool `json:"allowSync,omitempty"`
|
||||
Art *string `json:"art,omitempty"`
|
||||
Identifier *string `json:"identifier,omitempty"`
|
||||
MediaTagPrefix *string `json:"mediaTagPrefix,omitempty"`
|
||||
MediaTagVersion *int `json:"mediaTagVersion,omitempty"`
|
||||
Nocache *bool `json:"nocache,omitempty"`
|
||||
Thumb *string `json:"thumb,omitempty"`
|
||||
Title1 *string `json:"title1,omitempty"`
|
||||
Title2 *string `json:"title2,omitempty"`
|
||||
ViewGroup *string `json:"viewGroup,omitempty"`
|
||||
ViewMode *int `json:"viewMode,omitempty"`
|
||||
Metadata []SearchLibraryMetadata `json:"Metadata,omitempty"`
|
||||
}
|
||||
|
||||
func (o *SearchLibraryMediaContainer) GetSize() *int {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
return o.Size
|
||||
}
|
||||
|
||||
func (o *SearchLibraryMediaContainer) GetAllowSync() *bool {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
return o.AllowSync
|
||||
}
|
||||
|
||||
func (o *SearchLibraryMediaContainer) GetArt() *string {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
return o.Art
|
||||
}
|
||||
|
||||
func (o *SearchLibraryMediaContainer) GetIdentifier() *string {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
return o.Identifier
|
||||
}
|
||||
|
||||
func (o *SearchLibraryMediaContainer) GetMediaTagPrefix() *string {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
return o.MediaTagPrefix
|
||||
}
|
||||
|
||||
func (o *SearchLibraryMediaContainer) GetMediaTagVersion() *int {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
return o.MediaTagVersion
|
||||
}
|
||||
|
||||
func (o *SearchLibraryMediaContainer) GetNocache() *bool {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
return o.Nocache
|
||||
}
|
||||
|
||||
func (o *SearchLibraryMediaContainer) GetThumb() *string {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
return o.Thumb
|
||||
}
|
||||
|
||||
func (o *SearchLibraryMediaContainer) GetTitle1() *string {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
return o.Title1
|
||||
}
|
||||
|
||||
func (o *SearchLibraryMediaContainer) GetTitle2() *string {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
return o.Title2
|
||||
}
|
||||
|
||||
func (o *SearchLibraryMediaContainer) GetViewGroup() *string {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
return o.ViewGroup
|
||||
}
|
||||
|
||||
func (o *SearchLibraryMediaContainer) GetViewMode() *int {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
return o.ViewMode
|
||||
}
|
||||
|
||||
func (o *SearchLibraryMediaContainer) GetMetadata() []SearchLibraryMetadata {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
return o.Metadata
|
||||
}
|
||||
|
||||
// SearchLibraryResponseBody - The contents of the library by section and type
|
||||
type SearchLibraryResponseBody struct {
|
||||
MediaContainer *SearchLibraryMediaContainer `json:"MediaContainer,omitempty"`
|
||||
}
|
||||
|
||||
func (o *SearchLibraryResponseBody) GetMediaContainer() *SearchLibraryMediaContainer {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
return o.MediaContainer
|
||||
}
|
||||
|
||||
type SearchLibraryResponse 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 contents of the library by section and type
|
||||
Object *SearchLibraryResponseBody
|
||||
}
|
||||
|
||||
func (o *SearchLibraryResponse) GetContentType() string {
|
||||
if o == nil {
|
||||
return ""
|
||||
}
|
||||
return o.ContentType
|
||||
}
|
||||
|
||||
func (o *SearchLibraryResponse) GetStatusCode() int {
|
||||
if o == nil {
|
||||
return 0
|
||||
}
|
||||
return o.StatusCode
|
||||
}
|
||||
|
||||
func (o *SearchLibraryResponse) GetRawResponse() *http.Response {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
return o.RawResponse
|
||||
}
|
||||
|
||||
func (o *SearchLibraryResponse) GetObject() *SearchLibraryResponseBody {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
return o.Object
|
||||
}
|
||||
49
models/sdkerrors/getpin.go
Normal file
49
models/sdkerrors/getpin.go
Normal file
@@ -0,0 +1,49 @@
|
||||
// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT.
|
||||
|
||||
package sdkerrors
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
// GetPinResponseBody - X-Plex-Client-Identifier is missing
|
||||
type GetPinResponseBody struct {
|
||||
Errors []GetPinErrors `json:"errors,omitempty"`
|
||||
// Raw HTTP response; suitable for custom response parsing
|
||||
RawResponse *http.Response `json:"-"`
|
||||
}
|
||||
|
||||
var _ error = &GetPinResponseBody{}
|
||||
|
||||
func (e *GetPinResponseBody) Error() string {
|
||||
data, _ := json.Marshal(e)
|
||||
return string(data)
|
||||
}
|
||||
49
models/sdkerrors/getstatistics.go
Normal file
49
models/sdkerrors/getstatistics.go
Normal file
@@ -0,0 +1,49 @@
|
||||
// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT.
|
||||
|
||||
package sdkerrors
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type GetStatisticsErrors struct {
|
||||
Code *float64 `json:"code,omitempty"`
|
||||
Message *string `json:"message,omitempty"`
|
||||
Status *float64 `json:"status,omitempty"`
|
||||
}
|
||||
|
||||
func (o *GetStatisticsErrors) GetCode() *float64 {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
return o.Code
|
||||
}
|
||||
|
||||
func (o *GetStatisticsErrors) GetMessage() *string {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
return o.Message
|
||||
}
|
||||
|
||||
func (o *GetStatisticsErrors) GetStatus() *float64 {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
return o.Status
|
||||
}
|
||||
|
||||
// GetStatisticsResponseBody - Unauthorized - Returned if the X-Plex-Token is missing from the header or query.
|
||||
type GetStatisticsResponseBody struct {
|
||||
Errors []GetStatisticsErrors `json:"errors,omitempty"`
|
||||
// Raw HTTP response; suitable for custom response parsing
|
||||
RawResponse *http.Response `json:"-"`
|
||||
}
|
||||
|
||||
var _ error = &GetStatisticsResponseBody{}
|
||||
|
||||
func (e *GetStatisticsResponseBody) Error() string {
|
||||
data, _ := json.Marshal(e)
|
||||
return string(data)
|
||||
}
|
||||
49
models/sdkerrors/gettoken.go
Normal file
49
models/sdkerrors/gettoken.go
Normal file
@@ -0,0 +1,49 @@
|
||||
// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT.
|
||||
|
||||
package sdkerrors
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
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"`
|
||||
// Raw HTTP response; suitable for custom response parsing
|
||||
RawResponse *http.Response `json:"-"`
|
||||
}
|
||||
|
||||
var _ error = &GetTokenResponseBody{}
|
||||
|
||||
func (e *GetTokenResponseBody) Error() string {
|
||||
data, _ := json.Marshal(e)
|
||||
return string(data)
|
||||
}
|
||||
365
playlists.go
365
playlists.go
@@ -6,12 +6,13 @@ import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/LukeHagar/plexgo/internal/hooks"
|
||||
"github.com/LukeHagar/plexgo/internal/utils"
|
||||
"github.com/LukeHagar/plexgo/models/operations"
|
||||
"github.com/LukeHagar/plexgo/models/sdkerrors"
|
||||
"io"
|
||||
"net/http"
|
||||
"strings"
|
||||
"net/url"
|
||||
)
|
||||
|
||||
// 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").
|
||||
@@ -33,30 +34,53 @@ func newPlaylists(sdkConfig sdkConfiguration) *Playlists {
|
||||
// - `uri` - The content URI for what we're playing (e.g. `server://1234/com.plexapp.plugins.library/library/metadata/1`).
|
||||
// - `playQueueID` - To create a playlist from an existing play queue.
|
||||
func (s *Playlists) CreatePlaylist(ctx context.Context, request operations.CreatePlaylistRequest) (*operations.CreatePlaylistResponse, error) {
|
||||
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
|
||||
url := strings.TrimSuffix(baseURL, "/") + "/playlists"
|
||||
hookCtx := hooks.HookContext{OperationID: "createPlaylist"}
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, "POST", url, nil)
|
||||
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
|
||||
opURL, err := url.JoinPath(baseURL, "/playlists")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error generating URL: %w", err)
|
||||
}
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, "POST", opURL, 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)
|
||||
req.Header.Set("User-Agent", s.sdkConfiguration.UserAgent)
|
||||
|
||||
if err := utils.PopulateQueryParams(ctx, req, request, nil); err != nil {
|
||||
return nil, fmt.Errorf("error populating query params: %w", err)
|
||||
}
|
||||
|
||||
req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{hookCtx}, req)
|
||||
if err != nil {
|
||||
return nil, 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")
|
||||
}
|
||||
if err != nil || httpRes == nil {
|
||||
if err != nil {
|
||||
err = fmt.Errorf("error sending request: %w", err)
|
||||
} else {
|
||||
err = fmt.Errorf("error sending request: no response")
|
||||
}
|
||||
|
||||
_, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{hookCtx}, nil, err)
|
||||
return nil, err
|
||||
} else if utils.MatchStatusCodes([]string{"400", "401", "4XX", "5XX"}, httpRes.StatusCode) {
|
||||
httpRes, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{hookCtx}, httpRes, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{hookCtx}, httpRes)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
contentType := httpRes.Header.Get("Content-Type")
|
||||
|
||||
res := &operations.CreatePlaylistResponse{
|
||||
@@ -71,6 +95,7 @@ func (s *Playlists) CreatePlaylist(ctx context.Context, request operations.Creat
|
||||
}
|
||||
httpRes.Body.Close()
|
||||
httpRes.Body = io.NopCloser(bytes.NewBuffer(rawBody))
|
||||
|
||||
switch {
|
||||
case httpRes.StatusCode == 200:
|
||||
switch {
|
||||
@@ -111,35 +136,58 @@ func (s *Playlists) CreatePlaylist(ctx context.Context, request operations.Creat
|
||||
// GetPlaylists - Get All Playlists
|
||||
// Get All Playlists given the specified filters.
|
||||
func (s *Playlists) GetPlaylists(ctx context.Context, playlistType *operations.PlaylistType, smart *operations.QueryParamSmart) (*operations.GetPlaylistsResponse, error) {
|
||||
hookCtx := hooks.HookContext{OperationID: "getPlaylists"}
|
||||
|
||||
request := operations.GetPlaylistsRequest{
|
||||
PlaylistType: playlistType,
|
||||
Smart: smart,
|
||||
}
|
||||
|
||||
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
|
||||
url := strings.TrimSuffix(baseURL, "/") + "/playlists"
|
||||
opURL, err := url.JoinPath(baseURL, "/playlists")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error generating URL: %w", err)
|
||||
}
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", url, nil)
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", opURL, 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)
|
||||
req.Header.Set("User-Agent", s.sdkConfiguration.UserAgent)
|
||||
|
||||
if err := utils.PopulateQueryParams(ctx, req, request, nil); err != nil {
|
||||
return nil, fmt.Errorf("error populating query params: %w", err)
|
||||
}
|
||||
|
||||
req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{hookCtx}, req)
|
||||
if err != nil {
|
||||
return nil, 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")
|
||||
}
|
||||
if err != nil || httpRes == nil {
|
||||
if err != nil {
|
||||
err = fmt.Errorf("error sending request: %w", err)
|
||||
} else {
|
||||
err = fmt.Errorf("error sending request: no response")
|
||||
}
|
||||
|
||||
_, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{hookCtx}, nil, err)
|
||||
return nil, err
|
||||
} else if utils.MatchStatusCodes([]string{"400", "401", "4XX", "5XX"}, httpRes.StatusCode) {
|
||||
httpRes, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{hookCtx}, httpRes, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{hookCtx}, httpRes)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
contentType := httpRes.Header.Get("Content-Type")
|
||||
|
||||
res := &operations.GetPlaylistsResponse{
|
||||
@@ -154,6 +202,7 @@ func (s *Playlists) GetPlaylists(ctx context.Context, playlistType *operations.P
|
||||
}
|
||||
httpRes.Body.Close()
|
||||
httpRes.Body = io.NopCloser(bytes.NewBuffer(rawBody))
|
||||
|
||||
switch {
|
||||
case httpRes.StatusCode == 200:
|
||||
switch {
|
||||
@@ -195,33 +244,53 @@ func (s *Playlists) GetPlaylists(ctx context.Context, playlistType *operations.P
|
||||
// Gets detailed metadata for a playlist. A playlist for many purposes (rating, editing metadata, tagging), can be treated like a regular metadata item:
|
||||
// Smart playlist details contain the `content` attribute. This is the content URI for the generator. This can then be parsed by a client to provide smart playlist editing.
|
||||
func (s *Playlists) GetPlaylist(ctx context.Context, playlistID float64) (*operations.GetPlaylistResponse, error) {
|
||||
hookCtx := hooks.HookContext{OperationID: "getPlaylist"}
|
||||
|
||||
request := operations.GetPlaylistRequest{
|
||||
PlaylistID: playlistID,
|
||||
}
|
||||
|
||||
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
|
||||
url, err := utils.GenerateURL(ctx, baseURL, "/playlists/{playlistID}", request, nil)
|
||||
opURL, err := utils.GenerateURL(ctx, baseURL, "/playlists/{playlistID}", request, nil)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error generating URL: %w", err)
|
||||
}
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", url, nil)
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", opURL, 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)
|
||||
req.Header.Set("User-Agent", s.sdkConfiguration.UserAgent)
|
||||
|
||||
req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{hookCtx}, req)
|
||||
if err != nil {
|
||||
return nil, 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")
|
||||
}
|
||||
if err != nil || httpRes == nil {
|
||||
if err != nil {
|
||||
err = fmt.Errorf("error sending request: %w", err)
|
||||
} else {
|
||||
err = fmt.Errorf("error sending request: no response")
|
||||
}
|
||||
|
||||
_, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{hookCtx}, nil, err)
|
||||
return nil, err
|
||||
} else if utils.MatchStatusCodes([]string{"400", "401", "4XX", "5XX"}, httpRes.StatusCode) {
|
||||
httpRes, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{hookCtx}, httpRes, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{hookCtx}, httpRes)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
contentType := httpRes.Header.Get("Content-Type")
|
||||
|
||||
res := &operations.GetPlaylistResponse{
|
||||
@@ -236,6 +305,7 @@ func (s *Playlists) GetPlaylist(ctx context.Context, playlistID float64) (*opera
|
||||
}
|
||||
httpRes.Body.Close()
|
||||
httpRes.Body = io.NopCloser(bytes.NewBuffer(rawBody))
|
||||
|
||||
switch {
|
||||
case httpRes.StatusCode == 200:
|
||||
switch {
|
||||
@@ -276,33 +346,53 @@ func (s *Playlists) GetPlaylist(ctx context.Context, playlistID float64) (*opera
|
||||
// DeletePlaylist - Deletes a Playlist
|
||||
// This endpoint will delete a playlist
|
||||
func (s *Playlists) DeletePlaylist(ctx context.Context, playlistID float64) (*operations.DeletePlaylistResponse, error) {
|
||||
hookCtx := hooks.HookContext{OperationID: "deletePlaylist"}
|
||||
|
||||
request := operations.DeletePlaylistRequest{
|
||||
PlaylistID: playlistID,
|
||||
}
|
||||
|
||||
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
|
||||
url, err := utils.GenerateURL(ctx, baseURL, "/playlists/{playlistID}", request, nil)
|
||||
opURL, err := utils.GenerateURL(ctx, baseURL, "/playlists/{playlistID}", request, nil)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error generating URL: %w", err)
|
||||
}
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, "DELETE", url, nil)
|
||||
req, err := http.NewRequestWithContext(ctx, "DELETE", opURL, 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)
|
||||
req.Header.Set("User-Agent", s.sdkConfiguration.UserAgent)
|
||||
|
||||
req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{hookCtx}, req)
|
||||
if err != nil {
|
||||
return nil, 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")
|
||||
}
|
||||
if err != nil || httpRes == nil {
|
||||
if err != nil {
|
||||
err = fmt.Errorf("error sending request: %w", err)
|
||||
} else {
|
||||
err = fmt.Errorf("error sending request: no response")
|
||||
}
|
||||
|
||||
_, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{hookCtx}, nil, err)
|
||||
return nil, err
|
||||
} else if utils.MatchStatusCodes([]string{"400", "401", "4XX", "5XX"}, httpRes.StatusCode) {
|
||||
httpRes, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{hookCtx}, httpRes, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{hookCtx}, httpRes)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
contentType := httpRes.Header.Get("Content-Type")
|
||||
|
||||
res := &operations.DeletePlaylistResponse{
|
||||
@@ -317,6 +407,7 @@ func (s *Playlists) DeletePlaylist(ctx context.Context, playlistID float64) (*op
|
||||
}
|
||||
httpRes.Body.Close()
|
||||
httpRes.Body = io.NopCloser(bytes.NewBuffer(rawBody))
|
||||
|
||||
switch {
|
||||
case httpRes.StatusCode == 200:
|
||||
case httpRes.StatusCode == 400:
|
||||
@@ -346,6 +437,8 @@ func (s *Playlists) DeletePlaylist(ctx context.Context, playlistID float64) (*op
|
||||
// UpdatePlaylist - Update a Playlist
|
||||
// From PMS version 1.9.1 clients can also edit playlist metadata using this endpoint as they would via `PUT /library/metadata/{playlistID}`
|
||||
func (s *Playlists) UpdatePlaylist(ctx context.Context, playlistID float64, title *string, summary *string) (*operations.UpdatePlaylistResponse, error) {
|
||||
hookCtx := hooks.HookContext{OperationID: "updatePlaylist"}
|
||||
|
||||
request := operations.UpdatePlaylistRequest{
|
||||
PlaylistID: playlistID,
|
||||
Title: title,
|
||||
@@ -353,32 +446,50 @@ func (s *Playlists) UpdatePlaylist(ctx context.Context, playlistID float64, titl
|
||||
}
|
||||
|
||||
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
|
||||
url, err := utils.GenerateURL(ctx, baseURL, "/playlists/{playlistID}", request, nil)
|
||||
opURL, err := utils.GenerateURL(ctx, baseURL, "/playlists/{playlistID}", request, nil)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error generating URL: %w", err)
|
||||
}
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, "PUT", url, nil)
|
||||
req, err := http.NewRequestWithContext(ctx, "PUT", opURL, 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)
|
||||
req.Header.Set("User-Agent", s.sdkConfiguration.UserAgent)
|
||||
|
||||
if err := utils.PopulateQueryParams(ctx, req, request, nil); err != nil {
|
||||
return nil, fmt.Errorf("error populating query params: %w", err)
|
||||
}
|
||||
|
||||
req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{hookCtx}, req)
|
||||
if err != nil {
|
||||
return nil, 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")
|
||||
}
|
||||
if err != nil || httpRes == nil {
|
||||
if err != nil {
|
||||
err = fmt.Errorf("error sending request: %w", err)
|
||||
} else {
|
||||
err = fmt.Errorf("error sending request: no response")
|
||||
}
|
||||
|
||||
_, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{hookCtx}, nil, err)
|
||||
return nil, err
|
||||
} else if utils.MatchStatusCodes([]string{"400", "401", "4XX", "5XX"}, httpRes.StatusCode) {
|
||||
httpRes, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{hookCtx}, httpRes, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{hookCtx}, httpRes)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
contentType := httpRes.Header.Get("Content-Type")
|
||||
|
||||
res := &operations.UpdatePlaylistResponse{
|
||||
@@ -393,6 +504,7 @@ func (s *Playlists) UpdatePlaylist(ctx context.Context, playlistID float64, titl
|
||||
}
|
||||
httpRes.Body.Close()
|
||||
httpRes.Body = io.NopCloser(bytes.NewBuffer(rawBody))
|
||||
|
||||
switch {
|
||||
case httpRes.StatusCode == 200:
|
||||
case httpRes.StatusCode == 400:
|
||||
@@ -425,38 +537,58 @@ func (s *Playlists) UpdatePlaylist(ctx context.Context, playlistID float64, titl
|
||||
// For example, you could use this to display a list of recently added albums vis a smart playlist.
|
||||
// Note that for dumb playlists, items have a `playlistItemID` attribute which is used for deleting or moving items.
|
||||
func (s *Playlists) GetPlaylistContents(ctx context.Context, playlistID float64, type_ float64) (*operations.GetPlaylistContentsResponse, error) {
|
||||
hookCtx := hooks.HookContext{OperationID: "getPlaylistContents"}
|
||||
|
||||
request := operations.GetPlaylistContentsRequest{
|
||||
PlaylistID: playlistID,
|
||||
Type: type_,
|
||||
}
|
||||
|
||||
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
|
||||
url, err := utils.GenerateURL(ctx, baseURL, "/playlists/{playlistID}/items", request, nil)
|
||||
opURL, err := utils.GenerateURL(ctx, baseURL, "/playlists/{playlistID}/items", request, nil)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error generating URL: %w", err)
|
||||
}
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", url, nil)
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", opURL, 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)
|
||||
req.Header.Set("User-Agent", s.sdkConfiguration.UserAgent)
|
||||
|
||||
if err := utils.PopulateQueryParams(ctx, req, request, nil); err != nil {
|
||||
return nil, fmt.Errorf("error populating query params: %w", err)
|
||||
}
|
||||
|
||||
req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{hookCtx}, req)
|
||||
if err != nil {
|
||||
return nil, 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")
|
||||
}
|
||||
if err != nil || httpRes == nil {
|
||||
if err != nil {
|
||||
err = fmt.Errorf("error sending request: %w", err)
|
||||
} else {
|
||||
err = fmt.Errorf("error sending request: no response")
|
||||
}
|
||||
|
||||
_, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{hookCtx}, nil, err)
|
||||
return nil, err
|
||||
} else if utils.MatchStatusCodes([]string{"400", "401", "4XX", "5XX"}, httpRes.StatusCode) {
|
||||
httpRes, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{hookCtx}, httpRes, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{hookCtx}, httpRes)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
contentType := httpRes.Header.Get("Content-Type")
|
||||
|
||||
res := &operations.GetPlaylistContentsResponse{
|
||||
@@ -471,6 +603,7 @@ func (s *Playlists) GetPlaylistContents(ctx context.Context, playlistID float64,
|
||||
}
|
||||
httpRes.Body.Close()
|
||||
httpRes.Body = io.NopCloser(bytes.NewBuffer(rawBody))
|
||||
|
||||
switch {
|
||||
case httpRes.StatusCode == 200:
|
||||
switch {
|
||||
@@ -511,33 +644,53 @@ func (s *Playlists) GetPlaylistContents(ctx context.Context, playlistID float64,
|
||||
// ClearPlaylistContents - Delete Playlist Contents
|
||||
// Clears a playlist, only works with dumb playlists. Returns the playlist.
|
||||
func (s *Playlists) ClearPlaylistContents(ctx context.Context, playlistID float64) (*operations.ClearPlaylistContentsResponse, error) {
|
||||
hookCtx := hooks.HookContext{OperationID: "clearPlaylistContents"}
|
||||
|
||||
request := operations.ClearPlaylistContentsRequest{
|
||||
PlaylistID: playlistID,
|
||||
}
|
||||
|
||||
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
|
||||
url, err := utils.GenerateURL(ctx, baseURL, "/playlists/{playlistID}/items", request, nil)
|
||||
opURL, err := utils.GenerateURL(ctx, baseURL, "/playlists/{playlistID}/items", request, nil)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error generating URL: %w", err)
|
||||
}
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, "DELETE", url, nil)
|
||||
req, err := http.NewRequestWithContext(ctx, "DELETE", opURL, 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)
|
||||
req.Header.Set("User-Agent", s.sdkConfiguration.UserAgent)
|
||||
|
||||
req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{hookCtx}, req)
|
||||
if err != nil {
|
||||
return nil, 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")
|
||||
}
|
||||
if err != nil || httpRes == nil {
|
||||
if err != nil {
|
||||
err = fmt.Errorf("error sending request: %w", err)
|
||||
} else {
|
||||
err = fmt.Errorf("error sending request: no response")
|
||||
}
|
||||
|
||||
_, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{hookCtx}, nil, err)
|
||||
return nil, err
|
||||
} else if utils.MatchStatusCodes([]string{"400", "401", "4XX", "5XX"}, httpRes.StatusCode) {
|
||||
httpRes, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{hookCtx}, httpRes, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{hookCtx}, httpRes)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
contentType := httpRes.Header.Get("Content-Type")
|
||||
|
||||
res := &operations.ClearPlaylistContentsResponse{
|
||||
@@ -552,6 +705,7 @@ func (s *Playlists) ClearPlaylistContents(ctx context.Context, playlistID float6
|
||||
}
|
||||
httpRes.Body.Close()
|
||||
httpRes.Body = io.NopCloser(bytes.NewBuffer(rawBody))
|
||||
|
||||
switch {
|
||||
case httpRes.StatusCode == 200:
|
||||
case httpRes.StatusCode == 400:
|
||||
@@ -582,6 +736,8 @@ func (s *Playlists) ClearPlaylistContents(ctx context.Context, playlistID float6
|
||||
// Adds a generator to a playlist, same parameters as the POST to create. With a dumb playlist, this adds the specified items to the playlist.
|
||||
// With a smart playlist, passing a new `uri` parameter replaces the rules for the playlist. Returns the playlist.
|
||||
func (s *Playlists) AddPlaylistContents(ctx context.Context, playlistID float64, uri string, playQueueID *float64) (*operations.AddPlaylistContentsResponse, error) {
|
||||
hookCtx := hooks.HookContext{OperationID: "addPlaylistContents"}
|
||||
|
||||
request := operations.AddPlaylistContentsRequest{
|
||||
PlaylistID: playlistID,
|
||||
URI: uri,
|
||||
@@ -589,32 +745,50 @@ func (s *Playlists) AddPlaylistContents(ctx context.Context, playlistID float64,
|
||||
}
|
||||
|
||||
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
|
||||
url, err := utils.GenerateURL(ctx, baseURL, "/playlists/{playlistID}/items", request, nil)
|
||||
opURL, err := utils.GenerateURL(ctx, baseURL, "/playlists/{playlistID}/items", request, nil)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error generating URL: %w", err)
|
||||
}
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, "PUT", url, nil)
|
||||
req, err := http.NewRequestWithContext(ctx, "PUT", opURL, 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)
|
||||
req.Header.Set("User-Agent", s.sdkConfiguration.UserAgent)
|
||||
|
||||
if err := utils.PopulateQueryParams(ctx, req, request, nil); err != nil {
|
||||
return nil, fmt.Errorf("error populating query params: %w", err)
|
||||
}
|
||||
|
||||
req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{hookCtx}, req)
|
||||
if err != nil {
|
||||
return nil, 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")
|
||||
}
|
||||
if err != nil || httpRes == nil {
|
||||
if err != nil {
|
||||
err = fmt.Errorf("error sending request: %w", err)
|
||||
} else {
|
||||
err = fmt.Errorf("error sending request: no response")
|
||||
}
|
||||
|
||||
_, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{hookCtx}, nil, err)
|
||||
return nil, err
|
||||
} else if utils.MatchStatusCodes([]string{"400", "401", "4XX", "5XX"}, httpRes.StatusCode) {
|
||||
httpRes, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{hookCtx}, httpRes, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{hookCtx}, httpRes)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
contentType := httpRes.Header.Get("Content-Type")
|
||||
|
||||
res := &operations.AddPlaylistContentsResponse{
|
||||
@@ -629,6 +803,7 @@ func (s *Playlists) AddPlaylistContents(ctx context.Context, playlistID float64,
|
||||
}
|
||||
httpRes.Body.Close()
|
||||
httpRes.Body = io.NopCloser(bytes.NewBuffer(rawBody))
|
||||
|
||||
switch {
|
||||
case httpRes.StatusCode == 200:
|
||||
switch {
|
||||
@@ -669,35 +844,58 @@ func (s *Playlists) AddPlaylistContents(ctx context.Context, playlistID float64,
|
||||
// UploadPlaylist - Upload Playlist
|
||||
// Imports m3u playlists by passing a path on the server to scan for m3u-formatted playlist files, or a path to a single playlist file.
|
||||
func (s *Playlists) UploadPlaylist(ctx context.Context, path string, force operations.Force) (*operations.UploadPlaylistResponse, error) {
|
||||
hookCtx := hooks.HookContext{OperationID: "uploadPlaylist"}
|
||||
|
||||
request := operations.UploadPlaylistRequest{
|
||||
Path: path,
|
||||
Force: force,
|
||||
}
|
||||
|
||||
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
|
||||
url := strings.TrimSuffix(baseURL, "/") + "/playlists/upload"
|
||||
opURL, err := url.JoinPath(baseURL, "/playlists/upload")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error generating URL: %w", err)
|
||||
}
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, "POST", url, nil)
|
||||
req, err := http.NewRequestWithContext(ctx, "POST", opURL, 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)
|
||||
req.Header.Set("User-Agent", s.sdkConfiguration.UserAgent)
|
||||
|
||||
if err := utils.PopulateQueryParams(ctx, req, request, nil); err != nil {
|
||||
return nil, fmt.Errorf("error populating query params: %w", err)
|
||||
}
|
||||
|
||||
req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{hookCtx}, req)
|
||||
if err != nil {
|
||||
return nil, 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")
|
||||
}
|
||||
if err != nil || httpRes == nil {
|
||||
if err != nil {
|
||||
err = fmt.Errorf("error sending request: %w", err)
|
||||
} else {
|
||||
err = fmt.Errorf("error sending request: no response")
|
||||
}
|
||||
|
||||
_, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{hookCtx}, nil, err)
|
||||
return nil, err
|
||||
} else if utils.MatchStatusCodes([]string{"400", "401", "4XX", "5XX"}, httpRes.StatusCode) {
|
||||
httpRes, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{hookCtx}, httpRes, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{hookCtx}, httpRes)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
contentType := httpRes.Header.Get("Content-Type")
|
||||
|
||||
res := &operations.UploadPlaylistResponse{
|
||||
@@ -712,6 +910,7 @@ func (s *Playlists) UploadPlaylist(ctx context.Context, path string, force opera
|
||||
}
|
||||
httpRes.Body.Close()
|
||||
httpRes.Body = io.NopCloser(bytes.NewBuffer(rawBody))
|
||||
|
||||
switch {
|
||||
case httpRes.StatusCode == 200:
|
||||
case httpRes.StatusCode == 400:
|
||||
|
||||
254
plex.go
Normal file
254
plex.go
Normal file
@@ -0,0 +1,254 @@
|
||||
// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT.
|
||||
|
||||
package plexgo
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/LukeHagar/plexgo/internal/hooks"
|
||||
"github.com/LukeHagar/plexgo/internal/utils"
|
||||
"github.com/LukeHagar/plexgo/models/operations"
|
||||
"github.com/LukeHagar/plexgo/models/sdkerrors"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
)
|
||||
|
||||
// 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,
|
||||
}
|
||||
}
|
||||
|
||||
// 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) {
|
||||
hookCtx := hooks.HookContext{OperationID: "getPin"}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
opURL, err := url.JoinPath(baseURL, "/pins")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error generating URL: %w", err)
|
||||
}
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, "POST", opURL, 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)
|
||||
}
|
||||
|
||||
req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{hookCtx}, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
client := s.sdkConfiguration.SecurityClient
|
||||
|
||||
httpRes, err := client.Do(req)
|
||||
if err != nil || httpRes == nil {
|
||||
if err != nil {
|
||||
err = fmt.Errorf("error sending request: %w", err)
|
||||
} else {
|
||||
err = fmt.Errorf("error sending request: no response")
|
||||
}
|
||||
|
||||
_, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{hookCtx}, nil, err)
|
||||
return nil, err
|
||||
} else if utils.MatchStatusCodes([]string{"400", "4XX", "5XX"}, httpRes.StatusCode) {
|
||||
httpRes, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{hookCtx}, httpRes, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{hookCtx}, httpRes)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
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) {
|
||||
hookCtx := hooks.HookContext{OperationID: "getToken"}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
opURL, 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", opURL, 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)
|
||||
|
||||
req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{hookCtx}, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
client := s.sdkConfiguration.SecurityClient
|
||||
|
||||
httpRes, err := client.Do(req)
|
||||
if err != nil || httpRes == nil {
|
||||
if err != nil {
|
||||
err = fmt.Errorf("error sending request: %w", err)
|
||||
} else {
|
||||
err = fmt.Errorf("error sending request: no response")
|
||||
}
|
||||
|
||||
_, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{hookCtx}, nil, err)
|
||||
return nil, err
|
||||
} else if utils.MatchStatusCodes([]string{"400", "4XX", "5XX"}, httpRes.StatusCode) {
|
||||
httpRes, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{hookCtx}, httpRes, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{hookCtx}, httpRes)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
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
|
||||
}
|
||||
40
plexapi.go
40
plexapi.go
@@ -6,6 +6,7 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/LukeHagar/plexgo/internal/hooks"
|
||||
"github.com/LukeHagar/plexgo/internal/utils"
|
||||
"github.com/LukeHagar/plexgo/models/components"
|
||||
"net/http"
|
||||
@@ -54,6 +55,7 @@ type sdkConfiguration struct {
|
||||
GenVersion string
|
||||
UserAgent string
|
||||
RetryConfig *utils.RetryConfig
|
||||
Hooks *hooks.Hooks
|
||||
}
|
||||
|
||||
func (c *sdkConfiguration) GetServerDetails() (string, map[string]string) {
|
||||
@@ -73,6 +75,9 @@ type PlexAPI struct {
|
||||
// API Calls interacting with Plex Media Server Media
|
||||
//
|
||||
Media *Media
|
||||
// API Calls that perform operations with Plex Media Server Videos
|
||||
//
|
||||
Video *Video
|
||||
// Activities are awesome. They provide a way to monitor and control asynchronous operations on the server. In order to receive real-time updates for activities, a client would normally subscribe via either EventSource or Websocket endpoints.
|
||||
// Activities are associated with HTTP replies via a special `X-Plex-Activity` header which contains the UUID of the activity.
|
||||
// Activities are optional cancellable. If cancellable, they may be cancelled via the `DELETE` endpoint. Other details:
|
||||
@@ -97,6 +102,9 @@ type PlexAPI struct {
|
||||
// Submit logs to the Log Handler for Plex Media Server
|
||||
//
|
||||
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.
|
||||
// Retrieving a playlist, or its items, will trigger a refresh of its metadata.
|
||||
@@ -106,6 +114,9 @@ type PlexAPI struct {
|
||||
// API Calls against Security for Plex Media Server
|
||||
//
|
||||
Security *Security
|
||||
// API Calls that perform operations with Plex Media Server Statistics
|
||||
//
|
||||
Statistics *Statistics
|
||||
// API Calls that perform search operations with Plex Media Server Sessions
|
||||
//
|
||||
Sessions *Sessions
|
||||
@@ -113,9 +124,6 @@ type PlexAPI struct {
|
||||
// Updates to the status can be observed via the Event API.
|
||||
//
|
||||
Updater *Updater
|
||||
// API Calls that perform operations with Plex Media Server Videos
|
||||
//
|
||||
Video *Video
|
||||
|
||||
sdkConfiguration sdkConfiguration
|
||||
}
|
||||
@@ -239,6 +247,15 @@ func WithSecurity(accessToken string) SDKOption {
|
||||
}
|
||||
}
|
||||
|
||||
// WithSecuritySource configures the SDK to invoke the Security Source function on each method call to determine authentication
|
||||
func WithSecuritySource(security func(context.Context) (components.Security, error)) SDKOption {
|
||||
return func(sdk *PlexAPI) {
|
||||
sdk.sdkConfiguration.Security = func(ctx context.Context) (interface{}, error) {
|
||||
return security(ctx)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func WithRetryConfig(retryConfig utils.RetryConfig) SDKOption {
|
||||
return func(sdk *PlexAPI) {
|
||||
sdk.sdkConfiguration.RetryConfig = &retryConfig
|
||||
@@ -251,9 +268,9 @@ func New(opts ...SDKOption) *PlexAPI {
|
||||
sdkConfiguration: sdkConfiguration{
|
||||
Language: "go",
|
||||
OpenAPIDocVersion: "0.0.3",
|
||||
SDKVersion: "0.1.1",
|
||||
GenVersion: "2.237.3",
|
||||
UserAgent: "speakeasy-sdk/go 0.1.1 2.237.3 0.0.3 github.com/LukeHagar/plexgo",
|
||||
SDKVersion: "0.4.0",
|
||||
GenVersion: "2.269.0",
|
||||
UserAgent: "speakeasy-sdk/go 0.4.0 2.269.0 0.0.3 github.com/LukeHagar/plexgo",
|
||||
ServerDefaults: []map[string]string{
|
||||
{
|
||||
"protocol": "http",
|
||||
@@ -261,12 +278,15 @@ func New(opts ...SDKOption) *PlexAPI {
|
||||
"port": "32400",
|
||||
},
|
||||
},
|
||||
Hooks: hooks.New(),
|
||||
},
|
||||
}
|
||||
for _, opt := range opts {
|
||||
opt(sdk)
|
||||
}
|
||||
|
||||
sdk.sdkConfiguration.DefaultClient = sdk.sdkConfiguration.Hooks.ClientInit(sdk.sdkConfiguration.DefaultClient)
|
||||
|
||||
// Use WithClient to override the default client if you would like to customize the timeout
|
||||
if sdk.sdkConfiguration.DefaultClient == nil {
|
||||
sdk.sdkConfiguration.DefaultClient = &http.Client{Timeout: 60 * time.Second}
|
||||
@@ -283,6 +303,8 @@ func New(opts ...SDKOption) *PlexAPI {
|
||||
|
||||
sdk.Media = newMedia(sdk.sdkConfiguration)
|
||||
|
||||
sdk.Video = newVideo(sdk.sdkConfiguration)
|
||||
|
||||
sdk.Activities = newActivities(sdk.sdkConfiguration)
|
||||
|
||||
sdk.Butler = newButler(sdk.sdkConfiguration)
|
||||
@@ -295,15 +317,17 @@ func New(opts ...SDKOption) *PlexAPI {
|
||||
|
||||
sdk.Log = newLog(sdk.sdkConfiguration)
|
||||
|
||||
sdk.Plex = newPlex(sdk.sdkConfiguration)
|
||||
|
||||
sdk.Playlists = newPlaylists(sdk.sdkConfiguration)
|
||||
|
||||
sdk.Security = newSecurity(sdk.sdkConfiguration)
|
||||
|
||||
sdk.Statistics = newStatistics(sdk.sdkConfiguration)
|
||||
|
||||
sdk.Sessions = newSessions(sdk.sdkConfiguration)
|
||||
|
||||
sdk.Updater = newUpdater(sdk.sdkConfiguration)
|
||||
|
||||
sdk.Video = newVideo(sdk.sdkConfiguration)
|
||||
|
||||
return sdk
|
||||
}
|
||||
|
||||
129
search.go
129
search.go
@@ -6,12 +6,13 @@ import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/LukeHagar/plexgo/internal/hooks"
|
||||
"github.com/LukeHagar/plexgo/internal/utils"
|
||||
"github.com/LukeHagar/plexgo/models/operations"
|
||||
"github.com/LukeHagar/plexgo/models/sdkerrors"
|
||||
"io"
|
||||
"net/http"
|
||||
"strings"
|
||||
"net/url"
|
||||
)
|
||||
|
||||
// Search - API Calls that perform search operations with Plex Media Server
|
||||
@@ -40,6 +41,8 @@ func newSearch(sdkConfig sdkConfiguration) *Search {
|
||||
//
|
||||
// This request is intended to be very fast, and called as the user types.
|
||||
func (s *Search) PerformSearch(ctx context.Context, query string, sectionID *float64, limit *float64) (*operations.PerformSearchResponse, error) {
|
||||
hookCtx := hooks.HookContext{OperationID: "performSearch"}
|
||||
|
||||
request := operations.PerformSearchRequest{
|
||||
Query: query,
|
||||
SectionID: sectionID,
|
||||
@@ -47,29 +50,50 @@ func (s *Search) PerformSearch(ctx context.Context, query string, sectionID *flo
|
||||
}
|
||||
|
||||
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
|
||||
url := strings.TrimSuffix(baseURL, "/") + "/hubs/search"
|
||||
opURL, err := url.JoinPath(baseURL, "/hubs/search")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error generating URL: %w", err)
|
||||
}
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", url, nil)
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", opURL, 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)
|
||||
req.Header.Set("User-Agent", s.sdkConfiguration.UserAgent)
|
||||
|
||||
if err := utils.PopulateQueryParams(ctx, req, request, nil); err != nil {
|
||||
return nil, fmt.Errorf("error populating query params: %w", err)
|
||||
}
|
||||
|
||||
req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{hookCtx}, req)
|
||||
if err != nil {
|
||||
return nil, 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")
|
||||
}
|
||||
if err != nil || httpRes == nil {
|
||||
if err != nil {
|
||||
err = fmt.Errorf("error sending request: %w", err)
|
||||
} else {
|
||||
err = fmt.Errorf("error sending request: no response")
|
||||
}
|
||||
|
||||
_, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{hookCtx}, nil, err)
|
||||
return nil, err
|
||||
} else if utils.MatchStatusCodes([]string{"400", "401", "4XX", "5XX"}, httpRes.StatusCode) {
|
||||
httpRes, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{hookCtx}, httpRes, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{hookCtx}, httpRes)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
contentType := httpRes.Header.Get("Content-Type")
|
||||
|
||||
res := &operations.PerformSearchResponse{
|
||||
@@ -84,6 +108,7 @@ func (s *Search) PerformSearch(ctx context.Context, query string, sectionID *flo
|
||||
}
|
||||
httpRes.Body.Close()
|
||||
httpRes.Body = io.NopCloser(bytes.NewBuffer(rawBody))
|
||||
|
||||
switch {
|
||||
case httpRes.StatusCode == 200:
|
||||
case httpRes.StatusCode == 400:
|
||||
@@ -116,6 +141,8 @@ func (s *Search) PerformSearch(ctx context.Context, query string, sectionID *flo
|
||||
// Whenever possible, clients should limit the search to the appropriate type.
|
||||
// Results, as well as their containing per-type hubs, contain a `distance` attribute which can be used to judge result quality.
|
||||
func (s *Search) PerformVoiceSearch(ctx context.Context, query string, sectionID *float64, limit *float64) (*operations.PerformVoiceSearchResponse, error) {
|
||||
hookCtx := hooks.HookContext{OperationID: "performVoiceSearch"}
|
||||
|
||||
request := operations.PerformVoiceSearchRequest{
|
||||
Query: query,
|
||||
SectionID: sectionID,
|
||||
@@ -123,29 +150,50 @@ func (s *Search) PerformVoiceSearch(ctx context.Context, query string, sectionID
|
||||
}
|
||||
|
||||
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
|
||||
url := strings.TrimSuffix(baseURL, "/") + "/hubs/search/voice"
|
||||
opURL, err := url.JoinPath(baseURL, "/hubs/search/voice")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error generating URL: %w", err)
|
||||
}
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", url, nil)
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", opURL, 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)
|
||||
req.Header.Set("User-Agent", s.sdkConfiguration.UserAgent)
|
||||
|
||||
if err := utils.PopulateQueryParams(ctx, req, request, nil); err != nil {
|
||||
return nil, fmt.Errorf("error populating query params: %w", err)
|
||||
}
|
||||
|
||||
req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{hookCtx}, req)
|
||||
if err != nil {
|
||||
return nil, 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")
|
||||
}
|
||||
if err != nil || httpRes == nil {
|
||||
if err != nil {
|
||||
err = fmt.Errorf("error sending request: %w", err)
|
||||
} else {
|
||||
err = fmt.Errorf("error sending request: no response")
|
||||
}
|
||||
|
||||
_, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{hookCtx}, nil, err)
|
||||
return nil, err
|
||||
} else if utils.MatchStatusCodes([]string{"400", "401", "4XX", "5XX"}, httpRes.StatusCode) {
|
||||
httpRes, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{hookCtx}, httpRes, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{hookCtx}, httpRes)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
contentType := httpRes.Header.Get("Content-Type")
|
||||
|
||||
res := &operations.PerformVoiceSearchResponse{
|
||||
@@ -160,6 +208,7 @@ func (s *Search) PerformVoiceSearch(ctx context.Context, query string, sectionID
|
||||
}
|
||||
httpRes.Body.Close()
|
||||
httpRes.Body = io.NopCloser(bytes.NewBuffer(rawBody))
|
||||
|
||||
switch {
|
||||
case httpRes.StatusCode == 200:
|
||||
case httpRes.StatusCode == 400:
|
||||
@@ -189,34 +238,57 @@ func (s *Search) PerformVoiceSearch(ctx context.Context, query string, sectionID
|
||||
// GetSearchResults - Get Search Results
|
||||
// This will search the database for the string provided.
|
||||
func (s *Search) GetSearchResults(ctx context.Context, query string) (*operations.GetSearchResultsResponse, error) {
|
||||
hookCtx := hooks.HookContext{OperationID: "getSearchResults"}
|
||||
|
||||
request := operations.GetSearchResultsRequest{
|
||||
Query: query,
|
||||
}
|
||||
|
||||
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
|
||||
url := strings.TrimSuffix(baseURL, "/") + "/search"
|
||||
opURL, err := url.JoinPath(baseURL, "/search")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error generating URL: %w", err)
|
||||
}
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", url, nil)
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", opURL, 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)
|
||||
req.Header.Set("User-Agent", s.sdkConfiguration.UserAgent)
|
||||
|
||||
if err := utils.PopulateQueryParams(ctx, req, request, nil); err != nil {
|
||||
return nil, fmt.Errorf("error populating query params: %w", err)
|
||||
}
|
||||
|
||||
req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{hookCtx}, req)
|
||||
if err != nil {
|
||||
return nil, 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")
|
||||
}
|
||||
if err != nil || httpRes == nil {
|
||||
if err != nil {
|
||||
err = fmt.Errorf("error sending request: %w", err)
|
||||
} else {
|
||||
err = fmt.Errorf("error sending request: no response")
|
||||
}
|
||||
|
||||
_, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{hookCtx}, nil, err)
|
||||
return nil, err
|
||||
} else if utils.MatchStatusCodes([]string{"400", "401", "4XX", "5XX"}, httpRes.StatusCode) {
|
||||
httpRes, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{hookCtx}, httpRes, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{hookCtx}, httpRes)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
contentType := httpRes.Header.Get("Content-Type")
|
||||
|
||||
res := &operations.GetSearchResultsResponse{
|
||||
@@ -231,6 +303,7 @@ func (s *Search) GetSearchResults(ctx context.Context, query string) (*operation
|
||||
}
|
||||
httpRes.Body.Close()
|
||||
httpRes.Body = io.NopCloser(bytes.NewBuffer(rawBody))
|
||||
|
||||
switch {
|
||||
case httpRes.StatusCode == 200:
|
||||
switch {
|
||||
|
||||
89
security.go
89
security.go
@@ -6,12 +6,13 @@ import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/LukeHagar/plexgo/internal/hooks"
|
||||
"github.com/LukeHagar/plexgo/internal/utils"
|
||||
"github.com/LukeHagar/plexgo/models/operations"
|
||||
"github.com/LukeHagar/plexgo/models/sdkerrors"
|
||||
"io"
|
||||
"net/http"
|
||||
"strings"
|
||||
"net/url"
|
||||
)
|
||||
|
||||
// Security - API Calls against Security for Plex Media Server
|
||||
@@ -27,36 +28,59 @@ func newSecurity(sdkConfig sdkConfiguration) *Security {
|
||||
|
||||
// GetTransientToken - Get a Transient Token.
|
||||
// This endpoint provides the caller with a temporary token with the same access level as the caller's token. These tokens are valid for up to 48 hours and are destroyed if the server instance is restarted.
|
||||
func (s *Security) GetTransientToken(ctx context.Context, type_ operations.QueryParamType, scope operations.Scope) (*operations.GetTransientTokenResponse, error) {
|
||||
func (s *Security) GetTransientToken(ctx context.Context, type_ operations.GetTransientTokenQueryParamType, scope operations.Scope) (*operations.GetTransientTokenResponse, error) {
|
||||
hookCtx := hooks.HookContext{OperationID: "getTransientToken"}
|
||||
|
||||
request := operations.GetTransientTokenRequest{
|
||||
Type: type_,
|
||||
Scope: scope,
|
||||
}
|
||||
|
||||
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
|
||||
url := strings.TrimSuffix(baseURL, "/") + "/security/token"
|
||||
opURL, err := url.JoinPath(baseURL, "/security/token")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error generating URL: %w", err)
|
||||
}
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", url, nil)
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", opURL, 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)
|
||||
req.Header.Set("User-Agent", s.sdkConfiguration.UserAgent)
|
||||
|
||||
if err := utils.PopulateQueryParams(ctx, req, request, nil); err != nil {
|
||||
return nil, fmt.Errorf("error populating query params: %w", err)
|
||||
}
|
||||
|
||||
req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{hookCtx}, req)
|
||||
if err != nil {
|
||||
return nil, 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")
|
||||
}
|
||||
if err != nil || httpRes == nil {
|
||||
if err != nil {
|
||||
err = fmt.Errorf("error sending request: %w", err)
|
||||
} else {
|
||||
err = fmt.Errorf("error sending request: no response")
|
||||
}
|
||||
|
||||
_, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{hookCtx}, nil, err)
|
||||
return nil, err
|
||||
} else if utils.MatchStatusCodes([]string{"400", "401", "4XX", "5XX"}, httpRes.StatusCode) {
|
||||
httpRes, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{hookCtx}, httpRes, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{hookCtx}, httpRes)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
contentType := httpRes.Header.Get("Content-Type")
|
||||
|
||||
res := &operations.GetTransientTokenResponse{
|
||||
@@ -71,6 +95,7 @@ func (s *Security) GetTransientToken(ctx context.Context, type_ operations.Query
|
||||
}
|
||||
httpRes.Body.Close()
|
||||
httpRes.Body = io.NopCloser(bytes.NewBuffer(rawBody))
|
||||
|
||||
switch {
|
||||
case httpRes.StatusCode == 200:
|
||||
case httpRes.StatusCode == 400:
|
||||
@@ -101,34 +126,57 @@ func (s *Security) GetTransientToken(ctx context.Context, type_ operations.Query
|
||||
// If a caller requires connection details and a transient token for a source that is known to the server, for example a cloud media provider or shared PMS, then this endpoint can be called. This endpoint is only accessible with either an admin token or a valid transient token generated from an admin token.
|
||||
// Note: requires Plex Media Server >= 1.15.4.
|
||||
func (s *Security) GetSourceConnectionInformation(ctx context.Context, source string) (*operations.GetSourceConnectionInformationResponse, error) {
|
||||
hookCtx := hooks.HookContext{OperationID: "getSourceConnectionInformation"}
|
||||
|
||||
request := operations.GetSourceConnectionInformationRequest{
|
||||
Source: source,
|
||||
}
|
||||
|
||||
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
|
||||
url := strings.TrimSuffix(baseURL, "/") + "/security/resources"
|
||||
opURL, err := url.JoinPath(baseURL, "/security/resources")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error generating URL: %w", err)
|
||||
}
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", url, nil)
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", opURL, 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)
|
||||
req.Header.Set("User-Agent", s.sdkConfiguration.UserAgent)
|
||||
|
||||
if err := utils.PopulateQueryParams(ctx, req, request, nil); err != nil {
|
||||
return nil, fmt.Errorf("error populating query params: %w", err)
|
||||
}
|
||||
|
||||
req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{hookCtx}, req)
|
||||
if err != nil {
|
||||
return nil, 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")
|
||||
}
|
||||
if err != nil || httpRes == nil {
|
||||
if err != nil {
|
||||
err = fmt.Errorf("error sending request: %w", err)
|
||||
} else {
|
||||
err = fmt.Errorf("error sending request: no response")
|
||||
}
|
||||
|
||||
_, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{hookCtx}, nil, err)
|
||||
return nil, err
|
||||
} else if utils.MatchStatusCodes([]string{"400", "401", "4XX", "5XX"}, httpRes.StatusCode) {
|
||||
httpRes, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{hookCtx}, httpRes, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{hookCtx}, httpRes)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
contentType := httpRes.Header.Get("Content-Type")
|
||||
|
||||
res := &operations.GetSourceConnectionInformationResponse{
|
||||
@@ -143,6 +191,7 @@ func (s *Security) GetSourceConnectionInformation(ctx context.Context, source st
|
||||
}
|
||||
httpRes.Body.Close()
|
||||
httpRes.Body = io.NopCloser(bytes.NewBuffer(rawBody))
|
||||
|
||||
switch {
|
||||
case httpRes.StatusCode == 200:
|
||||
case httpRes.StatusCode == 400:
|
||||
|
||||
355
server.go
355
server.go
@@ -6,12 +6,13 @@ import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/LukeHagar/plexgo/internal/hooks"
|
||||
"github.com/LukeHagar/plexgo/internal/utils"
|
||||
"github.com/LukeHagar/plexgo/models/operations"
|
||||
"github.com/LukeHagar/plexgo/models/sdkerrors"
|
||||
"io"
|
||||
"net/http"
|
||||
"strings"
|
||||
"net/url"
|
||||
)
|
||||
|
||||
// Server - Operations against the Plex Media Server System.
|
||||
@@ -28,26 +29,49 @@ func newServer(sdkConfig sdkConfiguration) *Server {
|
||||
// GetServerCapabilities - Server Capabilities
|
||||
// Server Capabilities
|
||||
func (s *Server) GetServerCapabilities(ctx context.Context) (*operations.GetServerCapabilitiesResponse, error) {
|
||||
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
|
||||
url := strings.TrimSuffix(baseURL, "/") + "/"
|
||||
hookCtx := hooks.HookContext{OperationID: "getServerCapabilities"}
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", url, nil)
|
||||
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
|
||||
opURL, err := url.JoinPath(baseURL, "/")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error generating URL: %w", err)
|
||||
}
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", opURL, 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)
|
||||
req.Header.Set("User-Agent", s.sdkConfiguration.UserAgent)
|
||||
|
||||
req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{hookCtx}, req)
|
||||
if err != nil {
|
||||
return nil, 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")
|
||||
}
|
||||
if err != nil || httpRes == nil {
|
||||
if err != nil {
|
||||
err = fmt.Errorf("error sending request: %w", err)
|
||||
} else {
|
||||
err = fmt.Errorf("error sending request: no response")
|
||||
}
|
||||
|
||||
_, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{hookCtx}, nil, err)
|
||||
return nil, err
|
||||
} else if utils.MatchStatusCodes([]string{"400", "401", "4XX", "5XX"}, httpRes.StatusCode) {
|
||||
httpRes, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{hookCtx}, httpRes, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{hookCtx}, httpRes)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
contentType := httpRes.Header.Get("Content-Type")
|
||||
|
||||
res := &operations.GetServerCapabilitiesResponse{
|
||||
@@ -62,6 +86,7 @@ func (s *Server) GetServerCapabilities(ctx context.Context) (*operations.GetServ
|
||||
}
|
||||
httpRes.Body.Close()
|
||||
httpRes.Body = io.NopCloser(bytes.NewBuffer(rawBody))
|
||||
|
||||
switch {
|
||||
case httpRes.StatusCode == 200:
|
||||
switch {
|
||||
@@ -102,26 +127,49 @@ func (s *Server) GetServerCapabilities(ctx context.Context) (*operations.GetServ
|
||||
// GetServerPreferences - Get Server Preferences
|
||||
// Get Server Preferences
|
||||
func (s *Server) GetServerPreferences(ctx context.Context) (*operations.GetServerPreferencesResponse, error) {
|
||||
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
|
||||
url := strings.TrimSuffix(baseURL, "/") + "/:/prefs"
|
||||
hookCtx := hooks.HookContext{OperationID: "getServerPreferences"}
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", url, nil)
|
||||
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
|
||||
opURL, err := url.JoinPath(baseURL, "/:/prefs")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error generating URL: %w", err)
|
||||
}
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", opURL, 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)
|
||||
req.Header.Set("User-Agent", s.sdkConfiguration.UserAgent)
|
||||
|
||||
req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{hookCtx}, req)
|
||||
if err != nil {
|
||||
return nil, 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")
|
||||
}
|
||||
if err != nil || httpRes == nil {
|
||||
if err != nil {
|
||||
err = fmt.Errorf("error sending request: %w", err)
|
||||
} else {
|
||||
err = fmt.Errorf("error sending request: no response")
|
||||
}
|
||||
|
||||
_, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{hookCtx}, nil, err)
|
||||
return nil, err
|
||||
} else if utils.MatchStatusCodes([]string{"400", "401", "4XX", "5XX"}, httpRes.StatusCode) {
|
||||
httpRes, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{hookCtx}, httpRes, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{hookCtx}, httpRes)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
contentType := httpRes.Header.Get("Content-Type")
|
||||
|
||||
res := &operations.GetServerPreferencesResponse{
|
||||
@@ -136,6 +184,7 @@ func (s *Server) GetServerPreferences(ctx context.Context) (*operations.GetServe
|
||||
}
|
||||
httpRes.Body.Close()
|
||||
httpRes.Body = io.NopCloser(bytes.NewBuffer(rawBody))
|
||||
|
||||
switch {
|
||||
case httpRes.StatusCode == 200:
|
||||
switch {
|
||||
@@ -176,26 +225,49 @@ func (s *Server) GetServerPreferences(ctx context.Context) (*operations.GetServe
|
||||
// GetAvailableClients - Get Available Clients
|
||||
// Get Available Clients
|
||||
func (s *Server) GetAvailableClients(ctx context.Context) (*operations.GetAvailableClientsResponse, error) {
|
||||
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
|
||||
url := strings.TrimSuffix(baseURL, "/") + "/clients"
|
||||
hookCtx := hooks.HookContext{OperationID: "getAvailableClients"}
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", url, nil)
|
||||
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
|
||||
opURL, err := url.JoinPath(baseURL, "/clients")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error generating URL: %w", err)
|
||||
}
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", opURL, 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)
|
||||
req.Header.Set("User-Agent", s.sdkConfiguration.UserAgent)
|
||||
|
||||
req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{hookCtx}, req)
|
||||
if err != nil {
|
||||
return nil, 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")
|
||||
}
|
||||
if err != nil || httpRes == nil {
|
||||
if err != nil {
|
||||
err = fmt.Errorf("error sending request: %w", err)
|
||||
} else {
|
||||
err = fmt.Errorf("error sending request: no response")
|
||||
}
|
||||
|
||||
_, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{hookCtx}, nil, err)
|
||||
return nil, err
|
||||
} else if utils.MatchStatusCodes([]string{"400", "401", "4XX", "5XX"}, httpRes.StatusCode) {
|
||||
httpRes, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{hookCtx}, httpRes, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{hookCtx}, httpRes)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
contentType := httpRes.Header.Get("Content-Type")
|
||||
|
||||
res := &operations.GetAvailableClientsResponse{
|
||||
@@ -210,6 +282,7 @@ func (s *Server) GetAvailableClients(ctx context.Context) (*operations.GetAvaila
|
||||
}
|
||||
httpRes.Body.Close()
|
||||
httpRes.Body = io.NopCloser(bytes.NewBuffer(rawBody))
|
||||
|
||||
switch {
|
||||
case httpRes.StatusCode == 200:
|
||||
switch {
|
||||
@@ -250,26 +323,49 @@ func (s *Server) GetAvailableClients(ctx context.Context) (*operations.GetAvaila
|
||||
// GetDevices - Get Devices
|
||||
// Get Devices
|
||||
func (s *Server) GetDevices(ctx context.Context) (*operations.GetDevicesResponse, error) {
|
||||
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
|
||||
url := strings.TrimSuffix(baseURL, "/") + "/devices"
|
||||
hookCtx := hooks.HookContext{OperationID: "getDevices"}
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", url, nil)
|
||||
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
|
||||
opURL, err := url.JoinPath(baseURL, "/devices")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error generating URL: %w", err)
|
||||
}
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", opURL, 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)
|
||||
req.Header.Set("User-Agent", s.sdkConfiguration.UserAgent)
|
||||
|
||||
req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{hookCtx}, req)
|
||||
if err != nil {
|
||||
return nil, 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")
|
||||
}
|
||||
if err != nil || httpRes == nil {
|
||||
if err != nil {
|
||||
err = fmt.Errorf("error sending request: %w", err)
|
||||
} else {
|
||||
err = fmt.Errorf("error sending request: no response")
|
||||
}
|
||||
|
||||
_, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{hookCtx}, nil, err)
|
||||
return nil, err
|
||||
} else if utils.MatchStatusCodes([]string{"400", "401", "4XX", "5XX"}, httpRes.StatusCode) {
|
||||
httpRes, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{hookCtx}, httpRes, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{hookCtx}, httpRes)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
contentType := httpRes.Header.Get("Content-Type")
|
||||
|
||||
res := &operations.GetDevicesResponse{
|
||||
@@ -284,6 +380,7 @@ func (s *Server) GetDevices(ctx context.Context) (*operations.GetDevicesResponse
|
||||
}
|
||||
httpRes.Body.Close()
|
||||
httpRes.Body = io.NopCloser(bytes.NewBuffer(rawBody))
|
||||
|
||||
switch {
|
||||
case httpRes.StatusCode == 200:
|
||||
switch {
|
||||
@@ -324,26 +421,49 @@ func (s *Server) GetDevices(ctx context.Context) (*operations.GetDevicesResponse
|
||||
// GetServerIdentity - Get Server Identity
|
||||
// Get Server Identity
|
||||
func (s *Server) GetServerIdentity(ctx context.Context) (*operations.GetServerIdentityResponse, error) {
|
||||
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
|
||||
url := strings.TrimSuffix(baseURL, "/") + "/identity"
|
||||
hookCtx := hooks.HookContext{OperationID: "getServerIdentity"}
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", url, nil)
|
||||
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
|
||||
opURL, err := url.JoinPath(baseURL, "/identity")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error generating URL: %w", err)
|
||||
}
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", opURL, 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)
|
||||
req.Header.Set("User-Agent", s.sdkConfiguration.UserAgent)
|
||||
|
||||
req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{hookCtx}, req)
|
||||
if err != nil {
|
||||
return nil, 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")
|
||||
}
|
||||
if err != nil || httpRes == nil {
|
||||
if err != nil {
|
||||
err = fmt.Errorf("error sending request: %w", err)
|
||||
} else {
|
||||
err = fmt.Errorf("error sending request: no response")
|
||||
}
|
||||
|
||||
_, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{hookCtx}, nil, err)
|
||||
return nil, err
|
||||
} else if utils.MatchStatusCodes([]string{"400", "401", "4XX", "5XX"}, httpRes.StatusCode) {
|
||||
httpRes, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{hookCtx}, httpRes, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{hookCtx}, httpRes)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
contentType := httpRes.Header.Get("Content-Type")
|
||||
|
||||
res := &operations.GetServerIdentityResponse{
|
||||
@@ -358,6 +478,7 @@ func (s *Server) GetServerIdentity(ctx context.Context) (*operations.GetServerId
|
||||
}
|
||||
httpRes.Body.Close()
|
||||
httpRes.Body = io.NopCloser(bytes.NewBuffer(rawBody))
|
||||
|
||||
switch {
|
||||
case httpRes.StatusCode == 200:
|
||||
switch {
|
||||
@@ -398,26 +519,49 @@ func (s *Server) GetServerIdentity(ctx context.Context) (*operations.GetServerId
|
||||
// GetMyPlexAccount - Get MyPlex Account
|
||||
// Returns MyPlex Account Information
|
||||
func (s *Server) GetMyPlexAccount(ctx context.Context) (*operations.GetMyPlexAccountResponse, error) {
|
||||
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
|
||||
url := strings.TrimSuffix(baseURL, "/") + "/myplex/account"
|
||||
hookCtx := hooks.HookContext{OperationID: "getMyPlexAccount"}
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", url, nil)
|
||||
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
|
||||
opURL, err := url.JoinPath(baseURL, "/myplex/account")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error generating URL: %w", err)
|
||||
}
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", opURL, 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)
|
||||
req.Header.Set("User-Agent", s.sdkConfiguration.UserAgent)
|
||||
|
||||
req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{hookCtx}, req)
|
||||
if err != nil {
|
||||
return nil, 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")
|
||||
}
|
||||
if err != nil || httpRes == nil {
|
||||
if err != nil {
|
||||
err = fmt.Errorf("error sending request: %w", err)
|
||||
} else {
|
||||
err = fmt.Errorf("error sending request: no response")
|
||||
}
|
||||
|
||||
_, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{hookCtx}, nil, err)
|
||||
return nil, err
|
||||
} else if utils.MatchStatusCodes([]string{"400", "401", "4XX", "5XX"}, httpRes.StatusCode) {
|
||||
httpRes, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{hookCtx}, httpRes, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{hookCtx}, httpRes)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
contentType := httpRes.Header.Get("Content-Type")
|
||||
|
||||
res := &operations.GetMyPlexAccountResponse{
|
||||
@@ -432,6 +576,7 @@ func (s *Server) GetMyPlexAccount(ctx context.Context) (*operations.GetMyPlexAcc
|
||||
}
|
||||
httpRes.Body.Close()
|
||||
httpRes.Body = io.NopCloser(bytes.NewBuffer(rawBody))
|
||||
|
||||
switch {
|
||||
case httpRes.StatusCode == 200:
|
||||
switch {
|
||||
@@ -472,30 +617,53 @@ func (s *Server) GetMyPlexAccount(ctx context.Context) (*operations.GetMyPlexAcc
|
||||
// GetResizedPhoto - Get a Resized Photo
|
||||
// Plex's Photo transcoder is used throughout the service to serve images at specified sizes.
|
||||
func (s *Server) GetResizedPhoto(ctx context.Context, request operations.GetResizedPhotoRequest) (*operations.GetResizedPhotoResponse, error) {
|
||||
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
|
||||
url := strings.TrimSuffix(baseURL, "/") + "/photo/:/transcode"
|
||||
hookCtx := hooks.HookContext{OperationID: "getResizedPhoto"}
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", url, nil)
|
||||
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
|
||||
opURL, err := url.JoinPath(baseURL, "/photo/:/transcode")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error generating URL: %w", err)
|
||||
}
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", opURL, 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)
|
||||
req.Header.Set("User-Agent", s.sdkConfiguration.UserAgent)
|
||||
|
||||
if err := utils.PopulateQueryParams(ctx, req, request, nil); err != nil {
|
||||
return nil, fmt.Errorf("error populating query params: %w", err)
|
||||
}
|
||||
|
||||
req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{hookCtx}, req)
|
||||
if err != nil {
|
||||
return nil, 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")
|
||||
}
|
||||
if err != nil || httpRes == nil {
|
||||
if err != nil {
|
||||
err = fmt.Errorf("error sending request: %w", err)
|
||||
} else {
|
||||
err = fmt.Errorf("error sending request: no response")
|
||||
}
|
||||
|
||||
_, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{hookCtx}, nil, err)
|
||||
return nil, err
|
||||
} else if utils.MatchStatusCodes([]string{"400", "401", "4XX", "5XX"}, httpRes.StatusCode) {
|
||||
httpRes, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{hookCtx}, httpRes, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{hookCtx}, httpRes)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
contentType := httpRes.Header.Get("Content-Type")
|
||||
|
||||
res := &operations.GetResizedPhotoResponse{
|
||||
@@ -510,6 +678,7 @@ func (s *Server) GetResizedPhoto(ctx context.Context, request operations.GetResi
|
||||
}
|
||||
httpRes.Body.Close()
|
||||
httpRes.Body = io.NopCloser(bytes.NewBuffer(rawBody))
|
||||
|
||||
switch {
|
||||
case httpRes.StatusCode == 200:
|
||||
case httpRes.StatusCode == 400:
|
||||
@@ -539,26 +708,49 @@ func (s *Server) GetResizedPhoto(ctx context.Context, request operations.GetResi
|
||||
// GetServerList - Get Server List
|
||||
// Get Server List
|
||||
func (s *Server) GetServerList(ctx context.Context) (*operations.GetServerListResponse, error) {
|
||||
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
|
||||
url := strings.TrimSuffix(baseURL, "/") + "/servers"
|
||||
hookCtx := hooks.HookContext{OperationID: "getServerList"}
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", url, nil)
|
||||
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
|
||||
opURL, err := url.JoinPath(baseURL, "/servers")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error generating URL: %w", err)
|
||||
}
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", opURL, 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)
|
||||
req.Header.Set("User-Agent", s.sdkConfiguration.UserAgent)
|
||||
|
||||
req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{hookCtx}, req)
|
||||
if err != nil {
|
||||
return nil, 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")
|
||||
}
|
||||
if err != nil || httpRes == nil {
|
||||
if err != nil {
|
||||
err = fmt.Errorf("error sending request: %w", err)
|
||||
} else {
|
||||
err = fmt.Errorf("error sending request: no response")
|
||||
}
|
||||
|
||||
_, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{hookCtx}, nil, err)
|
||||
return nil, err
|
||||
} else if utils.MatchStatusCodes([]string{"400", "401", "4XX", "5XX"}, httpRes.StatusCode) {
|
||||
httpRes, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{hookCtx}, httpRes, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{hookCtx}, httpRes)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
contentType := httpRes.Header.Get("Content-Type")
|
||||
|
||||
res := &operations.GetServerListResponse{
|
||||
@@ -573,6 +765,7 @@ func (s *Server) GetServerList(ctx context.Context) (*operations.GetServerListRe
|
||||
}
|
||||
httpRes.Body.Close()
|
||||
httpRes.Body = io.NopCloser(bytes.NewBuffer(rawBody))
|
||||
|
||||
switch {
|
||||
case httpRes.StatusCode == 200:
|
||||
switch {
|
||||
|
||||
174
sessions.go
174
sessions.go
@@ -6,12 +6,13 @@ import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/LukeHagar/plexgo/internal/hooks"
|
||||
"github.com/LukeHagar/plexgo/internal/utils"
|
||||
"github.com/LukeHagar/plexgo/models/operations"
|
||||
"github.com/LukeHagar/plexgo/models/sdkerrors"
|
||||
"io"
|
||||
"net/http"
|
||||
"strings"
|
||||
"net/url"
|
||||
)
|
||||
|
||||
// Sessions - API Calls that perform search operations with Plex Media Server Sessions
|
||||
@@ -28,26 +29,49 @@ func newSessions(sdkConfig sdkConfiguration) *Sessions {
|
||||
// GetSessions - Get Active Sessions
|
||||
// This will retrieve the "Now Playing" Information of the PMS.
|
||||
func (s *Sessions) GetSessions(ctx context.Context) (*operations.GetSessionsResponse, error) {
|
||||
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
|
||||
url := strings.TrimSuffix(baseURL, "/") + "/status/sessions"
|
||||
hookCtx := hooks.HookContext{OperationID: "getSessions"}
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", url, nil)
|
||||
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
|
||||
opURL, err := url.JoinPath(baseURL, "/status/sessions")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error generating URL: %w", err)
|
||||
}
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", opURL, 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)
|
||||
req.Header.Set("User-Agent", s.sdkConfiguration.UserAgent)
|
||||
|
||||
req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{hookCtx}, req)
|
||||
if err != nil {
|
||||
return nil, 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")
|
||||
}
|
||||
if err != nil || httpRes == nil {
|
||||
if err != nil {
|
||||
err = fmt.Errorf("error sending request: %w", err)
|
||||
} else {
|
||||
err = fmt.Errorf("error sending request: no response")
|
||||
}
|
||||
|
||||
_, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{hookCtx}, nil, err)
|
||||
return nil, err
|
||||
} else if utils.MatchStatusCodes([]string{"400", "401", "4XX", "5XX"}, httpRes.StatusCode) {
|
||||
httpRes, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{hookCtx}, httpRes, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{hookCtx}, httpRes)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
contentType := httpRes.Header.Get("Content-Type")
|
||||
|
||||
res := &operations.GetSessionsResponse{
|
||||
@@ -62,6 +86,7 @@ func (s *Sessions) GetSessions(ctx context.Context) (*operations.GetSessionsResp
|
||||
}
|
||||
httpRes.Body.Close()
|
||||
httpRes.Body = io.NopCloser(bytes.NewBuffer(rawBody))
|
||||
|
||||
switch {
|
||||
case httpRes.StatusCode == 200:
|
||||
switch {
|
||||
@@ -102,26 +127,49 @@ func (s *Sessions) GetSessions(ctx context.Context) (*operations.GetSessionsResp
|
||||
// GetSessionHistory - Get Session History
|
||||
// This will Retrieve a listing of all history views.
|
||||
func (s *Sessions) GetSessionHistory(ctx context.Context) (*operations.GetSessionHistoryResponse, error) {
|
||||
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
|
||||
url := strings.TrimSuffix(baseURL, "/") + "/status/sessions/history/all"
|
||||
hookCtx := hooks.HookContext{OperationID: "getSessionHistory"}
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", url, nil)
|
||||
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
|
||||
opURL, err := url.JoinPath(baseURL, "/status/sessions/history/all")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error generating URL: %w", err)
|
||||
}
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", opURL, 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)
|
||||
req.Header.Set("User-Agent", s.sdkConfiguration.UserAgent)
|
||||
|
||||
req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{hookCtx}, req)
|
||||
if err != nil {
|
||||
return nil, 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")
|
||||
}
|
||||
if err != nil || httpRes == nil {
|
||||
if err != nil {
|
||||
err = fmt.Errorf("error sending request: %w", err)
|
||||
} else {
|
||||
err = fmt.Errorf("error sending request: no response")
|
||||
}
|
||||
|
||||
_, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{hookCtx}, nil, err)
|
||||
return nil, err
|
||||
} else if utils.MatchStatusCodes([]string{"400", "401", "4XX", "5XX"}, httpRes.StatusCode) {
|
||||
httpRes, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{hookCtx}, httpRes, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{hookCtx}, httpRes)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
contentType := httpRes.Header.Get("Content-Type")
|
||||
|
||||
res := &operations.GetSessionHistoryResponse{
|
||||
@@ -136,6 +184,7 @@ func (s *Sessions) GetSessionHistory(ctx context.Context) (*operations.GetSessio
|
||||
}
|
||||
httpRes.Body.Close()
|
||||
httpRes.Body = io.NopCloser(bytes.NewBuffer(rawBody))
|
||||
|
||||
switch {
|
||||
case httpRes.StatusCode == 200:
|
||||
switch {
|
||||
@@ -176,26 +225,49 @@ func (s *Sessions) GetSessionHistory(ctx context.Context) (*operations.GetSessio
|
||||
// GetTranscodeSessions - Get Transcode Sessions
|
||||
// Get Transcode Sessions
|
||||
func (s *Sessions) GetTranscodeSessions(ctx context.Context) (*operations.GetTranscodeSessionsResponse, error) {
|
||||
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
|
||||
url := strings.TrimSuffix(baseURL, "/") + "/transcode/sessions"
|
||||
hookCtx := hooks.HookContext{OperationID: "getTranscodeSessions"}
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", url, nil)
|
||||
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
|
||||
opURL, err := url.JoinPath(baseURL, "/transcode/sessions")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error generating URL: %w", err)
|
||||
}
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", opURL, 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)
|
||||
req.Header.Set("User-Agent", s.sdkConfiguration.UserAgent)
|
||||
|
||||
req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{hookCtx}, req)
|
||||
if err != nil {
|
||||
return nil, 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")
|
||||
}
|
||||
if err != nil || httpRes == nil {
|
||||
if err != nil {
|
||||
err = fmt.Errorf("error sending request: %w", err)
|
||||
} else {
|
||||
err = fmt.Errorf("error sending request: no response")
|
||||
}
|
||||
|
||||
_, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{hookCtx}, nil, err)
|
||||
return nil, err
|
||||
} else if utils.MatchStatusCodes([]string{"400", "401", "4XX", "5XX"}, httpRes.StatusCode) {
|
||||
httpRes, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{hookCtx}, httpRes, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{hookCtx}, httpRes)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
contentType := httpRes.Header.Get("Content-Type")
|
||||
|
||||
res := &operations.GetTranscodeSessionsResponse{
|
||||
@@ -210,6 +282,7 @@ func (s *Sessions) GetTranscodeSessions(ctx context.Context) (*operations.GetTra
|
||||
}
|
||||
httpRes.Body.Close()
|
||||
httpRes.Body = io.NopCloser(bytes.NewBuffer(rawBody))
|
||||
|
||||
switch {
|
||||
case httpRes.StatusCode == 200:
|
||||
switch {
|
||||
@@ -250,33 +323,53 @@ func (s *Sessions) GetTranscodeSessions(ctx context.Context) (*operations.GetTra
|
||||
// StopTranscodeSession - Stop a Transcode Session
|
||||
// Stop a Transcode Session
|
||||
func (s *Sessions) StopTranscodeSession(ctx context.Context, sessionKey string) (*operations.StopTranscodeSessionResponse, error) {
|
||||
hookCtx := hooks.HookContext{OperationID: "stopTranscodeSession"}
|
||||
|
||||
request := operations.StopTranscodeSessionRequest{
|
||||
SessionKey: sessionKey,
|
||||
}
|
||||
|
||||
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
|
||||
url, err := utils.GenerateURL(ctx, baseURL, "/transcode/sessions/{sessionKey}", request, nil)
|
||||
opURL, err := utils.GenerateURL(ctx, baseURL, "/transcode/sessions/{sessionKey}", request, nil)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error generating URL: %w", err)
|
||||
}
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, "DELETE", url, nil)
|
||||
req, err := http.NewRequestWithContext(ctx, "DELETE", opURL, 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)
|
||||
req.Header.Set("User-Agent", s.sdkConfiguration.UserAgent)
|
||||
|
||||
req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{hookCtx}, req)
|
||||
if err != nil {
|
||||
return nil, 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")
|
||||
}
|
||||
if err != nil || httpRes == nil {
|
||||
if err != nil {
|
||||
err = fmt.Errorf("error sending request: %w", err)
|
||||
} else {
|
||||
err = fmt.Errorf("error sending request: no response")
|
||||
}
|
||||
|
||||
_, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{hookCtx}, nil, err)
|
||||
return nil, err
|
||||
} else if utils.MatchStatusCodes([]string{"400", "401", "4XX", "5XX"}, httpRes.StatusCode) {
|
||||
httpRes, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{hookCtx}, httpRes, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{hookCtx}, httpRes)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
contentType := httpRes.Header.Get("Content-Type")
|
||||
|
||||
res := &operations.StopTranscodeSessionResponse{
|
||||
@@ -291,6 +384,7 @@ func (s *Sessions) StopTranscodeSession(ctx context.Context, sessionKey string)
|
||||
}
|
||||
httpRes.Body.Close()
|
||||
httpRes.Body = io.NopCloser(bytes.NewBuffer(rawBody))
|
||||
|
||||
switch {
|
||||
case httpRes.StatusCode == 204:
|
||||
case httpRes.StatusCode == 400:
|
||||
|
||||
133
statistics.go
Normal file
133
statistics.go
Normal file
@@ -0,0 +1,133 @@
|
||||
// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT.
|
||||
|
||||
package plexgo
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/LukeHagar/plexgo/internal/hooks"
|
||||
"github.com/LukeHagar/plexgo/internal/utils"
|
||||
"github.com/LukeHagar/plexgo/models/operations"
|
||||
"github.com/LukeHagar/plexgo/models/sdkerrors"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
)
|
||||
|
||||
// Statistics - API Calls that perform operations with Plex Media Server Statistics
|
||||
type Statistics struct {
|
||||
sdkConfiguration sdkConfiguration
|
||||
}
|
||||
|
||||
func newStatistics(sdkConfig sdkConfiguration) *Statistics {
|
||||
return &Statistics{
|
||||
sdkConfiguration: sdkConfig,
|
||||
}
|
||||
}
|
||||
|
||||
// GetStatistics - Get Media Statistics
|
||||
// This will return the media statistics for the server
|
||||
func (s *Statistics) GetStatistics(ctx context.Context, timespan *int64) (*operations.GetStatisticsResponse, error) {
|
||||
hookCtx := hooks.HookContext{OperationID: "getStatistics"}
|
||||
|
||||
request := operations.GetStatisticsRequest{
|
||||
Timespan: timespan,
|
||||
}
|
||||
|
||||
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
|
||||
opURL, err := url.JoinPath(baseURL, "/statistics/media")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error generating URL: %w", err)
|
||||
}
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", opURL, 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)
|
||||
|
||||
if err := utils.PopulateQueryParams(ctx, req, request, nil); err != nil {
|
||||
return nil, fmt.Errorf("error populating query params: %w", err)
|
||||
}
|
||||
|
||||
req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{hookCtx}, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
client := s.sdkConfiguration.SecurityClient
|
||||
|
||||
httpRes, err := client.Do(req)
|
||||
if err != nil || httpRes == nil {
|
||||
if err != nil {
|
||||
err = fmt.Errorf("error sending request: %w", err)
|
||||
} else {
|
||||
err = fmt.Errorf("error sending request: no response")
|
||||
}
|
||||
|
||||
_, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{hookCtx}, nil, err)
|
||||
return nil, err
|
||||
} else if utils.MatchStatusCodes([]string{"400", "401", "4XX", "5XX"}, httpRes.StatusCode) {
|
||||
httpRes, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{hookCtx}, httpRes, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{hookCtx}, httpRes)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
contentType := httpRes.Header.Get("Content-Type")
|
||||
|
||||
res := &operations.GetStatisticsResponse{
|
||||
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.GetStatisticsResponseBody
|
||||
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:
|
||||
fallthrough
|
||||
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)
|
||||
case httpRes.StatusCode == 401:
|
||||
switch {
|
||||
case utils.MatchContentType(contentType, `application/json`):
|
||||
var out sdkerrors.GetStatisticsResponseBody
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
return res, nil
|
||||
}
|
||||
131
updater.go
131
updater.go
@@ -6,12 +6,13 @@ import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/LukeHagar/plexgo/internal/hooks"
|
||||
"github.com/LukeHagar/plexgo/internal/utils"
|
||||
"github.com/LukeHagar/plexgo/models/operations"
|
||||
"github.com/LukeHagar/plexgo/models/sdkerrors"
|
||||
"io"
|
||||
"net/http"
|
||||
"strings"
|
||||
"net/url"
|
||||
)
|
||||
|
||||
// Updater - This describes the API for searching and applying updates to the Plex Media Server.
|
||||
@@ -29,26 +30,49 @@ func newUpdater(sdkConfig sdkConfiguration) *Updater {
|
||||
// GetUpdateStatus - Querying status of updates
|
||||
// Querying status of updates
|
||||
func (s *Updater) GetUpdateStatus(ctx context.Context) (*operations.GetUpdateStatusResponse, error) {
|
||||
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
|
||||
url := strings.TrimSuffix(baseURL, "/") + "/updater/status"
|
||||
hookCtx := hooks.HookContext{OperationID: "getUpdateStatus"}
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", url, nil)
|
||||
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
|
||||
opURL, err := url.JoinPath(baseURL, "/updater/status")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error generating URL: %w", err)
|
||||
}
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", opURL, 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)
|
||||
req.Header.Set("User-Agent", s.sdkConfiguration.UserAgent)
|
||||
|
||||
req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{hookCtx}, req)
|
||||
if err != nil {
|
||||
return nil, 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")
|
||||
}
|
||||
if err != nil || httpRes == nil {
|
||||
if err != nil {
|
||||
err = fmt.Errorf("error sending request: %w", err)
|
||||
} else {
|
||||
err = fmt.Errorf("error sending request: no response")
|
||||
}
|
||||
|
||||
_, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{hookCtx}, nil, err)
|
||||
return nil, err
|
||||
} else if utils.MatchStatusCodes([]string{"400", "401", "4XX", "5XX"}, httpRes.StatusCode) {
|
||||
httpRes, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{hookCtx}, httpRes, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{hookCtx}, httpRes)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
contentType := httpRes.Header.Get("Content-Type")
|
||||
|
||||
res := &operations.GetUpdateStatusResponse{
|
||||
@@ -63,6 +87,7 @@ func (s *Updater) GetUpdateStatus(ctx context.Context) (*operations.GetUpdateSta
|
||||
}
|
||||
httpRes.Body.Close()
|
||||
httpRes.Body = io.NopCloser(bytes.NewBuffer(rawBody))
|
||||
|
||||
switch {
|
||||
case httpRes.StatusCode == 200:
|
||||
switch {
|
||||
@@ -103,34 +128,57 @@ func (s *Updater) GetUpdateStatus(ctx context.Context) (*operations.GetUpdateSta
|
||||
// CheckForUpdates - Checking for updates
|
||||
// Checking for updates
|
||||
func (s *Updater) CheckForUpdates(ctx context.Context, download *operations.Download) (*operations.CheckForUpdatesResponse, error) {
|
||||
hookCtx := hooks.HookContext{OperationID: "checkForUpdates"}
|
||||
|
||||
request := operations.CheckForUpdatesRequest{
|
||||
Download: download,
|
||||
}
|
||||
|
||||
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
|
||||
url := strings.TrimSuffix(baseURL, "/") + "/updater/check"
|
||||
opURL, err := url.JoinPath(baseURL, "/updater/check")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error generating URL: %w", err)
|
||||
}
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, "PUT", url, nil)
|
||||
req, err := http.NewRequestWithContext(ctx, "PUT", opURL, 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)
|
||||
req.Header.Set("User-Agent", s.sdkConfiguration.UserAgent)
|
||||
|
||||
if err := utils.PopulateQueryParams(ctx, req, request, nil); err != nil {
|
||||
return nil, fmt.Errorf("error populating query params: %w", err)
|
||||
}
|
||||
|
||||
req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{hookCtx}, req)
|
||||
if err != nil {
|
||||
return nil, 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")
|
||||
}
|
||||
if err != nil || httpRes == nil {
|
||||
if err != nil {
|
||||
err = fmt.Errorf("error sending request: %w", err)
|
||||
} else {
|
||||
err = fmt.Errorf("error sending request: no response")
|
||||
}
|
||||
|
||||
_, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{hookCtx}, nil, err)
|
||||
return nil, err
|
||||
} else if utils.MatchStatusCodes([]string{"400", "401", "4XX", "5XX"}, httpRes.StatusCode) {
|
||||
httpRes, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{hookCtx}, httpRes, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{hookCtx}, httpRes)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
contentType := httpRes.Header.Get("Content-Type")
|
||||
|
||||
res := &operations.CheckForUpdatesResponse{
|
||||
@@ -145,6 +193,7 @@ func (s *Updater) CheckForUpdates(ctx context.Context, download *operations.Down
|
||||
}
|
||||
httpRes.Body.Close()
|
||||
httpRes.Body = io.NopCloser(bytes.NewBuffer(rawBody))
|
||||
|
||||
switch {
|
||||
case httpRes.StatusCode == 200:
|
||||
case httpRes.StatusCode == 400:
|
||||
@@ -174,35 +223,58 @@ func (s *Updater) CheckForUpdates(ctx context.Context, download *operations.Down
|
||||
// ApplyUpdates - Apply Updates
|
||||
// Note that these two parameters are effectively mutually exclusive. The `tonight` parameter takes precedence and `skip` will be ignored if `tonight` is also passed
|
||||
func (s *Updater) ApplyUpdates(ctx context.Context, tonight *operations.Tonight, skip *operations.Skip) (*operations.ApplyUpdatesResponse, error) {
|
||||
hookCtx := hooks.HookContext{OperationID: "applyUpdates"}
|
||||
|
||||
request := operations.ApplyUpdatesRequest{
|
||||
Tonight: tonight,
|
||||
Skip: skip,
|
||||
}
|
||||
|
||||
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
|
||||
url := strings.TrimSuffix(baseURL, "/") + "/updater/apply"
|
||||
opURL, err := url.JoinPath(baseURL, "/updater/apply")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error generating URL: %w", err)
|
||||
}
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, "PUT", url, nil)
|
||||
req, err := http.NewRequestWithContext(ctx, "PUT", opURL, 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)
|
||||
req.Header.Set("User-Agent", s.sdkConfiguration.UserAgent)
|
||||
|
||||
if err := utils.PopulateQueryParams(ctx, req, request, nil); err != nil {
|
||||
return nil, fmt.Errorf("error populating query params: %w", err)
|
||||
}
|
||||
|
||||
req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{hookCtx}, req)
|
||||
if err != nil {
|
||||
return nil, 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")
|
||||
}
|
||||
if err != nil || httpRes == nil {
|
||||
if err != nil {
|
||||
err = fmt.Errorf("error sending request: %w", err)
|
||||
} else {
|
||||
err = fmt.Errorf("error sending request: no response")
|
||||
}
|
||||
|
||||
_, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{hookCtx}, nil, err)
|
||||
return nil, err
|
||||
} else if utils.MatchStatusCodes([]string{"400", "401", "4XX", "500", "5XX"}, httpRes.StatusCode) {
|
||||
httpRes, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{hookCtx}, httpRes, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{hookCtx}, httpRes)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
contentType := httpRes.Header.Get("Content-Type")
|
||||
|
||||
res := &operations.ApplyUpdatesResponse{
|
||||
@@ -217,6 +289,7 @@ func (s *Updater) ApplyUpdates(ctx context.Context, tonight *operations.Tonight,
|
||||
}
|
||||
httpRes.Body.Close()
|
||||
httpRes.Body = io.NopCloser(bytes.NewBuffer(rawBody))
|
||||
|
||||
switch {
|
||||
case httpRes.StatusCode == 200:
|
||||
case httpRes.StatusCode == 400:
|
||||
|
||||
205
video.go
205
video.go
@@ -6,12 +6,13 @@ import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/LukeHagar/plexgo/internal/hooks"
|
||||
"github.com/LukeHagar/plexgo/internal/utils"
|
||||
"github.com/LukeHagar/plexgo/models/operations"
|
||||
"github.com/LukeHagar/plexgo/models/sdkerrors"
|
||||
"io"
|
||||
"net/http"
|
||||
"strings"
|
||||
"net/url"
|
||||
)
|
||||
|
||||
// Video - API Calls that perform operations with Plex Media Server Videos
|
||||
@@ -25,100 +26,56 @@ func newVideo(sdkConfig sdkConfiguration) *Video {
|
||||
}
|
||||
}
|
||||
|
||||
// StartUniversalTranscode - Start Universal Transcode
|
||||
// Begin a Universal Transcode Session
|
||||
func (s *Video) StartUniversalTranscode(ctx context.Context, request operations.StartUniversalTranscodeRequest) (*operations.StartUniversalTranscodeResponse, error) {
|
||||
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
|
||||
url := strings.TrimSuffix(baseURL, "/") + "/video/:/transcode/universal/start.mpd"
|
||||
|
||||
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)
|
||||
|
||||
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.StartUniversalTranscodeResponse{
|
||||
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:
|
||||
fallthrough
|
||||
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)
|
||||
case httpRes.StatusCode == 401:
|
||||
switch {
|
||||
case utils.MatchContentType(contentType, `application/json`):
|
||||
var out sdkerrors.StartUniversalTranscodeResponseBody
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
return res, nil
|
||||
}
|
||||
|
||||
// GetTimeline - Get the timeline for a media item
|
||||
// Get the timeline for a media item
|
||||
func (s *Video) GetTimeline(ctx context.Context, request operations.GetTimelineRequest) (*operations.GetTimelineResponse, error) {
|
||||
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
|
||||
url := strings.TrimSuffix(baseURL, "/") + "/:/timeline"
|
||||
hookCtx := hooks.HookContext{OperationID: "getTimeline"}
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", url, nil)
|
||||
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
|
||||
opURL, err := url.JoinPath(baseURL, "/:/timeline")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error generating URL: %w", err)
|
||||
}
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", opURL, 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)
|
||||
req.Header.Set("User-Agent", s.sdkConfiguration.UserAgent)
|
||||
|
||||
if err := utils.PopulateQueryParams(ctx, req, request, nil); err != nil {
|
||||
return nil, fmt.Errorf("error populating query params: %w", err)
|
||||
}
|
||||
|
||||
req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{hookCtx}, req)
|
||||
if err != nil {
|
||||
return nil, 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")
|
||||
}
|
||||
if err != nil || httpRes == nil {
|
||||
if err != nil {
|
||||
err = fmt.Errorf("error sending request: %w", err)
|
||||
} else {
|
||||
err = fmt.Errorf("error sending request: no response")
|
||||
}
|
||||
|
||||
_, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{hookCtx}, nil, err)
|
||||
return nil, err
|
||||
} else if utils.MatchStatusCodes([]string{"400", "401", "4XX", "5XX"}, httpRes.StatusCode) {
|
||||
httpRes, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{hookCtx}, httpRes, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{hookCtx}, httpRes)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
contentType := httpRes.Header.Get("Content-Type")
|
||||
|
||||
res := &operations.GetTimelineResponse{
|
||||
@@ -133,6 +90,7 @@ func (s *Video) GetTimeline(ctx context.Context, request operations.GetTimelineR
|
||||
}
|
||||
httpRes.Body.Close()
|
||||
httpRes.Body = io.NopCloser(bytes.NewBuffer(rawBody))
|
||||
|
||||
switch {
|
||||
case httpRes.StatusCode == 200:
|
||||
case httpRes.StatusCode == 400:
|
||||
@@ -158,3 +116,94 @@ func (s *Video) GetTimeline(ctx context.Context, request operations.GetTimelineR
|
||||
|
||||
return res, nil
|
||||
}
|
||||
|
||||
// StartUniversalTranscode - Start Universal Transcode
|
||||
// Begin a Universal Transcode Session
|
||||
func (s *Video) StartUniversalTranscode(ctx context.Context, request operations.StartUniversalTranscodeRequest) (*operations.StartUniversalTranscodeResponse, error) {
|
||||
hookCtx := hooks.HookContext{OperationID: "startUniversalTranscode"}
|
||||
|
||||
baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
|
||||
opURL, err := url.JoinPath(baseURL, "/video/:/transcode/universal/start.mpd")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error generating URL: %w", err)
|
||||
}
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", opURL, 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)
|
||||
|
||||
if err := utils.PopulateQueryParams(ctx, req, request, nil); err != nil {
|
||||
return nil, fmt.Errorf("error populating query params: %w", err)
|
||||
}
|
||||
|
||||
req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{hookCtx}, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
client := s.sdkConfiguration.SecurityClient
|
||||
|
||||
httpRes, err := client.Do(req)
|
||||
if err != nil || httpRes == nil {
|
||||
if err != nil {
|
||||
err = fmt.Errorf("error sending request: %w", err)
|
||||
} else {
|
||||
err = fmt.Errorf("error sending request: no response")
|
||||
}
|
||||
|
||||
_, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{hookCtx}, nil, err)
|
||||
return nil, err
|
||||
} else if utils.MatchStatusCodes([]string{"400", "401", "4XX", "5XX"}, httpRes.StatusCode) {
|
||||
httpRes, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{hookCtx}, httpRes, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{hookCtx}, httpRes)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
contentType := httpRes.Header.Get("Content-Type")
|
||||
|
||||
res := &operations.StartUniversalTranscodeResponse{
|
||||
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:
|
||||
fallthrough
|
||||
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)
|
||||
case httpRes.StatusCode == 401:
|
||||
switch {
|
||||
case utils.MatchContentType(contentType, `application/json`):
|
||||
var out sdkerrors.StartUniversalTranscodeResponseBody
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
return res, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user