com.truelayer.java.http.mappers.HeadersMapper Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of truelayer-java Show documentation
Show all versions of truelayer-java Show documentation
TrueLayer Java SDK for https://truelayer.com
package com.truelayer.java.http.mappers;
import static org.apache.commons.lang3.ObjectUtils.isEmpty;
import static org.apache.commons.lang3.ObjectUtils.isNotEmpty;
import com.truelayer.java.Constants;
import com.truelayer.java.http.entities.Headers;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
/**
* Utility class for Headers to Map conversions.
*/
public class HeadersMapper {
public static Map toMap(Headers customHeaders) {
Map headersMap = new HashMap<>();
if (isEmpty(customHeaders)) {
return Collections.unmodifiableMap(headersMap);
}
String idempotencyKey = customHeaders.getIdempotencyKey();
if (isNotEmpty(idempotencyKey)) {
headersMap.put(Constants.HeaderNames.IDEMPOTENCY_KEY, idempotencyKey);
}
String signature = customHeaders.getSignature();
if (isNotEmpty(signature)) {
headersMap.put(Constants.HeaderNames.TL_SIGNATURE, signature);
}
String xForwardedFor = customHeaders.getXForwardedFor();
if (isNotEmpty(xForwardedFor)) {
headersMap.put(Constants.HeaderNames.X_FORWARDED_FOR, xForwardedFor);
}
String xDeviceUserAgent = customHeaders.getXDeviceUserAgent();
if (isNotEmpty(xDeviceUserAgent)) {
headersMap.put(Constants.HeaderNames.X_DEVICE_USER_AGENT, xDeviceUserAgent);
}
if (customHeaders.isEnablePagination()) {
headersMap.put(Constants.HeaderNames.TL_ENABLE_PAGINATION, "true");
}
return Collections.unmodifiableMap(headersMap);
}
}