sharelock-client
Advanced tools
Comparing version 0.0.0 to 0.0.1
{ | ||
"name": "sharelock-client", | ||
"version": "0.0.0", | ||
"version": "0.0.1", | ||
"description": "Node.js wrapper for https://sharelock.io", | ||
@@ -14,3 +14,2 @@ "homepage": "https://sharelock.io", | ||
"dependencies": { | ||
"lodash": "^3.3.1", | ||
"request": "^2.53.0", | ||
@@ -17,0 +16,0 @@ "valid-url": "^1.0.9" |
var request = require('request'); | ||
var ld = require('lodash'); | ||
var validUrl = require('valid-url'); | ||
function Sharelock (uri) { | ||
if (!uri) { | ||
this.uri = 'https://sharelock.io'; | ||
} else if (validUrl.isUri(uri)) { | ||
this.url = uri; | ||
} else { | ||
throw 'Invalid Sharelock URI specified: ' + uri; | ||
} | ||
if (!uri) { | ||
this.uri = 'https://sharelock.io'; | ||
} else if (validUrl.isUri(uri)) { | ||
this.url = uri; | ||
} else { | ||
throw 'Invalid Sharelock URI specified: ' + uri; | ||
} | ||
} | ||
@@ -17,34 +16,34 @@ | ||
Sharelock.init = function (url) { | ||
return new Sharelock(url); | ||
return new Sharelock(url); | ||
}; | ||
Sharelock.prototype.create = function (secret, acl, cb) { | ||
var uri = this.uri; | ||
var options = { | ||
uri: uri + '/create', | ||
method: 'POST', | ||
json: { | ||
"d": secret, | ||
"a": parseAcl(acl) | ||
} | ||
}; | ||
request.post(options, function (err, response, body) { | ||
if (!err && response.statusCode === 200) { | ||
return cb(null, uri + body); | ||
} else { | ||
return cb(err, null); | ||
} | ||
}); | ||
var uri = this.uri; | ||
var options = { | ||
uri: uri + '/create', | ||
method: 'POST', | ||
json: { | ||
"d": secret, | ||
"a": parseAcl(acl) | ||
} | ||
}; | ||
request.post(options, function (err, response, body) { | ||
if (!err && response.statusCode === 200) { | ||
return cb(null, uri + body); | ||
} else { | ||
return cb(err, null); | ||
} | ||
}); | ||
}; | ||
function parseAcl(acl) { | ||
if (acl.constructor === Array && acl.length > 0) { | ||
return acl.join(','); | ||
} else if (ld.isString(acl)) { | ||
return acl; | ||
} else { | ||
throw 'Invalid recipient list (ACL) specified: ' + acl; | ||
} | ||
if (acl.constructor === Array && acl.length > 0) { | ||
return acl.join(','); | ||
} else if (typeof acl === 'string') { | ||
return acl; | ||
} else { | ||
throw 'Invalid recipient list (ACL) specified: ' + acl; | ||
} | ||
} | ||
module.exports = Sharelock; |
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
2485
2
43
- Removedlodash@^3.3.1
- Removedlodash@3.10.1(transitive)