added code to support GetResponse.com as a contacts/lists manager
This commit is contained in:
		
							parent
							
								
									d4674971da
								
							
						
					
					
						commit
						f246cf0b93
					
				
							
								
								
									
										57
									
								
								lib/apis.js
									
									
									
									
									
								
							
							
						
						
									
										57
									
								
								lib/apis.js
									
									
									
									
									
								
							@ -3,6 +3,7 @@
 | 
				
			|||||||
module.exports.create = function (xconfx, apiFactories, apiDeps) {
 | 
					module.exports.create = function (xconfx, apiFactories, apiDeps) {
 | 
				
			||||||
  var PromiseA = apiDeps.Promise;
 | 
					  var PromiseA = apiDeps.Promise;
 | 
				
			||||||
  var mkdirpAsync = PromiseA.promisify(require('mkdirp'));
 | 
					  var mkdirpAsync = PromiseA.promisify(require('mkdirp'));
 | 
				
			||||||
 | 
					  var request = PromiseA.promisify(require('request'));
 | 
				
			||||||
  //var express = require('express');
 | 
					  //var express = require('express');
 | 
				
			||||||
  var express = require('express-lazy');
 | 
					  var express = require('express-lazy');
 | 
				
			||||||
  var fs = PromiseA.promisifyAll(require('fs'));
 | 
					  var fs = PromiseA.promisifyAll(require('fs'));
 | 
				
			||||||
@ -320,6 +321,7 @@ module.exports.create = function (xconfx, apiFactories, apiDeps) {
 | 
				
			|||||||
        var _mandrill;
 | 
					        var _mandrill;
 | 
				
			||||||
        var _mailchimp;
 | 
					        var _mailchimp;
 | 
				
			||||||
        var _twilio;
 | 
					        var _twilio;
 | 
				
			||||||
 | 
					        var _get_response;
 | 
				
			||||||
        myApp.use('/', function preHandler(req, res, next) {
 | 
					        myApp.use('/', function preHandler(req, res, next) {
 | 
				
			||||||
          return getSiteConfig(clientUrih).then(function (siteConfig) {
 | 
					          return getSiteConfig(clientUrih).then(function (siteConfig) {
 | 
				
			||||||
            Object.defineProperty(req, 'getSiteMailer', {
 | 
					            Object.defineProperty(req, 'getSiteMailer', {
 | 
				
			||||||
@ -435,6 +437,51 @@ module.exports.create = function (xconfx, apiFactories, apiDeps) {
 | 
				
			|||||||
              }
 | 
					              }
 | 
				
			||||||
            });
 | 
					            });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            Object.defineProperty(req, 'GetResponse', {
 | 
				
			||||||
 | 
					              enumerable: true
 | 
				
			||||||
 | 
					            , configurable: false
 | 
				
			||||||
 | 
					            , get: function () {
 | 
				
			||||||
 | 
					                if (_get_response) {
 | 
				
			||||||
 | 
					                  return _get_response;
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					                _get_response = {
 | 
				
			||||||
 | 
					                  saveSubscriber: function (email, opts) {
 | 
				
			||||||
 | 
					                    var config = siteConfig['getresponse@daplie.com'];
 | 
				
			||||||
 | 
					                    var customFields = [];
 | 
				
			||||||
 | 
					                    Object.keys(config.customFields).forEach(function (name) {
 | 
				
			||||||
 | 
					                      if (typeof opts[name] !== 'undefined') {
 | 
				
			||||||
 | 
					                        customFields.push({
 | 
				
			||||||
 | 
					                          customFieldId: config.customFields[name]
 | 
				
			||||||
 | 
					                        , value: [ String(opts[name]) ]
 | 
				
			||||||
 | 
					                        });
 | 
				
			||||||
 | 
					                      }
 | 
				
			||||||
 | 
					                    });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                    return request({
 | 
				
			||||||
 | 
					                      method: 'POST'
 | 
				
			||||||
 | 
					                    , url: 'https://api.getresponse.com/v3/contacts'
 | 
				
			||||||
 | 
					                    , headers: { 'X-Auth-Token': 'api-key ' + config.apiKey }
 | 
				
			||||||
 | 
					                    , json: true
 | 
				
			||||||
 | 
					                    , body: {
 | 
				
			||||||
 | 
					                        name: opts.name
 | 
				
			||||||
 | 
					                      , email: email
 | 
				
			||||||
 | 
					                      , ipAddress: opts.ipAddress
 | 
				
			||||||
 | 
					                      , campaign: { campaignId: config.campaignId }
 | 
				
			||||||
 | 
					                      , customFieldValues: customFields
 | 
				
			||||||
 | 
					                      }
 | 
				
			||||||
 | 
					                    }).then(function (resp) {
 | 
				
			||||||
 | 
					                      if (resp.statusCode === 202) {
 | 
				
			||||||
 | 
					                        return;
 | 
				
			||||||
 | 
					                      }
 | 
				
			||||||
 | 
					                      return PromiseA.reject(resp.body.message);
 | 
				
			||||||
 | 
					                    });
 | 
				
			||||||
 | 
					                  }
 | 
				
			||||||
 | 
					                };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                return _get_response;
 | 
				
			||||||
 | 
					              }
 | 
				
			||||||
 | 
					            });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            var Twilio = require('twilio');
 | 
					            var Twilio = require('twilio');
 | 
				
			||||||
            function twilioTel(/*opts*/) {
 | 
					            function twilioTel(/*opts*/) {
 | 
				
			||||||
              if (_twilio) {
 | 
					              if (_twilio) {
 | 
				
			||||||
@ -496,6 +543,9 @@ module.exports.create = function (xconfx, apiFactories, apiDeps) {
 | 
				
			|||||||
            function mailgunMail(/*opts*/) {
 | 
					            function mailgunMail(/*opts*/) {
 | 
				
			||||||
              return apiDeps.Promise.resolve(req.getSiteMailer());
 | 
					              return apiDeps.Promise.resolve(req.getSiteMailer());
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					            function getResponseList() {
 | 
				
			||||||
 | 
					              return apiDeps.Promise.resolve(req.GetResponse);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            // Twilio Parameters are often 26 long
 | 
					            // Twilio Parameters are often 26 long
 | 
				
			||||||
            var bodyParserTwilio = require('body-parser').urlencoded({ limit: '4kb', parameterLimit: 100, extended: false });
 | 
					            var bodyParserTwilio = require('body-parser').urlencoded({ limit: '4kb', parameterLimit: 100, extended: false });
 | 
				
			||||||
@ -560,6 +610,7 @@ module.exports.create = function (xconfx, apiFactories, apiDeps) {
 | 
				
			|||||||
            , 'twilio@daplie.com': twilioTel      // specifically twilio
 | 
					            , 'twilio@daplie.com': twilioTel      // specifically twilio
 | 
				
			||||||
            , 'com.daplie.tel.twilio': twilioTel  // deprecated alias
 | 
					            , 'com.daplie.tel.twilio': twilioTel  // deprecated alias
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            , 'getresponse@daplie.com': getResponseList
 | 
				
			||||||
              //
 | 
					              //
 | 
				
			||||||
              // Webhook Parsers
 | 
					              // Webhook Parsers
 | 
				
			||||||
              //
 | 
					              //
 | 
				
			||||||
@ -642,6 +693,12 @@ module.exports.create = function (xconfx, apiFactories, apiDeps) {
 | 
				
			|||||||
              if (caps[capname]) {
 | 
					              if (caps[capname]) {
 | 
				
			||||||
                return caps[capname](opts, b, c);
 | 
					                return caps[capname](opts, b, c);
 | 
				
			||||||
              }
 | 
					              }
 | 
				
			||||||
 | 
					              if (siteConfig[capname]) {
 | 
				
			||||||
 | 
					                var service = siteConfig[capname].service || siteConfig[capname];
 | 
				
			||||||
 | 
					                if (caps[service]) {
 | 
				
			||||||
 | 
					                  return caps[service](opts, b, c);
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					              }
 | 
				
			||||||
              return apiDeps.Promise.reject(
 | 
					              return apiDeps.Promise.reject(
 | 
				
			||||||
                new Error("['" + req.clientApiUri + '/' + pkgId + "'] "
 | 
					                new Error("['" + req.clientApiUri + '/' + pkgId + "'] "
 | 
				
			||||||
                  + "capability '" + capname + "' not implemented")
 | 
					                  + "capability '" + capname + "' not implemented")
 | 
				
			||||||
 | 
				
			|||||||
@ -60,6 +60,7 @@
 | 
				
			|||||||
    "nodemailer": "^1.4.0",
 | 
					    "nodemailer": "^1.4.0",
 | 
				
			||||||
    "nodemailer-mailgun-transport": "1.x",
 | 
					    "nodemailer-mailgun-transport": "1.x",
 | 
				
			||||||
    "oauthcommon": "git+https://git.daplie.com/node/oauthcommon.git",
 | 
					    "oauthcommon": "git+https://git.daplie.com/node/oauthcommon.git",
 | 
				
			||||||
 | 
					    "request": "^2.81.0",
 | 
				
			||||||
    "serve-static": "1.x",
 | 
					    "serve-static": "1.x",
 | 
				
			||||||
    "sqlite3-cluster": "git+https://git.daplie.com/coolaj86/sqlite3-cluster.git#v2",
 | 
					    "sqlite3-cluster": "git+https://git.daplie.com/coolaj86/sqlite3-cluster.git#v2",
 | 
				
			||||||
    "stripe": "^4.22.0",
 | 
					    "stripe": "^4.22.0",
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user