@@ -7,11 +7,13 @@ var Settings = require('./settings');
77var util = require ( './util' ) ;
88var throttle = require ( './throttle' ) ;
99
10+ var API_HOSTNAME = 'api.addsearch.com' ;
1011var API_THROTTLE_TIME_MS = 200 ;
1112
1213var client = function ( sitekey , privatekey ) {
1314 this . sitekey = sitekey ;
1415 this . privatekey = privatekey ;
16+ this . apiHostname = API_HOSTNAME ;
1517 this . settings = new Settings ( ) ;
1618 this . sessionId = ( 'a-' + ( Math . random ( ) * 100000000 ) ) . substring ( 0 , 10 ) ;
1719
@@ -53,7 +55,7 @@ var client = function(sitekey, privatekey) {
5355 if ( ! this . throttledSearchFetch ) {
5456 this . throttledSearchFetch = throttle ( API_THROTTLE_TIME_MS , executeApiFetch ) ;
5557 }
56- this . throttledSearchFetch ( this . sitekey , 'search' , this . settings . getSettings ( ) , callback ) ;
58+ this . throttledSearchFetch ( this . apiHostname , this . sitekey , 'search' , this . settings . getSettings ( ) , callback ) ;
5759 }
5860
5961
@@ -71,7 +73,7 @@ var client = function(sitekey, privatekey) {
7173 if ( ! this . throttledSuggestionsFetch ) {
7274 this . throttledSuggestionsFetch = throttle ( API_THROTTLE_TIME_MS , executeApiFetch ) ;
7375 }
74- this . throttledSuggestionsFetch ( this . sitekey , 'suggest' , this . settings . getSettings ( ) , callback ) ;
76+ this . throttledSuggestionsFetch ( this . apiHostname , this . sitekey , 'suggest' , this . settings . getSettings ( ) , callback ) ;
7577 }
7678
7779
@@ -89,37 +91,37 @@ var client = function(sitekey, privatekey) {
8991 if ( ! this . throttledAutocompleteFetch ) {
9092 this . throttledAutocompleteFetch = throttle ( API_THROTTLE_TIME_MS , executeApiFetch ) ;
9193 }
92- this . throttledAutocompleteFetch ( this . sitekey , 'autocomplete' , this . settings . getSettings ( ) , callback ) ;
94+ this . throttledAutocompleteFetch ( this . apiHostname , this . sitekey , 'autocomplete' , this . settings . getSettings ( ) , callback ) ;
9395 }
9496
9597
9698 /**
9799 * Indexing API functions
98100 */
99101 this . getDocument = function ( id ) {
100- return indexingapi . getDocument ( this . sitekey , this . privatekey , id ) ;
102+ return indexingapi . getDocument ( this . apiHostname , this . sitekey , this . privatekey , id ) ;
101103 }
102104
103105 this . saveDocument = function ( document ) {
104- return indexingapi . saveDocument ( this . sitekey , this . privatekey , document ) ;
106+ return indexingapi . saveDocument ( this . apiHostname , this . sitekey , this . privatekey , document ) ;
105107 }
106108
107109 this . saveDocumentsBatch = function ( batch ) {
108110 if ( ! batch || ! batch . documents || ! Array . isArray ( batch . documents ) ) {
109111 throw "Please provide an array of documents: {documents: []}" ;
110112 }
111- return indexingapi . saveDocumentsBatch ( this . sitekey , this . privatekey , batch ) ;
113+ return indexingapi . saveDocumentsBatch ( this . apiHostname , this . sitekey , this . privatekey , batch ) ;
112114 }
113115
114116 this . deleteDocument = function ( id ) {
115- return indexingapi . deleteDocument ( this . sitekey , this . privatekey , id ) ;
117+ return indexingapi . deleteDocument ( this . apiHostname , this . sitekey , this . privatekey , id ) ;
116118 }
117119
118120 this . deleteDocumentsBatch = function ( batch ) {
119121 if ( ! batch || ! batch . documents || ! Array . isArray ( batch . documents ) ) {
120122 throw "Please provide an array of document ids: {documents: []}" ;
121123 }
122- return indexingapi . deleteDocumentsBatch ( this . sitekey , this . privatekey , batch ) ;
124+ return indexingapi . deleteDocumentsBatch ( this . apiHostname , this . sitekey , this . privatekey , batch ) ;
123125 }
124126
125127
@@ -128,6 +130,7 @@ var client = function(sitekey, privatekey) {
128130 /**
129131 * Public functions
130132 */
133+ this . setApiHostname = function ( hostname ) { this . apiHostname = hostname ; }
131134 this . getSettings = function ( ) { return this . settings . getSettings ( ) ; }
132135 this . setLanguage = function ( lang ) { this . settings . setLanguage ( lang ) ; }
133136 this . setCategoryFilters = function ( categories ) { this . settings . setCategoryFilters ( categories ) ; }
@@ -165,7 +168,7 @@ var client = function(sitekey, privatekey) {
165168 keyword : keyword ,
166169 numberOfResults : data . numberOfResults
167170 } ;
168- sendStats ( this . sitekey , data ) ;
171+ sendStats ( this . apiHostname , this . sitekey , data ) ;
169172 }
170173
171174 else if ( type === 'click' ) {
@@ -176,7 +179,7 @@ var client = function(sitekey, privatekey) {
176179 docid : data . documentId ,
177180 position : data . position
178181 } ;
179- sendStats ( this . sitekey , data ) ;
182+ sendStats ( this . apiHostname , this . sitekey , data ) ;
180183 }
181184
182185 else {
0 commit comments