<commit_before>package pl.project13.janbanery.config;

import com.ning.http.client.AsyncHttpClient;
import sun.misc.BASE64Encoder;

import static pl.project13.janbanery.config.AuthMode.API_KEY_MODE;
import static pl.project13.janbanery.config.AuthMode.USER_AND_PASS_MODE;

/**
 * Date: 4/20/11
 *
 * @author <NAME>
 */
public class DefaultConfiguration implements Configuration {

  private AuthMode authMode         = API_KEY_MODE;
  private String   API_TOKEN_HEADER = "X-Kanbanery-ApiToken";
  private String   apiKey           = "";
  private String   encodedLogon     = "";

  public DefaultConfiguration(String apiKey) {
    forceKeyAuthMode(apiKey);
  }

  public DefaultConfiguration(String user, String password) {
    forceUserPassAuthMode(user, password);
  }

  public DefaultConfiguration() {
  }

  @Override
  public void forceUserPassAuthMode(String user, String password) {
    authMode = USER_AND_PASS_MODE;
    this.encodedLogon = encodeUserPassword(user, password);
  }

  @Override
  public void forceKeyAuthMode(String apiKey) {
    authMode = API_KEY_MODE;
    this.apiKey = apiKey;
  }

  @Override
  public AsyncHttpClient.BoundRequestBuilder authorize(AsyncHttpClient.BoundRequestBuilder requestBuilder) {
    // todo could be refactored into this enum hmhm
    switch (authMode) {
      case USER_AND_PASS_MODE:
        return requestBuilder.addHeader("Authorization", "Basic " + encodedLogon);
      case API_KEY_MODE:
        return requestBuilder.addHeader(API_TOKEN_HEADER, getApiKey());
      default:
        throw new UnsupportedOperationException("Could not authorize request, unknown mode: '" + authMode + "'");
    }
  }

  @Override
  public String getApiKey() {
    return apiKey;
  }

  @Override
  public AuthMode getAuthMode() {
    return authMode;
  }

  @Override
  public String getApiUrl() {
    return "https://kanbanery.com/api/v1/user/";
  }

  private String encodeUserPassword(String user, String password) {
    byte[] logon = String.format("%s:%s", user, password).getBytes();
    return new BASE64Encoder().encode(logon);
  }

  @Override
  public String getApiUrl() {
    return "https://kanbanery.com/api/v1/user/";
  }
}<commit_msg>small fix of duplicate method due to refactor<commit_after>package pl.project13.janbanery.config;

import com.ning.http.client.AsyncHttpClient;
import sun.misc.BASE64Encoder;

import static pl.project13.janbanery.config.AuthMode.API_KEY_MODE;
import static pl.project13.janbanery.config.AuthMode.USER_AND_PASS_MODE;

/**
 * Date: 4/20/11
 *
 * @author <NAME>
 */
public class DefaultConfiguration implements Configuration {

  private AuthMode authMode         = API_KEY_MODE;
  private String   API_TOKEN_HEADER = "X-Kanbanery-ApiToken";
  private String   apiKey           = "";
  private String   encodedLogon     = "";

  public DefaultConfiguration(String apiKey) {
    forceKeyAuthMode(apiKey);
  }

  public DefaultConfiguration(String user, String password) {
    forceUserPassAuthMode(user, password);
  }

  public DefaultConfiguration() {
  }

  @Override
  public void forceUserPassAuthMode(String user, String password) {
    authMode = USER_AND_PASS_MODE;
    this.encodedLogon = encodeUserPassword(user, password);
  }

  @Override
  public void forceKeyAuthMode(String apiKey) {
    authMode = API_KEY_MODE;
    this.apiKey = apiKey;
  }

  @Override
  public AsyncHttpClient.BoundRequestBuilder authorize(AsyncHttpClient.BoundRequestBuilder requestBuilder) {
    // todo could be refactored into this enum hmhm
    switch (authMode) {
      case USER_AND_PASS_MODE:
        return requestBuilder.addHeader("Authorization", "Basic " + encodedLogon);
      case API_KEY_MODE:
        return requestBuilder.addHeader(API_TOKEN_HEADER, getApiKey());
      default:
        throw new UnsupportedOperationException("Could not authorize request, unknown mode: '" + authMode + "'");
    }
  }

  @Override
  public String getApiKey() {
    return apiKey;
  }

  @Override
  public AuthMode getAuthMode() {
    return authMode;
  }

  @Override
  public String getApiUrl() {
    return "https://kanbanery.com/api/v1/user/";
  }

  private String encodeUserPassword(String user, String password) {
    byte[] logon = String.format("%s:%s", user, password).getBytes();
    return new BASE64Encoder().encode(logon);
  }

}
{'fraction_non_alphanumeric': 0.09867963863794302, 'fraction_numerical': 0.007644197359277276, 'mean_word_length': 3.8245810055865923, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 3, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3141356', 'n_tokens_mistral': 1333, 'n_tokens_neox': 1290, 'n_words': 287}