Files
plexjava/src/main/java/dev/plexapi/sdk/Sessions.java

719 lines
29 KiB
Java

/*
* Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
*/
package dev.plexapi.sdk;
import com.fasterxml.jackson.core.type.TypeReference;
import dev.plexapi.sdk.models.errors.GetSessionHistoryBadRequest;
import dev.plexapi.sdk.models.errors.GetSessionHistoryUnauthorized;
import dev.plexapi.sdk.models.errors.GetSessionsBadRequest;
import dev.plexapi.sdk.models.errors.GetSessionsUnauthorized;
import dev.plexapi.sdk.models.errors.GetTranscodeSessionsBadRequest;
import dev.plexapi.sdk.models.errors.GetTranscodeSessionsUnauthorized;
import dev.plexapi.sdk.models.errors.SDKError;
import dev.plexapi.sdk.models.errors.StopTranscodeSessionBadRequest;
import dev.plexapi.sdk.models.errors.StopTranscodeSessionUnauthorized;
import dev.plexapi.sdk.models.operations.GetSessionHistoryRequest;
import dev.plexapi.sdk.models.operations.GetSessionHistoryRequestBuilder;
import dev.plexapi.sdk.models.operations.GetSessionHistoryResponse;
import dev.plexapi.sdk.models.operations.GetSessionHistoryResponseBody;
import dev.plexapi.sdk.models.operations.GetSessionsRequestBuilder;
import dev.plexapi.sdk.models.operations.GetSessionsResponse;
import dev.plexapi.sdk.models.operations.GetSessionsResponseBody;
import dev.plexapi.sdk.models.operations.GetTranscodeSessionsRequestBuilder;
import dev.plexapi.sdk.models.operations.GetTranscodeSessionsResponse;
import dev.plexapi.sdk.models.operations.GetTranscodeSessionsResponseBody;
import dev.plexapi.sdk.models.operations.QueryParamFilter;
import dev.plexapi.sdk.models.operations.SDKMethodInterfaces.*;
import dev.plexapi.sdk.models.operations.StopTranscodeSessionRequest;
import dev.plexapi.sdk.models.operations.StopTranscodeSessionRequestBuilder;
import dev.plexapi.sdk.models.operations.StopTranscodeSessionResponse;
import dev.plexapi.sdk.utils.HTTPClient;
import dev.plexapi.sdk.utils.HTTPRequest;
import dev.plexapi.sdk.utils.Hook.AfterErrorContextImpl;
import dev.plexapi.sdk.utils.Hook.AfterSuccessContextImpl;
import dev.plexapi.sdk.utils.Hook.BeforeRequestContextImpl;
import dev.plexapi.sdk.utils.Utils;
import java.io.InputStream;
import java.lang.Exception;
import java.lang.Long;
import java.lang.String;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.util.List;
import java.util.Optional;
/**
* API Calls that perform search operations with Plex Media Server Sessions
*
*/
public class Sessions implements
MethodCallGetSessions,
MethodCallGetSessionHistory,
MethodCallGetTranscodeSessions,
MethodCallStopTranscodeSession {
private final SDKConfiguration sdkConfiguration;
Sessions(SDKConfiguration sdkConfiguration) {
this.sdkConfiguration = sdkConfiguration;
}
/**
* Get Active Sessions
* This will retrieve the "Now Playing" Information of the PMS.
* @return The call builder
*/
public GetSessionsRequestBuilder getSessions() {
return new GetSessionsRequestBuilder(this);
}
/**
* Get Active Sessions
* This will retrieve the "Now Playing" Information of the PMS.
* @return The response from the API call
* @throws Exception if the API call fails
*/
public GetSessionsResponse getSessionsDirect() throws Exception {
String _baseUrl = Utils.templateUrl(
this.sdkConfiguration.serverUrl, this.sdkConfiguration.getServerVariableDefaults());
String _url = Utils.generateURL(
_baseUrl,
"/status/sessions");
HTTPRequest _req = new HTTPRequest(_url, "GET");
_req.addHeader("Accept", "application/json")
.addHeader("user-agent",
SDKConfiguration.USER_AGENT);
Optional<SecuritySource> _hookSecuritySource = this.sdkConfiguration.securitySource();
Utils.configureSecurity(_req,
this.sdkConfiguration.securitySource.getSecurity());
HTTPClient _client = this.sdkConfiguration.defaultClient;
HttpRequest _r =
sdkConfiguration.hooks()
.beforeRequest(
new BeforeRequestContextImpl(
"getSessions",
Optional.of(List.of()),
_hookSecuritySource),
_req.build());
HttpResponse<InputStream> _httpRes;
try {
_httpRes = _client.send(_r);
if (Utils.statusCodeMatches(_httpRes.statusCode(), "400", "401", "4XX", "5XX")) {
_httpRes = sdkConfiguration.hooks()
.afterError(
new AfterErrorContextImpl(
"getSessions",
Optional.of(List.of()),
_hookSecuritySource),
Optional.of(_httpRes),
Optional.empty());
} else {
_httpRes = sdkConfiguration.hooks()
.afterSuccess(
new AfterSuccessContextImpl(
"getSessions",
Optional.of(List.of()),
_hookSecuritySource),
_httpRes);
}
} catch (Exception _e) {
_httpRes = sdkConfiguration.hooks()
.afterError(
new AfterErrorContextImpl(
"getSessions",
Optional.of(List.of()),
_hookSecuritySource),
Optional.empty(),
Optional.of(_e));
}
String _contentType = _httpRes
.headers()
.firstValue("Content-Type")
.orElse("application/octet-stream");
GetSessionsResponse.Builder _resBuilder =
GetSessionsResponse
.builder()
.contentType(_contentType)
.statusCode(_httpRes.statusCode())
.rawResponse(_httpRes);
GetSessionsResponse _res = _resBuilder.build();
if (Utils.statusCodeMatches(_httpRes.statusCode(), "200")) {
if (Utils.contentTypeMatches(_contentType, "application/json")) {
GetSessionsResponseBody _out = Utils.mapper().readValue(
Utils.toUtf8AndClose(_httpRes.body()),
new TypeReference<GetSessionsResponseBody>() {});
_res.withObject(Optional.ofNullable(_out));
return _res;
} else {
throw new SDKError(
_httpRes,
_httpRes.statusCode(),
"Unexpected content-type received: " + _contentType,
Utils.extractByteArrayFromBody(_httpRes));
}
}
if (Utils.statusCodeMatches(_httpRes.statusCode(), "400")) {
if (Utils.contentTypeMatches(_contentType, "application/json")) {
GetSessionsBadRequest _out = Utils.mapper().readValue(
Utils.toUtf8AndClose(_httpRes.body()),
new TypeReference<GetSessionsBadRequest>() {});
_out.withRawResponse(Optional.ofNullable(_httpRes));
throw _out;
} else {
throw new SDKError(
_httpRes,
_httpRes.statusCode(),
"Unexpected content-type received: " + _contentType,
Utils.extractByteArrayFromBody(_httpRes));
}
}
if (Utils.statusCodeMatches(_httpRes.statusCode(), "401")) {
if (Utils.contentTypeMatches(_contentType, "application/json")) {
GetSessionsUnauthorized _out = Utils.mapper().readValue(
Utils.toUtf8AndClose(_httpRes.body()),
new TypeReference<GetSessionsUnauthorized>() {});
_out.withRawResponse(Optional.ofNullable(_httpRes));
throw _out;
} else {
throw new SDKError(
_httpRes,
_httpRes.statusCode(),
"Unexpected content-type received: " + _contentType,
Utils.extractByteArrayFromBody(_httpRes));
}
}
if (Utils.statusCodeMatches(_httpRes.statusCode(), "4XX")) {
// no content
throw new SDKError(
_httpRes,
_httpRes.statusCode(),
"API error occurred",
Utils.extractByteArrayFromBody(_httpRes));
}
if (Utils.statusCodeMatches(_httpRes.statusCode(), "5XX")) {
// no content
throw new SDKError(
_httpRes,
_httpRes.statusCode(),
"API error occurred",
Utils.extractByteArrayFromBody(_httpRes));
}
throw new SDKError(
_httpRes,
_httpRes.statusCode(),
"Unexpected status code received: " + _httpRes.statusCode(),
Utils.extractByteArrayFromBody(_httpRes));
}
/**
* Get Session History
* This will Retrieve a listing of all history views.
* @return The call builder
*/
public GetSessionHistoryRequestBuilder getSessionHistory() {
return new GetSessionHistoryRequestBuilder(this);
}
/**
* Get Session History
* This will Retrieve a listing of all history views.
* @return The response from the API call
* @throws Exception if the API call fails
*/
public GetSessionHistoryResponse getSessionHistoryDirect() throws Exception {
return getSessionHistory(Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty());
}
/**
* Get Session History
* This will Retrieve a listing of all history views.
* @param sort Sorts the results by the specified field followed by the direction (asc, desc)
* @param accountId Filter results by those that are related to a specific users id
* @param filter Filters content by field and direction/equality
(Unknown if viewedAt is the only supported column)
* @param librarySectionID Filters the results based on the id of a valid library section
* @return The response from the API call
* @throws Exception if the API call fails
*/
public GetSessionHistoryResponse getSessionHistory(
Optional<String> sort,
Optional<Long> accountId,
Optional<? extends QueryParamFilter> filter,
Optional<Long> librarySectionID) throws Exception {
GetSessionHistoryRequest request =
GetSessionHistoryRequest
.builder()
.sort(sort)
.accountId(accountId)
.filter(filter)
.librarySectionID(librarySectionID)
.build();
String _baseUrl = Utils.templateUrl(
this.sdkConfiguration.serverUrl, this.sdkConfiguration.getServerVariableDefaults());
String _url = Utils.generateURL(
_baseUrl,
"/status/sessions/history/all");
HTTPRequest _req = new HTTPRequest(_url, "GET");
_req.addHeader("Accept", "application/json")
.addHeader("user-agent",
SDKConfiguration.USER_AGENT);
_req.addQueryParams(Utils.getQueryParams(
GetSessionHistoryRequest.class,
request,
null));
Optional<SecuritySource> _hookSecuritySource = this.sdkConfiguration.securitySource();
Utils.configureSecurity(_req,
this.sdkConfiguration.securitySource.getSecurity());
HTTPClient _client = this.sdkConfiguration.defaultClient;
HttpRequest _r =
sdkConfiguration.hooks()
.beforeRequest(
new BeforeRequestContextImpl(
"getSessionHistory",
Optional.of(List.of()),
_hookSecuritySource),
_req.build());
HttpResponse<InputStream> _httpRes;
try {
_httpRes = _client.send(_r);
if (Utils.statusCodeMatches(_httpRes.statusCode(), "400", "401", "4XX", "5XX")) {
_httpRes = sdkConfiguration.hooks()
.afterError(
new AfterErrorContextImpl(
"getSessionHistory",
Optional.of(List.of()),
_hookSecuritySource),
Optional.of(_httpRes),
Optional.empty());
} else {
_httpRes = sdkConfiguration.hooks()
.afterSuccess(
new AfterSuccessContextImpl(
"getSessionHistory",
Optional.of(List.of()),
_hookSecuritySource),
_httpRes);
}
} catch (Exception _e) {
_httpRes = sdkConfiguration.hooks()
.afterError(
new AfterErrorContextImpl(
"getSessionHistory",
Optional.of(List.of()),
_hookSecuritySource),
Optional.empty(),
Optional.of(_e));
}
String _contentType = _httpRes
.headers()
.firstValue("Content-Type")
.orElse("application/octet-stream");
GetSessionHistoryResponse.Builder _resBuilder =
GetSessionHistoryResponse
.builder()
.contentType(_contentType)
.statusCode(_httpRes.statusCode())
.rawResponse(_httpRes);
GetSessionHistoryResponse _res = _resBuilder.build();
if (Utils.statusCodeMatches(_httpRes.statusCode(), "200")) {
if (Utils.contentTypeMatches(_contentType, "application/json")) {
GetSessionHistoryResponseBody _out = Utils.mapper().readValue(
Utils.toUtf8AndClose(_httpRes.body()),
new TypeReference<GetSessionHistoryResponseBody>() {});
_res.withObject(Optional.ofNullable(_out));
return _res;
} else {
throw new SDKError(
_httpRes,
_httpRes.statusCode(),
"Unexpected content-type received: " + _contentType,
Utils.extractByteArrayFromBody(_httpRes));
}
}
if (Utils.statusCodeMatches(_httpRes.statusCode(), "400")) {
if (Utils.contentTypeMatches(_contentType, "application/json")) {
GetSessionHistoryBadRequest _out = Utils.mapper().readValue(
Utils.toUtf8AndClose(_httpRes.body()),
new TypeReference<GetSessionHistoryBadRequest>() {});
_out.withRawResponse(Optional.ofNullable(_httpRes));
throw _out;
} else {
throw new SDKError(
_httpRes,
_httpRes.statusCode(),
"Unexpected content-type received: " + _contentType,
Utils.extractByteArrayFromBody(_httpRes));
}
}
if (Utils.statusCodeMatches(_httpRes.statusCode(), "401")) {
if (Utils.contentTypeMatches(_contentType, "application/json")) {
GetSessionHistoryUnauthorized _out = Utils.mapper().readValue(
Utils.toUtf8AndClose(_httpRes.body()),
new TypeReference<GetSessionHistoryUnauthorized>() {});
_out.withRawResponse(Optional.ofNullable(_httpRes));
throw _out;
} else {
throw new SDKError(
_httpRes,
_httpRes.statusCode(),
"Unexpected content-type received: " + _contentType,
Utils.extractByteArrayFromBody(_httpRes));
}
}
if (Utils.statusCodeMatches(_httpRes.statusCode(), "4XX")) {
// no content
throw new SDKError(
_httpRes,
_httpRes.statusCode(),
"API error occurred",
Utils.extractByteArrayFromBody(_httpRes));
}
if (Utils.statusCodeMatches(_httpRes.statusCode(), "5XX")) {
// no content
throw new SDKError(
_httpRes,
_httpRes.statusCode(),
"API error occurred",
Utils.extractByteArrayFromBody(_httpRes));
}
throw new SDKError(
_httpRes,
_httpRes.statusCode(),
"Unexpected status code received: " + _httpRes.statusCode(),
Utils.extractByteArrayFromBody(_httpRes));
}
/**
* Get Transcode Sessions
* Get Transcode Sessions
* @return The call builder
*/
public GetTranscodeSessionsRequestBuilder getTranscodeSessions() {
return new GetTranscodeSessionsRequestBuilder(this);
}
/**
* Get Transcode Sessions
* Get Transcode Sessions
* @return The response from the API call
* @throws Exception if the API call fails
*/
public GetTranscodeSessionsResponse getTranscodeSessionsDirect() throws Exception {
String _baseUrl = Utils.templateUrl(
this.sdkConfiguration.serverUrl, this.sdkConfiguration.getServerVariableDefaults());
String _url = Utils.generateURL(
_baseUrl,
"/transcode/sessions");
HTTPRequest _req = new HTTPRequest(_url, "GET");
_req.addHeader("Accept", "application/json")
.addHeader("user-agent",
SDKConfiguration.USER_AGENT);
Optional<SecuritySource> _hookSecuritySource = this.sdkConfiguration.securitySource();
Utils.configureSecurity(_req,
this.sdkConfiguration.securitySource.getSecurity());
HTTPClient _client = this.sdkConfiguration.defaultClient;
HttpRequest _r =
sdkConfiguration.hooks()
.beforeRequest(
new BeforeRequestContextImpl(
"getTranscodeSessions",
Optional.of(List.of()),
_hookSecuritySource),
_req.build());
HttpResponse<InputStream> _httpRes;
try {
_httpRes = _client.send(_r);
if (Utils.statusCodeMatches(_httpRes.statusCode(), "400", "401", "4XX", "5XX")) {
_httpRes = sdkConfiguration.hooks()
.afterError(
new AfterErrorContextImpl(
"getTranscodeSessions",
Optional.of(List.of()),
_hookSecuritySource),
Optional.of(_httpRes),
Optional.empty());
} else {
_httpRes = sdkConfiguration.hooks()
.afterSuccess(
new AfterSuccessContextImpl(
"getTranscodeSessions",
Optional.of(List.of()),
_hookSecuritySource),
_httpRes);
}
} catch (Exception _e) {
_httpRes = sdkConfiguration.hooks()
.afterError(
new AfterErrorContextImpl(
"getTranscodeSessions",
Optional.of(List.of()),
_hookSecuritySource),
Optional.empty(),
Optional.of(_e));
}
String _contentType = _httpRes
.headers()
.firstValue("Content-Type")
.orElse("application/octet-stream");
GetTranscodeSessionsResponse.Builder _resBuilder =
GetTranscodeSessionsResponse
.builder()
.contentType(_contentType)
.statusCode(_httpRes.statusCode())
.rawResponse(_httpRes);
GetTranscodeSessionsResponse _res = _resBuilder.build();
if (Utils.statusCodeMatches(_httpRes.statusCode(), "200")) {
if (Utils.contentTypeMatches(_contentType, "application/json")) {
GetTranscodeSessionsResponseBody _out = Utils.mapper().readValue(
Utils.toUtf8AndClose(_httpRes.body()),
new TypeReference<GetTranscodeSessionsResponseBody>() {});
_res.withObject(Optional.ofNullable(_out));
return _res;
} else {
throw new SDKError(
_httpRes,
_httpRes.statusCode(),
"Unexpected content-type received: " + _contentType,
Utils.extractByteArrayFromBody(_httpRes));
}
}
if (Utils.statusCodeMatches(_httpRes.statusCode(), "400")) {
if (Utils.contentTypeMatches(_contentType, "application/json")) {
GetTranscodeSessionsBadRequest _out = Utils.mapper().readValue(
Utils.toUtf8AndClose(_httpRes.body()),
new TypeReference<GetTranscodeSessionsBadRequest>() {});
_out.withRawResponse(Optional.ofNullable(_httpRes));
throw _out;
} else {
throw new SDKError(
_httpRes,
_httpRes.statusCode(),
"Unexpected content-type received: " + _contentType,
Utils.extractByteArrayFromBody(_httpRes));
}
}
if (Utils.statusCodeMatches(_httpRes.statusCode(), "401")) {
if (Utils.contentTypeMatches(_contentType, "application/json")) {
GetTranscodeSessionsUnauthorized _out = Utils.mapper().readValue(
Utils.toUtf8AndClose(_httpRes.body()),
new TypeReference<GetTranscodeSessionsUnauthorized>() {});
_out.withRawResponse(Optional.ofNullable(_httpRes));
throw _out;
} else {
throw new SDKError(
_httpRes,
_httpRes.statusCode(),
"Unexpected content-type received: " + _contentType,
Utils.extractByteArrayFromBody(_httpRes));
}
}
if (Utils.statusCodeMatches(_httpRes.statusCode(), "4XX")) {
// no content
throw new SDKError(
_httpRes,
_httpRes.statusCode(),
"API error occurred",
Utils.extractByteArrayFromBody(_httpRes));
}
if (Utils.statusCodeMatches(_httpRes.statusCode(), "5XX")) {
// no content
throw new SDKError(
_httpRes,
_httpRes.statusCode(),
"API error occurred",
Utils.extractByteArrayFromBody(_httpRes));
}
throw new SDKError(
_httpRes,
_httpRes.statusCode(),
"Unexpected status code received: " + _httpRes.statusCode(),
Utils.extractByteArrayFromBody(_httpRes));
}
/**
* Stop a Transcode Session
* Stop a Transcode Session
* @return The call builder
*/
public StopTranscodeSessionRequestBuilder stopTranscodeSession() {
return new StopTranscodeSessionRequestBuilder(this);
}
/**
* Stop a Transcode Session
* Stop a Transcode Session
* @param sessionKey the Key of the transcode session to stop
* @return The response from the API call
* @throws Exception if the API call fails
*/
public StopTranscodeSessionResponse stopTranscodeSession(
String sessionKey) throws Exception {
StopTranscodeSessionRequest request =
StopTranscodeSessionRequest
.builder()
.sessionKey(sessionKey)
.build();
String _baseUrl = Utils.templateUrl(
this.sdkConfiguration.serverUrl, this.sdkConfiguration.getServerVariableDefaults());
String _url = Utils.generateURL(
StopTranscodeSessionRequest.class,
_baseUrl,
"/transcode/sessions/{sessionKey}",
request, null);
HTTPRequest _req = new HTTPRequest(_url, "DELETE");
_req.addHeader("Accept", "application/json")
.addHeader("user-agent",
SDKConfiguration.USER_AGENT);
Optional<SecuritySource> _hookSecuritySource = this.sdkConfiguration.securitySource();
Utils.configureSecurity(_req,
this.sdkConfiguration.securitySource.getSecurity());
HTTPClient _client = this.sdkConfiguration.defaultClient;
HttpRequest _r =
sdkConfiguration.hooks()
.beforeRequest(
new BeforeRequestContextImpl(
"stopTranscodeSession",
Optional.of(List.of()),
_hookSecuritySource),
_req.build());
HttpResponse<InputStream> _httpRes;
try {
_httpRes = _client.send(_r);
if (Utils.statusCodeMatches(_httpRes.statusCode(), "400", "401", "4XX", "5XX")) {
_httpRes = sdkConfiguration.hooks()
.afterError(
new AfterErrorContextImpl(
"stopTranscodeSession",
Optional.of(List.of()),
_hookSecuritySource),
Optional.of(_httpRes),
Optional.empty());
} else {
_httpRes = sdkConfiguration.hooks()
.afterSuccess(
new AfterSuccessContextImpl(
"stopTranscodeSession",
Optional.of(List.of()),
_hookSecuritySource),
_httpRes);
}
} catch (Exception _e) {
_httpRes = sdkConfiguration.hooks()
.afterError(
new AfterErrorContextImpl(
"stopTranscodeSession",
Optional.of(List.of()),
_hookSecuritySource),
Optional.empty(),
Optional.of(_e));
}
String _contentType = _httpRes
.headers()
.firstValue("Content-Type")
.orElse("application/octet-stream");
StopTranscodeSessionResponse.Builder _resBuilder =
StopTranscodeSessionResponse
.builder()
.contentType(_contentType)
.statusCode(_httpRes.statusCode())
.rawResponse(_httpRes);
StopTranscodeSessionResponse _res = _resBuilder.build();
if (Utils.statusCodeMatches(_httpRes.statusCode(), "204")) {
// no content
return _res;
}
if (Utils.statusCodeMatches(_httpRes.statusCode(), "400")) {
if (Utils.contentTypeMatches(_contentType, "application/json")) {
StopTranscodeSessionBadRequest _out = Utils.mapper().readValue(
Utils.toUtf8AndClose(_httpRes.body()),
new TypeReference<StopTranscodeSessionBadRequest>() {});
_out.withRawResponse(Optional.ofNullable(_httpRes));
throw _out;
} else {
throw new SDKError(
_httpRes,
_httpRes.statusCode(),
"Unexpected content-type received: " + _contentType,
Utils.extractByteArrayFromBody(_httpRes));
}
}
if (Utils.statusCodeMatches(_httpRes.statusCode(), "401")) {
if (Utils.contentTypeMatches(_contentType, "application/json")) {
StopTranscodeSessionUnauthorized _out = Utils.mapper().readValue(
Utils.toUtf8AndClose(_httpRes.body()),
new TypeReference<StopTranscodeSessionUnauthorized>() {});
_out.withRawResponse(Optional.ofNullable(_httpRes));
throw _out;
} else {
throw new SDKError(
_httpRes,
_httpRes.statusCode(),
"Unexpected content-type received: " + _contentType,
Utils.extractByteArrayFromBody(_httpRes));
}
}
if (Utils.statusCodeMatches(_httpRes.statusCode(), "4XX")) {
// no content
throw new SDKError(
_httpRes,
_httpRes.statusCode(),
"API error occurred",
Utils.extractByteArrayFromBody(_httpRes));
}
if (Utils.statusCodeMatches(_httpRes.statusCode(), "5XX")) {
// no content
throw new SDKError(
_httpRes,
_httpRes.statusCode(),
"API error occurred",
Utils.extractByteArrayFromBody(_httpRes));
}
throw new SDKError(
_httpRes,
_httpRes.statusCode(),
"Unexpected status code received: " + _httpRes.statusCode(),
Utils.extractByteArrayFromBody(_httpRes));
}
}