node-myjohndeere
MyJohnDeere API helper library for node.js.
Installation
npm install --save myjohndeere
var MyJohnDeere =
Usage
Getting request token (initial authorization)
var mjd = apiUrl appId appSecret mjd
Trading for access token (inside handler for callbackUrl)
var mjd = apiUrl appId appSecret // oauth_token and oauth_verifier are from URL query paramsmjd
Making authorized requests
var mjd = apiUrl appId appSecret accessToken accessTokenSecret // getLinks() stores the top level API catalog in .linksmjd
Notes
- Links (
apiRes.body.links
,apiRes.body.values[i].links
) are transformed from arrays of dictionaries ([{rel: ..., uri: ...}]
) into flat dictionaries ({self: <uri>, nextPage: <uri>, prevPage: <uri>}
) for convenience. .request([method='GET'], url, [options={}])
returns a pre-signed superagent request object configured to accept JSON and with support for relative URLs. If you need a different return type, simply override it with.set('Accept', ...)
..(get|post|put|delete)
are convenience wrappers for.request
.- Requires node 4.x or above.
- URL interpolation is supported via the
options
parameter to.request
and its convenience wrappers- e.g.
mjd.get(mjd.links.organizationMaintenancePlans, {orgId: 12345})
- e.g.
Test server
A small express server is included for testing and as an example implementation. To use it, you'll need to drop in a settings.js
file:
moduleexports = mjdEndpoint: 'https://apicert.soa-proxy.deere.com/platform' mjdAppId: '...' mjdAppSecret: '...'
From there, just run node server.js
in the module directory.
Contributing
Issues and pull requests welcome.
TODO
- Embeds
- Recursive calls