org.whispersystems.signalservice.internal.websocket.ResponseMapper Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of signal-service-java Show documentation
Show all versions of signal-service-java Show documentation
Signal Service communication library for Java, unofficial fork
package org.whispersystems.signalservice.internal.websocket;
import org.whispersystems.signalservice.internal.ServiceResponse;
import java.util.function.Function;
/**
* Responsible for taking an API response and converting it to a {@link ServiceResponse}. This includes
* parsing for a success as well as any application errors. All errors (application or parsing related)
* are encapsulated in an error version of a {@link ServiceResponse}, hence why no method throws an
* exception.
*
* Unless you need to do something really special, you should only be extending this to be provided to
* {@link DefaultResponseMapper}.
*
* @param - The final type the API response will map into.
*/
public interface ResponseMapper {
ServiceResponse map(int status, String body, Function getHeader, boolean unidentified);
default ServiceResponse map(WebsocketResponse response) {
return map(response.getStatus(), response.getBody(), response::getHeader, response.isUnidentified());
}
}