<commit_before>/*
 * Fitbit-js
 *
 * Copyright (c) 2011 <NAME> <<EMAIL>>
 */

var url = require('url');
var http = require('http');
var OAuth = require('oauth').OAuth;
var querystring = require('querystring');
var Serializer = require('serializer');

var baseURI = 'http://api.fitbit.com/1';

module.exports = function (api_key, api_secret, callbackURI) {
    var client = {version: '0.1.0'};
    var serializer = Serializer.createSecureSerializer(api_key, api_secret);

    var oAuth = new OAuth('http://api.fitbit.com/oauth/request_token',
                          'http://api.fitbit.com/oauth/access_token',
                          api_key, api_secret, '1.0', callbackURI,
                          'HMAC-SHA1', null,
        {'Accept': '*/*', 'Connection': 'close', 'User-Agent': 'fitbit-js ' + client.version});


    function requestCallback(callback) {
      return function (err, data, response) {
        if (err) return callback(err, data);
        var exception = null;
        try {
          data = JSON.parse(data);
        } catch (e) { exception = e; }
        callback(exception, response, data);
      };
    }

    function get(path, params, token, callback) {
      oAuth.get(baseURI + path + '?' + querystring.stringify(params),
                token.oauth_token, token.oauth_token_secret, requestCallback(callback));
    }

    function post(path, params, token, callback) {
      oAuth.post(baseURI + path, token.oauth_token, token.oauth_token_secret,
                 params, null, requestCallback(callback));
    }

    // PUBLIC
    client.apiCall = function (method, path, params, callback) {
      var token = params.token;
      delete params.token;
      if (method === 'GET') get(path, params, token, callback);
      else if (method === 'POST') post(path, params, token, callback);
    }
<commit_msg>Added unit system option to client constructor<commit_after>/*
 * Fitbit-js
 *
 * Copyright (c) 2011 <NAME> <<EMAIL>>
 */

var url = require('url');
var http = require('http');
var OAuth = require('oauth').OAuth;
var querystring = require('querystring');
var Serializer = require('serializer');

var baseURI = 'http://api.fitbit.com/1';

module.exports = function (api_key, api_secret, callbackURI, unit_system) {
    var client = {version: '0.1.0'};
    var serializer = Serializer.createSecureSerializer(api_key, api_secret);

    var oAuth = new OAuth('http://api.fitbit.com/oauth/request_token',
                          'http://api.fitbit.com/oauth/access_token',
                          api_key, api_secret, '1.0', callbackURI,
                          'HMAC-SHA1', null,
        {'Accept': '*/*', 'Connection': 'close', 'User-Agent': 'fitbit-js ' + client.version, 'Accept-Language': unit_system});


    function requestCallback(callback) {
      return function (err, data, response) {
        if (err) return callback(err, data);
        var exception = null;
        try {
          data = JSON.parse(data);
        } catch (e) { exception = e; }
        callback(exception, response, data);
      };
    }

    function get(path, params, token, callback) {
      oAuth.get(baseURI + path + '?' + querystring.stringify(params),
                token.oauth_token, token.oauth_token_secret, requestCallback(callback));
    }

    function post(path, params, token, callback) {
      oAuth.post(baseURI + path, token.oauth_token, token.oauth_token_secret,
                 params, null, requestCallback(callback));
    }

    // PUBLIC
    client.apiCall = function (method, path, params, callback) {
      var token = params.token;
      delete params.token;
      if (method === 'GET') get(path, params, token, callback);
      else if (method === 'POST') post(path, params, token, callback);
    }

{'fraction_non_alphanumeric': 0.14621131270010673, 'fraction_numerical': 0.005869797225186766, 'mean_word_length': 2.7303482587064676, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '6159909', 'n_tokens_mistral': 1154, 'n_tokens_neox': 1117, 'n_words': 269}