All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.jamesnetherton.zulip.client.api.stream.request.DeleteTopicApiRequest Maven / Gradle / Ivy

The newest version!
package com.github.jamesnetherton.zulip.client.api.stream.request;

import static com.github.jamesnetherton.zulip.client.api.stream.request.StreamRequestConstants.TOPIC_DELETE;

import com.github.jamesnetherton.zulip.client.api.core.VoidExecutableApiRequest;
import com.github.jamesnetherton.zulip.client.api.core.ZulipApiRequest;
import com.github.jamesnetherton.zulip.client.api.stream.response.DeleteTopicApiResponse;
import com.github.jamesnetherton.zulip.client.exception.ZulipClientException;
import com.github.jamesnetherton.zulip.client.http.ZulipHttpClient;

/**
 * Zulip API request builder for deleting a topic.
 *
 * @see https://zulip.com/api/delete-topic
 */
public class DeleteTopicApiRequest extends ZulipApiRequest implements VoidExecutableApiRequest {

    public static final String TOPIC_NAME = "topic_name";
    private final String path;

    /**
     * Constructs a {@link DeleteTopicApiRequest}.
     *
     * @param client    The Zulip HTTP client
     * @param streamId  The id of the stream containing the topic to delete
     * @param topicName The name of the topic to delete
     */
    public DeleteTopicApiRequest(ZulipHttpClient client, long streamId, String topicName) {
        super(client);
        this.path = String.format(TOPIC_DELETE, streamId);
        putParam(TOPIC_NAME, topicName);
    }

    /**
     * Executes the Zulip API request for deleting a topic.
     *
     * @throws ZulipClientException if the request was not successful
     */
    @Override
    public void execute() throws ZulipClientException {
        DeleteTopicApiResponse response = null;
        while (response == null || response.isPartiallyCompleted()) {
            response = client().post(this.path, getParams(), DeleteTopicApiResponse.class);
        }
        while (!response.isComplete()) {
            response = client().post(this.path, getParams(), DeleteTopicApiResponse.class);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy