/** * Obtains the username/password credentials from the environment * * @return */ private static UsernamePasswordCredentials getCredentials() { // Obtain the username and password final String username = SecurityActions.getEnvironmentVariable(ENV_VAR_NAME_TWITTER_USERNAME); final String password = SecurityActions.getEnvironmentVariable(ENV_VAR_NAME_TWITTER_PASSWORD); // Return as unified view final UsernamePasswordCredentials creds = new UsernamePasswordCredentials(); creds.username = username; creds.password = password; return creds; }
/** * Obtains a Twitter client for the username and password as specified from the environment. If * the environment is not fully set up, an {@link IllegalStateException} will be raised noting the * environment variables expected to be in place. To avoid the ISE first check for the integrity * of the environment by using {@link * EnvironmentSpecificTwitterClientUtil#isSupportedEnvironment()} * * @throws IllegalStateException If the environment does not support creation of a Twitter client */ static Twitter getTwitterClient() throws IllegalStateException { // Obtain the username and password final String username = SecurityActions.getEnvironmentVariable(ENV_VAR_NAME_TWITTER_USERNAME); final String password = SecurityActions.getEnvironmentVariable(ENV_VAR_NAME_TWITTER_PASSWORD); /* * We're only supported if both the username and password have been set */ if (!isSupportedEnvironment()) { throw new IllegalStateException(MSG_UNSUPPORTED_ENVIRONMENT); } // Get a Twitter client final Twitter twitterClient = new Twitter(username, password); // Return return twitterClient; }