Comparing version 0.1.1 to 0.1.2
115
index.js
@@ -27,5 +27,5 @@ /** | ||
var version = packagejson.version; | ||
this.client_id = options.client_id; | ||
this.client_secret = options.client_secret; | ||
this.access_token = options.access_token; | ||
var client_id = options.client_id; | ||
var client_secret = options.client_secret; | ||
var access_token = options.access_token; | ||
@@ -82,17 +82,12 @@ /** | ||
var api_get = function(options, callback) { | ||
if(!options.fake) { | ||
request({ | ||
url: options.url, | ||
headers: { | ||
'Authorization': 'Bearer ' + access_token, | ||
'Accept': 'application/json' | ||
} | ||
}, | ||
function(error, response, body) { | ||
callback(error, body); | ||
}); | ||
} | ||
else { | ||
callback(null, options.url); | ||
} | ||
request({ | ||
url: options.url, | ||
headers: { | ||
'Authorization': 'Bearer ' + access_token, | ||
'Accept': 'application/json' | ||
} | ||
}, | ||
function(error, response, body) { | ||
callback(error, body); | ||
}); | ||
}; | ||
@@ -110,19 +105,14 @@ | ||
var api_post = function(options, callback) { | ||
if(!options.fake) { | ||
request({ | ||
method: 'post', | ||
url: options.url, | ||
headers: { | ||
'Authorization': 'Bearer ' + access_token, | ||
'Content-Type': 'application/x-www-form-urlencoded' | ||
}, | ||
form: options.data | ||
request({ | ||
method: 'post', | ||
url: options.url, | ||
headers: { | ||
'Authorization': 'Bearer ' + access_token, | ||
'Content-Type': 'application/x-www-form-urlencoded' | ||
}, | ||
function(error, response, body) { | ||
callback(error, body); | ||
}); | ||
} | ||
else { | ||
callback(null, options.url); | ||
} | ||
form: options.data | ||
}, | ||
function(error, response, body) { | ||
callback(error, body); | ||
}); | ||
}; | ||
@@ -138,25 +128,20 @@ | ||
var api_delete = function(options, callback) { | ||
if(!options.fake) { | ||
request({ | ||
method: 'delete', | ||
url: options.url, | ||
headers: { | ||
'Authorization': 'Bearer ' + access_token | ||
} | ||
}, | ||
function(error, response, body) { | ||
callback(error, body); | ||
}); | ||
} | ||
else { | ||
callback(null, options.url); | ||
} | ||
request({ | ||
method: 'delete', | ||
url: options.url, | ||
headers: { | ||
'Authorization': 'Bearer ' + access_token | ||
} | ||
}, | ||
function(error, response, body) { | ||
callback(error, body); | ||
}); | ||
}; | ||
function create_getter_xid(str) { | ||
return function(options, callback, fake) { | ||
return function(options, callback) { | ||
if(good_params(options, callback)) { | ||
var xid = options.xid; | ||
var url = BASE_URL + (xid ? '/' + str + '/' + xid : '/users/@me/' + str + '?' + serialize(options)); | ||
api_get({ url: url, fake: fake }, callback); | ||
api_get({ url: url }, callback); | ||
} | ||
@@ -167,6 +152,6 @@ }; | ||
function create_getter(str) { | ||
return function(options, callback, fake) { | ||
return function(options, callback) { | ||
if(good_params(options, callback)) { | ||
var url = BASE_URL + '/users/@me/' + str; | ||
api_get({ url: url, fake: fake }, callback); | ||
api_get({ url: url }, callback); | ||
} | ||
@@ -177,3 +162,3 @@ }; | ||
function create_getter_type(obj_str, str_type) { | ||
return function(options, callback, fake) { | ||
return function(options, callback) { | ||
if(good_params(options, callback)) { | ||
@@ -186,3 +171,3 @@ var xid = options.xid; | ||
var url = BASE_URL + '/'+ obj_str + '/' + xid + '/' + str_type; | ||
api_get({ url: url, fake: fake }, callback); | ||
api_get({ url: url }, callback); | ||
} | ||
@@ -194,6 +179,6 @@ } | ||
function create_creator(obj_str) { | ||
return function(data, callback, fake) { | ||
return function(data, callback) { | ||
if(good_params(data, callback)) { | ||
var url = BASE_URL + '/users/@me/' + obj_str; | ||
api_post({ url: url, fake: fake, data: data }, callback); | ||
api_post({ url: url, data: data }, callback); | ||
} | ||
@@ -204,3 +189,3 @@ }; | ||
function create_deletor(obj_str) { | ||
return function(options, callback, fake) { | ||
return function(options, callback) { | ||
if(good_params(options, callback)) { | ||
@@ -213,3 +198,3 @@ var xid = options.xid; | ||
var url = BASE_URL + '/' + obj_str + '/' + xid; | ||
api_delete({ url: url, fake: fake }, callback); | ||
api_delete({ url: url }, callback); | ||
} | ||
@@ -238,3 +223,3 @@ } | ||
var url = BASE_URL + '/users/@me/refreshToken'; | ||
api_post({ url: url, fake: false, data: { secret: client_secret } }, callback); | ||
api_post({ url: url, data: { secret: client_secret } }, callback); | ||
} | ||
@@ -260,6 +245,6 @@ else { | ||
var delete_webhook = function(callback, fake) { | ||
var delete_webhook = function(callback) { | ||
if(good_params(options, callback)) { | ||
var url = BASE_URL + '/users/@me/pubsub'; | ||
api_delete({ url: url, fake: fake }, callback); | ||
api_delete({ url: url }, callback); | ||
} | ||
@@ -271,3 +256,3 @@ }; | ||
get access_token() { | ||
return self.access_token; | ||
return access_token; | ||
}, | ||
@@ -277,3 +262,3 @@ | ||
if(typeof(token) === 'string') { | ||
self.access_token = token; | ||
access_token = token; | ||
} | ||
@@ -288,3 +273,3 @@ }, | ||
me: { | ||
get: create_getter(''), | ||
get: create_getter('') | ||
}, | ||
@@ -291,0 +276,0 @@ /** @class moves */ |
{ | ||
"name": "jawbone-up", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"dependencies": { | ||
@@ -13,4 +13,4 @@ "request": "2.27.0" | ||
"jsdoc": "git+https://github.com/jsdoc3/jsdoc.git", | ||
"should": "~2.1.0", | ||
"mocha": "~1.14.0" | ||
"mocha": "^2.0.1", | ||
"nock": "^0.51.0" | ||
}, | ||
@@ -17,0 +17,0 @@ "optionalDependencies": {}, |
# node-jawbone-up | ||
Jawbone UP API Node.js Library | ||
Jawbone UP API Node.js Client | ||
API Version: v.1.1 | ||
If you would like to contribute to this project in any way, including to update it to support API v1.1, please send me a pull request! | ||
Official UP API: [jawbone.com/up/developer](https://jawbone.com/up/developer/) | ||
[![Build Status](https://secure.travis-ci.org/ryanseys/node-jawbone-up.png)](http://travis-ci.org/ryanseys/node-jawbone-up) | ||
[![Build Status](https://travis-ci.org/ryanseys/node-jawbone-up.svg?branch=master)](http://travis-ci.org/ryanseys/node-jawbone-up) | ||
[![NPM](https://nodei.co/npm/jawbone-up.png)](https://npmjs.org/package/jawbone-up) | ||
[![NPM](https://nodei.co/npm/jawbone-up.svg?downloads=true)](https://npmjs.org/package/jawbone-up) | ||
## Installation | ||
`npm install jawbone-up` | ||
``` sh | ||
npm install jawbone-up --save | ||
``` | ||
@@ -38,3 +38,3 @@ ## Usage | ||
# Documentation | ||
## Documentation | ||
@@ -59,3 +59,3 @@ Official UP API can be found at [jawbone.com/up/developer](https://jawbone.com/up/developer/) | ||
## User information | ||
### User information | ||
@@ -79,3 +79,3 @@ ```javascript | ||
## Moves | ||
### Moves | ||
@@ -96,3 +96,3 @@ ```javascript | ||
## Workouts | ||
### Workouts | ||
@@ -119,3 +119,3 @@ ```javascript | ||
## Sleeps | ||
### Sleeps | ||
@@ -142,3 +142,3 @@ ```javascript | ||
## Meals | ||
### Meals | ||
@@ -159,3 +159,3 @@ ```javascript | ||
## Body Composition | ||
### Body Composition | ||
@@ -176,3 +176,3 @@ ```javascript | ||
## Cardiac Metrics | ||
### Cardiac Metrics | ||
@@ -193,3 +193,3 @@ ```javascript | ||
## Generic Events | ||
### Generic Events | ||
@@ -213,3 +213,3 @@ ```javascript | ||
## Mood | ||
### Mood | ||
@@ -230,3 +230,3 @@ ```javascript | ||
## Time Zone | ||
### Time Zone | ||
@@ -247,3 +247,3 @@ ```javascript | ||
## Settings | ||
### Settings | ||
@@ -257,3 +257,3 @@ Added in v.1.1 | ||
## Webhook | ||
### Webhook | ||
@@ -270,3 +270,3 @@ Added in v.1.1 | ||
# Tests | ||
## Tests | ||
@@ -289,4 +289,4 @@ Tests can be found in the `test` folder. | ||
# License | ||
## License | ||
[MIT](https://github.com/ryanseys/node-jawbone-up/blob/master/LICENSE.md) © 2014 Ryan Seys |
@@ -1,14 +0,25 @@ | ||
var config = require('./config'); | ||
var should = require('should'); | ||
var debug = false; | ||
var up = require('../index')(config); | ||
var up = require('../index')({}); | ||
var assert = require('assert'); | ||
var nock = require('nock'); | ||
nock.disableNetConnect(); | ||
var baseApi = nock('https://jawbone.com') | ||
.matchHeader('Authorization', /.*/); | ||
describe('up', function(){ | ||
describe('.moves', function(){ | ||
describe('.get()', function(){ | ||
it('should return correct url', function(){ | ||
it('should call correct url', function(done){ | ||
var api = baseApi.matchHeader('Accept', 'application/json') | ||
.get('/nudge/api/v.1.1/users/@me/moves?') | ||
.reply(200, 'OK!'); | ||
up.moves.get({}, function(err, body) { | ||
body.should.equal('https://jawbone.com/nudge/api/v.1.1/users/@me/moves?'); | ||
}, debug); | ||
assert.equal(err, void 0); | ||
assert.equal(body, 'OK!'); | ||
api.done(); | ||
done(); | ||
}); | ||
}); | ||
@@ -18,6 +29,15 @@ }); | ||
describe('.get({ xid: 123 })', function(){ | ||
it('should return correct url', function(){ | ||
it('should return correct url', function(done){ | ||
var api = baseApi.matchHeader('Accept', 'application/json') | ||
.get('/nudge/api/v.1.1/moves/123') | ||
.reply(200, 'OK!'); | ||
up.moves.get({ xid: 123 }, function(err, body) { | ||
body.should.equal('https://jawbone.com/nudge/api/v.1.1/moves/123'); | ||
}, debug); | ||
assert.equal(err, void 0); | ||
assert.equal(body, 'OK!'); | ||
api.done(); | ||
done(); | ||
}); | ||
}); | ||
@@ -24,0 +44,0 @@ }); |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
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
0
21104
8
361