From d656a82106ca23994bae89109c52da3bcd664755 Mon Sep 17 00:00:00 2001 From: Sidd Date: Tue, 28 Jun 2022 15:34:32 -0500 Subject: [PATCH] feat: add user_id and type args to getEventSubSubscriptions --- .../github/twitch4j/helix/TwitchHelix.java | 35 +++++++++++++++++-- .../EventSubSubscriptionNameExpander.java | 13 +++++++ .../helix/endpoints/WebhooksServiceTest.java | 2 ++ 3 files changed, 47 insertions(+), 3 deletions(-) create mode 100644 rest-helix/src/main/java/com/github/twitch4j/helix/interceptor/EventSubSubscriptionNameExpander.java diff --git a/rest-helix/src/main/java/com/github/twitch4j/helix/TwitchHelix.java b/rest-helix/src/main/java/com/github/twitch4j/helix/TwitchHelix.java index 335050132..f88b130c3 100644 --- a/rest-helix/src/main/java/com/github/twitch4j/helix/TwitchHelix.java +++ b/rest-helix/src/main/java/com/github/twitch4j/helix/TwitchHelix.java @@ -6,7 +6,9 @@ import com.github.twitch4j.eventsub.EventSubSubscription; import com.github.twitch4j.eventsub.EventSubSubscriptionStatus; import com.github.twitch4j.eventsub.domain.RedemptionStatus; +import com.github.twitch4j.eventsub.subscriptions.SubscriptionType; import com.github.twitch4j.helix.domain.*; +import com.github.twitch4j.helix.interceptor.EventSubSubscriptionNameExpander; import com.github.twitch4j.helix.webhooks.domain.WebhookRequest; import com.netflix.hystrix.HystrixCommand; import feign.*; @@ -562,22 +564,51 @@ HystrixCommand deleteEventSubSubscription( /** * Get a list of your EventSub subscriptions. + *

+ * The list is paginated and ordered by the oldest subscription first. + *

+ * Use the status, type, and user_id query parameters to filter the list of subscriptions that are returned. + * The filters are mutually exclusive; the request fails if you specify more than one filter. * * @param authToken Required: App Access Token. * @param status Optional: Include this parameter to filter subscriptions by their status. + * @param type Optional: Include this parameter to filter subscriptions by subscription type. + * @param userId Optional: Include this parameter to filter subscriptions by user ID in the condition object. * @param after Optional: Cursor for forward pagination. * @param limit Optional: Maximum number of objects to return. Maximum: 100. Minimum: 10. * @return EventSubSubscriptionList */ - @RequestLine("GET /eventsub/subscriptions?status={status}&after={after}&first={first}") + @RequestLine("GET /eventsub/subscriptions?status={status}&type={type}&user_id={user_id}&after={after}&first={first}") @Headers("Authorization: Bearer {token}") HystrixCommand getEventSubSubscriptions( @Param("token") String authToken, @Param("status") EventSubSubscriptionStatus status, + @Param(value = "type", expander = EventSubSubscriptionNameExpander.class) SubscriptionType type, + @Param("user_id") String userId, @Param("after") String after, @Param("first") Integer limit ); + /** + * Get a list of your EventSub subscriptions. + * + * @param authToken Required: App Access Token. + * @param status Optional: Include this parameter to filter subscriptions by their status. + * @param after Optional: Cursor for forward pagination. + * @param limit Optional: Maximum number of objects to return. Maximum: 100. Minimum: 10. + * @return EventSubSubscriptionList + * @deprecated in favor of {@link #getEventSubSubscriptions(String, EventSubSubscriptionStatus, SubscriptionType, String, String, Integer)} + */ + @Deprecated + default HystrixCommand getEventSubSubscriptions( + @Param("token") String authToken, + @Param("status") EventSubSubscriptionStatus status, + @Param("after") String after, + @Param("first") Integer limit + ) { + return getEventSubSubscriptions(authToken, status, null, null, after, limit); + } + /** * Gets information about your Extensions; either the current version or a specified version. * @@ -1637,7 +1668,6 @@ HystrixCommand endPrediction( * @return RaidRequestList * @see com.github.twitch4j.auth.domain.TwitchScopes#HELIX_CHANNEL_RAIDS_MANAGE */ - @Unofficial // currently in open beta @RequestLine("POST /raids?from_broadcaster_id={from_broadcaster_id}&to_broadcaster_id={to_broadcaster_id}") @Headers("Authorization: Bearer {token}") HystrixCommand startRaid( @@ -1655,7 +1685,6 @@ HystrixCommand startRaid( * @param broadcasterId The ID of the broadcaster that sent the raiding party. * @return 204 No Content upon a successful raid cancel call */ - @Unofficial // currently in open beta @RequestLine("DELETE /raids?broadcaster_id={broadcaster_id}") @Headers("Authorization: Bearer {token}") HystrixCommand cancelRaid( diff --git a/rest-helix/src/main/java/com/github/twitch4j/helix/interceptor/EventSubSubscriptionNameExpander.java b/rest-helix/src/main/java/com/github/twitch4j/helix/interceptor/EventSubSubscriptionNameExpander.java new file mode 100644 index 000000000..6a274c9fa --- /dev/null +++ b/rest-helix/src/main/java/com/github/twitch4j/helix/interceptor/EventSubSubscriptionNameExpander.java @@ -0,0 +1,13 @@ +package com.github.twitch4j.helix.interceptor; + +import com.github.twitch4j.eventsub.subscriptions.SubscriptionType; +import feign.Param; + +public class EventSubSubscriptionNameExpander implements Param.Expander { + @Override + public String expand(Object value) { + if (value instanceof SubscriptionType) + return ((SubscriptionType) value).getName(); + return null; + } +} diff --git a/rest-helix/src/test/java/com/github/twitch4j/helix/endpoints/WebhooksServiceTest.java b/rest-helix/src/test/java/com/github/twitch4j/helix/endpoints/WebhooksServiceTest.java index 3cc04738a..df92af30e 100644 --- a/rest-helix/src/test/java/com/github/twitch4j/helix/endpoints/WebhooksServiceTest.java +++ b/rest-helix/src/test/java/com/github/twitch4j/helix/endpoints/WebhooksServiceTest.java @@ -42,6 +42,8 @@ public void getStreams() { System.getenv("APP_ACCESS_TOKEN"), null, null, + null, + null, null ).execute(); assertTrue(subList.getTotal() > 0, "Sub list size was " + subList.getTotal());