<commit_before>var request = require('request');
var moment = require('moment');
var util = require('util');

var scheduleTo = require('../scheduleTo');
var logger = require('./../../utils/logger');
var handleUnexpected = require('../handleUnexpected');
var config = require('../../../config');

var API = 'https://www.behance.net/v2';

function connector(state, callback) {
	var accessToken = state.accessToken;
	var username = state.username;
	var log = logger.connector('behance');

	if (!accessToken) {
		return callback('missing accessToken for user: ' + state.user);
	}

	if (!username) {
		return callback('missing username for user: ' + state.user);
	}

	initState(state);

	log.info('prepearing request in (' + state.mode + ') mode for user: ' + state.user);

	var uri = formatRequestUri(accessToken, username, state);
	var headers = { 'Content-Type': 'application/json', 'User-Agent': 'likeastore/collector'};

	request({uri: uri, headers: headers, timeout: config.collector.request.timeout, json: true}, function (err, response, body) {
		if (err) {
			return handleUnexpected(response, body, state, err, function (err) {
				callback (err, state);
			});
		}

		return handleResponse(response, body);
	});

	function initState(state) {
		if (!state.mode) {
			state.mode = 'initial';
		}

		if (!state.errors) {
			state.errors = 0;
		}

		if (state.mode === 'initial' && !state.page) {
			state.page = 1;
		}

		if (state.mode === 'rateLimit') {
			state.mode = state.prevMode;
		}
	}

	function formatRequestUri(accessToken, username, state) {
		var base = util.format('%s/users/%s/appreciations?access_token=%s', API, username, accessToken);
		return state.mode === 'initial' && state.page ?
			util.format('%s&page=%s', base, state.page) :
			base;
	}

	function handleResponse(response, body) {
		var rateLimit = response.statusCode === 429 ? 0 : 9999;
		var appreciations = body.appreciations;

		log.info('rate limit remaining: ' +  rateLimit + ' for user: ' + state.user);

		if (!Array.isArray(appreciations)) {
			return handleUnexpected(response, body, state, function (err) {
				callback(err, scheduleTo(updateState(state, [], rateLimit, true)));
			});
		}

		var stars = appreciations.map(function (r) {
			return {
				itemId: r.project.id.toString(),
				idInt: r.project.id,
				user: state.user,
				created: moment(r.project.created_on).toDate(),
				title: r.project.name,
				authorName: first(r.project.owners).display_name,
				authorUrl: first(r.project.owners).url,<commit_msg>corrected timestamp for behance<commit_after>var request = require('request');
var moment = require('moment');
var util = require('util');

var scheduleTo = require('../scheduleTo');
var logger = require('./../../utils/logger');
var handleUnexpected = require('../handleUnexpected');
var config = require('../../../config');

var API = 'https://www.behance.net/v2';

function connector(state, callback) {
	var accessToken = state.accessToken;
	var username = state.username;
	var log = logger.connector('behance');

	if (!accessToken) {
		return callback('missing accessToken for user: ' + state.user);
	}

	if (!username) {
		return callback('missing username for user: ' + state.user);
	}

	initState(state);

	log.info('prepearing request in (' + state.mode + ') mode for user: ' + state.user);

	var uri = formatRequestUri(accessToken, username, state);
	var headers = { 'Content-Type': 'application/json', 'User-Agent': 'likeastore/collector'};

	request({uri: uri, headers: headers, timeout: config.collector.request.timeout, json: true}, function (err, response, body) {
		if (err) {
			return handleUnexpected(response, body, state, err, function (err) {
				callback (err, state);
			});
		}

		return handleResponse(response, body);
	});

	function initState(state) {
		if (!state.mode) {
			state.mode = 'initial';
		}

		if (!state.errors) {
			state.errors = 0;
		}

		if (state.mode === 'initial' && !state.page) {
			state.page = 1;
		}

		if (state.mode === 'rateLimit') {
			state.mode = state.prevMode;
		}
	}

	function formatRequestUri(accessToken, username, state) {
		var base = util.format('%s/users/%s/appreciations?access_token=%s', API, username, accessToken);
		return state.mode === 'initial' && state.page ?
			util.format('%s&page=%s', base, state.page) :
			base;
	}

	function handleResponse(response, body) {
		var rateLimit = response.statusCode === 429 ? 0 : 9999;
		var appreciations = body.appreciations;

		log.info('rate limit remaining: ' +  rateLimit + ' for user: ' + state.user);

		if (!Array.isArray(appreciations)) {
			return handleUnexpected(response, body, state, function (err) {
				callback(err, scheduleTo(updateState(state, [], rateLimit, true)));
			});
		}

		var stars = appreciations.map(function (r) {
			return {
				itemId: r.project.id.toString(),
				idInt: r.project.id,
				user: state.user,
				created: moment.unix(r.project.created_on).toDate(),
				title: r.project.name,
				authorName: first(r.project.owners).display_name,
				authorUrl: first(r.project.owners).url,
{'fraction_non_alphanumeric': 0.16722738966950326, 'fraction_numerical': 0.004353849198495943, 'mean_word_length': 4.028855721393035, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, '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': '6420705', 'n_tokens_mistral': 1788, 'n_tokens_neox': 1591, 'n_words': 378}