/* eslint dot-notation: 'off' */
'use strict';
var package_json = require('./../package.json');
var emptyRequest = require('sendgrid-rest').emptyRequest;
var Client = require('sendgrid-rest').Client;
var SendGridError = require('./helpers/error');

//Helper to check if response is valid
function isValidResponse(response) {
  return (
    response &&
    response.statusCode &&
    response.statusCode >= 200 &&
    response.statusCode <= 299
  );
}

//Helper to get a new empty request
function getEmptyRequest() {
  return JSON.parse(JSON.stringify(emptyRequest));
}

// SendGrid allows for quick and easy access to the v3 Web API
function SendGrid(apiKey, host, globalHeaders) {
  var globalRequest = getEmptyRequest();
  globalRequest.host = host || 'api.sendgrid.com';
  globalRequest.headers['Authorization'] = 'Bearer '.concat(apiKey);
  globalRequest.headers['Accept'] = 'application/json';
  globalRequest.headers['User-Agent'] =
    'sendgrid/' + package_json.version + ';nodejs';
  if (globalHeaders) {
    for (var obj in globalHeaders) {
      if (globalHeaders.hasOwnProperty(obj) &&
        typeof globalHeaders[obj] === 'object') {
        for (var key in globalHeaders[obj]) {
          if (globalHeaders[obj].hasOwnProperty(key)) {
            globalRequest.headers[key] = globalHeaders[obj][key];
          }
        }
      }
    }
  }
  var client = new Client(globalRequest);

  //Interact with the API with this function
  this.API = function(request, callback) {

    //If no callback provided, we will return a promise
    if (!callback) {
      if (!SendGrid.Promise) {
        throw new SendGridError('Promise API not supported');
      }
      return new SendGrid.Promise(function(resolve, reject) {
        client.API(request, function(response) {
          if (isValidResponse(response)) {
            resolve(response);
          }
          else {
            reject(response);
          }
        });
      });
    }

    //Use callback
    client.API(request, function(response) {
      if (isValidResponse(response)) {
        callback(null, response);
      }
      else {
        var error = new SendGridError('Response error');
        callback(error, response);
      }
    });
  };

  this.emptyRequest = getEmptyRequest;
  this.globalRequest = globalRequest;
  return this;
}

//Try to use native promises by default
SendGrid.Promise = Promise || null;

module.exports = {
  SendGrid: SendGrid,
  emptyRequest: getEmptyRequest(),
};

@@ -506,28 +506,39 @@
 Request(
+data
 ) %7B%0A  
-return
+let request =
  JSON.pa
@@ -576,99 +576,270 @@
 ));%0A
-%7D%0A%0A// SendGrid allows for quick and easy access to the v3 Web API%0Afunction SendGrid
+  if (data && typeof data === 'object') %7B%0A    for (var key in data) %7B%0A      if (data.hasOwnProperty(key)) %7B%0A        request%5Bkey%5D = JSON.parse(JSON.stringify(data%5Bkey%5D));%0A      %7D%0A    %7D%0A  %7D%0A  return request;%0A%7D%0A%0A//Helper to make headers%0Afunction makeHeaders
 (apiKey,
  hos
@@ -838,14 +838,8 @@
 Key,
- host,
  glo
@@ -862,110 +862,24 @@
 var 
-globalRequest = getEmptyRequest();%0A  globalRequest.host = host %7C%7C 'api.sendgrid.com';%0A  globalRequest.
+headers = %7B%7D;%0A  
 head
@@ -925,38 +925,24 @@
 (apiKey);%0A  
-globalRequest.
 headers%5B'Acc
@@ -971,30 +971,16 @@
 son';%0A  
-globalRequest.
 headers%5B
@@ -994,20 +994,16 @@
 gent'%5D =
-%0A   
  'sendgr
@@ -1318,22 +1318,8 @@
     
-globalRequest.
 head
@@ -1394,16 +1394,335 @@
   %7D%0A  %7D%0A
+  return headers;%0A%7D%0A%0A//SendGrid allows for quick and easy access to the v3 Web API%0Afunction SendGrid(apiKey, host, globalHeaders) %7B%0A%0A  //Create global request%0A  var globalRequest = getEmptyRequest(%7B%0A    host: host %7C%7C 'api.sendgrid.com',%0A    headers: makeHeaders(apiKey, globalHeaders),%0A  %7D);%0A%0A  //Initialize new client%0A
   var cl
@@ -2580,16 +2580,33 @@
 ;%0A  %7D;%0A%0A
+  //Set requests%0A
   this.e
@@ -2769,16 +2769,25 @@
  null;%0A%0A
+//Export%0A
 module.e

Add helpers