'use strict';

var request = require('request');
var dns = require('dns');
var shouldBeTelemetry = false;

exports.record = function (logkey, gokey) {
  if (!shouldBeTelemetry) {
    return;
  }
  var url = 'http://gm.mmstat.com' + logkey + '?';
  for (var i in gokey) {
    if (gokey.hasOwnProperty(i)) {
      url += i + '=' + gokey[i] + '&';
    }
  }
  url += 't=' + new Date().getTime();
  dns.resolve('gm.mmstat.com', function (err) {
    if (!err) {
      request.get(url);
    }
  });
};

exports.allowTarck = function () {
  shouldBeTelemetry = true;
};