package leigh.tansu.test;

import leigh.esp.sdk.ESPClient;
import leigh.esp.sdk.link23.Link23Response;
import leigh.mecha.lang.FutureResult;
import leigh.mecha.log.MechaLogger;
import leigh.mecha.log.MechaLoggerFactory;
import leigh.tansu.sdk.v1.TansuClient;
import org.apache.commons.io.IOUtils;

import java.io.FileInputStream;

public class TansuTest {
    private static final MechaLogger logger = MechaLoggerFactory.getLogger(TansuTest.class);

    public static void main(String args[]) throws Exception {
        String id = "/etc/passwd";

        TansuClient client = new TansuClient(new ESPClient("http://localhost:8123/"));
        logger.info("Sending request...");
        FutureResult<Link23Response> result = client.objectPut("test", id,
                new FileInputStream("/etc/passwd"), "text/plain");

        try (Link23Response putResult = (Link23Response) result.get()) {
            logger.info("Got result from API: {}", putResult.getResponse());
        }

        FutureResult<Link23Response> getFuture = client.objectGet("test", id);
        try (Link23Response getResult = (Link23Response) getFuture.get()) {
            logger.info("GET response: {} {}", getResult, IOUtils.toString(getResult.getInputStream()));
        }
    }
}
