add twilio capability
This commit is contained in:
parent
b9551e7b8a
commit
bd497902f0
22
lib/apis.js
22
lib/apis.js
|
@ -318,6 +318,7 @@ module.exports.create = function (xconfx, apiFactories, apiDeps) {
|
||||||
var _stripe_test;
|
var _stripe_test;
|
||||||
var _mandrill;
|
var _mandrill;
|
||||||
var _mailchimp;
|
var _mailchimp;
|
||||||
|
var _twilio;
|
||||||
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', {
|
||||||
|
@ -429,6 +430,27 @@ module.exports.create = function (xconfx, apiFactories, apiDeps) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
var caps = {
|
||||||
|
'com.daplie.tel.twilio': function (/*opts*/) {
|
||||||
|
if (_twilio) {
|
||||||
|
return _twilio;
|
||||||
|
}
|
||||||
|
|
||||||
|
var Twilio = require('twilio');
|
||||||
|
_twilio = new Twilio.RestClient(siteConfig['twilio.com'].id, siteConfig['twilio.com'].auth);
|
||||||
|
return apiDeps.Promise.resolve(_twilio);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
req.getSiteCapability = function (capname, opts) {
|
||||||
|
if (caps[capname]) {
|
||||||
|
return caps[capname](opts);
|
||||||
|
}
|
||||||
|
return apiDeps.Promise.reject(
|
||||||
|
new Error("['" + req.clientApiUri + '/' + pkgId + "'] "
|
||||||
|
+ "capability '" + capname + "' not implemented")
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
req._walnutOriginalUrl = req.url;
|
req._walnutOriginalUrl = req.url;
|
||||||
// "/path/api/com.example/hello".replace(/.*\/api\//, '').replace(/([^\/]*\/+)/, '/') => '/hello'
|
// "/path/api/com.example/hello".replace(/.*\/api\//, '').replace(/([^\/]*\/+)/, '/') => '/hello'
|
||||||
req.url = req.url.replace(/\/api\//, '').replace(/.*\/api\//, '').replace(/([^\/]*\/+)/, '/');
|
req.url = req.url.replace(/\/api\//, '').replace(/.*\/api\//, '').replace(/([^\/]*\/+)/, '/');
|
||||||
|
|
Loading…
Reference in New Issue