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

com.chargebee.Result Maven / Gradle / Ivy

There is a newer version: 3.26.0
Show newest version
package com.chargebee;

import com.chargebee.internal.ResultBase;
import org.json.JSONObject;

import java.util.List;
import java.util.Map;
import java.util.Optional;

import static com.chargebee.IdempotencyConstants.IDEMPOTENCY_REPLAY_HEADER;

public class Result extends ResultBase implements ApiResponse {

    public final int httpCode;
    public Map> responseHeaders;

    public Result(int httpCode, JSONObject jsonObj) {
        super(jsonObj);
        this.httpCode = httpCode;
    }

    public Result(int httpCode, JSONObject jsonObj, Map> responseHeaders) {
        this(httpCode,jsonObj);
        this.responseHeaders = responseHeaders;
    }

    public int httpCode() {
        return httpCode;
    }

    public Map> getResponseHeaders() {
        return responseHeaders;
    }

    public boolean isIdempotencyReplayed() {
        Map> headers = responseHeaders;
        Optional replayedHeader = headers.entrySet().stream()
            .filter(entry -> IDEMPOTENCY_REPLAY_HEADER.equalsIgnoreCase(entry.getKey()))
            .findFirst()
            .flatMap(entry -> entry.getValue().stream().findFirst());

        return replayedHeader.isPresent();
    }

    public JSONObject jsonResponse() {
        return jsonObj();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy