Comparing version 0.0.3 to 0.0.4
93
index.js
var request = require('request'); | ||
module.exports = function (api_key, api_url) { | ||
apiurl = api_url || 'https://api.authy.com'; | ||
apikey = module.exports.apikey = api_key; | ||
return module.exports; | ||
return new Authy(api_key, api_url); | ||
}; | ||
module.exports.register_user = function (email, cellphone, country_code, cb) { | ||
var url = apiurl + "/protected/json/users/new"; | ||
var qs = {api_key: apikey}; | ||
// Default to USA if no country_code is provided | ||
var country = 'USA'; | ||
function Authy(apiKey, api_url) { | ||
this.apiKey = apiKey; | ||
this.apiURL = api_url || "https://api.authy.com"; | ||
} | ||
Authy.prototype.register_user = function (email, cellphone, country_code, callback) { | ||
var country = "1"; | ||
if (arguments.length > 3) { | ||
country = country_code; | ||
country = country_code; | ||
} else { | ||
cb = country_code; | ||
callback = country_code; | ||
} | ||
var form = { | ||
"user[email]": email, | ||
"user[cellphone]": cellphone, | ||
"user[country_code]": country | ||
}; | ||
request.post({ | ||
url: this.apiURL + "/protected/json/users/new", | ||
form: { | ||
"user[email]": email, | ||
"user[cellphone]": cellphone, | ||
"user[country_code]": country | ||
}, | ||
qs: { | ||
api_key: this.apiKey | ||
} | ||
}, function (err, res, body) { | ||
if (!err) { | ||
if(res.statusCode === 200) { | ||
callback(null, JSON.parse(body)); | ||
} else { | ||
callback(body); | ||
} | ||
} else { | ||
throw new Error(err); | ||
} | ||
}); | ||
}; | ||
Authy.prototype.delete_user = function (id, callback) { | ||
request.post({ | ||
url: url, | ||
form: form, | ||
qs: qs | ||
url: this.apiURL + "/protected/json/users/delete/" + id, | ||
qs: { | ||
api_key: this.apiKey | ||
} | ||
}, function (err, res, body) { | ||
if (!err) { | ||
if (res.statusCode === 200) { | ||
cb(null, toJSON(body)); | ||
if(res.statusCode === 200) { | ||
callback(null, body); | ||
} else { | ||
cb(JSON.parse(toJSON(body))); | ||
callback(body); | ||
} | ||
@@ -45,14 +62,15 @@ } else { | ||
module.exports.verify = function (id, token, force, cb) { | ||
var url = apiurl + "/protected/json/verify/" + token + "/" + id; | ||
Authy.prototype.verify = function (id, token, force, callback) { | ||
var qs = { | ||
api_key: this.apiKey | ||
}; | ||
var qs = {api_key: apikey}; | ||
if (arguments.length > 3) { | ||
qs.force = force; | ||
} else { | ||
cb = force; | ||
callback = force; | ||
} | ||
request.get({ | ||
url: url, | ||
url: this.apiURL + "/protected/json/verify/" + token + "/" + id, | ||
qs: qs | ||
@@ -62,5 +80,5 @@ }, function (err, res, body) { | ||
if (res.statusCode === 200) { | ||
cb(null, toJSON(body)); | ||
callback(null, toJSON(body)); | ||
} else { | ||
cb(toJSON(body)); | ||
callback(toJSON(body)); | ||
} | ||
@@ -73,14 +91,15 @@ } else { | ||
module.exports.request_sms = function (id, force, cb) { | ||
var url = apiurl + "/protected/json/sms/" + id; | ||
Authy.prototype.request_sms = function (id, force, callback) { | ||
var qs = { | ||
api_key: this.apiKey | ||
}; | ||
var qs = {api_key: apikey}; | ||
if (arguments.length > 2) { | ||
qs.force = force; | ||
} else { | ||
cb = force; | ||
callback = force; | ||
} | ||
request.get({ | ||
url: url, | ||
url: this.apiURL + "/protected/json/sms/" + id, | ||
qs: qs | ||
@@ -90,5 +109,5 @@ }, function (err, res, body) { | ||
if (res.statusCode === 200) { | ||
cb(null, toJSON(body)); | ||
callback(null, toJSON(body)); | ||
} else { | ||
cb(toJSON(body)); | ||
callback(body); | ||
} | ||
@@ -95,0 +114,0 @@ } else { |
{ | ||
"name": "authy", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"description": "Authy.com API lib for node.js", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -50,3 +50,3 @@ node-authy | ||
```javascript | ||
authy.verify('1337', '0000000' function (err, res) { | ||
authy.verify('1337', '0000000', function (err, res) { | ||
@@ -67,1 +67,16 @@ }); | ||
Delete Registered User | ||
---------------------- | ||
delete_user(id, callback); | ||
```javascript | ||
authy.delete_user('1337', function (err, res) { | ||
}); | ||
``` | ||
Additional Contributors | ||
----------------------- | ||
[Daniel Barnes](https://github.com/DanielBarnes) | ||
@@ -1,5 +0,5 @@ | ||
var apikey = "41f3fe0a27e1c9cba05c30933811a2b8"; | ||
var apikey = "0cd08abec2e9b9641e40e9470a7fc336"; | ||
var authy = require('../index')(apikey,'http://sandbox-api.authy.com'); | ||
var test_user = {email: 'baldwin@andyet.net', phone: '509-555-1212', country: 'UK'}; | ||
var test_user = {email: 'baldwin@andyet.net', phone: '825-589-8570', country: '5'}; | ||
@@ -6,0 +6,0 @@ /* |
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
7749
175
81