-
Notifications
You must be signed in to change notification settings - Fork 447
/
Copy pathsmarterer.js
30 lines (24 loc) · 844 Bytes
/
smarterer.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
var oauthModule = require('./oauth2')
, querystring= require('querystring');
var smarterer = module.exports =
oauthModule.submodule('smarterer')
.oauthHost('https://smarterer.com')
.apiHost('https://smarterer.com')
.entryPath('/auth/smarterer')
.callbackPath('/auth/smarterer/callback')
.authQueryParam('callback_url', function() {
return this._myHostname + this._callbackPath;
})
.accessTokenParam('grant_type', 'authorization_code')
.fetchOAuthUser( function (accessToken) {
var p = this.Promise();
this.oauth.get(this.apiHost() + '/api/badges', accessToken, function (err, data) {
if (err) return p.fail(err.error_message);
var oauthUser = JSON.parse(data);
p.fulfill(oauthUser);
})
return p;
})
.convertErr( function (data) {
return new Error(data.error_message);
});