Skip to content

Commit 38a413b

Browse files
committed
Strict mode + preparing for required authentication for database().search()
1 parent 7fb2057 commit 38a413b

11 files changed

+39
-10
lines changed

HISTORY.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
Unreleased
2+
==================
3+
* Use `strict`
4+
* Added local authentication check for the `database().search()` function
5+
16
0.3.4 / 2014-07-30
27
==================
38
* Added `user().contributions()` and `user().submissions()` for the newly implemented endpoints

index.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use strict';
2+
13
var discogs = module.exports = {};
24

35
/**

lib/client.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
'use strict';
2+
13
var http = require('http'),
24
zlib = require('zlib'),
35
url = require('url'),
46
queryString = require('querystring'),
57
OAuth = require('oauth-1.0a'),
6-
package = require('../package.json'),
8+
pkg = require('../package.json'),
79
error = require('./error.js'),
810
queue = require('./queue.js');
911

@@ -33,7 +35,7 @@ var config = {
3335
customHeaders: {
3436
'Accept': 'application/json; application/octet-stream',
3537
'Accept-Encoding': 'gzip,deflate',
36-
'User-Agent': 'DisConnectClient/'+package.version+' +'+package.homepage
38+
'User-Agent': 'DisConnectClient/'+pkg.version+' +'+pkg.homepage
3739
}
3840
};
3941

@@ -147,7 +149,7 @@ DiscogsClient.prototype.identity = function(callback){
147149

148150
DiscogsClient.prototype.about = function(callback){
149151
this.get('', function(err, data){
150-
if(data){ data.disconnect = { version: package.version, userAgent: (this.userAgent||config.customHeaders['User-Agent']) }; }
152+
if(data){ data.disconnect = { version: pkg.version, userAgent: (this.userAgent||config.customHeaders['User-Agent']) }; }
151153
(typeof callback === 'function')&&callback(err, data);
152154
});
153155
};

lib/collection.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use strict';
2+
13
var util = require('./util.js'),
24
AuthError = require('./error.js').AuthError;
35

lib/database.js

+13-7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use strict';
2+
13
var util = require('./util.js'),
24
authError = require('./error.js').AuthError;
35

@@ -99,21 +101,25 @@ module.exports = function(client){
99101
};
100102

101103
/**
102-
* Search the database
104+
* Search the database (requires authentication starting 2014-08-15)
103105
* @param {String} query - The search query
104106
* @param {Object} [params] - Search parameters as defined on http://www.discogs.com/developers/resources/database/search-endpoint.html
105107
* @param {Function} [callback] - Callback function
106108
*/
107109

108110
database.search = function(query, params, callback){
109-
var obj = {};
110-
if(arguments.length <= 2){
111-
(typeof params === 'function')&&(callback = params); // No extra search params, the callback is the second function param
111+
if(client.authenticated()){
112+
var obj = {};
113+
if(arguments.length <= 2){
114+
(typeof params === 'function')&&(callback = params); // No extra search params, the callback is the second function param
115+
}else{
116+
obj = params;
117+
}
118+
obj.q = util.escape(query);
119+
client.get(util.addParams('/database/search', obj), callback);
112120
}else{
113-
obj = params;
121+
callback(new AuthError());
114122
}
115-
obj.q = util.escape(query);
116-
client.get(util.addParams('/database/search', obj), callback);
117123
};
118124

119125
return database;

lib/error.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use strict';
2+
13
var Errors = module.exports = {};
24

35
/**

lib/marketplace.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use strict';
2+
13
var util = require('./util.js'),
24
AuthError = require('./error.js').AuthError;
35

lib/queue.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use strict';
2+
13
var queue = module.exports = {},
24
DiscogsError = require('./error.js').DiscogsError,
35
stack = [],

lib/user.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use strict';
2+
13
var util = require('./util.js');
24

35
module.exports = function(client){

lib/util.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use strict';
2+
13
var queryString = require('querystring');
24

35
var util = module.exports = {};

lib/wantlist.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use strict';
2+
13
var util = require('./util.js'),
24
AuthError = require('./error.js').AuthError;
35

0 commit comments

Comments
 (0)