Skip to content

Commit a2f1969

Browse files
committed
Expose indexing api functions
1 parent ee3cc1f commit a2f1969

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

src/index.js

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
'use strict';
22

33
var executeApiFetch = require('./apifetch');
4+
var indexingapi = require('./indexingapi');
45
var sendStats = require('./stats');
56
var Settings = require('./settings');
67
var util = require('./util');
78
var throttle = require('./throttle');
89

910
var API_THROTTLE_TIME_MS = 200;
1011

11-
var client = function(sitekey) {
12+
var client = function(sitekey, privatekey) {
1213
this.sitekey = sitekey;
14+
this.privatekey = privatekey;
1315
this.settings = new Settings();
1416
this.sessionId = ('a-' + (Math.random() * 100000000)).substring(0, 10);
1517

@@ -91,6 +93,38 @@ var client = function(sitekey) {
9193
}
9294

9395

96+
/**
97+
* Indexing API functions
98+
*/
99+
this.getDocument = function(id) {
100+
return indexingapi.getDocument(this.sitekey, this.privatekey, id);
101+
}
102+
103+
this.saveDocument = function(document) {
104+
return indexingapi.saveDocument(this.sitekey, this.privatekey, document);
105+
}
106+
107+
this.saveDocumentsBatch = function(batch) {
108+
if (!batch || !batch.documents || !Array.isArray(batch.documents)) {
109+
throw "Please provide an array of documents: {documents: []}";
110+
}
111+
return indexingapi.saveDocumentsBatch(this.sitekey, this.privatekey, batch);
112+
}
113+
114+
this.deleteDocument = function(id) {
115+
return indexingapi.deleteDocument(this.sitekey, this.privatekey, id);
116+
}
117+
118+
this.deleteDocumentsBatch = function(batch) {
119+
if (!batch || !batch.documents || !Array.isArray(batch.documents)) {
120+
throw "Please provide an array of document ids: {documents: []}";
121+
}
122+
return indexingapi.deleteDocumentsBatch(this.sitekey, this.privatekey, batch);
123+
}
124+
125+
126+
127+
94128
/**
95129
* Public functions
96130
*/

0 commit comments

Comments
 (0)