<commit_before>import * as oauth from 'oauth';

export interface AccountsOauthTwitterOptions {
  key: string;
  secret: string;
}

class AccountsOauthTwitter {
  private options: AccountsOauthTwitterOptions;

  constructor(options: AccountsOauthTwitterOptions) {
    this.options = options;
  }

  public authenticate(params) {
    const oa = new oauth.OAuth(
      'https://twitter.com/oauth/request_token',
      'https://twitter.com/oauth/access_token',
      this.options.key,
      this.options.secret,
      '1.0A',
      null,
      'HMAC-SHA1',
    );
    return new Promise((resolve, reject) => {
      oa.get(
        'https://api.twitter.com/1.1/account/verify_credentials.json?include_email=true',
        params.access_token,
        params.access_token_secret,
        (err, data) => {
          if (err) {
            reject(err);
          } else {
            data = JSON.parse(data);
            const user = {
              id: data.id_str,
              screenName: data.screen_name,
              profilePicture: data.profile_image_url_https,
              email: data.email,
              accessToken: params.access_token,
              accessTokenSecret: params.access_token_secret,
            };
            resolve(user);
          }
        },
      );
    });

  }
}

export default AccountsOauthTwitter;
<commit_msg>move oauth instance in constructor<commit_after>import * as oauth from 'oauth';

export interface AccountsOauthTwitterOptions {
  key: string;
  secret: string;
}

class AccountsOauthTwitter {
  private options: AccountsOauthTwitterOptions;
  private oauth: any;

  constructor(options: AccountsOauthTwitterOptions) {
    this.options = options;
    this.oauth = new oauth.OAuth(
      'https://twitter.com/oauth/request_token',
      'https://twitter.com/oauth/access_token',
      this.options.key,
      this.options.secret,
      '1.0A',
      null,
      'HMAC-SHA1',
    );
  }

  public authenticate(params) {
    return new Promise((resolve, reject) => {
      this.oauth.get(
        'https://api.twitter.com/1.1/account/verify_credentials.json?include_email=true',
        params.access_token,
        params.access_token_secret,
        (err, data) => {
          if (err) {
            reject(err);
          } else {
            data = JSON.parse(data);
            const user = {
              id: data.id_str,
              screenName: data.screen_name,
              profilePicture: data.profile_image_url_https,
              email: data.email,
              accessToken: params.access_token,
              accessTokenSecret: params.access_token_secret,
            };
            resolve(user);
          }
        },
      );
    });

  }
}

export default AccountsOauthTwitter;

{'fraction_non_alphanumeric': 0.10936930368209989, 'fraction_numerical': 0.0036456434560699965, 'mean_word_length': 2.079685746352413, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 6, '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': '1669280', 'n_tokens_mistral': 835, 'n_tokens_neox': 813, 'n_words': 142}