com.github.twitch4j.extensions.compat.TwitchExtensionsCompatibilityLayer Maven / Gradle / Ivy
The newest version!
package com.github.twitch4j.extensions.compat;
import com.github.twitch4j.common.config.ProxyConfig;
import com.github.twitch4j.common.config.Twitch4JGlobal;
import com.github.twitch4j.extensions.TwitchExtensions;
import com.github.twitch4j.extensions.domain.ChannelList;
import com.github.twitch4j.extensions.domain.ConfigurationSegment;
import com.github.twitch4j.extensions.domain.ConfigurationSegmentType;
import com.github.twitch4j.extensions.domain.ExtensionConfigurationSegment;
import com.github.twitch4j.extensions.domain.ExtensionInformation;
import com.github.twitch4j.extensions.domain.ExtensionSecretList;
import com.github.twitch4j.helix.TwitchHelix;
import com.github.twitch4j.helix.TwitchHelixBuilder;
import com.github.twitch4j.helix.domain.ExtensionConfigurationSegmentInput;
import com.github.twitch4j.helix.domain.ExtensionSegment;
import com.github.twitch4j.helix.domain.SendPubSubMessageInput;
import com.netflix.hystrix.HystrixCommand;
import feign.Logger;
import lombok.Builder;
import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.ApiStatus;
import java.util.Arrays;
import java.util.Collections;
import java.util.Map;
import static com.github.twitch4j.extensions.compat.ExtensionsTypeConverters.*; // Must be wildcard import for static: https://github.com/projectlombok/lombok/issues/2044
/**
* Forwards twitch extensions api calls to the new helix api
*/
@SuppressWarnings("deprecation")
@Deprecated
@ApiStatus.ScheduledForRemoval(inVersion = "2.0.0")
public final class TwitchExtensionsCompatibilityLayer implements TwitchExtensions {
private final String clientId;
private final TwitchHelix helix;
@Builder
public TwitchExtensionsCompatibilityLayer(String clientId, String clientSecret, String userAgent, Long timeout, Integer requestQueueSize, Logger.Level logLevel, ProxyConfig proxyConfig) {
this.clientId = clientId;
this.helix = TwitchHelixBuilder.builder()
.withClientId(clientId)
.withClientSecret(clientSecret)
.withUserAgent(userAgent != null ? userAgent : Twitch4JGlobal.userAgent)
.withTimeout(timeout != null ? timeout.intValue() : 5000)
.withRequestQueueSize(requestQueueSize != null ? requestQueueSize : -1)
.withLogLevel(logLevel != null ? logLevel : Logger.Level.NONE)
.withProxyConfig(proxyConfig)
.build();
}
@Override
public HystrixCommand createExtensionSecret(String clientId, String jsonWebToken, int activationDelaySeconds) {
return new HystrixCommandConverter<>(
helix.createExtensionSecret(jsonWebToken, getClientId(clientId), activationDelaySeconds),
SECRETS_CONVERTER
);
}
@Override
public HystrixCommand getExtensionSecret(String clientId, String jsonWebToken) {
return new HystrixCommandConverter<>(
helix.getExtensionSecrets(jsonWebToken, getClientId(clientId)),
SECRETS_CONVERTER
);
}
@Override
public HystrixCommand revokeExtensionSecrets(String clientId, String jsonWebToken) {
throw new UnsupportedOperationException("There is no direct Helix replacement for this endpoint.");
}
@Override
public HystrixCommand getLiveChannelsWithExtensionActivated(String clientId, String cursor) {
return new HystrixCommandConverter<>(
helix.getExtensionLiveChannels(null, getClientId(clientId), 100, cursor),
LIVE_CHANNELS_CONVERTER
);
}
@Override
public HystrixCommand setExtensionRequiredConfiguration(String clientId, String jsonWebToken, String extensionVersion, String channelId, String requiredConfiguration) {
return helix.setExtensionRequiredConfiguration(
jsonWebToken,
getClientId(clientId),
extensionVersion,
requiredConfiguration,
channelId
);
}
@Override
public HystrixCommand setExtensionConfigurationSegment(String clientId, String jsonWebToken, ExtensionConfigurationSegment configurationSegment) {
final String extensionId = getClientId(clientId);
return helix.setExtensionConfigurationSegment(
jsonWebToken,
extensionId,
ExtensionConfigurationSegmentInput.builder()
.extensionId(extensionId)
.segment(SEGMENT_CONVERTER.apply(configurationSegment.getSegment()))
.broadcasterId(configurationSegment.getChannelId())
.content(configurationSegment.getContent())
.version(configurationSegment.getVersion())
.build()
);
}
@Override
public HystrixCommand
© 2015 - 2025 Weber Informatics LLC | Privacy Policy