Skip to content

Commit

Permalink
0.8.0
Browse files Browse the repository at this point in the history
  • Loading branch information
bartve committed Apr 13, 2016
1 parent f317759 commit 5964b81
Show file tree
Hide file tree
Showing 9 changed files with 214 additions and 55 deletions.
8 changes: 7 additions & 1 deletion HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
0.8.0 / 2016-04-13
==================
* Added the new release rating endpoints
* Changed a lot of function names to more consistent ones. Old function calls still work, but a deprecation
notice is shown on the console and the old function names will be removed in the next major version.

0.7.2 / 2016-02-09
==================
* Fixed default maximum number of requests per minute
Expand Down Expand Up @@ -105,7 +111,7 @@

0.3.1 / 2014-06-26
==================
* Fixed a litte bug in the calculation of free positions in the request queue
* Fixed a little bug in the calculation of free positions in the request queue
* Started adding unit tests using `wru`

0.3.0 / 2014-06-24
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ var Discogs = require('disconnect').Client;
Get the release data for a release with the id 176126.
```javascript
var db = new Discogs().database();
db.release(176126, function(err, data){
db.getRelease(176126, function(err, data){
console.log(data);
});
```
Expand All @@ -61,7 +61,7 @@ Get page 2 of USER_NAME's public collection showing 75 releases.
The second param is the collection folder ID where 0 is always the "All" folder.
```javascript
var col = new Discogs().user().collection();
col.releases('USER_NAME', 0, {page: 2, per_page: 75}, function(err, data){
col.getReleases('USER_NAME', 0, {page: 2, per_page: 75}, function(err, data){
console.log(data);
});
```
Expand Down Expand Up @@ -132,7 +132,7 @@ Simply provide the constructor with the `accessData` object persisted in step 3.
```javascript
app.get('/identity', function(req, res){
var dis = new Discogs(accessData);
dis.identity(function(err, data){
dis.getIdentity(function(err, data){
res.send(data);
});
});
Expand All @@ -142,9 +142,9 @@ app.get('/identity', function(req, res){
Image requests themselves don't require authentication, but obtaining the image URLs through, for example, release data does.
```javascript
var db = new Discogs(accessData).database();
db.release(176126, function(err, data){
db.getRelease(176126, function(err, data){
var url = data.images[0].resource_url;
db.image(url, function(err, data, rateLimit){
db.getImage(url, function(err, data, rateLimit){
// Data contains the raw binary image data
require('fs').writeFile('/tmp/image.jpg', data, 'binary', function(err){
console.log('Image saved!');
Expand Down
8 changes: 6 additions & 2 deletions lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ var https = require('https'),
url = require('url'),
pkg = require('../package.json'),
error = require('./error.js'),
util = require('./util.js');
util = require('./util.js'),
deprecate = require('depd')('disconnect');

module.exports = DiscogsClient;

Expand Down Expand Up @@ -99,10 +100,13 @@ DiscogsClient.prototype.authenticated = function(level){
* @param {function} callback - Callback function receiving the data
*/

DiscogsClient.prototype.identity = function(callback){
DiscogsClient.prototype.getIdentity = function(callback){
this.get({url: '/oauth/identity', authLevel: 2}, callback);
};

DiscogsClient.prototype.identity = deprecate.function(DiscogsClient.prototype.getIdentity,
'client.identity: Use client.getIdentity instead');

/**
* Get info about the Discogs API and this client
* @param {function} callback - Callback function receiving the data
Expand Down
56 changes: 42 additions & 14 deletions lib/collection.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,51 @@
'use strict';

var util = require('./util.js'),
deprecate = require('depd')('disconnect'),
AuthError = require('./error.js').AuthError;

module.exports = function(client){
var collection = {};

/**
* Get metadata for a specified collection folder or list all collection folders
* @param {string} user - The user name
* @param {string} user - The Discogs user name
* @param {number|string} [folder] - An optional folder ID
* @param {function} [callback] - The callback
*/

collection.folders = function(user, folder, callback){
var url = '/users/'+user+'/collection/folders';
if((arguments.length === 2) && (typeof folder === 'function')){ // Get all folders
client.get(url, folder);
deprecate('collection.folders: Use collection.getFolders instead');
collection.getFolders(user, folder);
}else{ // Get a specific folder
if(client.authenticated(2) || (parseInt(folder, 10) === 0)){
url += '/'+folder;
client.get(url, callback);
}else{
callback(new AuthError());
}
deprecate('collection.folders: Use collection.getFolder instead');
collection.getFolder(user, folder, callback);
}
};

/**
* Get a list of all collection folders for the given user
* @param {string} user - The user name
* @param {function} callback - The callback
*/

collection.getFolders = function(user, callback){
client.get('/users/'+util.escape(user)+'/collection/folders', callback);
};

/**
* Get metadata for a specified collection folder
* @param {string} user - The Discogs user name
* @param {number|string} folder - A folder ID (0 = public folder)
* @param {function} callback - The callback
*/

collection.getFolder = function(user, folder, callback){
if(client.authenticated(2) || (parseInt(folder, 10) === 0)){
client.get('/users/'+util.escape(user)+'/collection/folders/'+folder, callback);
}else{
callback(new AuthError());
}
};

Expand All @@ -46,10 +68,13 @@ module.exports = function(client){
* @param {function} [callback] - The callback
*/

collection.editFolder = function(user, folder, name, callback){
collection.setFolderName = function(user, folder, name, callback){
client.post({url: '/users/'+util.escape(user)+'/collection/folders/'+folder, authLevel: 2}, {name: name}, callback);
};

collection.editFolder = deprecate.function(collection.setFolderName,
'collection.editFolder: Use collection.setFolderName instead');

/**
* Delete a folder. A folder must be empty before it can be deleted.
* @param {string} user - The user name
Expand All @@ -69,7 +94,7 @@ module.exports = function(client){
* @param {function} [callback] - The callback
*/

collection.releases = function(user, folder, params, callback){
collection.getReleases = function(user, folder, params, callback){
if(client.authenticated(2) || (parseInt(folder, 10) === 0)){
var path = '/users/'+util.escape(user)+'/collection/folders/'+folder+'/releases';
if((arguments.length === 3) && (typeof params === 'function')){
Expand All @@ -83,17 +108,20 @@ module.exports = function(client){
}
};

collection.releases = deprecate.function(collection.getReleases,
'collection.releases: Use collection.getReleases instead');

/**
* Add a release instance to the given collection folder
* Add a release instance to the (optionally) given collection folder
* @param {string} user - The user name
* @param {(number|string)} [folder] - The folder ID (defaults to the "Uncategorized" folder)
* @param {(number|string)} release - The release ID
* @param {function} [callback] - The callback
*/

collection.addRelease = function(user, folder, release, callback){
if((arguments.length === 3) && (typeof params === 'function')){
release = folder; folder = 1; callback = release;
if((arguments.length === 3) && (typeof release === 'function')){
callback = release; release = folder; folder = 1;
}
client.post({url: '/users/'+util.escape(user)+'/collection/folders/'+(folder||1)+'/releases/'+release, authLevel: 2}, null, callback);
};
Expand Down
71 changes: 62 additions & 9 deletions lib/database.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

var util = require('./util.js');
var util = require('./util.js'),
deprecate = require('depd')('disconnect');

module.exports = function(client){
var database = {};
Expand All @@ -18,17 +19,20 @@ module.exports = function(client){
* @param {function} [callback] - Callback function
*/

database.artist = function(artist, callback){
database.getArtist = function(artist, callback){
client.get('/artists/'+artist, callback);
};

database.artist = deprecate.function(database.getArtist,
'database.artist: Use database.getArtist instead');

/**
* Get artist release data
* @param {(number|string)} artist - The Discogs artist ID
* @param {object} [params] - Paging params
* @param {function} [callback] - Callback function
*/
database.artistReleases = function(artist, params, callback){
database.getArtistReleases = function(artist, params, callback){
var path = '/artists/'+artist+'/releases';
if((arguments.length === 2) && (typeof params === 'function')){
callback = params;
Expand All @@ -37,26 +41,63 @@ module.exports = function(client){
}
client.get(path, callback);
};

database.artistReleases = deprecate.function(database.getArtistReleases,
'database.artistReleases: Use database.getArtistReleases instead');

/**
* Get release data
* @param {(number|string)} release - The Discogs release ID
* @param {function} [callback] - Callback function
*/

database.release = function(release, callback){
database.getRelease = function(release, callback){
client.get('/releases/'+release, callback);
};

database.release = deprecate.function(database.getRelease,
'database.release: Use database.getRelease instead');

/**
* Get the release rating for the given user
* @param {(number|string)} release - The Discogs release ID
* @param {string} user - The Discogs user name
* @param {function} [callback] - Callback function
*/

database.getReleaseRating = function(release, user, callback){
client.get('/releases/'+release+'/rating/'+util.escape(user), callback);
};

/**
* Set (or remove) a release rating for the given logged in user
* @param {(number|string)} release - The Discogs release ID
* @param {string} user - The Discogs user name
* @param {number} rating - The new rating for a release between 1 and 5. Null = remove rating
* @param {function} [callback] - Callback function
*/

database.setReleaseRating = function(release, user, rating, callback){
var url = '/releases/'+release+'/rating/'+util.escape(user);
if(!rating){
client.delete({url: url, authLevel: 2}, callback);
}else{
client.put({url: url, authLevel: 2}, {rating: ((rating > 5) ? 5 : rating)}, callback);
}
};

/**
* Get master release data
* @param {(number|string)} master - The Discogs master release ID
* @param {function} [callback] - Callback function
*/

database.master = function(master, callback){
database.getMaster = function(master, callback){
client.get('/masters/'+master, callback);
};

database.master = deprecate.function(database.getMaster,
'database.master: Use database.getMaster instead');

/**
* Get the release versions contained in the given master release
Expand All @@ -65,7 +106,7 @@ module.exports = function(client){
* @param {function} [callback] - Callback function
*/

database.masterVersions = function(master, params, callback){
database.getMasterVersions = function(master, params, callback){
var path = '/masters/'+master+'/versions';
if((arguments.length === 2) && (typeof params === 'function')){
callback = params;
Expand All @@ -74,16 +115,22 @@ module.exports = function(client){
}
client.get(path, callback);
};

database.masterVersions = deprecate.function(database.getMasterVersions,
'database.masterVersions: Use database.getMasterVersions instead');

/**
* Get label data
* @param {(number|string)} label - The Discogs label ID
* @param {function} [callback] - Callback function
*/

database.label = function(label, callback){
database.getLabel = function(label, callback){
client.get('/labels/'+label, callback);
};

database.label = deprecate.function(database.getLabel,
'database.label: Use database.getLabel instead');

/**
* Get label release data
Expand All @@ -92,7 +139,7 @@ module.exports = function(client){
* @param {function} [callback] - Callback function
*/

database.labelReleases = function(label, params, callback){
database.getLabelReleases = function(label, params, callback){
var path = '/labels/'+label+'/releases';
if((arguments.length === 2) && (typeof params === 'function')){
callback = params;
Expand All @@ -102,15 +149,21 @@ module.exports = function(client){
client.get(path, callback);
};

database.labelReleases = deprecate.function(database.getLabelReleases,
'database.labelReleases: Use database.getLabelReleases instead');

/**
* Get an image
* @param {string} url - The full image url
* @param {function} [callback] - Callback function
*/

database.image = function(url, callback){
database.getImage = function(url, callback){
client.get({url: url, encoding: 'binary', queue: false, json: false}, callback);
};

database.image = deprecate.function(database.getImage,
'database.image: Use database.getImage instead');

/**
* Search the database
Expand Down
Loading

0 comments on commit 5964b81

Please sign in to comment.