package com.sigmaflare.binancej; import com.codepoetics.ambivalence.LeftProjection; import com.codepoetics.ambivalence.RightProjection; import com.fasterxml.jackson.databind.ObjectMapper; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpPost; import java.util.function.Function; public final class Helpers { private Helpers() { } /** * Checks to insure the status code is ok. * * @param statusCode The status code * @return True of the status code is acceptable (200-399), and false otherwise */ public static boolean statusCodeIsOk(int statusCode) { return statusCode >= 200 && statusCode < 400; } /** * Builds a configured HttpGet * * @param url The full URL to GET to * @param apiKey The API key * @return A configured HttpGet object */ public static HttpGet getBuilder(String url, String apiKey) { HttpGet httpGet = new HttpGet(url); httpGet.setHeader("X-MBX-APIKEY", apiKey); return httpGet; } /** * Builds a configured HttpPost * * @param url The full URL to POST to * @param apiKey The API key * @return A configured HttpPost object */ public static HttpPost postBuilder(String url, String apiKey) { HttpPost httpPost = new HttpPost(url); httpPost.setHeader("X-MBX-APIKEY", apiKey); return httpPost; } /** * Builds a fully configured ObjectMapper * * @return A fully configured ObjectMapper */ public static ObjectMapper objectMapperBuilder() { return new ObjectMapper().findAndRegisterModules(); } /** * Safely extracts the value from a LeftProjection of an Either * * @param val The LeftProjection to perform the extraction on * @param The Left type * @param The Right type * @return The unwrapped L type object */ @SuppressWarnings("unchecked") public static L extractEitherValueSafely(LeftProjection val) { return (L) val.join(Function.identity(), Function.identity()); } /** * Safely extracts the value from a RightProjection of an Either * * @param val The RightProjection to perform the extraction on * @param The Left type * @param The Right type * @return The unwrapped R type object */ @SuppressWarnings("unchecked") public static R extractEitherValueSafely(RightProjection val) { return (R) val.join(Function.identity(), Function.identity()); } }