<commit_before>var Promise = require('bluebird');
var fs = require('fs');
var ProtoBuf = require('protobufjs');
var request = Promise.promisifyAll(require('request'));
var util = require('util');
var fmt = util.format;
var _ = require('lodash');
var assert = require('assert');
var qs = require('querystring');
var stringify = require('json-stable-stringify');
var debug = require('debug')('gp:api');

// protobuf initialization
var builder = ProtoBuf.loadProtoFile(__dirname + '/data/googleplay.proto');
var ResponseWrapper = builder.build("ResponseWrapper");
var PreFetch = builder.build("PreFetch");
var BulkDetailsRequest = builder.build("BulkDetailsRequest");
var getOrElseThrow = require('./get-or-throw');
var responseToObj = require('./response-to-obj');
var RequestError = require('./errors').RequestError;
var LoginError  = require('./errors').LoginError;


/**
 * GooglePlay API
 * @todo todo Consider allowing passing in Device configuration information to
 * configure user-agent etc.
 * @param {String} username - required
 * @param {String} password - required
 * @param {String} androidId - required
 * @param {Boolean} useCache - enable debug output (default: true)
 * @param {Boolean} debug - enable request debug output (default: false)
 * @param {Object} requestsDefaultParams - default params you can set to requests (see https://github.com/request/request#requestoptions-callback)
 * @return {type}
 */
var GooglePlay = (function GooglePlay(username, password, androidId, useCache, debug, requestsDefaultParams) {
  // default for args:
  androidId = androidId || null;
  debug = (!!process.env.DEBUG) || debug === true;

  var USE_CACHE = (useCache === true);
  var authToken;

  if (debug) {
    require('request-debug')(request);
  }

  if(requestsDefaultParams) {
    request = Promise.promisifyAll(require('request').defaults( requestsDefaultParams ) );
  }

  getOrElseThrow(username, 'Require username');
  getOrElseThrow(password, 'Require password');
  getOrElseThrow(androidId, 'Require Android ID');

  var DEVICE_COUNTRY, OPERATOR_COUNTRY, LOGIN_LANGUAGE;
  DEVICE_COUNTRY = LOGIN_LANGUAGE = OPERATOR_COUNTRY = "us";

  // Various constants used for requests:
  // TODO: consider using a single object to hold these values?
  var SERVICE = "androidmarket";
  var URL_LOGIN = "https://android.clients.google.com/auth";
  var ACCOUNT_TYPE_GOOGLE = "GOOGLE";<commit_msg>Only activate debug mode if process.env.DEBUG contains "gp:api".<commit_after>var Promise = require('bluebird');
var fs = require('fs');
var ProtoBuf = require('protobufjs');
var request = Promise.promisifyAll(require('request'));
var util = require('util');
var fmt = util.format;
var _ = require('lodash');
var assert = require('assert');
var qs = require('querystring');
var stringify = require('json-stable-stringify');
var debug = require('debug')('gp:api');

// protobuf initialization
var builder = ProtoBuf.loadProtoFile(__dirname + '/data/googleplay.proto');
var ResponseWrapper = builder.build("ResponseWrapper");
var PreFetch = builder.build("PreFetch");
var BulkDetailsRequest = builder.build("BulkDetailsRequest");
var getOrElseThrow = require('./get-or-throw');
var responseToObj = require('./response-to-obj');
var RequestError = require('./errors').RequestError;
var LoginError  = require('./errors').LoginError;


/**
 * GooglePlay API
 * @todo todo Consider allowing passing in Device configuration information to
 * configure user-agent etc.
 * @param {String} username - required
 * @param {String} password - required
 * @param {String} androidId - required
 * @param {Boolean} useCache - enable debug output (default: true)
 * @param {Boolean} debug - enable request debug output (default: false)
 * @param {Object} requestsDefaultParams - default params you can set to requests (see https://github.com/request/request#requestoptions-callback)
 * @return {type}
 */
var GooglePlay = (function GooglePlay(username, password, androidId, useCache, debug, requestsDefaultParams) {
  // default for args:
  androidId = androidId || null;
  debug = /gp:api/.test(process.env.DEBUG) || debug === true;

  var USE_CACHE = (useCache === true);
  var authToken;

  if (debug) {
    require('request-debug')(request);
  }

  if(requestsDefaultParams) {
    request = Promise.promisifyAll(require('request').defaults( requestsDefaultParams ) );
  }

  getOrElseThrow(username, 'Require username');
  getOrElseThrow(password, 'Require password');
  getOrElseThrow(androidId, 'Require Android ID');

  var DEVICE_COUNTRY, OPERATOR_COUNTRY, LOGIN_LANGUAGE;
  DEVICE_COUNTRY = LOGIN_LANGUAGE = OPERATOR_COUNTRY = "us";

  // Various constants used for requests:
  // TODO: consider using a single object to hold these values?
  var SERVICE = "androidmarket";
  var URL_LOGIN = "https://android.clients.google.com/auth";
  var ACCOUNT_TYPE_GOOGLE = "GOOGLE";
{'fraction_non_alphanumeric': 0.13651315789473684, 'fraction_numerical': 0.0, 'mean_word_length': 5.253213367609255, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 4, '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': '6661323', 'n_tokens_mistral': 1415, 'n_tokens_neox': 1380, 'n_words': 388}