private String generateSignature(Map<String, Object> params) { final String stringToSign = httpMethod.name() + "\n" + credentials.getApiHost().toLowerCase() + "\n" + path + "\n" + canonicalQueryString(params); return Utils.getHash(credentials.getSecretKey(), stringToSign); }
private Map<String, Object> getSignedParams() { Map<String, Object> signedParams = (data != null) ? new HashMap<>(data) : new HashMap<String, Object>(); if (factoryId != null) signedParams.put("factory_id", factoryId); signedParams.put("access_key", credentials.getAccessKey()); signedParams.put("timestamp", timestamp != null ? timestamp : Utils.isoTimestamp()); Map<String, Object> additionalParams = new HashMap<>(signedParams); additionalParams.remove("file"); String signature = generateSignature(additionalParams); signedParams.put("signature", signature); return signedParams; }
private URL buildRequestUrl() throws IOException { return new URL(apiProtocol().name(), credentials.getApiHost(), apiPort(), pathWithParams()); }
private String apiVersion() { return "/v" + credentials.getApiVersion(); }
private int apiPort() { return credentials.getApiPort() != 80 ? credentials.getApiPort() : -1; }
private HttpProtocol apiProtocol() { return credentials.isDefaultApiPort() ? HttpProtocol.HTTPS : HttpProtocol.HTTP; }