From bfac399eb0cb23c35ee810709e337f1f1305af04 Mon Sep 17 00:00:00 2001 From: Lennart <1247198+totalimmersion@users.noreply.github.com> Date: Wed, 18 Oct 2023 20:20:10 +0200 Subject: [PATCH] feat: sns support (#122) * feat: sns support --- DOCS.md | 15 ++++ .../io/getstream/chat/java/models/App.java | 89 +++++++++++++++++++ .../chat/java/services/AppService.java | 5 ++ .../java/io/getstream/chat/java/AppTest.java | 21 ++++- 4 files changed, 128 insertions(+), 2 deletions(-) diff --git a/DOCS.md b/DOCS.md index 2f9e6a28..7622bfbd 100644 --- a/DOCS.md +++ b/DOCS.md @@ -1538,6 +1538,21 @@ App.update() App.checkSqs().request(); ``` +**Check SNS** + + +```java +// set your SNS topic details +App.update() + .snsKey("yourkey") + .snsKey("yoursecret") + .snsTopicArn("arn:aws:sns:us-east-1:123456789012:my-topic") + .request(); + +// send a test message +App.checkSns().request(); +``` + **Create device** ```java diff --git a/src/main/java/io/getstream/chat/java/models/App.java b/src/main/java/io/getstream/chat/java/models/App.java index ea7aa90a..d360a47e 100644 --- a/src/main/java/io/getstream/chat/java/models/App.java +++ b/src/main/java/io/getstream/chat/java/models/App.java @@ -10,6 +10,7 @@ import com.fasterxml.jackson.databind.JsonDeserializer; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import io.getstream.chat.java.models.App.AppCheckPushRequestData.AppCheckPushRequest; +import io.getstream.chat.java.models.App.AppCheckSnsRequestData.AppCheckSnsRequest; import io.getstream.chat.java.models.App.AppCheckSqsRequestData.AppCheckSqsRequest; import io.getstream.chat.java.models.App.AppUpdateRequestData.AppUpdateRequest; import io.getstream.chat.java.models.App.PushProviderRequestData.PushProviderRequest; @@ -278,6 +279,18 @@ public static class AppConfig { @JsonProperty("sqs_secret") private String sqsSecret; + @Nullable + @JsonProperty("sns_topic_arn") + private String snsTopicArn; + + @Nullable + @JsonProperty("sns_key") + private String snsKey; + + @Nullable + @JsonProperty("sns_secret") + private String snsSecret; + @Nullable @JsonProperty("file_upload_config") private FileUploadConfig fileUploadConfig; @@ -709,6 +722,21 @@ public static class AppUpdateRequestData { @JsonInclude(Include.NON_NULL) private String sqsSecret; + @Nullable + @JsonProperty("sns_topic_arn") + @JsonInclude(Include.NON_NULL) + private String snsTopicArn; + + @Nullable + @JsonProperty("sns_key") + @JsonInclude(Include.NON_NULL) + private String snsKey; + + @Nullable + @JsonProperty("sns_secret") + @JsonInclude(Include.NON_NULL) + private String snsSecret; + @Nullable @JsonProperty("webhook_url") @JsonInclude(Include.NON_NULL) @@ -835,6 +863,31 @@ protected Call generateCall(Client client) { } } + @Builder( + builderClassName = "AppCheckSnsRequest", + builderMethodName = "", + buildMethodName = "internalBuild") + public static class AppCheckSnsRequestData { + @Nullable + @JsonProperty("sns_topic_arn") + private String snsTopicArn; + + @Nullable + @JsonProperty("sns_key") + private String snsKey; + + @Nullable + @JsonProperty("sns_secret") + private String snsSecret; + + public static class AppCheckSnsRequest extends StreamRequest { + @Override + protected Call generateCall(Client client) { + return client.create(AppService.class).checkSns(this.internalBuild()); + } + } + } + @Builder( builderClassName = "AppCheckPushRequest", builderMethodName = "", @@ -1034,6 +1087,32 @@ public enum Status { } } + @Data + @NoArgsConstructor + @EqualsAndHashCode(callSuper = true) + public static class AppCheckSnsResponse extends StreamResponseObject { + @NotNull + @JsonProperty("status") + private Status status; + + @Nullable + @JsonProperty("error") + private String error; + + @Nullable + @JsonProperty("data") + private Map data; + + public enum Status { + @JsonProperty("ok") + OK, + @JsonProperty("error") + ERROR, + @JsonEnumDefaultValue + UNKNOWN + } + } + @Data @NoArgsConstructor @EqualsAndHashCode(callSuper = true) @@ -1121,6 +1200,16 @@ public static AppCheckSqsRequest checkSqs() { return new AppCheckSqsRequest(); } + /** + * Creates a check SNS request. + * + * @return the created request + */ + @NotNull + public static AppCheckSnsRequest checkSns() { + return new AppCheckSnsRequest(); + } + /** * Creates a check push request. * diff --git a/src/main/java/io/getstream/chat/java/services/AppService.java b/src/main/java/io/getstream/chat/java/services/AppService.java index 26c25396..6d08fe77 100644 --- a/src/main/java/io/getstream/chat/java/services/AppService.java +++ b/src/main/java/io/getstream/chat/java/services/AppService.java @@ -3,6 +3,8 @@ import io.getstream.chat.java.models.App; import io.getstream.chat.java.models.App.AppCheckPushRequestData; import io.getstream.chat.java.models.App.AppCheckPushResponse; +import io.getstream.chat.java.models.App.AppCheckSnsRequestData; +import io.getstream.chat.java.models.App.AppCheckSnsResponse; import io.getstream.chat.java.models.App.AppCheckSqsRequestData; import io.getstream.chat.java.models.App.AppCheckSqsResponse; import io.getstream.chat.java.models.App.AppGetRateLimitsResponse; @@ -42,6 +44,9 @@ Call getRateLimits( @POST("check_sqs") Call checkSqs(@NotNull @Body AppCheckSqsRequestData appCheckSqsRequestData); + @POST("check_sns") + Call checkSns(@NotNull @Body AppCheckSnsRequestData appCheckSnsRequestData); + @POST("check_push") Call checkPush(@NotNull @Body AppCheckPushRequestData internalBuild); diff --git a/src/test/java/io/getstream/chat/java/AppTest.java b/src/test/java/io/getstream/chat/java/AppTest.java index e95c841d..07161ae5 100644 --- a/src/test/java/io/getstream/chat/java/AppTest.java +++ b/src/test/java/io/getstream/chat/java/AppTest.java @@ -2,8 +2,8 @@ import io.getstream.chat.java.exceptions.StreamException; import io.getstream.chat.java.models.App; +import io.getstream.chat.java.models.App.AppCheckSnsResponse; import io.getstream.chat.java.models.App.AppCheckSqsResponse; -import io.getstream.chat.java.models.App.AppCheckSqsResponse.Status; import io.getstream.chat.java.models.App.PushConfigRequestObject; import io.getstream.chat.java.models.App.PushVersion; import io.getstream.chat.java.models.Message; @@ -17,6 +17,9 @@ import org.junit.jupiter.api.Test; public class AppTest extends BasicTest { + private AppCheckSnsResponse.Status SnsStatus; + private AppCheckSqsResponse.Status SqsStatus; + @DisplayName("App Get does not throw Exception") @Test void whenCallingGetApp_thenNoException() { @@ -98,7 +101,21 @@ void whenCheckingBadSqs_thenError() { .sqsSecret("secret") .sqsUrl("https://foo.com/bar") .request()); - Assertions.assertEquals(Status.ERROR, response.getStatus()); + Assertions.assertEquals(SqsStatus.ERROR, response.getStatus()); + } + + @DisplayName("Can check sns") + @Test + void whenCheckingBadSns_thenError() { + AppCheckSnsResponse response = + Assertions.assertDoesNotThrow( + () -> + App.checkSns() + .snsKey("key") + .snsSecret("secret") + .snsTopicArn("arn:aws:sns:us-east-1:123456789012:sns-topic") + .request()); + Assertions.assertEquals(SnsStatus.ERROR, response.getStatus()); } @DisplayName("Can check push templates")