<commit_before>var q = require('q');
var powerdrill = require('powerdrill');

var EmailProvider = function (apiKey) {
  if (!apiKey) { throw new Error('API key required'); }
  var _api = powerdrill(apiKey);

  this.sendHtml = function (from, to, subject, html) {
    var deferred = q.defer();
    var message = _api()
    .subject(subject)
    .to(to)
    .from(from)
    .html(html)
    .send(function (err, resp) {
      if (err) { deferred.reject(err); }
      else if (resp[0].status === 'rejected') {
        deferred.reject(new Error('Email rejected'));
      } else { deferred.resolve(); }
    });
    return deferred.promise;
  }
}

module.exports = EmailProvider;<commit_msg>feat(EmailProvider): send html and template emails<commit_after>var q = require('q');
var powerdrill = require('powerdrill');

var EmailProvider = function (apiKey) {
  if (!apiKey) { throw new Error('API key required'); }
  var _api = powerdrill(apiKey);
  var handleResponse = function (err, resp, deferred) {
      if (err) { deferred.reject(err); }
      else if (resp.status === 'error') {
        deferred.reject(new Error(resp.message));
      } else if (resp[0] && resp[0].status === 'invalid') {
        deferred.reject(new Error('Invalid email'));
      } else if (resp[0] && resp[0].status === 'rejected') {
        deferred.reject(new Error('Email rejected'));
      } else if (resp[0] && resp[0].status === 'sent') {
        deferred.resolve();
      } else { deferred.reject(new Error('Uknown error')); }
  }

  this.sendHtml = function (from, to, subject, html) {
    var deferred = q.defer();
    var message = _api()
    .subject(subject)
    .to(to)
    .from(from)
    .html(html)
    .send(function (err, resp) {
      handleResponse(err, resp, deferred);
    });
    return deferred.promise;
  };

  this.sendTemplate = function (from, to, id, data) {
    var deferred = q.defer();
    var message = _api()
    .to(to)
    .from(from)
    .template(id);
    for (var key in data) {
      if (data.hasOwnProperty(key)) {
        message.templateContent(key, data[key]);
      }
    }
    message.send(function (err, resp) {
      handleResponse(err, resp, deferred);
    });
    return deferred.promise
  };

  
}

module.exports = EmailProvider;
{'fraction_non_alphanumeric': 0.16355555555555557, 'fraction_numerical': 0.003111111111111111, 'mean_word_length': 2.984070796460177, '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': '1943198', 'n_tokens_mistral': 738, 'n_tokens_neox': 720, 'n_words': 178}