-
-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(pubsub): support unofficial ads manager topic (#847)
- Loading branch information
Showing
6 changed files
with
98 additions
and
0 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
25 changes: 25 additions & 0 deletions
25
pubsub/src/main/java/com/github/twitch4j/pubsub/domain/ScheduleUpdate.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.pubsub.domain; | ||
|
||
import com.fasterxml.jackson.databind.PropertyNamingStrategies; | ||
import com.fasterxml.jackson.databind.annotation.JsonNaming; | ||
import lombok.AccessLevel; | ||
import lombok.Data; | ||
import lombok.Setter; | ||
|
||
import java.util.List; | ||
|
||
@Data | ||
@Setter(AccessLevel.PRIVATE) | ||
@JsonNaming(PropertyNamingStrategies.LowerCamelCaseStrategy.class) | ||
public class ScheduleUpdate { | ||
private String scheduleUpdateType; | ||
private List<ScheduledAd> adSchedule; | ||
|
||
public boolean isSnooze() { | ||
return "Snooze".equalsIgnoreCase(scheduleUpdateType); | ||
} | ||
|
||
public boolean isRemoval() { | ||
return "RemoveAdTime".equalsIgnoreCase(scheduleUpdateType); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
pubsub/src/main/java/com/github/twitch4j/pubsub/domain/ScheduledAd.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,17 @@ | ||
package com.github.twitch4j.pubsub.domain; | ||
|
||
import com.fasterxml.jackson.databind.PropertyNamingStrategies; | ||
import com.fasterxml.jackson.databind.annotation.JsonNaming; | ||
import lombok.AccessLevel; | ||
import lombok.Data; | ||
import lombok.Setter; | ||
|
||
import java.time.Instant; | ||
|
||
@Data | ||
@Setter(AccessLevel.PRIVATE) | ||
@JsonNaming(PropertyNamingStrategies.LowerCamelCaseStrategy.class) | ||
public class ScheduledAd { | ||
private Instant runAtTime; | ||
private Long durationSeconds; | ||
} |
13 changes: 13 additions & 0 deletions
13
pubsub/src/main/java/com/github/twitch4j/pubsub/events/AdsScheduleUpdateEvent.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,13 @@ | ||
package com.github.twitch4j.pubsub.events; | ||
|
||
import com.github.twitch4j.common.events.TwitchEvent; | ||
import com.github.twitch4j.pubsub.domain.ScheduleUpdate; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.Value; | ||
|
||
@Value | ||
@EqualsAndHashCode(callSuper = false) | ||
public class AdsScheduleUpdateEvent extends TwitchEvent { | ||
String channelId; | ||
ScheduleUpdate data; | ||
} |
29 changes: 29 additions & 0 deletions
29
pubsub/src/test/java/com/github/twitch4j/pubsub/domain/ScheduleUpdateTest.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,29 @@ | ||
package com.github.twitch4j.pubsub.domain; | ||
|
||
import com.github.twitch4j.common.util.TypeConvert; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.time.Instant; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
class ScheduleUpdateTest { | ||
|
||
@Test | ||
void deserializeSnooze() { | ||
String json = "{\"type\":\"ads-schedule-update\",\"scheduleUpdateType\":\"Snooze\",\"adSchedule\":[{\"runAtTime\":\"2023-07-20T16:30:45Z\",\"durationSeconds\":60}]}"; | ||
ScheduleUpdate data = TypeConvert.jsonToObject(json, ScheduleUpdate.class); | ||
assertNotNull(data); | ||
assertTrue(data.isSnooze()); | ||
assertNotNull(data.getAdSchedule()); | ||
assertFalse(data.getAdSchedule().isEmpty()); | ||
ScheduledAd ad = data.getAdSchedule().get(0); | ||
assertNotNull(ad); | ||
assertEquals(60L, ad.getDurationSeconds()); | ||
assertEquals(Instant.parse("2023-07-20T16:30:45Z"), ad.getRunAtTime()); | ||
} | ||
|
||
} |