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

com.tradeshift.sdk.documentfiles.TradeshiftDocumentFilesClient Maven / Gradle / Ivy

The newest version!
/*
 * Copyright (c) 2017 Tradeshift Inc. and/or its affiliates. All rights reserved.
 */
package com.tradeshift.sdk.documentfiles;

import static org.asynchttpclient.util.HttpConstants.Methods.PUT;

import java.util.Objects;
import java.util.concurrent.CompletionStage;

import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType;

import org.asynchttpclient.RequestBuilder;

import com.tradeshift.sdk.core.TradeshiftClient;
import com.tradeshift.sdk.core.TradeshiftClientConfiguration;
import com.tradeshift.sdk.documentfiles.domain.CreateDirectory;
import com.tradeshift.sdk.documentfiles.domain.CreatedDirectory;

/**
 * Tradeshift DocumentFiles (object store / virtual file) Client.
 *
 * DocumentFiles is a object store modeled as a virtual filesystem that can store arbitrary types of data. Typically
 * this is used for files that are of non-UBL types to be converted / processed before dispatch.
 */
public final class TradeshiftDocumentFilesClient extends TradeshiftClient implements TradeshiftDocumentFiles {

    public TradeshiftDocumentFilesClient(TradeshiftClientConfiguration config) {
        super(config);
    }

    @Override
    public CompletionStage createDirectory(CreateDirectory cmd) {
        Objects.requireNonNull(cmd);
        final String url = String.format("%s/rest/external/documentfiles/directory", endpoint);
        return execute(authenticated(cmd, new RequestBuilder(PUT)
                .setUrl(url)
                .addQueryParam("directory", cmd.getDirectory())
                .setHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
        )).thenApply(r -> {
            if (r.getStatusCode() == 204) {
                return new CreatedDirectory(cmd.getUserContext());
            }
            throw parseHttpStatusCode(cmd.getUserContext(), r);
        });
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy