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

1711 lines
71 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.GetAvailableClientsBadRequest;
import dev.plexapi.sdk.models.errors.GetAvailableClientsUnauthorized;
import dev.plexapi.sdk.models.errors.GetDevicesBadRequest;
import dev.plexapi.sdk.models.errors.GetDevicesUnauthorized;
import dev.plexapi.sdk.models.errors.GetMediaProvidersBadRequest;
import dev.plexapi.sdk.models.errors.GetMediaProvidersUnauthorized;
import dev.plexapi.sdk.models.errors.GetMyPlexAccountBadRequest;
import dev.plexapi.sdk.models.errors.GetMyPlexAccountUnauthorized;
import dev.plexapi.sdk.models.errors.GetResizedPhotoBadRequest;
import dev.plexapi.sdk.models.errors.GetResizedPhotoUnauthorized;
import dev.plexapi.sdk.models.errors.GetServerCapabilitiesBadRequest;
import dev.plexapi.sdk.models.errors.GetServerCapabilitiesUnauthorized;
import dev.plexapi.sdk.models.errors.GetServerIdentityRequestTimeout;
import dev.plexapi.sdk.models.errors.GetServerListBadRequest;
import dev.plexapi.sdk.models.errors.GetServerListUnauthorized;
import dev.plexapi.sdk.models.errors.GetServerPreferencesBadRequest;
import dev.plexapi.sdk.models.errors.GetServerPreferencesUnauthorized;
import dev.plexapi.sdk.models.errors.SDKError;
import dev.plexapi.sdk.models.operations.GetAvailableClientsRequestBuilder;
import dev.plexapi.sdk.models.operations.GetAvailableClientsResponse;
import dev.plexapi.sdk.models.operations.GetAvailableClientsResponseBody;
import dev.plexapi.sdk.models.operations.GetDevicesRequestBuilder;
import dev.plexapi.sdk.models.operations.GetDevicesResponse;
import dev.plexapi.sdk.models.operations.GetDevicesResponseBody;
import dev.plexapi.sdk.models.operations.GetMediaProvidersRequest;
import dev.plexapi.sdk.models.operations.GetMediaProvidersRequestBuilder;
import dev.plexapi.sdk.models.operations.GetMediaProvidersResponse;
import dev.plexapi.sdk.models.operations.GetMediaProvidersResponseBody;
import dev.plexapi.sdk.models.operations.GetMyPlexAccountRequestBuilder;
import dev.plexapi.sdk.models.operations.GetMyPlexAccountResponse;
import dev.plexapi.sdk.models.operations.GetMyPlexAccountResponseBody;
import dev.plexapi.sdk.models.operations.GetResizedPhotoRequest;
import dev.plexapi.sdk.models.operations.GetResizedPhotoRequestBuilder;
import dev.plexapi.sdk.models.operations.GetResizedPhotoResponse;
import dev.plexapi.sdk.models.operations.GetServerCapabilitiesRequestBuilder;
import dev.plexapi.sdk.models.operations.GetServerCapabilitiesResponse;
import dev.plexapi.sdk.models.operations.GetServerCapabilitiesResponseBody;
import dev.plexapi.sdk.models.operations.GetServerIdentityRequestBuilder;
import dev.plexapi.sdk.models.operations.GetServerIdentityResponse;
import dev.plexapi.sdk.models.operations.GetServerIdentityResponseBody;
import dev.plexapi.sdk.models.operations.GetServerListRequestBuilder;
import dev.plexapi.sdk.models.operations.GetServerListResponse;
import dev.plexapi.sdk.models.operations.GetServerListResponseBody;
import dev.plexapi.sdk.models.operations.GetServerPreferencesRequestBuilder;
import dev.plexapi.sdk.models.operations.GetServerPreferencesResponse;
import dev.plexapi.sdk.models.operations.GetServerPreferencesResponseBody;
import dev.plexapi.sdk.models.operations.SDKMethodInterfaces.*;
import dev.plexapi.sdk.utils.BackoffStrategy;
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.Options;
import dev.plexapi.sdk.utils.Retries.NonRetryableException;
import dev.plexapi.sdk.utils.Retries;
import dev.plexapi.sdk.utils.RetryConfig;
import dev.plexapi.sdk.utils.Utils;
import java.io.InputStream;
import java.lang.Exception;
import java.lang.String;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.TimeUnit;
/**
* Operations against the Plex Media Server System.
*
*/
public class Server implements
MethodCallGetServerCapabilities,
MethodCallGetServerPreferences,
MethodCallGetAvailableClients,
MethodCallGetDevices,
MethodCallGetServerIdentity,
MethodCallGetMyPlexAccount,
MethodCallGetResizedPhoto,
MethodCallGetMediaProviders,
MethodCallGetServerList {
private final SDKConfiguration sdkConfiguration;
Server(SDKConfiguration sdkConfiguration) {
this.sdkConfiguration = sdkConfiguration;
}
/**
* Get Server Capabilities
* Get Server Capabilities
* @return The call builder
*/
public GetServerCapabilitiesRequestBuilder getServerCapabilities() {
return new GetServerCapabilitiesRequestBuilder(this);
}
/**
* Get Server Capabilities
* Get Server Capabilities
* @return The response from the API call
* @throws Exception if the API call fails
*/
public GetServerCapabilitiesResponse getServerCapabilitiesDirect() throws Exception {
return getServerCapabilities(Optional.empty());
}
/**
* Get Server Capabilities
* Get Server Capabilities
* @param options additional options
* @return The response from the API call
* @throws Exception if the API call fails
*/
public GetServerCapabilitiesResponse getServerCapabilities(
Optional<Options> options) throws Exception {
if (options.isPresent()) {
options.get().validate(Arrays.asList(Options.Option.RETRY_CONFIG));
}
String _baseUrl = Utils.templateUrl(
this.sdkConfiguration.serverUrl, this.sdkConfiguration.getServerVariableDefaults());
String _url = Utils.generateURL(
_baseUrl,
"/");
HTTPRequest _req = new HTTPRequest(_url, "GET");
_req.addHeader("Accept", "application/json")
.addHeader("user-agent",
SDKConfiguration.USER_AGENT);
Utils.configureSecurity(_req,
this.sdkConfiguration.securitySource.getSecurity());
HTTPClient _client = this.sdkConfiguration.defaultClient;
HTTPRequest _finalReq = _req;
RetryConfig _retryConfig;
if (options.isPresent() && options.get().retryConfig().isPresent()) {
_retryConfig = options.get().retryConfig().get();
} else if (this.sdkConfiguration.retryConfig.isPresent()) {
_retryConfig = this.sdkConfiguration.retryConfig.get();
} else {
_retryConfig = RetryConfig.builder()
.backoff(BackoffStrategy.builder()
.initialInterval(500, TimeUnit.MILLISECONDS)
.maxInterval(60000, TimeUnit.MILLISECONDS)
.baseFactor((double)(1.5))
.maxElapsedTime(3600000, TimeUnit.MILLISECONDS)
.retryConnectError(true)
.build())
.build();
}
List<String> _statusCodes = new ArrayList<>();
_statusCodes.add("5XX");
Retries _retries = Retries.builder()
.action(() -> {
HttpRequest _r = null;
try {
_r = sdkConfiguration.hooks()
.beforeRequest(
new BeforeRequestContextImpl(
"getServerCapabilities",
Optional.of(List.of()),
sdkConfiguration.securitySource()),
_finalReq.build());
} catch (Exception _e) {
throw new NonRetryableException(_e);
}
try {
return _client.send(_r);
} catch (Exception _e) {
return sdkConfiguration.hooks()
.afterError(
new AfterErrorContextImpl(
"getServerCapabilities",
Optional.of(List.of()),
sdkConfiguration.securitySource()),
Optional.empty(),
Optional.of(_e));
}
})
.retryConfig(_retryConfig)
.statusCodes(_statusCodes)
.build();
HttpResponse<InputStream> _httpRes = sdkConfiguration.hooks()
.afterSuccess(
new AfterSuccessContextImpl(
"getServerCapabilities",
Optional.of(List.of()),
sdkConfiguration.securitySource()),
_retries.run());
String _contentType = _httpRes
.headers()
.firstValue("Content-Type")
.orElse("application/octet-stream");
GetServerCapabilitiesResponse.Builder _resBuilder =
GetServerCapabilitiesResponse
.builder()
.contentType(_contentType)
.statusCode(_httpRes.statusCode())
.rawResponse(_httpRes);
GetServerCapabilitiesResponse _res = _resBuilder.build();
if (Utils.statusCodeMatches(_httpRes.statusCode(), "200")) {
if (Utils.contentTypeMatches(_contentType, "application/json")) {
GetServerCapabilitiesResponseBody _out = Utils.mapper().readValue(
Utils.toUtf8AndClose(_httpRes.body()),
new TypeReference<GetServerCapabilitiesResponseBody>() {});
_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")) {
GetServerCapabilitiesBadRequest _out = Utils.mapper().readValue(
Utils.toUtf8AndClose(_httpRes.body()),
new TypeReference<GetServerCapabilitiesBadRequest>() {});
_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")) {
GetServerCapabilitiesUnauthorized _out = Utils.mapper().readValue(
Utils.toUtf8AndClose(_httpRes.body()),
new TypeReference<GetServerCapabilitiesUnauthorized>() {});
_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", "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 Server Preferences
* Get Server Preferences
* @return The call builder
*/
public GetServerPreferencesRequestBuilder getServerPreferences() {
return new GetServerPreferencesRequestBuilder(this);
}
/**
* Get Server Preferences
* Get Server Preferences
* @return The response from the API call
* @throws Exception if the API call fails
*/
public GetServerPreferencesResponse getServerPreferencesDirect() throws Exception {
return getServerPreferences(Optional.empty());
}
/**
* Get Server Preferences
* Get Server Preferences
* @param options additional options
* @return The response from the API call
* @throws Exception if the API call fails
*/
public GetServerPreferencesResponse getServerPreferences(
Optional<Options> options) throws Exception {
if (options.isPresent()) {
options.get().validate(Arrays.asList(Options.Option.RETRY_CONFIG));
}
String _baseUrl = Utils.templateUrl(
this.sdkConfiguration.serverUrl, this.sdkConfiguration.getServerVariableDefaults());
String _url = Utils.generateURL(
_baseUrl,
"/:/prefs");
HTTPRequest _req = new HTTPRequest(_url, "GET");
_req.addHeader("Accept", "application/json")
.addHeader("user-agent",
SDKConfiguration.USER_AGENT);
Utils.configureSecurity(_req,
this.sdkConfiguration.securitySource.getSecurity());
HTTPClient _client = this.sdkConfiguration.defaultClient;
HTTPRequest _finalReq = _req;
RetryConfig _retryConfig;
if (options.isPresent() && options.get().retryConfig().isPresent()) {
_retryConfig = options.get().retryConfig().get();
} else if (this.sdkConfiguration.retryConfig.isPresent()) {
_retryConfig = this.sdkConfiguration.retryConfig.get();
} else {
_retryConfig = RetryConfig.builder()
.backoff(BackoffStrategy.builder()
.initialInterval(500, TimeUnit.MILLISECONDS)
.maxInterval(60000, TimeUnit.MILLISECONDS)
.baseFactor((double)(1.5))
.maxElapsedTime(3600000, TimeUnit.MILLISECONDS)
.retryConnectError(true)
.build())
.build();
}
List<String> _statusCodes = new ArrayList<>();
_statusCodes.add("5XX");
Retries _retries = Retries.builder()
.action(() -> {
HttpRequest _r = null;
try {
_r = sdkConfiguration.hooks()
.beforeRequest(
new BeforeRequestContextImpl(
"getServerPreferences",
Optional.of(List.of()),
sdkConfiguration.securitySource()),
_finalReq.build());
} catch (Exception _e) {
throw new NonRetryableException(_e);
}
try {
return _client.send(_r);
} catch (Exception _e) {
return sdkConfiguration.hooks()
.afterError(
new AfterErrorContextImpl(
"getServerPreferences",
Optional.of(List.of()),
sdkConfiguration.securitySource()),
Optional.empty(),
Optional.of(_e));
}
})
.retryConfig(_retryConfig)
.statusCodes(_statusCodes)
.build();
HttpResponse<InputStream> _httpRes = sdkConfiguration.hooks()
.afterSuccess(
new AfterSuccessContextImpl(
"getServerPreferences",
Optional.of(List.of()),
sdkConfiguration.securitySource()),
_retries.run());
String _contentType = _httpRes
.headers()
.firstValue("Content-Type")
.orElse("application/octet-stream");
GetServerPreferencesResponse.Builder _resBuilder =
GetServerPreferencesResponse
.builder()
.contentType(_contentType)
.statusCode(_httpRes.statusCode())
.rawResponse(_httpRes);
GetServerPreferencesResponse _res = _resBuilder.build();
if (Utils.statusCodeMatches(_httpRes.statusCode(), "200")) {
if (Utils.contentTypeMatches(_contentType, "application/json")) {
GetServerPreferencesResponseBody _out = Utils.mapper().readValue(
Utils.toUtf8AndClose(_httpRes.body()),
new TypeReference<GetServerPreferencesResponseBody>() {});
_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")) {
GetServerPreferencesBadRequest _out = Utils.mapper().readValue(
Utils.toUtf8AndClose(_httpRes.body()),
new TypeReference<GetServerPreferencesBadRequest>() {});
_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")) {
GetServerPreferencesUnauthorized _out = Utils.mapper().readValue(
Utils.toUtf8AndClose(_httpRes.body()),
new TypeReference<GetServerPreferencesUnauthorized>() {});
_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", "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 Available Clients
* Get Available Clients
* @return The call builder
*/
public GetAvailableClientsRequestBuilder getAvailableClients() {
return new GetAvailableClientsRequestBuilder(this);
}
/**
* Get Available Clients
* Get Available Clients
* @return The response from the API call
* @throws Exception if the API call fails
*/
public GetAvailableClientsResponse getAvailableClientsDirect() throws Exception {
return getAvailableClients(Optional.empty());
}
/**
* Get Available Clients
* Get Available Clients
* @param options additional options
* @return The response from the API call
* @throws Exception if the API call fails
*/
public GetAvailableClientsResponse getAvailableClients(
Optional<Options> options) throws Exception {
if (options.isPresent()) {
options.get().validate(Arrays.asList(Options.Option.RETRY_CONFIG));
}
String _baseUrl = Utils.templateUrl(
this.sdkConfiguration.serverUrl, this.sdkConfiguration.getServerVariableDefaults());
String _url = Utils.generateURL(
_baseUrl,
"/clients");
HTTPRequest _req = new HTTPRequest(_url, "GET");
_req.addHeader("Accept", "application/json")
.addHeader("user-agent",
SDKConfiguration.USER_AGENT);
Utils.configureSecurity(_req,
this.sdkConfiguration.securitySource.getSecurity());
HTTPClient _client = this.sdkConfiguration.defaultClient;
HTTPRequest _finalReq = _req;
RetryConfig _retryConfig;
if (options.isPresent() && options.get().retryConfig().isPresent()) {
_retryConfig = options.get().retryConfig().get();
} else if (this.sdkConfiguration.retryConfig.isPresent()) {
_retryConfig = this.sdkConfiguration.retryConfig.get();
} else {
_retryConfig = RetryConfig.builder()
.backoff(BackoffStrategy.builder()
.initialInterval(500, TimeUnit.MILLISECONDS)
.maxInterval(60000, TimeUnit.MILLISECONDS)
.baseFactor((double)(1.5))
.maxElapsedTime(3600000, TimeUnit.MILLISECONDS)
.retryConnectError(true)
.build())
.build();
}
List<String> _statusCodes = new ArrayList<>();
_statusCodes.add("5XX");
Retries _retries = Retries.builder()
.action(() -> {
HttpRequest _r = null;
try {
_r = sdkConfiguration.hooks()
.beforeRequest(
new BeforeRequestContextImpl(
"getAvailableClients",
Optional.of(List.of()),
sdkConfiguration.securitySource()),
_finalReq.build());
} catch (Exception _e) {
throw new NonRetryableException(_e);
}
try {
return _client.send(_r);
} catch (Exception _e) {
return sdkConfiguration.hooks()
.afterError(
new AfterErrorContextImpl(
"getAvailableClients",
Optional.of(List.of()),
sdkConfiguration.securitySource()),
Optional.empty(),
Optional.of(_e));
}
})
.retryConfig(_retryConfig)
.statusCodes(_statusCodes)
.build();
HttpResponse<InputStream> _httpRes = sdkConfiguration.hooks()
.afterSuccess(
new AfterSuccessContextImpl(
"getAvailableClients",
Optional.of(List.of()),
sdkConfiguration.securitySource()),
_retries.run());
String _contentType = _httpRes
.headers()
.firstValue("Content-Type")
.orElse("application/octet-stream");
GetAvailableClientsResponse.Builder _resBuilder =
GetAvailableClientsResponse
.builder()
.contentType(_contentType)
.statusCode(_httpRes.statusCode())
.rawResponse(_httpRes);
GetAvailableClientsResponse _res = _resBuilder.build();
if (Utils.statusCodeMatches(_httpRes.statusCode(), "200")) {
if (Utils.contentTypeMatches(_contentType, "application/json")) {
GetAvailableClientsResponseBody _out = Utils.mapper().readValue(
Utils.toUtf8AndClose(_httpRes.body()),
new TypeReference<GetAvailableClientsResponseBody>() {});
_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")) {
GetAvailableClientsBadRequest _out = Utils.mapper().readValue(
Utils.toUtf8AndClose(_httpRes.body()),
new TypeReference<GetAvailableClientsBadRequest>() {});
_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")) {
GetAvailableClientsUnauthorized _out = Utils.mapper().readValue(
Utils.toUtf8AndClose(_httpRes.body()),
new TypeReference<GetAvailableClientsUnauthorized>() {});
_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", "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 Devices
* Get Devices
* @return The call builder
*/
public GetDevicesRequestBuilder getDevices() {
return new GetDevicesRequestBuilder(this);
}
/**
* Get Devices
* Get Devices
* @return The response from the API call
* @throws Exception if the API call fails
*/
public GetDevicesResponse getDevicesDirect() throws Exception {
return getDevices(Optional.empty());
}
/**
* Get Devices
* Get Devices
* @param options additional options
* @return The response from the API call
* @throws Exception if the API call fails
*/
public GetDevicesResponse getDevices(
Optional<Options> options) throws Exception {
if (options.isPresent()) {
options.get().validate(Arrays.asList(Options.Option.RETRY_CONFIG));
}
String _baseUrl = Utils.templateUrl(
this.sdkConfiguration.serverUrl, this.sdkConfiguration.getServerVariableDefaults());
String _url = Utils.generateURL(
_baseUrl,
"/devices");
HTTPRequest _req = new HTTPRequest(_url, "GET");
_req.addHeader("Accept", "application/json")
.addHeader("user-agent",
SDKConfiguration.USER_AGENT);
Utils.configureSecurity(_req,
this.sdkConfiguration.securitySource.getSecurity());
HTTPClient _client = this.sdkConfiguration.defaultClient;
HTTPRequest _finalReq = _req;
RetryConfig _retryConfig;
if (options.isPresent() && options.get().retryConfig().isPresent()) {
_retryConfig = options.get().retryConfig().get();
} else if (this.sdkConfiguration.retryConfig.isPresent()) {
_retryConfig = this.sdkConfiguration.retryConfig.get();
} else {
_retryConfig = RetryConfig.builder()
.backoff(BackoffStrategy.builder()
.initialInterval(500, TimeUnit.MILLISECONDS)
.maxInterval(60000, TimeUnit.MILLISECONDS)
.baseFactor((double)(1.5))
.maxElapsedTime(3600000, TimeUnit.MILLISECONDS)
.retryConnectError(true)
.build())
.build();
}
List<String> _statusCodes = new ArrayList<>();
_statusCodes.add("5XX");
Retries _retries = Retries.builder()
.action(() -> {
HttpRequest _r = null;
try {
_r = sdkConfiguration.hooks()
.beforeRequest(
new BeforeRequestContextImpl(
"getDevices",
Optional.of(List.of()),
sdkConfiguration.securitySource()),
_finalReq.build());
} catch (Exception _e) {
throw new NonRetryableException(_e);
}
try {
return _client.send(_r);
} catch (Exception _e) {
return sdkConfiguration.hooks()
.afterError(
new AfterErrorContextImpl(
"getDevices",
Optional.of(List.of()),
sdkConfiguration.securitySource()),
Optional.empty(),
Optional.of(_e));
}
})
.retryConfig(_retryConfig)
.statusCodes(_statusCodes)
.build();
HttpResponse<InputStream> _httpRes = sdkConfiguration.hooks()
.afterSuccess(
new AfterSuccessContextImpl(
"getDevices",
Optional.of(List.of()),
sdkConfiguration.securitySource()),
_retries.run());
String _contentType = _httpRes
.headers()
.firstValue("Content-Type")
.orElse("application/octet-stream");
GetDevicesResponse.Builder _resBuilder =
GetDevicesResponse
.builder()
.contentType(_contentType)
.statusCode(_httpRes.statusCode())
.rawResponse(_httpRes);
GetDevicesResponse _res = _resBuilder.build();
if (Utils.statusCodeMatches(_httpRes.statusCode(), "200")) {
if (Utils.contentTypeMatches(_contentType, "application/json")) {
GetDevicesResponseBody _out = Utils.mapper().readValue(
Utils.toUtf8AndClose(_httpRes.body()),
new TypeReference<GetDevicesResponseBody>() {});
_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")) {
GetDevicesBadRequest _out = Utils.mapper().readValue(
Utils.toUtf8AndClose(_httpRes.body()),
new TypeReference<GetDevicesBadRequest>() {});
_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")) {
GetDevicesUnauthorized _out = Utils.mapper().readValue(
Utils.toUtf8AndClose(_httpRes.body()),
new TypeReference<GetDevicesUnauthorized>() {});
_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", "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 Server Identity
* This request is useful to determine if the server is online or offline
* @return The call builder
*/
public GetServerIdentityRequestBuilder getServerIdentity() {
return new GetServerIdentityRequestBuilder(this);
}
/**
* Get Server Identity
* This request is useful to determine if the server is online or offline
* @return The response from the API call
* @throws Exception if the API call fails
*/
public GetServerIdentityResponse getServerIdentityDirect() throws Exception {
return getServerIdentity(Optional.empty());
}
/**
* Get Server Identity
* This request is useful to determine if the server is online or offline
* @param options additional options
* @return The response from the API call
* @throws Exception if the API call fails
*/
public GetServerIdentityResponse getServerIdentity(
Optional<Options> options) throws Exception {
if (options.isPresent()) {
options.get().validate(Arrays.asList(Options.Option.RETRY_CONFIG));
}
String _baseUrl = Utils.templateUrl(
this.sdkConfiguration.serverUrl, this.sdkConfiguration.getServerVariableDefaults());
String _url = Utils.generateURL(
_baseUrl,
"/identity");
HTTPRequest _req = new HTTPRequest(_url, "GET");
_req.addHeader("Accept", "application/json")
.addHeader("user-agent",
SDKConfiguration.USER_AGENT);
HTTPClient _client = this.sdkConfiguration.defaultClient;
HTTPRequest _finalReq = _req;
RetryConfig _retryConfig;
if (options.isPresent() && options.get().retryConfig().isPresent()) {
_retryConfig = options.get().retryConfig().get();
} else if (this.sdkConfiguration.retryConfig.isPresent()) {
_retryConfig = this.sdkConfiguration.retryConfig.get();
} else {
_retryConfig = RetryConfig.builder()
.backoff(BackoffStrategy.builder()
.initialInterval(500, TimeUnit.MILLISECONDS)
.maxInterval(60000, TimeUnit.MILLISECONDS)
.baseFactor((double)(1.5))
.maxElapsedTime(3600000, TimeUnit.MILLISECONDS)
.retryConnectError(true)
.build())
.build();
}
List<String> _statusCodes = new ArrayList<>();
_statusCodes.add("5XX");
Retries _retries = Retries.builder()
.action(() -> {
HttpRequest _r = null;
try {
_r = sdkConfiguration.hooks()
.beforeRequest(
new BeforeRequestContextImpl(
"get-server-identity",
Optional.of(List.of()),
sdkConfiguration.securitySource()),
_finalReq.build());
} catch (Exception _e) {
throw new NonRetryableException(_e);
}
try {
return _client.send(_r);
} catch (Exception _e) {
return sdkConfiguration.hooks()
.afterError(
new AfterErrorContextImpl(
"get-server-identity",
Optional.of(List.of()),
sdkConfiguration.securitySource()),
Optional.empty(),
Optional.of(_e));
}
})
.retryConfig(_retryConfig)
.statusCodes(_statusCodes)
.build();
HttpResponse<InputStream> _httpRes = sdkConfiguration.hooks()
.afterSuccess(
new AfterSuccessContextImpl(
"get-server-identity",
Optional.of(List.of()),
sdkConfiguration.securitySource()),
_retries.run());
String _contentType = _httpRes
.headers()
.firstValue("Content-Type")
.orElse("application/octet-stream");
GetServerIdentityResponse.Builder _resBuilder =
GetServerIdentityResponse
.builder()
.contentType(_contentType)
.statusCode(_httpRes.statusCode())
.rawResponse(_httpRes);
GetServerIdentityResponse _res = _resBuilder.build();
if (Utils.statusCodeMatches(_httpRes.statusCode(), "200")) {
if (Utils.contentTypeMatches(_contentType, "application/json")) {
GetServerIdentityResponseBody _out = Utils.mapper().readValue(
Utils.toUtf8AndClose(_httpRes.body()),
new TypeReference<GetServerIdentityResponseBody>() {});
_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(), "408")) {
if (Utils.contentTypeMatches(_contentType, "application/json")) {
GetServerIdentityRequestTimeout _out = Utils.mapper().readValue(
Utils.toUtf8AndClose(_httpRes.body()),
new TypeReference<GetServerIdentityRequestTimeout>() {});
_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", "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 MyPlex Account
* Returns MyPlex Account Information
* @return The call builder
*/
public GetMyPlexAccountRequestBuilder getMyPlexAccount() {
return new GetMyPlexAccountRequestBuilder(this);
}
/**
* Get MyPlex Account
* Returns MyPlex Account Information
* @return The response from the API call
* @throws Exception if the API call fails
*/
public GetMyPlexAccountResponse getMyPlexAccountDirect() throws Exception {
return getMyPlexAccount(Optional.empty());
}
/**
* Get MyPlex Account
* Returns MyPlex Account Information
* @param options additional options
* @return The response from the API call
* @throws Exception if the API call fails
*/
public GetMyPlexAccountResponse getMyPlexAccount(
Optional<Options> options) throws Exception {
if (options.isPresent()) {
options.get().validate(Arrays.asList(Options.Option.RETRY_CONFIG));
}
String _baseUrl = Utils.templateUrl(
this.sdkConfiguration.serverUrl, this.sdkConfiguration.getServerVariableDefaults());
String _url = Utils.generateURL(
_baseUrl,
"/myplex/account");
HTTPRequest _req = new HTTPRequest(_url, "GET");
_req.addHeader("Accept", "application/json")
.addHeader("user-agent",
SDKConfiguration.USER_AGENT);
Utils.configureSecurity(_req,
this.sdkConfiguration.securitySource.getSecurity());
HTTPClient _client = this.sdkConfiguration.defaultClient;
HTTPRequest _finalReq = _req;
RetryConfig _retryConfig;
if (options.isPresent() && options.get().retryConfig().isPresent()) {
_retryConfig = options.get().retryConfig().get();
} else if (this.sdkConfiguration.retryConfig.isPresent()) {
_retryConfig = this.sdkConfiguration.retryConfig.get();
} else {
_retryConfig = RetryConfig.builder()
.backoff(BackoffStrategy.builder()
.initialInterval(500, TimeUnit.MILLISECONDS)
.maxInterval(60000, TimeUnit.MILLISECONDS)
.baseFactor((double)(1.5))
.maxElapsedTime(3600000, TimeUnit.MILLISECONDS)
.retryConnectError(true)
.build())
.build();
}
List<String> _statusCodes = new ArrayList<>();
_statusCodes.add("5XX");
Retries _retries = Retries.builder()
.action(() -> {
HttpRequest _r = null;
try {
_r = sdkConfiguration.hooks()
.beforeRequest(
new BeforeRequestContextImpl(
"getMyPlexAccount",
Optional.of(List.of()),
sdkConfiguration.securitySource()),
_finalReq.build());
} catch (Exception _e) {
throw new NonRetryableException(_e);
}
try {
return _client.send(_r);
} catch (Exception _e) {
return sdkConfiguration.hooks()
.afterError(
new AfterErrorContextImpl(
"getMyPlexAccount",
Optional.of(List.of()),
sdkConfiguration.securitySource()),
Optional.empty(),
Optional.of(_e));
}
})
.retryConfig(_retryConfig)
.statusCodes(_statusCodes)
.build();
HttpResponse<InputStream> _httpRes = sdkConfiguration.hooks()
.afterSuccess(
new AfterSuccessContextImpl(
"getMyPlexAccount",
Optional.of(List.of()),
sdkConfiguration.securitySource()),
_retries.run());
String _contentType = _httpRes
.headers()
.firstValue("Content-Type")
.orElse("application/octet-stream");
GetMyPlexAccountResponse.Builder _resBuilder =
GetMyPlexAccountResponse
.builder()
.contentType(_contentType)
.statusCode(_httpRes.statusCode())
.rawResponse(_httpRes);
GetMyPlexAccountResponse _res = _resBuilder.build();
if (Utils.statusCodeMatches(_httpRes.statusCode(), "200")) {
if (Utils.contentTypeMatches(_contentType, "application/json")) {
GetMyPlexAccountResponseBody _out = Utils.mapper().readValue(
Utils.toUtf8AndClose(_httpRes.body()),
new TypeReference<GetMyPlexAccountResponseBody>() {});
_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")) {
GetMyPlexAccountBadRequest _out = Utils.mapper().readValue(
Utils.toUtf8AndClose(_httpRes.body()),
new TypeReference<GetMyPlexAccountBadRequest>() {});
_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")) {
GetMyPlexAccountUnauthorized _out = Utils.mapper().readValue(
Utils.toUtf8AndClose(_httpRes.body()),
new TypeReference<GetMyPlexAccountUnauthorized>() {});
_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", "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 a Resized Photo
* Plex's Photo transcoder is used throughout the service to serve images at specified sizes.
*
* @return The call builder
*/
public GetResizedPhotoRequestBuilder getResizedPhoto() {
return new GetResizedPhotoRequestBuilder(this);
}
/**
* Get a Resized Photo
* Plex's Photo transcoder is used throughout the service to serve images at specified sizes.
*
* @param request The request object containing all of the parameters for the API call.
* @return The response from the API call
* @throws Exception if the API call fails
*/
public GetResizedPhotoResponse getResizedPhoto(
GetResizedPhotoRequest request) throws Exception {
return getResizedPhoto(request, Optional.empty());
}
/**
* Get a Resized Photo
* Plex's Photo transcoder is used throughout the service to serve images at specified sizes.
*
* @param request The request object containing all of the parameters for the API call.
* @param options additional options
* @return The response from the API call
* @throws Exception if the API call fails
*/
public GetResizedPhotoResponse getResizedPhoto(
GetResizedPhotoRequest request,
Optional<Options> options) throws Exception {
if (options.isPresent()) {
options.get().validate(Arrays.asList(Options.Option.RETRY_CONFIG));
}
String _baseUrl = Utils.templateUrl(
this.sdkConfiguration.serverUrl, this.sdkConfiguration.getServerVariableDefaults());
String _url = Utils.generateURL(
_baseUrl,
"/photo/:/transcode");
HTTPRequest _req = new HTTPRequest(_url, "GET");
_req.addHeader("Accept", "application/json")
.addHeader("user-agent",
SDKConfiguration.USER_AGENT);
_req.addQueryParams(Utils.getQueryParams(
GetResizedPhotoRequest.class,
request,
this.sdkConfiguration.globals));
Utils.configureSecurity(_req,
this.sdkConfiguration.securitySource.getSecurity());
HTTPClient _client = this.sdkConfiguration.defaultClient;
HTTPRequest _finalReq = _req;
RetryConfig _retryConfig;
if (options.isPresent() && options.get().retryConfig().isPresent()) {
_retryConfig = options.get().retryConfig().get();
} else if (this.sdkConfiguration.retryConfig.isPresent()) {
_retryConfig = this.sdkConfiguration.retryConfig.get();
} else {
_retryConfig = RetryConfig.builder()
.backoff(BackoffStrategy.builder()
.initialInterval(500, TimeUnit.MILLISECONDS)
.maxInterval(60000, TimeUnit.MILLISECONDS)
.baseFactor((double)(1.5))
.maxElapsedTime(3600000, TimeUnit.MILLISECONDS)
.retryConnectError(true)
.build())
.build();
}
List<String> _statusCodes = new ArrayList<>();
_statusCodes.add("5XX");
Retries _retries = Retries.builder()
.action(() -> {
HttpRequest _r = null;
try {
_r = sdkConfiguration.hooks()
.beforeRequest(
new BeforeRequestContextImpl(
"getResizedPhoto",
Optional.of(List.of()),
sdkConfiguration.securitySource()),
_finalReq.build());
} catch (Exception _e) {
throw new NonRetryableException(_e);
}
try {
return _client.send(_r);
} catch (Exception _e) {
return sdkConfiguration.hooks()
.afterError(
new AfterErrorContextImpl(
"getResizedPhoto",
Optional.of(List.of()),
sdkConfiguration.securitySource()),
Optional.empty(),
Optional.of(_e));
}
})
.retryConfig(_retryConfig)
.statusCodes(_statusCodes)
.build();
HttpResponse<InputStream> _httpRes = sdkConfiguration.hooks()
.afterSuccess(
new AfterSuccessContextImpl(
"getResizedPhoto",
Optional.of(List.of()),
sdkConfiguration.securitySource()),
_retries.run());
String _contentType = _httpRes
.headers()
.firstValue("Content-Type")
.orElse("application/octet-stream");
GetResizedPhotoResponse.Builder _resBuilder =
GetResizedPhotoResponse
.builder()
.contentType(_contentType)
.statusCode(_httpRes.statusCode())
.rawResponse(_httpRes);
GetResizedPhotoResponse _res = _resBuilder.build();
if (Utils.statusCodeMatches(_httpRes.statusCode(), "200")) {
// no content
return _res;
}
if (Utils.statusCodeMatches(_httpRes.statusCode(), "400")) {
if (Utils.contentTypeMatches(_contentType, "application/json")) {
GetResizedPhotoBadRequest _out = Utils.mapper().readValue(
Utils.toUtf8AndClose(_httpRes.body()),
new TypeReference<GetResizedPhotoBadRequest>() {});
_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")) {
GetResizedPhotoUnauthorized _out = Utils.mapper().readValue(
Utils.toUtf8AndClose(_httpRes.body()),
new TypeReference<GetResizedPhotoUnauthorized>() {});
_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", "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 Media Providers
* Retrieves media providers and their features from the Plex server.
* @return The call builder
*/
public GetMediaProvidersRequestBuilder getMediaProviders() {
return new GetMediaProvidersRequestBuilder(this);
}
/**
* Get Media Providers
* Retrieves media providers and their features from the Plex server.
* @param xPlexToken An authentication token, obtained from plex.tv
* @return The response from the API call
* @throws Exception if the API call fails
*/
public GetMediaProvidersResponse getMediaProviders(
String xPlexToken) throws Exception {
return getMediaProviders(xPlexToken, Optional.empty());
}
/**
* Get Media Providers
* Retrieves media providers and their features from the Plex server.
* @param xPlexToken An authentication token, obtained from plex.tv
* @param options additional options
* @return The response from the API call
* @throws Exception if the API call fails
*/
public GetMediaProvidersResponse getMediaProviders(
String xPlexToken,
Optional<Options> options) throws Exception {
if (options.isPresent()) {
options.get().validate(Arrays.asList(Options.Option.RETRY_CONFIG));
}
GetMediaProvidersRequest request =
GetMediaProvidersRequest
.builder()
.xPlexToken(xPlexToken)
.build();
String _baseUrl = Utils.templateUrl(
this.sdkConfiguration.serverUrl, this.sdkConfiguration.getServerVariableDefaults());
String _url = Utils.generateURL(
_baseUrl,
"/media/providers");
HTTPRequest _req = new HTTPRequest(_url, "GET");
_req.addHeader("Accept", "application/json")
.addHeader("user-agent",
SDKConfiguration.USER_AGENT);
_req.addHeaders(Utils.getHeadersFromMetadata(request, this.sdkConfiguration.globals));
Utils.configureSecurity(_req,
this.sdkConfiguration.securitySource.getSecurity());
HTTPClient _client = this.sdkConfiguration.defaultClient;
HTTPRequest _finalReq = _req;
RetryConfig _retryConfig;
if (options.isPresent() && options.get().retryConfig().isPresent()) {
_retryConfig = options.get().retryConfig().get();
} else if (this.sdkConfiguration.retryConfig.isPresent()) {
_retryConfig = this.sdkConfiguration.retryConfig.get();
} else {
_retryConfig = RetryConfig.builder()
.backoff(BackoffStrategy.builder()
.initialInterval(500, TimeUnit.MILLISECONDS)
.maxInterval(60000, TimeUnit.MILLISECONDS)
.baseFactor((double)(1.5))
.maxElapsedTime(3600000, TimeUnit.MILLISECONDS)
.retryConnectError(true)
.build())
.build();
}
List<String> _statusCodes = new ArrayList<>();
_statusCodes.add("5XX");
Retries _retries = Retries.builder()
.action(() -> {
HttpRequest _r = null;
try {
_r = sdkConfiguration.hooks()
.beforeRequest(
new BeforeRequestContextImpl(
"get-media-providers",
Optional.of(List.of()),
sdkConfiguration.securitySource()),
_finalReq.build());
} catch (Exception _e) {
throw new NonRetryableException(_e);
}
try {
return _client.send(_r);
} catch (Exception _e) {
return sdkConfiguration.hooks()
.afterError(
new AfterErrorContextImpl(
"get-media-providers",
Optional.of(List.of()),
sdkConfiguration.securitySource()),
Optional.empty(),
Optional.of(_e));
}
})
.retryConfig(_retryConfig)
.statusCodes(_statusCodes)
.build();
HttpResponse<InputStream> _httpRes = sdkConfiguration.hooks()
.afterSuccess(
new AfterSuccessContextImpl(
"get-media-providers",
Optional.of(List.of()),
sdkConfiguration.securitySource()),
_retries.run());
String _contentType = _httpRes
.headers()
.firstValue("Content-Type")
.orElse("application/octet-stream");
GetMediaProvidersResponse.Builder _resBuilder =
GetMediaProvidersResponse
.builder()
.contentType(_contentType)
.statusCode(_httpRes.statusCode())
.rawResponse(_httpRes);
GetMediaProvidersResponse _res = _resBuilder.build();
if (Utils.statusCodeMatches(_httpRes.statusCode(), "200")) {
if (Utils.contentTypeMatches(_contentType, "application/json")) {
GetMediaProvidersResponseBody _out = Utils.mapper().readValue(
Utils.toUtf8AndClose(_httpRes.body()),
new TypeReference<GetMediaProvidersResponseBody>() {});
_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")) {
GetMediaProvidersBadRequest _out = Utils.mapper().readValue(
Utils.toUtf8AndClose(_httpRes.body()),
new TypeReference<GetMediaProvidersBadRequest>() {});
_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")) {
GetMediaProvidersUnauthorized _out = Utils.mapper().readValue(
Utils.toUtf8AndClose(_httpRes.body()),
new TypeReference<GetMediaProvidersUnauthorized>() {});
_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", "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 Server List
* Get Server List
* @return The call builder
*/
public GetServerListRequestBuilder getServerList() {
return new GetServerListRequestBuilder(this);
}
/**
* Get Server List
* Get Server List
* @return The response from the API call
* @throws Exception if the API call fails
*/
public GetServerListResponse getServerListDirect() throws Exception {
return getServerList(Optional.empty());
}
/**
* Get Server List
* Get Server List
* @param options additional options
* @return The response from the API call
* @throws Exception if the API call fails
*/
public GetServerListResponse getServerList(
Optional<Options> options) throws Exception {
if (options.isPresent()) {
options.get().validate(Arrays.asList(Options.Option.RETRY_CONFIG));
}
String _baseUrl = Utils.templateUrl(
this.sdkConfiguration.serverUrl, this.sdkConfiguration.getServerVariableDefaults());
String _url = Utils.generateURL(
_baseUrl,
"/servers");
HTTPRequest _req = new HTTPRequest(_url, "GET");
_req.addHeader("Accept", "application/json")
.addHeader("user-agent",
SDKConfiguration.USER_AGENT);
Utils.configureSecurity(_req,
this.sdkConfiguration.securitySource.getSecurity());
HTTPClient _client = this.sdkConfiguration.defaultClient;
HTTPRequest _finalReq = _req;
RetryConfig _retryConfig;
if (options.isPresent() && options.get().retryConfig().isPresent()) {
_retryConfig = options.get().retryConfig().get();
} else if (this.sdkConfiguration.retryConfig.isPresent()) {
_retryConfig = this.sdkConfiguration.retryConfig.get();
} else {
_retryConfig = RetryConfig.builder()
.backoff(BackoffStrategy.builder()
.initialInterval(500, TimeUnit.MILLISECONDS)
.maxInterval(60000, TimeUnit.MILLISECONDS)
.baseFactor((double)(1.5))
.maxElapsedTime(3600000, TimeUnit.MILLISECONDS)
.retryConnectError(true)
.build())
.build();
}
List<String> _statusCodes = new ArrayList<>();
_statusCodes.add("5XX");
Retries _retries = Retries.builder()
.action(() -> {
HttpRequest _r = null;
try {
_r = sdkConfiguration.hooks()
.beforeRequest(
new BeforeRequestContextImpl(
"getServerList",
Optional.of(List.of()),
sdkConfiguration.securitySource()),
_finalReq.build());
} catch (Exception _e) {
throw new NonRetryableException(_e);
}
try {
return _client.send(_r);
} catch (Exception _e) {
return sdkConfiguration.hooks()
.afterError(
new AfterErrorContextImpl(
"getServerList",
Optional.of(List.of()),
sdkConfiguration.securitySource()),
Optional.empty(),
Optional.of(_e));
}
})
.retryConfig(_retryConfig)
.statusCodes(_statusCodes)
.build();
HttpResponse<InputStream> _httpRes = sdkConfiguration.hooks()
.afterSuccess(
new AfterSuccessContextImpl(
"getServerList",
Optional.of(List.of()),
sdkConfiguration.securitySource()),
_retries.run());
String _contentType = _httpRes
.headers()
.firstValue("Content-Type")
.orElse("application/octet-stream");
GetServerListResponse.Builder _resBuilder =
GetServerListResponse
.builder()
.contentType(_contentType)
.statusCode(_httpRes.statusCode())
.rawResponse(_httpRes);
GetServerListResponse _res = _resBuilder.build();
if (Utils.statusCodeMatches(_httpRes.statusCode(), "200")) {
if (Utils.contentTypeMatches(_contentType, "application/json")) {
GetServerListResponseBody _out = Utils.mapper().readValue(
Utils.toUtf8AndClose(_httpRes.body()),
new TypeReference<GetServerListResponseBody>() {});
_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")) {
GetServerListBadRequest _out = Utils.mapper().readValue(
Utils.toUtf8AndClose(_httpRes.body()),
new TypeReference<GetServerListBadRequest>() {});
_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")) {
GetServerListUnauthorized _out = Utils.mapper().readValue(
Utils.toUtf8AndClose(_httpRes.body()),
new TypeReference<GetServerListUnauthorized>() {});
_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", "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));
}
}