Comparing version 0.0.3 to 0.0.4
@@ -1,80 +0,6 @@ | ||
var request = require('superagent'), | ||
q = require('q'); | ||
exports.url = 'https://api.authbase.io/v1'; | ||
function AuthBase(appId, appSecret) { | ||
function toError(status, message) { | ||
var json; | ||
try { json = JSON.parse(message); message = undefined; } catch(ex) { } | ||
return { | ||
status: status, | ||
message: message, | ||
json: json | ||
} | ||
} | ||
function exceptionToError(ex) { | ||
return toError(null, ex.message); | ||
} | ||
function promisify(callback) { | ||
var deferred = q.defer(); | ||
callback(function(err, value) { | ||
if (err) deferred.reject(err); | ||
else deferred.resolve(value); | ||
}); | ||
return deferred.promise; | ||
} | ||
function completable(callback, promised) { | ||
return function(error, user) { | ||
// call the callback if it was provided | ||
if (typeof callback === 'function') { | ||
if (error) callback(error); | ||
else callback(undefined, user); | ||
} | ||
// fulfill the promise | ||
if (error) promised(error); | ||
else promised(undefined, user); | ||
} | ||
} | ||
function responseHandler(complete) { | ||
return function(err, res) { | ||
try { | ||
if (err) complete(exceptionToError(err)); | ||
else if (res.error) complete(toError(res.error.status, res.error.text)); | ||
else complete(undefined, res.body); | ||
} catch(ex) { | ||
complete(exceptionToError(ex)); | ||
} | ||
} | ||
} | ||
function api(method, endpoint) { | ||
return function(user, callback) { | ||
return promisify(function(promised) { | ||
method(AuthBase.url + endpoint) | ||
.set('X-App-Id', appId) | ||
.set('X-App-Secret', appSecret) | ||
.send(user) | ||
.buffer() | ||
.end(responseHandler(completable(callback, promised))); | ||
}); | ||
} | ||
} | ||
// public API | ||
return { | ||
register: api(request.post, '/register'), | ||
update: api(request.post, '/update'), | ||
unregister: api(request.post, '/unregister'), | ||
verify: api(request.get, '/verify') | ||
} | ||
} | ||
// static override of the AuthBase url | ||
AuthBase.url = 'https://api.authbase.io/v1'; | ||
module.exports = AuthBase; | ||
module.exports = { | ||
Client: require('./client'), | ||
Router: require('./router') | ||
}; |
{ | ||
"name": "authbase", | ||
"version": "0.0.3", | ||
"description": "AuthBase API Client", | ||
"version": "0.0.4", | ||
"description": "AuthBase API Client and Router", | ||
"main": "./lib", | ||
@@ -6,0 +6,0 @@ "scripts": { |
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
8371
5
232
1