Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: sns support #122

Merged
merged 8 commits into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions DOCS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
89 changes: 89 additions & 0 deletions src/main/java/io/getstream/chat/java/models/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -835,6 +863,31 @@ protected Call<AppCheckSqsResponse> 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<AppCheckSnsResponse> {
@Override
protected Call<AppCheckSnsResponse> generateCall(Client client) {
return client.create(AppService.class).checkSns(this.internalBuild());
}
}
}

@Builder(
builderClassName = "AppCheckPushRequest",
builderMethodName = "",
Expand Down Expand Up @@ -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<String, Object> data;

public enum Status {
@JsonProperty("ok")
OK,
@JsonProperty("error")
ERROR,
@JsonEnumDefaultValue
UNKNOWN
}
}

@Data
@NoArgsConstructor
@EqualsAndHashCode(callSuper = true)
Expand Down Expand Up @@ -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.
*
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/io/getstream/chat/java/services/AppService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -42,6 +44,9 @@ Call<AppGetRateLimitsResponse> getRateLimits(
@POST("check_sqs")
Call<AppCheckSqsResponse> checkSqs(@NotNull @Body AppCheckSqsRequestData appCheckSqsRequestData);

@POST("check_sns")
Call<AppCheckSnsResponse> checkSns(@NotNull @Body AppCheckSnsRequestData appCheckSnsRequestData);

@POST("check_push")
Call<AppCheckPushResponse> checkPush(@NotNull @Body AppCheckPushRequestData internalBuild);

Expand Down
21 changes: 19 additions & 2 deletions src/test/java/io/getstream/chat/java/AppTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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() {
Expand Down Expand Up @@ -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")
Expand Down
Loading