Comparing version 0.1.1 to 0.2.0
(function() { | ||
var Discogs, compress, querystring, request; | ||
var compress, exports, querystring, request; | ||
var __indexOf = Array.prototype.indexOf || function(item) { | ||
@@ -12,22 +12,21 @@ for (var i = 0, l = this.length; i < l; i++) { | ||
compress = require('compress'); | ||
Discogs = (function() { | ||
function Discogs(config) { | ||
var _base, _ref; | ||
this.config = config; | ||
(_ref = (_base = this.config).f) != null ? _ref : _base.f = this.config.format || 'json'; | ||
this.params = querystring.stringify(config); | ||
this.gunzip = new compress.Gunzip(); | ||
this.gunzip.init(); | ||
} | ||
Discogs.prototype.getUrl = function(url) { | ||
exports = module.exports = function(config) { | ||
var discogsRequest, getUrl, gunzip, params, responseHandler, _config; | ||
_config = {}; | ||
_config.api_key = config.api_key; | ||
_config.f = config.f || 'json'; | ||
params = querystring.stringify(_config); | ||
gunzip = new compress.Gunzip(); | ||
gunzip.init(); | ||
getUrl = function(url) { | ||
var sep; | ||
if (url.substr(0, 7) !== 'http://') { | ||
url = "http://www.discogs.com/" + url; | ||
url = "http://www.discogs.com/" + (encodeURIComponent(url)); | ||
} | ||
sep = __indexOf.call(url, "?") >= 0 ? "&" : "?"; | ||
return "" + url + sep + this.params; | ||
return "" + url + sep + params; | ||
}; | ||
Discogs.prototype.request = function(url, next) { | ||
discogsRequest = function(url, next) { | ||
return request({ | ||
uri: this.getUrl(url), | ||
uri: getUrl(url), | ||
headers: { | ||
@@ -42,5 +41,5 @@ 'accept-encoding': 'gzip' | ||
if (__indexOf.call(res.headers['content-type'], 'gzip') >= 0) { | ||
body = this.gunzip.inflate(body); | ||
body = gunzip.inflate(body); | ||
} | ||
if (__indexOf.call(res.headers['content-type'], 'json') >= 0 || this.config.f === 'json') { | ||
if (__indexOf.call(res.headers['content-type'], 'json') >= 0 || _config.f === 'json') { | ||
body = JSON.parse(body); | ||
@@ -55,25 +54,3 @@ } | ||
}; | ||
Discogs.prototype.get = function(url, next) { | ||
return this.request(url, next); | ||
}; | ||
Discogs.prototype.release = function(id, next) { | ||
return this.request('release/' + id, Discogs.responseHandler('release', next)); | ||
}; | ||
Discogs.prototype.artist = function(name, next) { | ||
return this.request('artist/' + name, Discogs.responseHandler('artist', next)); | ||
}; | ||
Discogs.prototype.label = function(name, next) { | ||
return this.request('label/' + name, Discogs.responseHandler('label', next)); | ||
}; | ||
Discogs.prototype.search = function(query, type, next) { | ||
if (type instanceof Function) { | ||
next = type; | ||
type = 'all'; | ||
} | ||
return this.request('search?' + querystring.stringify({ | ||
type: type, | ||
q: query | ||
}), Discogs.responseHandler('search', next)); | ||
}; | ||
Discogs.responseHandler = function(type, next) { | ||
responseHandler = function(type, next) { | ||
return function(err, res) { | ||
@@ -86,7 +63,27 @@ if (err || !(res instanceof Object) || !(type in (res != null ? res.resp : void 0))) { | ||
}; | ||
return Discogs; | ||
})(); | ||
exports.discogs = function(config) { | ||
return new Discogs(config); | ||
return { | ||
get: function(url, next) { | ||
return discogsRequest(url, next); | ||
}, | ||
release: function(id, next) { | ||
return discogsRequest('release/' + id, responseHandler('release', next)); | ||
}, | ||
artist: function(name, next) { | ||
return discogsRequest('artist/' + name, responseHandler('artist', next)); | ||
}, | ||
label: function(name, next) { | ||
return discogsRequest('label/' + name, responseHandler('label', next)); | ||
}, | ||
search: function(query, type, next) { | ||
if (type instanceof Function) { | ||
next = type; | ||
type = 'all'; | ||
} | ||
return discogsRequest('search?' + querystring.stringify({ | ||
type: type, | ||
q: query | ||
}), responseHandler('search', next)); | ||
} | ||
}; | ||
}; | ||
}).call(this); |
{ | ||
"name": "discogs", | ||
"description": "Simple client for Discogs API", | ||
"version": "0.1.1", | ||
"version": "0.2.0", | ||
"author": "Linus G Thiel <linus@hanssonlarsson.se> (http://hanssonlarsson.se/)", | ||
@@ -6,0 +6,0 @@ "contributors": [ |
@@ -7,3 +7,3 @@ Discogs: A simple JavaScript wrapper for the Discogs API | ||
## Version | ||
0.1.1 | ||
0.2.0 | ||
@@ -26,6 +26,6 @@ ## Requirements | ||
var client = discogs.discogs({api_key: 'foo4711'}); | ||
var client = discogs({api_key: 'foo4711'}); | ||
client.artist('Jay-Z', function(err, artist) { | ||
console.log(artist.realname); // Shawn Corey Carter | ||
client.artist('Marcus Price', function(err, artist) { | ||
console.log(artist.name); // Marcus Price | ||
}); | ||
@@ -32,0 +32,0 @@ |
Sorry, the diff of this file is not supported yet
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
Install scripts
Supply chain riskInstall scripts are run when the package is installed. The majority of malware in npm is hidden in install scripts.
Found 1 instance in 1 package
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
Found 8 instances 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
Network access
Supply chain riskThis module accesses the network.
Found 3 instances in 1 package
Mixed license
License(Experimental) Package contains multiple licenses.
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
485525
72
1402
1
2
17