From 375f9d8943983bd672d553ffdc93b6e37b688780 Mon Sep 17 00:00:00 2001 From: Kevin Jiang Date: Wed, 17 Jan 2018 21:05:02 -0500 Subject: [PATCH] Tumblr API Key Choosing Fix Fixes API choosing. Creates Random objects, generates a number, then feeds that number to API_KEY. This is as opposed to the previous way where it created the Random object, generated a number, then fed it all in a single line. --- .../ripme/ripper/rippers/TumblrRipper.java | 33 +++++++++++++------ 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/rarchives/ripme/ripper/rippers/TumblrRipper.java b/src/main/java/com/rarchives/ripme/ripper/rippers/TumblrRipper.java index 7a8dff75..dc57c48f 100644 --- a/src/main/java/com/rarchives/ripme/ripper/rippers/TumblrRipper.java +++ b/src/main/java/com/rarchives/ripme/ripper/rippers/TumblrRipper.java @@ -34,23 +34,30 @@ public class TumblrRipper extends AlbumRipper { private ALBUM_TYPE albumType; private String subdomain, tagName, postNumber; - private static String TUMBLR_AUTH_CONFIG_KEY = "tumblr.auth"; + private static final String TUMBLR_AUTH_CONFIG_KEY = "tumblr.auth"; private static boolean useDefaultApiKey = false; // fall-back for bad user-specified key - private static final List apiKeys = Arrays.asList("JFNLu3CbINQjRdUvZibXW9VpSEVYYtiPJ86o8YmvgLZIoKyuNX", - "FQrwZMCxVnzonv90rgNUJcAk4FpnoS0mYuSuGYqIpM2cFgp9L4", - "qpdkY6nMknksfvYAhf2xIHp0iNRLkMlcWShxqzXyFJRxIsZ1Zz"); - private static final String API_KEY = apiKeys.get(new Random().nextInt(apiKeys.size())); + private static final List APIKEYS = Arrays.asList("JFNLu3CbINQjRdUvZibXW9VpSEVYYtiPJ86o8YmvgLZIoKyuNX", + "FQrwZMCxVnzonv90rgNUJcAk4FpnoS0mYuSuGYqIpM2cFgp9L4", + "qpdkY6nMknksfvYAhf2xIHp0iNRLkMlcWShxqzXyFJRxIsZ1Zz"); + private static int genNum = new Random().nextInt(APIKEYS.size()); + private static final String API_KEY = APIKEYS.get(genNum); // Select random API key from APIKEYS - - private static String getApiKey() { + /** + * Gets the API key. + * Chooses between default/included keys & user specified ones (from the config file). + * @return Tumblr API key + */ + public static String getApiKey() { if (useDefaultApiKey || Utils.getConfigString(TUMBLR_AUTH_CONFIG_KEY, "JFNLu3CbINQjRdUvZibXW9VpSEVYYtiPJ86o8YmvgLZIoKyuNX").equals("JFNLu3CbINQjRdUvZibXW9VpSEVYYtiPJ86o8YmvgLZIoKyuNX")) { logger.info("Using api key: " + API_KEY); return API_KEY; } else { - logger.info("Using user tumblr.auth api key"); - return Utils.getConfigString(TUMBLR_AUTH_CONFIG_KEY, "JFNLu3CbINQjRdUvZibXW9VpSEVYYtiPJ86o8YmvgLZIoKyuNX"); + String userDefinedAPIKey = Utils.getConfigString(TUMBLR_AUTH_CONFIG_KEY, "JFNLu3CbINQjRdUvZibXW9VpSEVYYtiPJ86o8YmvgLZIoKyuNX"); + logger.info("Using user tumblr.auth api key: " + userDefinedAPIKey); + return userDefinedAPIKey; } + } public TumblrRipper(URL url) throws IOException { @@ -64,7 +71,13 @@ public class TumblrRipper extends AlbumRipper { public boolean canRip(URL url) { return url.getHost().endsWith(DOMAIN); } - + + /** + * Sanitizes URL. + * @param url URL to be sanitized. + * @return Sanitized URL + * @throws MalformedURLException + */ @Override public URL sanitizeURL(URL url) throws MalformedURLException { String u = url.toExternalForm();