mirror of
https://github.com/LukeHagar/plexjava.git
synced 2025-12-06 20:47:45 +00:00
regerated and working on publishing
This commit is contained in:
502
src/main/java/dev/plexapi/sdk/PlexAPI.java
Normal file
502
src/main/java/dev/plexapi/sdk/PlexAPI.java
Normal file
@@ -0,0 +1,502 @@
|
||||
/*
|
||||
* Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
|
||||
*/
|
||||
|
||||
package dev.plexapi.sdk;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonValue;
|
||||
import dev.plexapi.sdk.models.operations.SDKMethodInterfaces.*;
|
||||
import dev.plexapi.sdk.utils.HTTPClient;
|
||||
import dev.plexapi.sdk.utils.RetryConfig;
|
||||
import dev.plexapi.sdk.utils.SpeakeasyHTTPClient;
|
||||
import java.lang.String;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* Plex-API: An Open API Spec for interacting with Plex.tv and Plex Media Server
|
||||
*/
|
||||
public class PlexAPI {
|
||||
|
||||
|
||||
/**
|
||||
* SERVERS contains the list of server urls available to the SDK.
|
||||
*/
|
||||
public static final String[] SERVERS = {
|
||||
/**
|
||||
* The full address of your Plex Server
|
||||
*/
|
||||
"{protocol}://{ip}:{port}",
|
||||
};
|
||||
|
||||
/**
|
||||
* Operations against the Plex Media Server System.
|
||||
*
|
||||
*/
|
||||
private final Server server;
|
||||
|
||||
/**
|
||||
* API Calls interacting with Plex Media Server Media
|
||||
*
|
||||
*/
|
||||
private final Media media;
|
||||
|
||||
/**
|
||||
* API Calls that perform operations with Plex Media Server Videos
|
||||
*
|
||||
*/
|
||||
private final 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:
|
||||
* - They can contain a `progress` (from 0 to 100) marking the percent completion of the activity.
|
||||
* - They must contain an `type` which is used by clients to distinguish the specific activity.
|
||||
* - They may contain a `Context` object with attributes which associate the activity with various specific entities (items, libraries, etc.)
|
||||
* - The may contain a `Response` object which attributes which represent the result of the asynchronous operation.
|
||||
*
|
||||
*/
|
||||
private final Activities activities;
|
||||
|
||||
/**
|
||||
* Butler is the task manager of the Plex Media Server Ecosystem.
|
||||
*
|
||||
*/
|
||||
private final Butler butler;
|
||||
|
||||
/**
|
||||
* API Calls that perform operations directly against https://Plex.tv
|
||||
*
|
||||
*/
|
||||
private final Plex plex;
|
||||
|
||||
/**
|
||||
* Hubs are a structured two-dimensional container for media, generally represented by multiple horizontal rows.
|
||||
*
|
||||
*/
|
||||
private final Hubs hubs;
|
||||
|
||||
/**
|
||||
* API Calls that perform search operations with Plex Media Server
|
||||
*
|
||||
*/
|
||||
private final Search search;
|
||||
|
||||
/**
|
||||
* API Calls interacting with Plex Media Server Libraries
|
||||
*
|
||||
*/
|
||||
private final Library library;
|
||||
|
||||
/**
|
||||
* API Calls that perform operations with Plex Media Server Watchlists
|
||||
*
|
||||
*/
|
||||
private final Watchlist watchlist;
|
||||
|
||||
/**
|
||||
* Submit logs to the Log Handler for Plex Media Server
|
||||
*
|
||||
*/
|
||||
private final Log log;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* This may cause the duration and number of items to change.
|
||||
*
|
||||
*/
|
||||
private final Playlists playlists;
|
||||
|
||||
/**
|
||||
* API Calls regarding authentication for Plex Media Server
|
||||
*
|
||||
*/
|
||||
private final Authentication authentication;
|
||||
|
||||
/**
|
||||
* API Calls that perform operations with Plex Media Server Statistics
|
||||
*
|
||||
*/
|
||||
private final Statistics statistics;
|
||||
|
||||
/**
|
||||
* API Calls that perform search operations with Plex Media Server Sessions
|
||||
*
|
||||
*/
|
||||
private final Sessions sessions;
|
||||
|
||||
/**
|
||||
* This describes the API for searching and applying updates to the Plex Media Server.
|
||||
* Updates to the status can be observed via the Event API.
|
||||
*
|
||||
*/
|
||||
private final Updater updater;
|
||||
|
||||
/**
|
||||
* Operations against the Plex Media Server System.
|
||||
*
|
||||
*/
|
||||
public Server server() {
|
||||
return server;
|
||||
}
|
||||
|
||||
/**
|
||||
* API Calls interacting with Plex Media Server Media
|
||||
*
|
||||
*/
|
||||
public Media media() {
|
||||
return media;
|
||||
}
|
||||
|
||||
/**
|
||||
* API Calls that perform operations with Plex Media Server Videos
|
||||
*
|
||||
*/
|
||||
public Video video() {
|
||||
return 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:
|
||||
* - They can contain a `progress` (from 0 to 100) marking the percent completion of the activity.
|
||||
* - They must contain an `type` which is used by clients to distinguish the specific activity.
|
||||
* - They may contain a `Context` object with attributes which associate the activity with various specific entities (items, libraries, etc.)
|
||||
* - The may contain a `Response` object which attributes which represent the result of the asynchronous operation.
|
||||
*
|
||||
*/
|
||||
public Activities activities() {
|
||||
return activities;
|
||||
}
|
||||
|
||||
/**
|
||||
* Butler is the task manager of the Plex Media Server Ecosystem.
|
||||
*
|
||||
*/
|
||||
public Butler butler() {
|
||||
return butler;
|
||||
}
|
||||
|
||||
/**
|
||||
* API Calls that perform operations directly against https://Plex.tv
|
||||
*
|
||||
*/
|
||||
public Plex plex() {
|
||||
return plex;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hubs are a structured two-dimensional container for media, generally represented by multiple horizontal rows.
|
||||
*
|
||||
*/
|
||||
public Hubs hubs() {
|
||||
return hubs;
|
||||
}
|
||||
|
||||
/**
|
||||
* API Calls that perform search operations with Plex Media Server
|
||||
*
|
||||
*/
|
||||
public Search search() {
|
||||
return search;
|
||||
}
|
||||
|
||||
/**
|
||||
* API Calls interacting with Plex Media Server Libraries
|
||||
*
|
||||
*/
|
||||
public Library library() {
|
||||
return library;
|
||||
}
|
||||
|
||||
/**
|
||||
* API Calls that perform operations with Plex Media Server Watchlists
|
||||
*
|
||||
*/
|
||||
public Watchlist watchlist() {
|
||||
return watchlist;
|
||||
}
|
||||
|
||||
/**
|
||||
* Submit logs to the Log Handler for Plex Media Server
|
||||
*
|
||||
*/
|
||||
public Log log() {
|
||||
return log;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* This may cause the duration and number of items to change.
|
||||
*
|
||||
*/
|
||||
public Playlists playlists() {
|
||||
return playlists;
|
||||
}
|
||||
|
||||
/**
|
||||
* API Calls regarding authentication for Plex Media Server
|
||||
*
|
||||
*/
|
||||
public Authentication authentication() {
|
||||
return authentication;
|
||||
}
|
||||
|
||||
/**
|
||||
* API Calls that perform operations with Plex Media Server Statistics
|
||||
*
|
||||
*/
|
||||
public Statistics statistics() {
|
||||
return statistics;
|
||||
}
|
||||
|
||||
/**
|
||||
* API Calls that perform search operations with Plex Media Server Sessions
|
||||
*
|
||||
*/
|
||||
public Sessions sessions() {
|
||||
return sessions;
|
||||
}
|
||||
|
||||
/**
|
||||
* This describes the API for searching and applying updates to the Plex Media Server.
|
||||
* Updates to the status can be observed via the Event API.
|
||||
*
|
||||
*/
|
||||
public Updater updater() {
|
||||
return updater;
|
||||
}
|
||||
|
||||
private final SDKConfiguration sdkConfiguration;
|
||||
|
||||
/**
|
||||
* The Builder class allows the configuration of a new instance of the SDK.
|
||||
*/
|
||||
public static class Builder {
|
||||
|
||||
private final SDKConfiguration sdkConfiguration = new SDKConfiguration();
|
||||
|
||||
private Builder() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows the default HTTP client to be overridden with a custom implementation.
|
||||
*
|
||||
* @param client The HTTP client to use for all requests.
|
||||
* @return The builder instance.
|
||||
*/
|
||||
public Builder client(HTTPClient client) {
|
||||
this.sdkConfiguration.defaultClient = client;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Configures the SDK security to use the provided secret.
|
||||
*
|
||||
* @param accessToken The secret to use for all requests.
|
||||
* @return The builder instance.
|
||||
*/
|
||||
public Builder accessToken(String accessToken) {
|
||||
this.sdkConfiguration.securitySource = SecuritySource.of(dev.plexapi.sdk.models.shared.Security.builder()
|
||||
.accessToken(accessToken)
|
||||
.build());
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Configures the SDK to use a custom security source.
|
||||
* @param securitySource The security source to use for all requests.
|
||||
* @return The builder instance.
|
||||
*/
|
||||
public Builder securitySource(SecuritySource securitySource) {
|
||||
this.sdkConfiguration.securitySource = securitySource;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Overrides the default server URL.
|
||||
*
|
||||
* @param serverUrl The server URL to use for all requests.
|
||||
* @return The builder instance.
|
||||
*/
|
||||
public Builder serverURL(String serverUrl) {
|
||||
this.sdkConfiguration.serverUrl = serverUrl;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Overrides the default server URL with a templated URL populated with the provided parameters.
|
||||
*
|
||||
* @param serverUrl The server URL to use for all requests.
|
||||
* @param params The parameters to use when templating the URL.
|
||||
* @return The builder instance.
|
||||
*/
|
||||
public Builder serverURL(String serverUrl, Map<String, String> params) {
|
||||
this.sdkConfiguration.serverUrl = dev.plexapi.sdk.utils.Utils.templateUrl(serverUrl, params);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Overrides the default server by index.
|
||||
*
|
||||
* @param serverIdx The server to use for all requests.
|
||||
* @return The builder instance.
|
||||
*/
|
||||
public Builder serverIndex(int serverIdx) {
|
||||
this.sdkConfiguration.serverIdx = serverIdx;
|
||||
this.sdkConfiguration.serverUrl = SERVERS[serverIdx];
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Overrides the default configuration for retries
|
||||
*
|
||||
* @param retryConfig The retry configuration to use for all requests.
|
||||
* @return The builder instance.
|
||||
*/
|
||||
public Builder retryConfig(RetryConfig retryConfig) {
|
||||
this.sdkConfiguration.retryConfig = Optional.of(retryConfig);
|
||||
return this;
|
||||
}
|
||||
public enum ServerProtocol {
|
||||
HTTP("http"),
|
||||
HTTPS("https");
|
||||
|
||||
@JsonValue
|
||||
private final String value;
|
||||
|
||||
private ServerProtocol(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public String value() {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Sets the protocol variable for url substitution.
|
||||
*
|
||||
* @param protocol The value to set.
|
||||
* @return The builder instance.
|
||||
*/
|
||||
public Builder protocol(ServerProtocol protocol) {
|
||||
for (Map<String, String> server : this.sdkConfiguration.serverDefaults) {
|
||||
if (!server.containsKey("protocol")) {
|
||||
continue;
|
||||
}
|
||||
server.put("protocol", protocol.toString());
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the ip variable for url substitution.
|
||||
*
|
||||
* @param ip The value to set.
|
||||
* @return The builder instance.
|
||||
*/
|
||||
public Builder ip(String ip) {
|
||||
for (Map<String, String> server : this.sdkConfiguration.serverDefaults) {
|
||||
if (!server.containsKey("ip")) {
|
||||
continue;
|
||||
}
|
||||
server.put("ip", ip.toString());
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the port variable for url substitution.
|
||||
*
|
||||
* @param port The value to set.
|
||||
* @return The builder instance.
|
||||
*/
|
||||
public Builder port(String port) {
|
||||
for (Map<String, String> server : this.sdkConfiguration.serverDefaults) {
|
||||
if (!server.containsKey("port")) {
|
||||
continue;
|
||||
}
|
||||
server.put("port", port.toString());
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows setting the xPlexClientIdentifier parameter for all supported operations.
|
||||
*
|
||||
* @param xPlexClientIdentifier The value to set.
|
||||
* @return The builder instance.
|
||||
*/
|
||||
public Builder xPlexClientIdentifier(String xPlexClientIdentifier) {
|
||||
if (!this.sdkConfiguration.globals.get("parameters").containsKey("queryParam")) {
|
||||
this.sdkConfiguration.globals.get("parameters").put("queryParam", new java.util.HashMap<>());
|
||||
}
|
||||
|
||||
this.sdkConfiguration.globals.get("parameters").get("queryParam").put("xPlexClientIdentifier", xPlexClientIdentifier);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
// Visible for testing, will be accessed via reflection
|
||||
void _hooks(dev.plexapi.sdk.utils.Hooks hooks) {
|
||||
sdkConfiguration.setHooks(hooks);
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds a new instance of the SDK.
|
||||
* @return The SDK instance.
|
||||
*/
|
||||
public PlexAPI build() {
|
||||
if (sdkConfiguration.defaultClient == null) {
|
||||
sdkConfiguration.defaultClient = new SpeakeasyHTTPClient();
|
||||
}
|
||||
if (sdkConfiguration.securitySource == null) {
|
||||
sdkConfiguration.securitySource = SecuritySource.of(null);
|
||||
}
|
||||
if (sdkConfiguration.serverUrl == null || sdkConfiguration.serverUrl.isBlank()) {
|
||||
sdkConfiguration.serverUrl = SERVERS[0];
|
||||
sdkConfiguration.serverIdx = 0;
|
||||
}
|
||||
if (sdkConfiguration.serverUrl.endsWith("/")) {
|
||||
sdkConfiguration.serverUrl = sdkConfiguration.serverUrl.substring(0, sdkConfiguration.serverUrl.length() - 1);
|
||||
}
|
||||
return new PlexAPI(sdkConfiguration);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a new instance of the SDK builder to configure a new instance of the SDK.
|
||||
* @return The SDK builder instance.
|
||||
*/
|
||||
public static Builder builder() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
private PlexAPI(SDKConfiguration sdkConfiguration) {
|
||||
this.sdkConfiguration = sdkConfiguration;
|
||||
this.server = new Server(sdkConfiguration);
|
||||
this.media = new Media(sdkConfiguration);
|
||||
this.video = new Video(sdkConfiguration);
|
||||
this.activities = new Activities(sdkConfiguration);
|
||||
this.butler = new Butler(sdkConfiguration);
|
||||
this.plex = new Plex(sdkConfiguration);
|
||||
this.hubs = new Hubs(sdkConfiguration);
|
||||
this.search = new Search(sdkConfiguration);
|
||||
this.library = new Library(sdkConfiguration);
|
||||
this.watchlist = new Watchlist(sdkConfiguration);
|
||||
this.log = new Log(sdkConfiguration);
|
||||
this.playlists = new Playlists(sdkConfiguration);
|
||||
this.authentication = new Authentication(sdkConfiguration);
|
||||
this.statistics = new Statistics(sdkConfiguration);
|
||||
this.sessions = new Sessions(sdkConfiguration);
|
||||
this.updater = new Updater(sdkConfiguration);
|
||||
this.sdkConfiguration.initialize();
|
||||
}}
|
||||
Reference in New Issue
Block a user