|
1 | 1 | 'use strict'; |
2 | 2 |
|
3 | 3 | var executeApiFetch = require('./apifetch'); |
| 4 | +var indexingapi = require('./indexingapi'); |
4 | 5 | var sendStats = require('./stats'); |
5 | 6 | var Settings = require('./settings'); |
6 | 7 | var util = require('./util'); |
7 | 8 | var throttle = require('./throttle'); |
8 | 9 |
|
9 | 10 | var API_THROTTLE_TIME_MS = 200; |
10 | 11 |
|
11 | | -var client = function(sitekey) { |
| 12 | +var client = function(sitekey, privatekey) { |
12 | 13 | this.sitekey = sitekey; |
| 14 | + this.privatekey = privatekey; |
13 | 15 | this.settings = new Settings(); |
14 | 16 | this.sessionId = ('a-' + (Math.random() * 100000000)).substring(0, 10); |
15 | 17 |
|
@@ -91,6 +93,38 @@ var client = function(sitekey) { |
91 | 93 | } |
92 | 94 |
|
93 | 95 |
|
| 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 | + |
94 | 128 | /** |
95 | 129 | * Public functions |
96 | 130 | */ |
|
0 commit comments