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

com.yoti.api.client.spi.remote.call.SignedRequest Maven / Gradle / Ivy

The newest version!
package com.yoti.api.client.spi.remote.call;

import java.io.IOException;
import java.net.URI;
import java.util.Map;

import com.yoti.api.client.Image;

import com.fasterxml.jackson.core.type.TypeReference;

public class SignedRequest {

    private final URI uri;
    private final String method;
    private final byte[] data;
    private final Map headers;
    private final JsonResourceFetcher jsonResourceFetcher;
    private final RawResourceFetcher rawResourceFetcher;
    private final ImageResourceFetcher imageResourceFetcher;

    SignedRequest(final URI uri,
            final String method,
            final byte[] data,
            final Map headers,
            JsonResourceFetcher jsonResourceFetcher,
            RawResourceFetcher rawResourceFetcher,
            ImageResourceFetcher imageResourceFetcher) {

        this.uri = uri;
        this.method = method;
        this.data = data;
        this.headers = headers;
        this.jsonResourceFetcher = jsonResourceFetcher;
        this.rawResourceFetcher = rawResourceFetcher;
        this.imageResourceFetcher = imageResourceFetcher;
    }

    public URI getUri() {
        return uri;
    }

    public String getMethod() {
        return method;
    }

    public byte[] getData() {
        return data != null ? data.clone() : null;
    }

    public Map getHeaders() {
        return headers;
    }

    public  T execute(Class clazz) throws ResourceException, IOException {
        if (Image.class.isAssignableFrom(clazz)) {
            return clazz.cast(imageResourceFetcher.doRequest(this));
        }
        return jsonResourceFetcher.doRequest(this, clazz);
    }

    public  T execute(TypeReference typeReference) throws ResourceException, IOException {
        return jsonResourceFetcher.doRequest(this, typeReference);
    }

    public SignedRequestResponse execute() throws ResourceException, IOException {
        return rawResourceFetcher.doRequest(this);
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy