From 6a655fc939f184412cc65b8663bf8332b2461976 Mon Sep 17 00:00:00 2001 From: Peter Deme Date: Tue, 29 Mar 2022 12:04:52 +0200 Subject: [PATCH] feat: add push provider (#57) --- .../io/getstream/chat/java/models/App.java | 171 ++++++++++++++++++ .../chat/java/services/AppService.java | 16 ++ 2 files changed, 187 insertions(+) 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 78f77752..32f7aace 100644 --- a/src/main/java/io/getstream/chat/java/models/App.java +++ b/src/main/java/io/getstream/chat/java/models/App.java @@ -12,6 +12,7 @@ import io.getstream.chat.java.models.App.AppCheckPushRequestData.AppCheckPushRequest; 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; import io.getstream.chat.java.models.ChannelType.ChannelTypeWithStringCommands; import io.getstream.chat.java.models.User.UserRequestObject; import io.getstream.chat.java.models.framework.RequestObjectBuilder; @@ -511,6 +512,28 @@ protected Call generateCall(Client client) { } } + public static class ListPushProvidersRequest extends StreamRequest { + @Override + protected Call generateCall(Client client) { + return client.create(AppService.class).listPushProviders(); + } + } + + public static class DeletePushProviderRequest extends StreamRequest { + private String providerType; + private String name; + + public DeletePushProviderRequest(@NotNull String providerType, @NotNull String name) { + this.providerType = providerType; + this.name = name; + } + + @Override + protected Call generateCall(Client client) { + return client.create(AppService.class).deletePushProvider(this.providerType, this.name); + } + } + @Builder( builderClassName = "AppUpdateRequest", builderMethodName = "", @@ -799,6 +822,103 @@ protected Call generateCall(Client client) { } } + @Data + @NoArgsConstructor + public static class PushProvider { + @NotNull + @JsonProperty("name") + private String name; + + @NotNull + @JsonProperty("type") + private PushProviderType type; + + @Nullable + @JsonProperty("description") + private String description; + + @Nullable + @JsonProperty("disabled_at") + private Date disabledAt; + + @Nullable + @JsonProperty("disabled_reason") + private String disabledReason; + + @Nullable + @JsonProperty("apn_auth_key") + private String apnAuthKey; + + @Nullable + @JsonProperty("apn_key_id") + private String apnKeyId; + + @Nullable + @JsonProperty("apn_team_id") + private String apnTeamId; + + @Nullable + @JsonProperty("apn_topic") + private String apnTopic; + + @Nullable + @JsonProperty("firebase_credentials") + private String firebaseCredentials; + + @Nullable + @JsonProperty("huawei_app_id") + private String huaweiAppId; + + @Nullable + @JsonProperty("huawei_app_secret") + private String huaweiAppSecret; + + @Nullable + @JsonProperty("xiaomi_package_name") + private String xiaomiPackageName; + + @Nullable + @JsonProperty("xiaomi_app_secret") + private String xiaomiAppSecret; + + @Nullable + @JsonProperty("created_at") + private Date createdAt; + + @Nullable + @JsonProperty("updated_at") + private Date updatedAt; + + public enum PushProviderType { + @JsonProperty("firebase") + Firebase, + @JsonProperty("apn") + Apn, + @JsonProperty("xiaomi") + Xiaomi, + @JsonProperty("huawei") + Huawei, + @JsonEnumDefaultValue + UNKNOWN + } + } + + @Builder( + builderClassName = "PushProviderRequest", + builderMethodName = "", + buildMethodName = "internalBuild") + public static class PushProviderRequestData { + @JsonProperty("push_provider") + private PushProvider pushProvider; + + public static class PushProviderRequest extends StreamRequest { + @Override + protected Call generateCall(Client client) { + return client.create(AppService.class).upsertPushProvider(this.internalBuild()); + } + } + } + @Data @NoArgsConstructor public static class AppGetRateLimitsResponse implements StreamResponse { @@ -878,6 +998,24 @@ public static class AppCheckPushResponse extends StreamResponseObject { private Map renderedMessage; } + @Data + @NoArgsConstructor + @EqualsAndHashCode(callSuper = true) + public static class UpsertPushProviderResponse extends StreamResponseObject { + @NotNull + @JsonProperty("push_provider") + private PushProvider pushProvider; + } + + @Data + @NoArgsConstructor + @EqualsAndHashCode(callSuper = true) + public static class ListPushProviderResponse extends StreamResponseObject { + @NotNull + @JsonProperty("push_providers") + private List pushProviders; + } + /** * Creates a get request. * @@ -939,6 +1077,39 @@ public static AppRevokeTokensRequest revokeTokens(@Nullable Date revokeTokensIss return new AppRevokeTokensRequest(revokeTokensIssuedBefore); } + /** + * Creates an upsert push provider request + * + * @return the created request + */ + @NotNull + public static PushProviderRequest upsertPushProvider() { + return new PushProviderRequest(); + } + + /** + * Creates a list push providers request + * + * @return the created request + */ + @NotNull + public static ListPushProvidersRequest listPushProviders() { + return new ListPushProvidersRequest(); + } + + /** + * Creates a delete push provider request + * + * @param providerType push provider type + * @param name push provider name + * @return the created request + */ + @NotNull + public static DeletePushProviderRequest deletePushProvider( + @NotNull String providerType, @NotNull String name) { + return new DeletePushProviderRequest(providerType, name); + } + /** * Validates if hmac signature is correct for message body. * 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 6ed74324..26c25396 100644 --- a/src/main/java/io/getstream/chat/java/services/AppService.java +++ b/src/main/java/io/getstream/chat/java/services/AppService.java @@ -7,14 +7,19 @@ import io.getstream.chat.java.models.App.AppCheckSqsResponse; import io.getstream.chat.java.models.App.AppGetRateLimitsResponse; import io.getstream.chat.java.models.App.AppUpdateRequestData; +import io.getstream.chat.java.models.App.ListPushProviderResponse; +import io.getstream.chat.java.models.App.PushProviderRequestData; +import io.getstream.chat.java.models.App.UpsertPushProviderResponse; import io.getstream.chat.java.models.framework.StreamResponseObject; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import retrofit2.Call; import retrofit2.http.Body; +import retrofit2.http.DELETE; import retrofit2.http.GET; import retrofit2.http.PATCH; import retrofit2.http.POST; +import retrofit2.http.Path; import retrofit2.http.Query; public interface AppService { @@ -39,4 +44,15 @@ Call getRateLimits( @POST("check_push") Call checkPush(@NotNull @Body AppCheckPushRequestData internalBuild); + + @POST("push_providers") + Call upsertPushProvider( + @NotNull @Body PushProviderRequestData pushProviderRequestData); + + @GET("push_providers") + Call listPushProviders(); + + @DELETE("push_providers/{type}/{name}") + Call deletePushProvider( + @NotNull @Path("type") String providerType, @NotNull @Path("name") String name); }