heroku-client
Advanced tools
Comparing version 3.0.0-alpha1 to 3.0.0-alpha2
{ | ||
"name": "heroku-client", | ||
"description": "A wrapper for the Heroku v3 API", | ||
"version": "3.0.0-alpha1", | ||
"version": "3.0.0-alpha2", | ||
"author": "Jeff Dickey", | ||
@@ -17,5 +17,2 @@ "bugs": { | ||
"dependencies": { | ||
"inflection": "^1.7.0", | ||
"path-proxy": "^1.0", | ||
"q": "^1.2.0", | ||
"tunnel-agent": "^0.4.0" | ||
@@ -22,0 +19,0 @@ }, |
163
README.md
@@ -12,4 +12,2 @@ # heroku-client | ||
- [Usage](#usage) | ||
- [Generic Requests](#generic-requests) | ||
- [Promises](#promises) | ||
- [Generators](#generators) | ||
@@ -20,4 +18,2 @@ - [HTTP Proxies](#http-proxies) | ||
- [Contributing](#contributing) | ||
- [Updating resources](#updating-resources) | ||
- [Generating documentation](#generating-documentation) | ||
- [Running tests](#running-tests) | ||
@@ -31,12 +27,4 @@ | ||
## Documentation | ||
Docs are auto-generated and live in the | ||
[docs directory](https://github.com/heroku/node-heroku-client/tree/master/docs). | ||
## Usage | ||
`heroku-client` works by providing functions that return proxy objects for | ||
interacting with different resources through the Heroku API. | ||
To begin, require the Heroku module and create a client, passing in an API | ||
@@ -46,50 +34,6 @@ token: | ||
```javascript | ||
var Heroku = require('heroku-client'), | ||
heroku = new Heroku({ token: process.env.HEROKU_API_TOKEN }); | ||
const Heroku = require('heroku-client') | ||
const heroku = new Heroku({ token: process.env.HEROKU_API_TOKEN }) | ||
``` | ||
The simplest example is listing a user's apps. First, we call `heroku.apps()`, | ||
which returns a proxy object to the /apps endpoint, then we call `list()` to | ||
actually perform the API call: | ||
```javascript | ||
heroku.apps().list(function (err, apps) { | ||
// `apps` is a parsed JSON response from the API | ||
}); | ||
``` | ||
The advantage of using proxy objects is that they are reusable. Let's get the | ||
info for the user's app "my-app", get the dynos for the app, and | ||
remove a collaborator: | ||
```javascript | ||
var app = heroku.apps('my-app'); | ||
app.info(function (err, app) { | ||
// Details about the `app` | ||
}); | ||
app.dynos().list(function (err, dynos) { | ||
// List of the app's `dynos` | ||
}); | ||
app.collaborators('user@example.com').delete(function (err, collaborator) { | ||
// The `collaborator` has been removed unless `err` | ||
}); | ||
``` | ||
Requests that require a body are easy, as well. Let's add a collaborator to | ||
the user's app "another-app": | ||
```javascript | ||
var app = heroku.apps('another-app'), | ||
user = { email: 'new-user@example.com' }; | ||
app.collaborators().create({ user: user }, function (err, collaborator) { | ||
// `collaborator` is the newly added collaborator unless `err` | ||
}); | ||
``` | ||
### Generic Requests | ||
heroku-client has `get`, `post`, `patch`, and `delete` functions which can make | ||
@@ -99,17 +43,19 @@ requests with the specified HTTP method to any endpoint: | ||
```javascript | ||
heroku.get('/apps', function (err, apps) { | ||
}); | ||
// Request body is optional on both `post` and `patch` | ||
heroku.post('/apps', function (err, app) { | ||
}); | ||
// GET requests | ||
heroku.get('/apps').then(apps => { | ||
// do something with apps | ||
}) | ||
heroku.post('/apps', { name: 'my-new-app' }, function (err, app) { | ||
}); | ||
// POST requests | ||
heroku.post('/apps').then(app => {}) | ||
heroku.patch('/apps/my-app', { name: 'my-renamed-app' }, function (err, app) { | ||
}); | ||
// POST requests with body | ||
heroku.post('/apps', {body: {name: 'my-new-app'}}).then(app => {}) | ||
heroku.delete('/apps/my-old-app', function (err, app) { | ||
}); | ||
// PATCH requests with body | ||
heroku.patch('/apps/my-app', {body: {name: 'my-renamed-app'}}).then(app => {}) | ||
// DELETE requests | ||
heroku.delete('/apps/my-old-app').then(app => {}) | ||
``` | ||
@@ -128,28 +74,5 @@ | ||
parseJSON: false | ||
}, function (err, responseBody) { | ||
}); | ||
}).then(response => {}) | ||
``` | ||
### Promises | ||
heroku-client works with Node-style callbacks, but also implements promises with | ||
the [Q][q] library. | ||
```javascript | ||
var q = require('q'); | ||
// Fetches dynos for all of my apps. | ||
heroku.apps().list().then(function (apps) { | ||
return q.all(apps.map(function (app) { | ||
return heroku.apps(app.name).dynos().list(); | ||
})); | ||
}).then(function (dynos) { | ||
console.log(dynos); | ||
}); | ||
``` | ||
### Generators | ||
@@ -162,26 +85,20 @@ | ||
```javascript | ||
let co = require('co'); | ||
let heroku = require('heroku-client'); | ||
let hk = heroku.createClient({ token: process.env.HEROKU_API_KEY }); | ||
const co = require('co') | ||
const heroku = require('heroku-client') | ||
const hk = heroku.createClient({ token: process.env.HEROKU_API_KEY }) | ||
let main = function* () { | ||
let apps = yield hk.apps().list(); | ||
let dynos = yield apps.map(getDynos); | ||
let main = function * () { | ||
let apps = yield hk.get('/apps') | ||
let dynos = yield apps.map(getDynos) | ||
console.log(dynos); | ||
console.log(dynos) | ||
function getDynos(app) { | ||
return hk.apps(app.name).dynos().list(); | ||
return hk.get(`/apps/${app.name}/dynos`) | ||
} | ||
}; | ||
} | ||
co(main)(); | ||
co(main)() | ||
``` | ||
As long as you're using Node >= 0.11, you can run this script with: | ||
```sh | ||
$ node --harmony --use-strict file.js | ||
``` | ||
Hooray, no callbacks or promises in sight! | ||
@@ -259,10 +176,2 @@ | ||
### Updating resources | ||
To fetch the latest schema, generate documentation, and run the tests: | ||
```sh | ||
$ bin/update | ||
``` | ||
Inspect your changes, and | ||
@@ -272,19 +181,5 @@ [bump the version number accordingly](http://semver.org/) when cutting a | ||
### Generating documentation | ||
Documentation for heroku-client is auto-generated from | ||
[the API schema](https://github.com/heroku/node-heroku-client/blob/master/lib/schema.js). | ||
Docs are generated like so: | ||
```bash | ||
$ bin/docs | ||
``` | ||
Generating docs also runs a cursory test, ensuring that every documented | ||
function *is* a function that can be called. | ||
### Running tests | ||
heroku-client uses [jasmine-node][jasmine-node] for tests: | ||
heroku-client uses [ava][https://github.com/avajs/ava] for tests: | ||
@@ -296,8 +191,4 @@ ```bash | ||
[platform-api-reference]: https://devcenter.heroku.com/articles/platform-api-reference | ||
[q]: https://github.com/kriskowal/q | ||
[memjs]: https://github.com/alevy/memjs | ||
[bin_secret]: https://github.com/heroku/node-heroku-client/blob/master/bin/secret | ||
[memcachier]: https://www.memcachier.com | ||
[jasmine-node]: https://github.com/mhevery/jasmine-node | ||
[generators]: https://github.com/JustinDrake/node-es6-examples#generators | ||
[co]: https://github.com/visionmedia/co |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
1
2
17104
185
- Removedinflection@^1.7.0
- Removedpath-proxy@^1.0
- Removedq@^1.2.0
- Removedinflection@1.13.41.3.8(transitive)
- Removedpath-proxy@1.0.0(transitive)
- Removedq@1.5.1(transitive)