You're Invited: Meet the Socket team at BSidesSF and RSAC - April 27 - May 1.RSVP

gofer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gofer - npm Package Compare versions

Comparing version

to
2.3.2

@@ -0,1 +1,5 @@

2.3.2
-----
* Make sure to be compatible with older hubs - @jkrems #32
2.3.1

@@ -2,0 +6,0 @@ -----

@@ -34,5 +34,7 @@ // Generated by CoffeeScript 1.9.0

*/
var Gofer, Hub, applyBaseUrl, buildUserAgent, cleanObject, extend, merge, parseDefaults, resolveOptional, _ref,
var Gofer, Hub, applyBaseUrl, buildUserAgent, cleanObject, extend, isJsonResponse, merge, parseDefaults, resolveOptional, safeParseJSON, _ref, _ref1,
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
extend = require('lodash').extend;
Hub = require('./hub');

@@ -42,10 +44,10 @@

extend = require('lodash').extend;
_ref1 = require('./json'), safeParseJSON = _ref1.safeParseJSON, isJsonResponse = _ref1.isJsonResponse;
Gofer = (function() {
function Gofer(config, _at_hub) {
var _ref1;
var _ref2;
this.hub = _at_hub;
this.request = __bind(this.request, this);
_ref1 = parseDefaults(config, this.serviceName), this.defaults = _ref1.defaults, this.endpointDefaults = _ref1.endpointDefaults;
_ref2 = parseDefaults(config, this.serviceName), this.defaults = _ref2.defaults, this.endpointDefaults = _ref2.endpointDefaults;
if (this.hub == null) {

@@ -57,9 +59,9 @@ this.hub = Hub();

Gofer.prototype["with"] = function(overrides) {
var copy, endpointDefaults, endpointName, _ref1;
var copy, endpointDefaults, endpointName, _ref2;
copy = new this.constructor({}, this.hub);
copy.defaults = merge(this.defaults, overrides);
copy.endpointDefaults = {};
_ref1 = this.endpointDefaults;
for (endpointName in _ref1) {
endpointDefaults = _ref1[endpointName];
_ref2 = this.endpointDefaults;
for (endpointName in _ref2) {
endpointDefaults = _ref2[endpointName];
copy.endpointDefaults[endpointName] = merge(endpointDefaults, overrides);

@@ -75,4 +77,4 @@ }

Gofer.prototype.request = function(uri, options, cb) {
var _ref1;
_ref1 = resolveOptional(uri, options, cb), options = _ref1.options, cb = _ref1.cb;
var _ref2;
_ref2 = resolveOptional(uri, options, cb), options = _ref2.options, cb = _ref2.cb;
return this._request(options, cb);

@@ -82,4 +84,4 @@ };

Gofer.prototype.put = function(uri, options, cb) {
var _ref1;
_ref1 = resolveOptional(uri, options, cb), options = _ref1.options, cb = _ref1.cb;
var _ref2;
_ref2 = resolveOptional(uri, options, cb), options = _ref2.options, cb = _ref2.cb;
options.method = 'PUT';

@@ -90,4 +92,4 @@ return this._request(options, cb);

Gofer.prototype.del = function(uri, options, cb) {
var _ref1;
_ref1 = resolveOptional(uri, options, cb), options = _ref1.options, cb = _ref1.cb;
var _ref2;
_ref2 = resolveOptional(uri, options, cb), options = _ref2.options, cb = _ref2.cb;
options.method = 'DELETE';

@@ -98,4 +100,4 @@ return this._request(options, cb);

Gofer.prototype.head = function(uri, options, cb) {
var _ref1;
_ref1 = resolveOptional(uri, options, cb), options = _ref1.options, cb = _ref1.cb;
var _ref2;
_ref2 = resolveOptional(uri, options, cb), options = _ref2.options, cb = _ref2.cb;
options.method = 'HEAD';

@@ -106,4 +108,4 @@ return this._request(options, cb);

Gofer.prototype.post = function(uri, options, cb) {
var _ref1;
_ref1 = resolveOptional(uri, options, cb), options = _ref1.options, cb = _ref1.cb;
var _ref2;
_ref2 = resolveOptional(uri, options, cb), options = _ref2.options, cb = _ref2.cb;
options.method = 'POST';

@@ -114,4 +116,4 @@ return this._request(options, cb);

Gofer.prototype.patch = function(uri, options, cb) {
var _ref1;
_ref1 = resolveOptional(uri, options, cb), options = _ref1.options, cb = _ref1.cb;
var _ref2;
_ref2 = resolveOptional(uri, options, cb), options = _ref2.options, cb = _ref2.cb;
options.method = 'PATCH';

@@ -160,4 +162,4 @@ return this._request(options, cb);

return function(uri, options, cb) {
var _ref1;
_ref1 = resolveOptional(uri, options, cb), options = _ref1.options, cb = _ref1.cb;
var _ref2;
_ref2 = resolveOptional(uri, options, cb), options = _ref2.options, cb = _ref2.cb;
options = merge(defaults, options);

@@ -189,6 +191,6 @@ return _this._request(options, cb);

Gofer.prototype._request = function(options, cb) {
var defaults, err, _base, _ref1;
var defaults, err, _base, _ref2;
defaults = this._getDefaults(this.defaults, options);
if (options.methodName == null) {
options.methodName = ((_ref1 = options.method) != null ? _ref1 : 'get').toLowerCase();
options.methodName = ((_ref2 = options.method) != null ? _ref2 : 'get').toLowerCase();
}

@@ -229,4 +231,9 @@ if (this.serviceName != null) {

if (typeof cb === 'function') {
return this.hub.fetch(options, function(err, body, response, responseData) {
return cb(err, body, responseData, response);
return this.hub.fetch(options, function(error, body, response, responseData) {
var parseJSON, _ref3, _ref4;
parseJSON = (_ref3 = options.parseJSON) != null ? _ref3 : isJsonResponse(response, body);
if (parseJSON) {
_ref4 = safeParseJSON(body, response), error = _ref4.error, body = _ref4.body;
}
return cb(error, body, responseData, response);
});

@@ -233,0 +240,0 @@ } else {

@@ -92,3 +92,3 @@ // Generated by CoffeeScript 1.9.0

if (parseJSON) {
_ref4 = safeParseJSON(body), error = _ref4.error, body = _ref4.result;
_ref4 = safeParseJSON(body, response), error = _ref4.error, body = _ref4.body;
}

@@ -95,0 +95,0 @@ responseData.fetchDuration = getSeconds();

@@ -34,6 +34,9 @@ // Generated by CoffeeScript 1.9.0

*/
var jsonHeader, nonEmpty;
var GOFER_PARSED, jsonHeader, nonEmpty;
this.safeParseJSON = function(str) {
GOFER_PARSED = 'GOFER_PARSED_RESPONSE';
this.safeParseJSON = function(str, res) {
var data, err;
res[GOFER_PARSED] = true;
data = {

@@ -43,7 +46,7 @@ error: null

try {
data.result = 'string' === typeof str ? JSON.parse(str) : str != null ? str : '';
data.body = 'string' === typeof str ? JSON.parse(str) : str != null ? str : '';
} catch (_error) {
err = _error;
data.error = err;
data.result = str;
data.body = str;
}

@@ -54,4 +57,4 @@ return data;

jsonHeader = function(res) {
var contentType, _ref;
contentType = res != null ? (_ref = res.headers) != null ? _ref['content-type'] : void 0 : void 0;
var contentType;
contentType = res.headers['content-type'];
if (contentType == null) {

@@ -68,3 +71,9 @@ return false;

this.isJsonResponse = function(res, body) {
if (!(res != null ? res.headers : void 0)) {
return false;
}
if (res[GOFER_PARSED]) {
return false;
}
return jsonHeader(res) && nonEmpty(body);
};
{
"name": "gofer",
"version": "2.3.1",
"version": "2.3.2",
"description": "A general purpose service client library for node.js",

@@ -5,0 +5,0 @@ "main": "lib/gofer.js",