Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

resource-client

Package Overview
Dependencies
Maintainers
2
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

resource-client - npm Package Compare versions

Comparing version 2.0.0 to 2.1.0

2

lib/default_actions.js

@@ -1,2 +0,2 @@

// Generated by CoffeeScript 1.8.0
// Generated by CoffeeScript 1.9.3
module.exports = {

@@ -3,0 +3,0 @@ 'get': {

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

// Generated by CoffeeScript 1.8.0
var defaultActions, request, resourceClient, urlBuilder, _,
__slice = [].slice;
// Generated by CoffeeScript 1.9.3
var Promise, _, defaultActions, request, resourceClient, urlBuilder,
slice = [].slice;
Promise = require('bluebird');
request = require('request');

@@ -35,3 +37,3 @@

Resource.action = function(actionName, actionOptions) {
var actionRequest, actionUrl, _ref;
var actionRequest, actionUrl, ref;
actionOptions.params = {};

@@ -49,14 +51,28 @@ actionUrl = actionOptions.url || resourceOptions.url;

return Resource[actionName] = function() {
var done, opts, requestOptions, requestParams, _i;
opts = 2 <= arguments.length ? __slice.call(arguments, 0, _i = arguments.length - 1) : (_i = 0, []), done = arguments[_i++];
requestParams = opts.shift() || {};
requestOptions = opts.pop() || {};
requestOptions.url = (function() {
var mergedParams;
mergedParams = _.assign({}, resourceOptions.params, actionOptions.params, requestParams);
return urlBuilder.build(actionUrl, mergedParams);
})();
return actionRequest.get(requestOptions, function(err, response) {
return handleResponse(err, response, null, done);
});
var done, opts, promise;
opts = 1 <= arguments.length ? slice.call(arguments, 0) : [];
if (typeof opts[opts.length - 1] === 'function') {
done = opts.pop();
}
promise = new Promise((function(_this) {
return function(resolve, reject) {
var requestOptions, requestParams;
requestParams = opts.shift() || {};
requestOptions = opts.pop() || {};
requestOptions.url = (function() {
var mergedParams;
mergedParams = _.assign({}, resourceOptions.params, actionOptions.params, requestParams);
return urlBuilder.build(actionUrl, mergedParams);
})();
return actionRequest.get(requestOptions, function(err, response) {
return handleResponse({
err: err,
response: response,
resolve: resolve,
reject: reject
});
});
};
})(this));
return promise.nodeify(done);
};

@@ -68,21 +84,36 @@ } else if (actionOptions.method === 'GET' && actionOptions.isArray) {

*
* call w/ `({params}, {requestOptions}, callback)`
* OR `({params}, callback)`
* OR `(callback)`
* call w/ `({params}, {requestOptions}, [callback])`
* OR `({params}, [callback])`
* OR `([callback])`
*/
return Resource[actionName] = function() {
var done, opts, requestOptions, requestParams, _i;
opts = 2 <= arguments.length ? __slice.call(arguments, 0, _i = arguments.length - 1) : (_i = 0, []), done = arguments[_i++];
requestParams = opts.shift() || {};
requestOptions = opts.pop() || {};
requestOptions.url = (function() {
var mergedParams;
mergedParams = _.assign({}, resourceOptions.params, actionOptions.params, requestParams);
return urlBuilder.build(actionUrl, mergedParams);
})();
return actionRequest.get(requestOptions, function(err, response) {
return handleResponse(err, response, null, done, actionOptions);
});
var done, opts, promise;
opts = 1 <= arguments.length ? slice.call(arguments, 0) : [];
if (typeof opts[opts.length - 1] === 'function') {
done = opts.pop();
}
promise = new Promise((function(_this) {
return function(resolve, reject) {
var requestOptions, requestParams;
requestParams = opts.shift() || {};
requestOptions = opts.pop() || {};
requestOptions.url = (function() {
var mergedParams;
mergedParams = _.assign({}, resourceOptions.params, actionOptions.params, requestParams);
return urlBuilder.build(actionUrl, mergedParams);
})();
return actionRequest.get(requestOptions, function(err, response) {
return handleResponse({
err: err,
response: response,
resolve: resolve,
reject: reject,
actionOptions: actionOptions
});
});
};
})(this));
return promise.nodeify(done);
};
} else if ((_ref = actionOptions.method) === 'PUT' || _ref === 'POST' || _ref === 'DELETE') {
} else if ((ref = actionOptions.method) === 'PUT' || ref === 'POST' || ref === 'DELETE') {
return (function(methodFn) {

@@ -96,21 +127,35 @@ if (methodFn === 'delete') {

*
* call w/ `({params}, body, {requestOptions}, callback)`
* OR `({params}, body, callback)`
* OR `({params}, callback)`
* call w/ `({params}, body, {requestOptions}, [callback])`
* OR `({params}, body, [callback])`
* OR `({params}, [callback])`
*/
Resource[actionName] = function() {
var done, opts, requestBody, requestOptions, requestParams, _i;
opts = 2 <= arguments.length ? __slice.call(arguments, 0, _i = arguments.length - 1) : (_i = 0, []), done = arguments[_i++];
requestParams = opts.shift() || {};
requestBody = opts.shift() || {};
requestOptions = opts.pop() || {};
requestOptions.body = requestBody;
requestOptions.url = (function() {
var mergedParams;
mergedParams = _.assign({}, resourceOptions.params, actionOptions.params, requestParams);
return urlBuilder.build(actionUrl, mergedParams, requestOptions.body);
})();
return actionRequest[methodFn](requestOptions, function(err, response) {
return handleResponse(err, response, null, done);
});
var done, opts, promise;
opts = 1 <= arguments.length ? slice.call(arguments, 0) : [];
if (typeof opts[opts.length - 1] === 'function') {
done = opts.pop();
}
promise = new Promise((function(_this) {
return function(resolve, reject) {
var requestBody, requestOptions, requestParams;
requestParams = opts.shift() || {};
requestBody = opts.shift() || {};
requestOptions = opts.pop() || {};
requestOptions.body = requestBody;
requestOptions.url = (function() {
var mergedParams;
mergedParams = _.assign({}, resourceOptions.params, actionOptions.params, requestParams);
return urlBuilder.build(actionUrl, mergedParams, requestOptions.body);
})();
return actionRequest[methodFn](requestOptions, function(err, response) {
return handleResponse({
err: err,
response: response,
resolve: resolve,
reject: reject
});
});
};
})(this));
return promise.nodeify(done);
};

@@ -121,20 +166,35 @@

*
* call w/ `({params}, {requestOptions}, callback)`
* OR `({params}, callback)`
* OR `(callback)`
* call w/ `({params}, {requestOptions}, [callback])`
* OR `({params}, [callback])`
* OR `([callback])`
*/
return Resource.prototype[actionName] = function() {
var done, opts, requestOptions, requestParams, _i;
opts = 2 <= arguments.length ? __slice.call(arguments, 0, _i = arguments.length - 1) : (_i = 0, []), done = arguments[_i++];
requestParams = opts.shift() || {};
requestOptions = opts.pop() || {};
requestOptions.body = this;
requestOptions.url = (function() {
var mergedParams;
mergedParams = _.assign({}, resourceOptions.params, actionOptions.params, requestParams);
return urlBuilder.build(actionUrl, mergedParams, requestOptions.body);
})();
return actionRequest[methodFn](requestOptions, function(err, response) {
return handleResponse(err, response, this, done);
});
var done, i, opts, promise;
opts = 2 <= arguments.length ? slice.call(arguments, 0, i = arguments.length - 1) : (i = 0, []), done = arguments[i++];
if (typeof opts[opts.length - 1] === 'function') {
done = opts.pop();
}
promise = new Promise((function(_this) {
return function(resolve, reject) {
var requestOptions, requestParams;
requestParams = opts.shift() || {};
requestOptions = opts.pop() || {};
requestOptions.body = _this;
requestOptions.url = (function() {
var mergedParams;
mergedParams = _.assign({}, resourceOptions.params, actionOptions.params, requestParams);
return urlBuilder.build(actionUrl, mergedParams, requestOptions.body);
})();
return actionRequest[methodFn](requestOptions, function(err, response) {
return handleResponse({
err: err,
response: response,
originalObject: this,
resolve: resolve,
reject: reject
});
});
};
})(this));
return promise.nodeify(done);
};

@@ -144,4 +204,5 @@ })(actionOptions.method.toLowerCase());

};
handleResponse = function(err, response, originalObject, done, actionOptions) {
var errorMessage, resource, resources, _ref;
handleResponse = function(arg) {
var actionOptions, err, errorMessage, originalObject, ref, reject, resolve, resource, resources, response;
err = arg.err, response = arg.response, originalObject = arg.originalObject, resolve = arg.resolve, reject = arg.reject, actionOptions = arg.actionOptions;
if (actionOptions == null) {

@@ -151,4 +212,4 @@ actionOptions = {};

if (err) {
return done(err);
} else if ((200 <= (_ref = response.statusCode) && _ref < 300)) {
return reject(err);
} else if ((200 <= (ref = response.statusCode) && ref < 300)) {
if (Array.isArray(response.body)) {

@@ -161,12 +222,12 @@ resources = response.body.map(function(resource) {

}
return done(null, resources);
return resolve(resources);
} else {
resource = originalObject ? _.assign(originalObject, response.body) : new Resource(response.body);
return done(null, resource);
resource = originalObject != null ? _.assign(originalObject, response.body) : new Resource(response.body);
return resolve(resource);
}
} else if (response.statusCode === 404) {
return done(null, void 0);
return resolve(void 0);
} else {
errorMessage = JSON.stringify(response.body);
return done(new Error(errorMessage));
return reject(new Error(errorMessage));
}

@@ -173,0 +234,0 @@ };

@@ -1,2 +0,2 @@

// Generated by CoffeeScript 1.8.0
// Generated by CoffeeScript 1.9.3
var UrlAssembler, populateUrlParamsFromBody, stripRemainingUrlParams;

@@ -3,0 +3,0 @@

{
"name": "resource-client",
"version": "2.0.0",
"version": "2.1.0",
"description": "Easily create api clients for your server side resources.",

@@ -25,4 +25,5 @@ "author": "Good Eggs <open-source@goodeggs.com>",

"dependencies": {
"bluebird": "^2.9.30",
"lodash": "^3.0.0",
"request": "2.54.0",
"lodash": "^3.0.0",
"url-assembler": "0.0.3"

@@ -29,0 +30,0 @@ },

@@ -26,6 +26,15 @@ # Resource Client

Product.query({isActive: true}, function(err, products) {
product = products[0]
product.name = 'apple'
product.save()
product = products[0];
product.name = 'apple';
product.save();
});
// or with a promise...
Product.query({isActive: true}).then(function (products) {
product = products[0];
product.name = 'apple';
product.save();
}).catch(function (err) {
if (err) console.log err;
});
```

@@ -32,0 +41,0 @@

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc