twilio-transport
Advanced tools
Comparing version 0.0.8 to 0.0.9-alpha.1
@@ -105,3 +105,3 @@ 'use strict'; | ||
_http: { value: request }, | ||
_useTwilsock: { get: () => this._twilsock && this._twilsock.isConnected } | ||
_twilsockIsAvailable: { get: () => this._twilsock && this._twilsock.isConnected } | ||
}); | ||
@@ -124,3 +124,3 @@ | ||
*/ | ||
Transport.prototype.get = function get(uri, headers) { | ||
Transport.prototype.get = function get(uri, headers, forceTwilsock) { | ||
if (this._activeGetRequests.has(uri)) { | ||
@@ -130,3 +130,3 @@ return this._activeGetRequests.get(uri); | ||
let promise = this._get(uri, headers).then((response) => { | ||
let promise = this._get(uri, headers, forceTwilsock).then((response) => { | ||
this._activeGetRequests.delete(uri); | ||
@@ -143,10 +143,29 @@ return response; | ||
function TwilsockUnavailableError() { | ||
Error.call(this); | ||
} | ||
TwilsockUnavailableError.prototype = Object.create(Error.prototype); | ||
Transport.prototype._oneOfBasedOnChannelAvailability = function _oneOfBasedOnChannelAvailability(sendingOptions, forceTwilsock) { | ||
const requestVia = (paths) => { | ||
const { sendViaTwilsock, sendDirectHttp } = paths; | ||
if (this._twilsockIsAvailable) { | ||
return sendViaTwilsock(); | ||
} else { | ||
return (!forceTwilsock) ? sendDirectHttp() | ||
: Promise.reject(new TwilsockUnavailableError()); | ||
} | ||
}; | ||
return requestVia(sendingOptions).then(lowercaseHeaders); | ||
}; | ||
/** | ||
* @private | ||
*/ | ||
Transport.prototype._get = function _get(uri, headers) { | ||
return (this._useTwilsock | ||
? this._twilsock.send(twilsockParams('GET', uri, headers)).then(adaptTwilsockResponse) | ||
: this._http.get(httpParams(uri, headers)).then(adaptHttpResponse)) | ||
.then(lowercaseHeaders); | ||
Transport.prototype._get = function _get(uri, headers, forceTwilsock) { | ||
return this._oneOfBasedOnChannelAvailability({ | ||
sendViaTwilsock: () => this._twilsock.send(twilsockParams('GET', uri, headers)).then(adaptTwilsockResponse), | ||
sendDirectHttp: () => this._http.get(httpParams(uri, headers)).then(adaptHttpResponse) | ||
}, forceTwilsock); | ||
}; | ||
@@ -158,7 +177,7 @@ | ||
*/ | ||
Transport.prototype.post = function post(uri, headers, body) { | ||
return (this._useTwilsock | ||
? this._twilsock.send(twilsockParams('POST', uri, headers, body)).then(adaptTwilsockResponse) | ||
: this._http.post(httpParams(uri, headers, body)).then(adaptHttpResponse)) | ||
.then(lowercaseHeaders); | ||
Transport.prototype.post = function post(uri, headers, body, forceTwilsock) { | ||
return this._oneOfBasedOnChannelAvailability({ | ||
sendViaTwilsock: () => this._twilsock.send(twilsockParams('POST', uri, headers, body)).then(adaptTwilsockResponse), | ||
sendDirectHttp: () => this._http.post(httpParams(uri, headers, body)).then(adaptHttpResponse) | ||
}, forceTwilsock); | ||
}; | ||
@@ -170,7 +189,7 @@ | ||
*/ | ||
Transport.prototype.put = function put(uri, headers, body) { | ||
return (this._useTwilsock | ||
? this._twilsock.send(twilsockParams('PUT', uri, headers, body)).then(adaptTwilsockResponse) | ||
: this._http.put(httpParams(uri, headers, body)).then(adaptHttpResponse)) | ||
.then(lowercaseHeaders); | ||
Transport.prototype.put = function put(uri, headers, body, forceTwilsock) { | ||
return this._oneOfBasedOnChannelAvailability({ | ||
sendViaTwilsock: () => this._twilsock.send(twilsockParams('PUT', uri, headers, body)).then(adaptTwilsockResponse), | ||
sendDirectHttp: () => this._http.put(httpParams(uri, headers, body)).then(adaptHttpResponse) | ||
}, forceTwilsock); | ||
}; | ||
@@ -182,7 +201,7 @@ | ||
*/ | ||
Transport.prototype.delete = function del(uri, headers) { | ||
return (this._useTwilsock | ||
? this._twilsock.send(twilsockParams('DELETE', uri, headers)).then(adaptTwilsockResponse) | ||
: this._http.delete(httpParams(uri, headers)).then(adaptHttpResponse)) | ||
.then(lowercaseHeaders); | ||
Transport.prototype.delete = function del(uri, headers, forceTwilsock) { | ||
return this._oneOfBasedOnChannelAvailability({ | ||
sendViaTwilsock: () => this._twilsock.send(twilsockParams('DELETE', uri, headers)).then(adaptTwilsockResponse), | ||
sendDirectHttp: () => this._http.delete(httpParams(uri, headers)).then(adaptHttpResponse) | ||
}, forceTwilsock); | ||
}; | ||
@@ -192,2 +211,3 @@ | ||
module.exports = Transport; | ||
module.exports.Transport = Transport; | ||
module.exports.TwilsockUnavailableError = TwilsockUnavailableError; |
{ | ||
"name": "twilio-transport", | ||
"version": "0.0.8", | ||
"version": "0.0.9-alpha.1", | ||
"description": "Twilio generic transport interface", | ||
@@ -32,3 +32,3 @@ "main": "lib/transport.js", | ||
"engines": { | ||
"node": ">=0.12" | ||
"node": ">=4" | ||
}, | ||
@@ -35,0 +35,0 @@ "browser": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
45654
762