Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(helix): add content classification and branded content management (
#811)
- Loading branch information
Showing
8 changed files
with
268 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
rest-helix/src/main/java/com/github/twitch4j/helix/domain/ContentClassificationInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.github.twitch4j.helix.domain; | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnore; | ||
import com.github.twitch4j.eventsub.domain.ContentClassification; | ||
import lombok.AccessLevel; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
|
||
@Data | ||
@Setter(AccessLevel.PRIVATE) | ||
@NoArgsConstructor | ||
public class ContentClassificationInfo { | ||
|
||
/** | ||
* Unique identifier for the CCL. | ||
*/ | ||
private String id; | ||
|
||
/** | ||
* Localized description of the CCL. | ||
*/ | ||
private String description; | ||
|
||
/** | ||
* Localized name of the CCL. | ||
*/ | ||
private String name; | ||
|
||
/** | ||
* @return {@link #getId()} parsed as {@link ContentClassification}. | ||
*/ | ||
@JsonIgnore | ||
public ContentClassification getLabel() { | ||
return ContentClassification.parse(id); | ||
} | ||
|
||
} |
25 changes: 25 additions & 0 deletions
25
rest-helix/src/main/java/com/github/twitch4j/helix/domain/ContentClassificationList.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.github.twitch4j.helix.domain; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import lombok.AccessLevel; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* Information about the available content classification labels. | ||
*/ | ||
@Data | ||
@Setter(AccessLevel.PRIVATE) | ||
@NoArgsConstructor | ||
public class ContentClassificationList { | ||
|
||
/** | ||
* The list of CCLs available. | ||
*/ | ||
@JsonProperty("data") | ||
private List<ContentClassificationInfo> labels; | ||
|
||
} |
32 changes: 32 additions & 0 deletions
32
rest-helix/src/main/java/com/github/twitch4j/helix/domain/ContentClassificationState.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.github.twitch4j.helix.domain; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.github.twitch4j.eventsub.domain.ContentClassification; | ||
import lombok.AccessLevel; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
import lombok.With; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
@Data | ||
@With | ||
@Setter(AccessLevel.PRIVATE) | ||
@NoArgsConstructor(access = AccessLevel.PRIVATE) | ||
@AllArgsConstructor | ||
public class ContentClassificationState { | ||
|
||
/** | ||
* ID of the Content Classification Labels that must be added/removed from the channel. | ||
*/ | ||
@NotNull | ||
private ContentClassification id; | ||
|
||
/** | ||
* Whether the label should be enabled (true) or disabled for the channel. | ||
*/ | ||
@JsonProperty("is_enabled") | ||
private boolean isEnabled; | ||
|
||
} |
36 changes: 36 additions & 0 deletions
36
.../java/com/github/twitch4j/helix/interceptor/ContentClassificationStateListSerializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.github.twitch4j.helix.interceptor; | ||
|
||
import com.fasterxml.jackson.core.JsonGenerator; | ||
import com.fasterxml.jackson.databind.JsonSerializer; | ||
import com.fasterxml.jackson.databind.SerializerProvider; | ||
import com.github.twitch4j.eventsub.domain.ContentClassification; | ||
import com.github.twitch4j.helix.domain.ChannelInformation; | ||
import com.github.twitch4j.helix.domain.ContentClassificationState; | ||
import org.jetbrains.annotations.ApiStatus; | ||
|
||
import java.io.IOException; | ||
import java.util.Collection; | ||
|
||
/** | ||
* Serializes {@code Collection<ContentClassificationState>} within {@link com.github.twitch4j.helix.domain.ChannelInformation} | ||
* for {@link com.github.twitch4j.helix.TwitchHelix#updateChannelInformation(String, String, ChannelInformation)} | ||
* where {@link ContentClassification#MATURE_GAME} is not included in {@link ChannelInformation#getContentClassificationLabels()} | ||
* since this label is controlled by the game category (rather than the user). | ||
*/ | ||
@ApiStatus.Internal | ||
public class ContentClassificationStateListSerializer extends JsonSerializer<Collection<ContentClassificationState>> { | ||
@Override | ||
public void serialize(Collection<ContentClassificationState> value, JsonGenerator gen, SerializerProvider serializers) throws IOException { | ||
if (value != null) { | ||
gen.writeStartArray(); | ||
for (ContentClassificationState ccl : value) { | ||
if (ccl == null) continue; | ||
if (ccl.getId() == ContentClassification.MATURE_GAME) continue; | ||
gen.writeObject(ccl); | ||
} | ||
gen.writeEndArray(); | ||
} else { | ||
gen.writeNull(); | ||
} | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
rest-helix/src/test/java/com/github/twitch4j/helix/domain/ChannelInformationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package com.github.twitch4j.helix.domain; | ||
|
||
import com.github.twitch4j.common.util.TypeConvert; | ||
import com.github.twitch4j.eventsub.domain.ContentClassification; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.Arrays; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
class ChannelInformationTest { | ||
|
||
@Test | ||
void deserializeLabels() { | ||
String json = "{\"content_classification_labels\":[\"Gambling\",\"DrugsIntoxication\",\"MatureGame\"],\"is_branded_content\":true}"; | ||
ChannelInformation info = TypeConvert.jsonToObject(json, ChannelInformation.class); | ||
assertNotNull(info); | ||
assertEquals( | ||
Arrays.asList( | ||
new ContentClassificationState(ContentClassification.GAMBLING, true), | ||
new ContentClassificationState(ContentClassification.DRUGS, true), | ||
new ContentClassificationState(ContentClassification.MATURE_GAME, true) | ||
), | ||
info.getContentClassificationLabels() | ||
); | ||
assertTrue(info.isBrandedContent()); | ||
} | ||
|
||
@Test | ||
void serializeLabels() { | ||
ChannelInformation info = ChannelInformation.builder() | ||
.contentClassificationLabel(new ContentClassificationState(ContentClassification.PROFANITY, true)) | ||
.contentClassificationLabel(new ContentClassificationState(ContentClassification.SEXUAL, false)) | ||
.build(); | ||
String expected = "{\"content_classification_labels\":[{\"id\":\"ProfanityVulgarity\",\"is_enabled\":true},{\"id\":\"SexualThemes\",\"is_enabled\":false}]}"; | ||
assertEquals(expected, TypeConvert.objectToJson(info)); | ||
} | ||
|
||
@Test | ||
void serializeWithoutMature() { | ||
ChannelInformation info = ChannelInformation.builder() | ||
.contentClassificationLabel(new ContentClassificationState(ContentClassification.MATURE_GAME, true)) | ||
.build(); | ||
String expected = "{\"content_classification_labels\":[]}"; | ||
assertEquals(expected, TypeConvert.objectToJson(info)); | ||
} | ||
|
||
} |