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

io.dangernoodle.slack.objects.api.SlackWebResponse Maven / Gradle / Ivy

The newest version!
package io.dangernoodle.slack.objects.api;

import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;


public class SlackWebResponse
{
    private final String rawResponse;
    private final Map response;

    public SlackWebResponse(Map response, String rawResponse)
    {
        this.response = response;
        this.rawResponse = rawResponse;
    }

    public String getError()
    {
        return get("error").orElse(null);
    }

    public String getRawResponse()
    {
        return rawResponse;
    }

    public Map getResponse()
    {
        // always a copy...
        return new HashMap<>(response);
    }

    public Collection getWarnings()
    {
        return get("warning").map(this::split).orElse(Collections.emptyList());
    }

    public boolean isOk()
    {
        return get("ok").map(Boolean::valueOf).orElse(false);
    }

    private Optional get(String key)
    {
        return response.containsKey(key) ? Optional.of(response.get(key).toString()) : Optional.empty();
    }

    private Collection split(Object toSplit)
    {
        return Arrays.asList(toSplit.toString().split(","));
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy