<commit_before>'use strict';

const _ = require('lodash');
const cleverClient = require('clever-client');

const Logger = require('../logger.js');
const { conf, loadOAuthConf } = require('./configuration.js');

function initApi () {

  return loadOAuthConf().flatMapLatest((tokens) => {

    const apiSettings = _.assign({}, conf, {
      API_HOST: conf.API_HOST,
      API_CONSUMER_KEY: conf.OAUTH_CONSUMER_KEY,
      API_CONSUMER_SECRET: conf.OAUTH_CONSUMER_SECRET,
      API_OAUTH_TOKEN: tokens.<PASSWORD>,
      API_OAUTH_TOKEN_SECRET: tokens.secret,
      logger: Logger,
    });

    const api = cleverClient(apiSettings);

    // Waiting for clever-client to be fully node compliant
    api.session.getAuthorization = (httpMethod, url, params) => {
      return api.session.getHMACAuthorization(httpMethod, url, params, {
        user_oauth_token: tokens.<PASSWORD>,
        user_oauth_token_secret: tokens.secret,
      });
    };

    return api;
  });
};

module.exports = initApi;
<commit_msg>Fix bad usage of Bacon<commit_after>'use strict';

const _ = require('lodash');
const cleverClient = require('clever-client');

const Logger = require('../logger.js');
const { conf, loadOAuthConf } = require('./configuration.js');

function initApi () {

  return loadOAuthConf().map((tokens) => {

    const apiSettings = _.assign({}, conf, {
      API_HOST: conf.API_HOST,
      API_CONSUMER_KEY: conf.OAUTH_CONSUMER_KEY,
      API_CONSUMER_SECRET: conf.OAUTH_CONSUMER_SECRET,
      API_OAUTH_TOKEN: tokens.<PASSWORD>,
      API_OAUTH_TOKEN_SECRET: tokens.secret,
      logger: Logger,
    });

    const api = cleverClient(apiSettings);

    // Waiting for clever-client to be fully node compliant
    api.session.getAuthorization = (httpMethod, url, params) => {
      return api.session.getHMACAuthorization(httpMethod, url, params, {
        user_oauth_token: tokens.token,
        user_oauth_token_secret: tokens.secret,
      });
    };

    return api;
  });
};

module.exports = initApi;

{'fraction_non_alphanumeric': 0.12787212787212787, 'fraction_numerical': 0.0, 'mean_word_length': 3.583524027459954, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 10, 'https://': 0, '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': '5677599', 'n_tokens_mistral': 656, 'n_tokens_neox': 640, 'n_words': 126}