From 20d999336b65fc0b68b1f77096c209877ac77245 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Sat, 11 Nov 2023 02:09:21 +0300 Subject: Do not use outdated Patreon library, use Rest API directly --- .../com/juick/www/api/webhooks/PatreonWebhook.java | 28 +++++++--------------- 1 file changed, 9 insertions(+), 19 deletions(-) (limited to 'src/main/java/com/juick/www/api') diff --git a/src/main/java/com/juick/www/api/webhooks/PatreonWebhook.java b/src/main/java/com/juick/www/api/webhooks/PatreonWebhook.java index 2bdeb020..99999838 100644 --- a/src/main/java/com/juick/www/api/webhooks/PatreonWebhook.java +++ b/src/main/java/com/juick/www/api/webhooks/PatreonWebhook.java @@ -18,11 +18,9 @@ package com.juick.www.api.webhooks; import com.fasterxml.jackson.databind.ObjectMapper; -import com.github.jasminb.jsonapi.JSONAPIDocument; +import com.juick.service.PatreonService; import com.juick.service.UserService; import com.juick.util.HttpForbiddenException; -import com.patreon.PatreonAPI; -import com.patreon.resources.User; import org.apache.commons.codec.digest.HmacUtils; import org.apache.commons.io.IOUtils; import org.slf4j.Logger; @@ -35,7 +33,6 @@ import org.springframework.web.bind.annotation.ResponseStatus; import org.springframework.web.bind.annotation.RestController; import javax.inject.Inject; -import java.io.IOException; import java.io.InputStream; import java.nio.charset.StandardCharsets; import java.util.ArrayList; @@ -48,7 +45,7 @@ public class PatreonWebhook { @Value("${patreon_secret:}") private String secretKey; @Inject - private PatreonAPI patreonClient; + private PatreonService patreonService; @Inject private ObjectMapper jsonMapper; @Inject @@ -70,21 +67,14 @@ public class PatreonWebhook { var updatedEmails = StreamSupport.stream(json.get("included").spliterator(), false) .filter(node -> node.get("type").textValue().equals("user")) .map(node -> node.get("attributes").get("email").textValue()).toList(); - JSONAPIDocument userResponse = patreonClient.fetchUser(); - User creator = userResponse.get(); - logger.info("Patreon user: {}", jsonMapper.writeValueAsString(creator)); - var campainsResponse = patreonClient.fetchCampaigns(); + var campainsResponse = patreonService.fetchCampaigns(); List activeEmails = new ArrayList<>(); - campainsResponse.get().forEach(campaign -> { - try { - var pledgesResponse = patreonClient.fetchAllPledges(campaign.getId()); - pledgesResponse.forEach(pledge -> { - logger.info("Pledge: {}, email: {}", pledge.getPatron().getFullName(), pledge.getPatron().getEmail()); - activeEmails.add(pledge.getPatron().getEmail()); - }); - } catch (IOException e) { - logger.warn("Patreon exception: {}", e.getMessage()); - } + campainsResponse.forEach(campaign -> { + var pledgesResponse = patreonService.fetchPledges(campaign); + pledgesResponse.forEach(pledge -> { + logger.info("Pledge email: {}", pledge); + activeEmails.add(pledge); + }); }); activeEmails.forEach(email -> { var user = userService.getUserByEmail(email); -- cgit v1.2.3