Skip to content

Commit

Permalink
feat: add push provider (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
peterdeme authored Mar 29, 2022
1 parent 0df895d commit 6a655fc
Show file tree
Hide file tree
Showing 2 changed files with 187 additions and 0 deletions.
171 changes: 171 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 @@ -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;
Expand Down Expand Up @@ -511,6 +512,28 @@ protected Call<App> generateCall(Client client) {
}
}

public static class ListPushProvidersRequest extends StreamRequest<ListPushProviderResponse> {
@Override
protected Call<ListPushProviderResponse> generateCall(Client client) {
return client.create(AppService.class).listPushProviders();
}
}

public static class DeletePushProviderRequest extends StreamRequest<StreamResponseObject> {
private String providerType;
private String name;

public DeletePushProviderRequest(@NotNull String providerType, @NotNull String name) {
this.providerType = providerType;
this.name = name;
}

@Override
protected Call<StreamResponseObject> generateCall(Client client) {
return client.create(AppService.class).deletePushProvider(this.providerType, this.name);
}
}

@Builder(
builderClassName = "AppUpdateRequest",
builderMethodName = "",
Expand Down Expand Up @@ -799,6 +822,103 @@ protected Call<StreamResponseObject> 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<UpsertPushProviderResponse> {
@Override
protected Call<UpsertPushProviderResponse> generateCall(Client client) {
return client.create(AppService.class).upsertPushProvider(this.internalBuild());
}
}
}

@Data
@NoArgsConstructor
public static class AppGetRateLimitsResponse implements StreamResponse {
Expand Down Expand Up @@ -878,6 +998,24 @@ public static class AppCheckPushResponse extends StreamResponseObject {
private Map<String, String> 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<PushProvider> pushProviders;
}

/**
* Creates a get request.
*
Expand Down Expand Up @@ -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.
*
Expand Down
16 changes: 16 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 @@ -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 {
Expand All @@ -39,4 +44,15 @@ Call<AppGetRateLimitsResponse> getRateLimits(

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

@POST("push_providers")
Call<UpsertPushProviderResponse> upsertPushProvider(
@NotNull @Body PushProviderRequestData pushProviderRequestData);

@GET("push_providers")
Call<ListPushProviderResponse> listPushProviders();

@DELETE("push_providers/{type}/{name}")
Call<StreamResponseObject> deletePushProvider(
@NotNull @Path("type") String providerType, @NotNull @Path("name") String name);
}

0 comments on commit 6a655fc

Please sign in to comment.