<commit_before>var http = require('http');

module.exports = function(api, config) {
	api.connect = function(userId, deviceId, done) {
		api.post('/connectedDevices', {
			userId : userId,
			deviceId : deviceId
		}, function(info, error) {
			config.deviceInfo = info;
			done(info, error);
		});
	};
};<commit_msg>Added status and error API calls<commit_after>var http = require('http');

var errorsContext = '/errors';
var devicesContext = '/connectedDevices';

module.exports = function(api, config) {
	/**
	 * Connect to windward service. Also store device info for other API usage.
	 */
	api.connect = function(userId, deviceId, done) {
		api.post(devicesContext, {
			userId : userId,
			deviceId : deviceId
		}, function(info, error) {
			config.deviceInfo = info;
			done(info, error);
			if (error) {
				api.error(error);
			}
		});
	};

	/**
	 * Get latest device info
	 */
	api.status = function(done) {
		api.put(devicesContext, config.deviceInfo, function(info, error) {
			if(info) {
				config.deviceInfo = info;
			}
			done(info, error);
			if (error) {
				api.error(error);
			}
		});
	};

	api.error = function(errorObj) {

		if (config.isDebug) {
			console.log("Error:");
			console.log(errorObj);
		}

		api.post(errorsContext, {
			connectId : config.deviceInfo.connectId,
			error : errorObj
		}, function(info, error) {
			if (error && config.isDebug) {
				console.log("Could not log error: ");
				console.log(error);
			}
		});
	};
};
{'fraction_non_alphanumeric': 0.15699658703071673, 'fraction_numerical': 0.0, 'mean_word_length': 3.363095238095238, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2084776', 'n_tokens_mistral': 565, 'n_tokens_neox': 492, 'n_words': 107}