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

com.gocardless.http.ApiResponse Maven / Gradle / Ivy

There is a newer version: 6.0.0
Show newest version
package com.gocardless.http;

import com.google.common.collect.ImmutableListMultimap;
import com.google.common.collect.Multimap;
import java.util.List;
import java.util.Map;

/**
 * Base class for API responses.
 *
 * @param  the type of the resource within this response.
 */
public class ApiResponse {
    private final T resource;
    private final int statusCode;
    private final Multimap headers;

    public ApiResponse(T resource, int statusCode, Map> headers) {
        this.resource = resource;
        this.statusCode = statusCode;
        this.headers = buildHeaderMap(headers);
    }

    public T getResource() {
        return resource;
    }

    public int getStatusCode() {
        return statusCode;
    }

    public Multimap getHeaders() {
        return headers;
    }

    private static Multimap buildHeaderMap(Map> headers) {
        ImmutableListMultimap.Builder builder = ImmutableListMultimap.builder();
        for (Map.Entry> entry : headers.entrySet()) {
            builder.putAll(entry.getKey(), entry.getValue());
        }
        return builder.build();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy