Java Code Examples for io.reactivex.rxjava3.core.Completable#fromObservable()

The following examples show how to use io.reactivex.rxjava3.core.Completable#fromObservable() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RestGuild.java    From catnip with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Nonnull
public Completable createGuildBan(@Nonnull final String guildId, @Nonnull final String userId,
                                  @Nullable final String reason,
                                  @Nonnegative final int deleteMessageDays) {
    if(deleteMessageDays > 7) {
        final CompletableFuture<Void> future = new CompletableFuture<>();
        future.completeExceptionally(new IllegalArgumentException("deleteMessageDays can't be above 7"));
        return Completable.fromFuture(future);
    }
    
    final QueryStringBuilder builder = new QueryStringBuilder();
    builder.append("reason", reason == null ? "" : reason);
    builder.append("delete-message-days", String.valueOf(deleteMessageDays));
    final String query = builder.build();
    return Completable.fromObservable(catnip().requester()
            .queue(new OutboundRequest(Routes.CREATE_GUILD_BAN.withMajorParam(guildId).withQueryString(query),
                    Map.of("user", userId)).reason(reason).emptyBody(true)));
}
 
Example 2
Source File: RestChannel.java    From catnip with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Nonnull
public Completable deleteUserReaction(@Nonnull final String channelId, @Nonnull final String messageId,
                                      @Nonnull final String userId, @Nonnull final String emoji) {
    return Completable.fromObservable(catnip().requester()
            .queue(new OutboundRequest(Routes.DELETE_USER_REACTION.withMajorParam(channelId),
                    Map.of("message", messageId, "emojis", encodeUTF8(emoji), "user", userId))
                    .emptyBody(true)));
}
 
Example 3
Source File: RestGuild.java    From catnip with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Nonnull
public Completable removeGuildMemberRole(@Nonnull final String guildId, @Nonnull final String userId,
                                         @Nonnull final String roleId, @Nullable final String reason) {
    return Completable.fromObservable(catnip().requester()
            .queue(new OutboundRequest(Routes.REMOVE_GUILD_MEMBER_ROLE.withMajorParam(guildId),
                    Map.of("user", userId, "role", roleId)).reason(reason).emptyBody(true)));
}
 
Example 4
Source File: RestGuild.java    From catnip with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Nonnull
public Completable removeGuildBan(@Nonnull final String guildId, @Nonnull final String userId,
                                  @Nullable final String reason) {
    return Completable.fromObservable(catnip().requester()
            .queue(new OutboundRequest(Routes.REMOVE_GUILD_BAN.withMajorParam(guildId),
                    Map.of("user", userId)).reason(reason).emptyBody(true)));
}
 
Example 5
Source File: RestGuild.java    From catnip with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Nonnull
@CheckReturnValue
public Completable deleteGuildRole(@Nonnull final String guildId, @Nonnull final String roleId,
                                   @Nullable final String reason) {
    return Completable.fromObservable(catnip().requester()
            .queue(new OutboundRequest(Routes.DELETE_GUILD_ROLE.withMajorParam(guildId),
                    Map.of("role", roleId)).reason(reason).emptyBody(true)));
}
 
Example 6
Source File: RestGuild.java    From catnip with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Nonnull
@CheckReturnValue
public Completable modifyGuildRolePositions(@Nonnull final PositionUpdater updater,
                                            @Nullable final String reason) {
    final JsonArray array = new JsonArray();
    updater.entries()
            .stream()
            .map(x -> JsonObject.builder().value("id", x.getKey()).value("position", x.getValue()).done())
            .forEach(array::add);
    return Completable.fromObservable(catnip().requester()
            .queue(new OutboundRequest(Routes.MODIFY_GUILD_ROLE_POSITIONS.withMajorParam(updater.guildId()),
                    Map.of(), array, reason)));
}
 
Example 7
Source File: RestGuild.java    From catnip with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Nonnull
@CheckReturnValue
public Completable modifyGuildChannelPositions(@Nonnull final PositionUpdater updater,
                                               @Nullable final String reason) {
    final JsonArray array = new JsonArray();
    updater.entries()
            .stream()
            .map(x -> JsonObject.builder().value("id", x.getKey()).value("position", x.getValue()).done())
            .forEach(array::add);
    return Completable.fromObservable(catnip().requester()
            .queue(new OutboundRequest(Routes.MODIFY_GUILD_CHANNEL_POSITIONS.withMajorParam(updater.guildId()),
                    Map.of(), array, reason)));
}
 
Example 8
Source File: RestGuild.java    From catnip with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Nonnull
@CheckReturnValue
public Completable modifyGuildMember(@Nonnull final String guildId, @Nonnull final String memberId,
                                     @Nonnull final MemberData data, @Nullable final String reason) {
    return Completable.fromObservable(catnip().requester()
            .queue(new OutboundRequest(Routes.MODIFY_GUILD_MEMBER.withMajorParam(guildId),
                    Map.of("user", memberId), data.toJson(), reason)));
}
 
Example 9
Source File: RestWebhook.java    From catnip with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Nonnull
@CheckReturnValue
public Completable deleteWebhook(@Nonnull final String webhookId, @Nullable final String reason) {
    return Completable.fromObservable(catnip().requester()
            .queue(new OutboundRequest(Routes.DELETE_WEBHOOK.withMajorParam(webhookId),
                    Map.of()).reason(reason).emptyBody(true)));
}
 
Example 10
Source File: RestEmoji.java    From catnip with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Nonnull
public Completable deleteGuildEmoji(@Nonnull final String guildId, @Nonnull final String emojiId,
                                    @Nullable final String reason) {
    return Completable.fromObservable(catnip().requester().queue(
            new OutboundRequest(
                    Routes.DELETE_GUILD_EMOJI.withMajorParam(guildId),
                    Map.of("emojis", emojiId)).reason(reason).emptyBody(true)));
}
 
Example 11
Source File: RestChannel.java    From catnip with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Nonnull
public Completable editPermissionOverride(@Nonnull final String channelId, @Nonnull final String overwriteId,
                                          @Nonnull final Collection<Permission> allowed,
                                          @Nonnull final Collection<Permission> denied,
                                          final boolean isMember, @Nullable final String reason) {
    return Completable.fromObservable(catnip().requester()
            .queue(new OutboundRequest(Routes.EDIT_CHANNEL_PERMISSIONS.withMajorParam(channelId),
                    Map.of("overwrite", overwriteId), JsonObject.builder()
                    .value("allow", Permission.from(allowed))
                    .value("deny", Permission.from(denied))
                    .value("type", isMember ? "member" : "role")
                    .done(),
                    reason
            )));
}
 
Example 12
Source File: RestChannel.java    From catnip with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Nonnull
public Completable deletePermissionOverride(@Nonnull final String channelId,
                                            @Nonnull final String overwriteId, @Nullable final String reason) {
    return Completable.fromObservable(catnip().requester()
            .queue(new OutboundRequest(Routes.DELETE_CHANNEL_PERMISSION.withMajorParam(channelId),
                    Map.of("overwrite", overwriteId)).reason(reason).emptyBody(true)));
}
 
Example 13
Source File: RestChannel.java    From catnip with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Nonnull
public Completable deleteEmojiReaction(@Nonnull final String channelId, @Nonnull final String messageId,
                                     @Nonnull final String emoji) {
    return Completable.fromObservable(catnip().requester()
            .queue(new OutboundRequest(Routes.DELETE_EMOJI_REACTIONS.withMajorParam(channelId),
                    Map.of("message", messageId, "emojis", encodeUTF8(emoji))).emptyBody(true)));
}
 
Example 14
Source File: RestChannel.java    From catnip with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Nonnull
public Completable deleteOwnReaction(@Nonnull final String channelId, @Nonnull final String messageId,
                                     @Nonnull final String emoji) {
    return Completable.fromObservable(catnip().requester()
            .queue(new OutboundRequest(Routes.DELETE_OWN_REACTION.withMajorParam(channelId),
                    Map.of("message", messageId, "emojis", encodeUTF8(emoji))).emptyBody(true)));
}
 
Example 15
Source File: RestChannel.java    From catnip with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Nonnull
public Completable deletePinnedMessage(@Nonnull final String channelId, @Nonnull final String messageId, @Nullable final String reason) {
    return Completable.fromObservable(catnip().requester()
            .queue(new OutboundRequest(Routes.DELETE_PINNED_CHANNEL_MESSAGE.withMajorParam(channelId),
                    Map.of("message", messageId)).reason(reason).emptyBody(true)));
}
 
Example 16
Source File: RestUser.java    From catnip with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Nonnull
public Completable leaveGuild(@Nonnull final String guildId) {
    return Completable.fromObservable(catnip().requester()
            .queue(new OutboundRequest(Routes.LEAVE_GUILD,
                    Map.of("guild", guildId)).emptyBody(true)));
}
 
Example 17
Source File: RestGuild.java    From catnip with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Nonnull
public Completable deleteGuild(@Nonnull final String guildId) {
    return Completable.fromObservable(catnip().requester()
            .queue(new OutboundRequest(Routes.DELETE_GUILD.withMajorParam(guildId),
                    Map.of()).emptyBody(true)));
}
 
Example 18
Source File: RestChannel.java    From catnip with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Nonnull
public Completable deleteAllReactions(@Nonnull final String channelId, @Nonnull final String messageId) {
    return Completable.fromObservable(catnip().requester()
            .queue(new OutboundRequest(Routes.DELETE_ALL_REACTIONS.withMajorParam(channelId),
                    Map.of("message", messageId)).emptyBody(true)));
}
 
Example 19
Source File: UntilLifecycleTransformerCompletableTest.java    From RxLifecycle with Apache License 2.0 4 votes vote down vote up
@Before
public void setup() {
    subject = PublishSubject.create();
    completable = Completable.fromObservable(subject);
    lifecycle = PublishSubject.create();
}
 
Example 20
Source File: UntilCorrespondingEventTransformerCompletableTest.java    From RxLifecycle with Apache License 2.0 4 votes vote down vote up
@Before
public void setup() {
    subject =  PublishSubject.create();
    completable = Completable.fromObservable(subject);
    lifecycle = PublishSubject.create();
}