Socket
Socket
Sign inDemoInstall

heroku-client

Package Overview
Dependencies
Maintainers
1
Versions
72
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

heroku-client - npm Package Compare versions

Comparing version 0.2.0 to 0.3.0

lib/resourceBuilder.js

120

lib/heroku.js

@@ -1,111 +0,25 @@

var inflection = require('inflection'),
client = require('./request'),
resources = require('./resources').resources,
_ = require('underscore');
var client = require('./request'),
_ = require('underscore');
exports.request = client.request;
exports.Heroku = Heroku;
module.exports = Heroku;
function Heroku(options) {
this.request = function(_options, callback) {
if (typeof _options === 'function') {
callback = _options;
_options = options;
} else {
_options = _.extend(_.clone(options), _options);
}
return client.request(_options, function(err, body) {
if (callback) callback(err, body);
});
};
function Heroku (options) {
this.options = options;
}
_.each(resources, function (resource) {
buildResource(resource);
});
Heroku.request = client.request;
function buildResource (resource) {
_.each(resource.actions, function (action, actionName) {
buildAction(action, actionName);
});
}
Heroku.prototype.request = function (options, callback) {
if (typeof options === 'function') {
callback = options;
options = this.options;
} else {
options = _.extend(_.clone(this.options), options);
}
function buildAction (action, actionName) {
var constructor = getResource(action.path);
constructor.prototype[getName(actionName)] = function (body, callback) {
var requestPath = action.path,
callback;
this.params.forEach(function (param) {
requestPath = requestPath.replace(/{[a-z_]+}/, param);
});
var options = {
method: action.method,
path: requestPath,
expectedStatus: action.statuses
};
if (typeof arguments[0] === 'function') {
callback = body;
} else if (typeof arguments[0] === 'object') {
options = _.extend(options, { body: body });
}
return this.client.request(options, callback);
};
}
function getResource(path) {
var proxy = Heroku,
segments;
path = path.split(/\//);
segments = path.slice(1, path.length);
segments.forEach(function (segment) {
var constructor;
if (proxy.prototype && proxy.prototype[segment]) {
return proxy = proxy.prototype[segment]._constructor;
}
if (!segment.match(/{.*}/)) {
constructor = function (client, params) {
this.client = client;
this.params = params;
};
proxy.prototype[segment] = function (param) {
var client, params, resource;
if (this instanceof Heroku) {
client = this;
} else {
client = this.client;
}
params = this.params || [];
if (param) params = params.concat(param);
return new constructor(client, params);
};
proxy.prototype[segment]._constructor = constructor;
return proxy = constructor;
}
return Heroku.request(options, function (err, body) {
if (callback) callback(err, body);
});
};
return proxy;
}
function getName(name) {
name = name.toLowerCase();
name = inflection.dasherize(name).replace(/-/g, '_');
name = inflection.camelize(name, true);
return name;
}
require('./resourceBuilder').build();
{
"name": "heroku-client",
"version": "0.2.0",
"version": "0.3.0",
"description": "A wrapper for the Heroku v3 API",

@@ -11,3 +11,3 @@ "main": "./lib/heroku.js",

"type": "git",
"url": "https://github.com/jclem/node-heroku"
"url": "https://github.com/jclem/node-heroku-client"
},

@@ -20,3 +20,3 @@ "keywords": [

"bugs": {
"url": "https://github.com/jclem/node-heroku/issues"
"url": "https://github.com/jclem/node-heroku-client/issues"
},

@@ -29,5 +29,5 @@ "devDependencies": {

"memjs": "~0.6.0",
"underscore": "~1.5.1",
"inflection": "~1.2.6"
"inflection": "~1.2.6",
"underscore": "~1.5.1"
}
}

@@ -9,4 +9,4 @@ # heroku-client [![Build Status](https://travis-ci.org/jclem/node-heroku-client.png?branch=master)](https://travis-ci.org/jclem/node-heroku-client)

// Create a new client and give it an API token
var Heroku = require('heroku-client').Heroku;
heroku = new Heroku({ token: user.apiToken });
var Heroku = require('heroku-client')
, heroku = new Heroku({ token: user.apiToken });

@@ -13,0 +13,0 @@ heroku.apps().list(function (err, apps) {

@@ -1,8 +0,7 @@

var client = require('../../lib/request'),
herokuModule = require('../../lib/heroku'),
heroku = new herokuModule.Heroku({ key: '12345' });
var Heroku = require('../../lib/heroku'),
heroku = new Heroku({ token: '12345' });
describe('Heroku', function() {
beforeEach(function() {
spyOn(client, 'request').andCallFake(function(options, callback) {
spyOn(Heroku, 'request').andCallFake(function(options, callback) {
callback();

@@ -14,3 +13,3 @@ });

heroku.apps('my-app').create({}, function() {
expect(client.request.mostRecentCall.args[0].method).toEqual('POST');
expect(Heroku.request.mostRecentCall.args[0].method).toEqual('POST');
done();

@@ -22,3 +21,3 @@ });

heroku.apps('my-app').dynos().list(function() {
expect(client.request.mostRecentCall.args[0].expectedStatus).toEqual([200, 206]);
expect(Heroku.request.mostRecentCall.args[0].expectedStatus).toEqual([200, 206]);
done();

@@ -31,3 +30,3 @@ });

heroku.apps().list(function() {
expect(client.request.mostRecentCall.args[0].path).toEqual('/apps');
expect(Heroku.request.mostRecentCall.args[0].path).toEqual('/apps');
done();

@@ -39,3 +38,3 @@ });

heroku.apps('my-app').info(function() {
expect(client.request.mostRecentCall.args[0].path).toEqual('/apps/my-app');
expect(Heroku.request.mostRecentCall.args[0].path).toEqual('/apps/my-app');
done();

@@ -47,3 +46,3 @@ });

heroku.apps('my-app').collaborators('jonathan@heroku.com').info(function() {
expect(client.request.mostRecentCall.args[0].path).toEqual('/apps/my-app/collaborators/jonathan@heroku.com');
expect(Heroku.request.mostRecentCall.args[0].path).toEqual('/apps/my-app/collaborators/jonathan@heroku.com');
done();

@@ -57,3 +56,3 @@ });

heroku.apps().create({ name: 'my-app' }, function() {
expect(client.request.mostRecentCall.args[0].path).toEqual('/apps');
expect(Heroku.request.mostRecentCall.args[0].path).toEqual('/apps');
done();

@@ -65,3 +64,3 @@ });

heroku.apps().create({ name: 'my-new-app' }, function() {
expect(client.request.mostRecentCall.args[0].body).toEqual({ name: 'my-new-app' });
expect(Heroku.request.mostRecentCall.args[0].body).toEqual({ name: 'my-new-app' });
done();

@@ -75,3 +74,3 @@ });

heroku.apps('my-app').addons().create({ name: 'papertrail:choklad' }, function() {
expect(client.request.mostRecentCall.args[0].path).toEqual('/apps/my-app/addons');
expect(Heroku.request.mostRecentCall.args[0].path).toEqual('/apps/my-app/addons');
done();

@@ -83,3 +82,3 @@ });

heroku.apps('my-app').addons().create({ name: 'papertrail:choklad' }, function() {
expect(client.request.mostRecentCall.args[0].body).toEqual({ name: 'papertrail:choklad' });
expect(Heroku.request.mostRecentCall.args[0].body).toEqual({ name: 'papertrail:choklad' });
done();

@@ -93,3 +92,3 @@ });

heroku.apps('my-app').addons('papertrail:choklad').update({ name: 'papertrail:fixa' }, function() {
expect(client.request.mostRecentCall.args[0].path).toEqual('/apps/my-app/addons/papertrail:choklad');
expect(Heroku.request.mostRecentCall.args[0].path).toEqual('/apps/my-app/addons/papertrail:choklad');
done();

@@ -101,3 +100,3 @@ });

heroku.apps('my-app').addons('papertrail:choklad').update({ name: 'papertrail:fixa' }, function() {
expect(client.request.mostRecentCall.args[0].body).toEqual({ name: 'papertrail:fixa' });
expect(Heroku.request.mostRecentCall.args[0].body).toEqual({ name: 'papertrail:fixa' });
done();

@@ -104,0 +103,0 @@ });

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