Skip to content

Commit 25d73c9

Browse files
committedMay 27, 2019
Add validation
1 parent 0110977 commit 25d73c9

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed
 

‎src/index.js

+13-4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
var executeApiFetch = require('./apifetch');
44
var Settings = require('./settings');
55
var util = require('./util');
6+
var sendClickHit = require('./stats');
67

78
var client = function(sitekey) {
89
this.sitekey = sitekey;
@@ -18,14 +19,22 @@ var client = function(sitekey) {
1819
*/
1920
this.search = function(a1, a2) {
2021

21-
var keyword = a1;
22-
var callback = a2;
22+
var keyword = null;
23+
var callback = null;
2324

25+
// Keyword and callback
26+
if (a1 && util.isFunction(a2)) {
27+
keyword = a1;
28+
callback = a2;
29+
}
2430
// If function is called with callback only, use previous keyword from settings object
25-
if (!a2 && util.isFunction(a1)) {
31+
else if (!a2 && util.isFunction(a1)) {
2632
keyword = this.settings.getSettings().keyword;
2733
callback = a1;
2834
}
35+
else {
36+
throw "Illegal search parameters. Should be (keyword, callbackFunction) or just (callbackFunction)";
37+
}
2938

3039
this.settings.setKeyword(keyword);
3140
executeApiFetch(this.sitekey, 'search', this.settings.getSettings(), callback);
@@ -55,7 +64,7 @@ var client = function(sitekey) {
5564
this.setPaging = function(page, pageSize, sortBy, sortOder) { this.settings.setPaging(page, pageSize, sortBy, sortOder); }
5665
this.nextPage = function() { this.settings.nextPage(); }
5766
this.previousPage = function() { this.settings.previousPage(); }
58-
67+
this.hitClicked = function(docid, position) { sendClickHit(this.sitekey, this.settings.getSettings().keyword, docid, position); }
5968
}
6069

6170
module.exports = client;

0 commit comments

Comments
 (0)