aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/juick/www/api
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2023-11-11 02:09:21 +0300
committerGravatar Vitaly Takmazov2023-11-11 02:09:47 +0300
commit20d999336b65fc0b68b1f77096c209877ac77245 (patch)
treeed114b1c5245b1d63344082eca6c8ad5f976d2aa /src/main/java/com/juick/www/api
parent6abbbe10f4b753bbc32e9760adc70ab1818beefa (diff)
Do not use outdated Patreon library, use Rest API directly
Diffstat (limited to 'src/main/java/com/juick/www/api')
-rw-r--r--src/main/java/com/juick/www/api/webhooks/PatreonWebhook.java28
1 files changed, 9 insertions, 19 deletions
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<User> userResponse = patreonClient.fetchUser();
- User creator = userResponse.get();
- logger.info("Patreon user: {}", jsonMapper.writeValueAsString(creator));
- var campainsResponse = patreonClient.fetchCampaigns();
+ var campainsResponse = patreonService.fetchCampaigns();
List<String> 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);