1
1
import localVarRequest from 'request' ;
2
2
import http from 'http' ;
3
3
4
- import { MultipleQueries } from '../model/multipleQueries' ;
4
+ import { BatchObject } from '../model/batchObject' ;
5
+ import { BatchResponse } from '../model/batchResponse' ;
6
+ import { MultipleQueriesObject } from '../model/multipleQueriesObject' ;
5
7
import { MultipleQueriesResponse } from '../model/multipleQueriesResponse' ;
8
+ import { SaveObjectResponse } from '../model/saveObjectResponse' ;
6
9
7
10
import { ObjectSerializer , Authentication , VoidAuth , Interceptor } from '../model/models' ;
8
11
@@ -72,17 +75,131 @@ export class SearchApi {
72
75
this . interceptors . push ( interceptor ) ;
73
76
}
74
77
78
+ /**
79
+ *
80
+ * @summary Performs multiple write operations in a single API call
81
+ * @param xAlgoliaApplicationId Algolia appID
82
+ * @param xAlgoliaAPIKey Algolia API key
83
+ * @param indexName The index in which to perform the request
84
+ * @param batchObject
85
+ */
86
+ public async batch (
87
+ xAlgoliaApplicationId : string ,
88
+ xAlgoliaAPIKey : string ,
89
+ indexName : string ,
90
+ batchObject : BatchObject ,
91
+ options : { headers : { [ name : string ] : string } } = { headers : { } }
92
+ ) : Promise < { response : http . IncomingMessage ; body : BatchResponse } > {
93
+ const localVarPath =
94
+ this . basePath +
95
+ '/1/indexes/{indexName}/batch' . replace (
96
+ '{' + 'indexName' + '}' ,
97
+ encodeURIComponent ( String ( indexName ) )
98
+ ) ;
99
+ let localVarQueryParameters : any = { } ;
100
+ let localVarHeaderParams : any = ( < any > Object ) . assign ( { } , this . _defaultHeaders ) ;
101
+ const produces = [ 'application/json' ] ;
102
+ // give precedence to 'application/json'
103
+ if ( produces . indexOf ( 'application/json' ) >= 0 ) {
104
+ localVarHeaderParams . Accept = 'application/json' ;
105
+ } else {
106
+ localVarHeaderParams . Accept = produces . join ( ',' ) ;
107
+ }
108
+ let localVarFormParams : any = { } ;
109
+
110
+ // verify required parameter 'xAlgoliaApplicationId' is not null or undefined
111
+ if ( xAlgoliaApplicationId === null || xAlgoliaApplicationId === undefined ) {
112
+ throw new Error (
113
+ 'Required parameter xAlgoliaApplicationId was null or undefined when calling batch.'
114
+ ) ;
115
+ }
116
+
117
+ // verify required parameter 'xAlgoliaAPIKey' is not null or undefined
118
+ if ( xAlgoliaAPIKey === null || xAlgoliaAPIKey === undefined ) {
119
+ throw new Error (
120
+ 'Required parameter xAlgoliaAPIKey was null or undefined when calling batch.'
121
+ ) ;
122
+ }
123
+
124
+ // verify required parameter 'indexName' is not null or undefined
125
+ if ( indexName === null || indexName === undefined ) {
126
+ throw new Error ( 'Required parameter indexName was null or undefined when calling batch.' ) ;
127
+ }
128
+
129
+ // verify required parameter 'batchObject' is not null or undefined
130
+ if ( batchObject === null || batchObject === undefined ) {
131
+ throw new Error ( 'Required parameter batchObject was null or undefined when calling batch.' ) ;
132
+ }
133
+
134
+ localVarHeaderParams [ 'X-Algolia-Application-Id' ] = ObjectSerializer . serialize (
135
+ xAlgoliaApplicationId ,
136
+ 'string'
137
+ ) ;
138
+ localVarHeaderParams [ 'X-Algolia-API-Key' ] = ObjectSerializer . serialize (
139
+ xAlgoliaAPIKey ,
140
+ 'string'
141
+ ) ;
142
+ ( < any > Object ) . assign ( localVarHeaderParams , options . headers ) ;
143
+
144
+ let localVarUseFormData = false ;
145
+
146
+ let localVarRequestOptions : localVarRequest . Options = {
147
+ method : 'POST' ,
148
+ qs : localVarQueryParameters ,
149
+ headers : localVarHeaderParams ,
150
+ uri : localVarPath ,
151
+ useQuerystring : this . _useQuerystring ,
152
+ json : true ,
153
+ body : ObjectSerializer . serialize ( batchObject , 'BatchObject' ) ,
154
+ } ;
155
+
156
+ let authenticationPromise = Promise . resolve ( ) ;
157
+ authenticationPromise = authenticationPromise . then ( ( ) =>
158
+ this . authentications . default . applyToRequest ( localVarRequestOptions )
159
+ ) ;
160
+
161
+ let interceptorPromise = authenticationPromise ;
162
+ for ( const interceptor of this . interceptors ) {
163
+ interceptorPromise = interceptorPromise . then ( ( ) => interceptor ( localVarRequestOptions ) ) ;
164
+ }
165
+
166
+ return interceptorPromise . then ( ( ) => {
167
+ if ( Object . keys ( localVarFormParams ) . length ) {
168
+ if ( localVarUseFormData ) {
169
+ ( < any > localVarRequestOptions ) . formData = localVarFormParams ;
170
+ } else {
171
+ localVarRequestOptions . form = localVarFormParams ;
172
+ }
173
+ }
174
+ return new Promise < { response : http . IncomingMessage ; body : BatchResponse } > (
175
+ ( resolve , reject ) => {
176
+ localVarRequest ( localVarRequestOptions , ( error , response , body ) => {
177
+ if ( error ) {
178
+ reject ( error ) ;
179
+ } else {
180
+ body = ObjectSerializer . deserialize ( body , 'BatchResponse' ) ;
181
+ if ( response . statusCode && response . statusCode >= 200 && response . statusCode <= 299 ) {
182
+ resolve ( { response : response , body : body } ) ;
183
+ } else {
184
+ reject ( new HttpError ( response , body , response . statusCode ) ) ;
185
+ }
186
+ }
187
+ } ) ;
188
+ }
189
+ ) ;
190
+ } ) ;
191
+ }
75
192
/**
76
193
*
77
194
* @summary Get search results for the given requests.
78
- * @param multipleQueries
79
195
* @param xAlgoliaApplicationId Algolia appID
80
196
* @param xAlgoliaAPIKey Algolia API key
197
+ * @param multipleQueriesObject
81
198
*/
82
- public async search (
83
- multipleQueries : Array < MultipleQueries > ,
84
- xAlgoliaApplicationId ? : string ,
85
- xAlgoliaAPIKey ?: string ,
199
+ public async multipleQueries (
200
+ xAlgoliaApplicationId : string ,
201
+ xAlgoliaAPIKey : string ,
202
+ multipleQueriesObject : MultipleQueriesObject ,
86
203
options : { headers : { [ name : string ] : string } } = { headers : { } }
87
204
) : Promise < { response : http . IncomingMessage ; body : MultipleQueriesResponse } > {
88
205
const localVarPath = this . basePath + '/1/indexes/*/queries' ;
@@ -97,10 +214,24 @@ export class SearchApi {
97
214
}
98
215
let localVarFormParams : any = { } ;
99
216
100
- // verify required parameter 'multipleQueries ' is not null or undefined
101
- if ( multipleQueries === null || multipleQueries === undefined ) {
217
+ // verify required parameter 'xAlgoliaApplicationId ' is not null or undefined
218
+ if ( xAlgoliaApplicationId === null || xAlgoliaApplicationId === undefined ) {
102
219
throw new Error (
103
- 'Required parameter multipleQueries was null or undefined when calling search.'
220
+ 'Required parameter xAlgoliaApplicationId was null or undefined when calling multipleQueries.'
221
+ ) ;
222
+ }
223
+
224
+ // verify required parameter 'xAlgoliaAPIKey' is not null or undefined
225
+ if ( xAlgoliaAPIKey === null || xAlgoliaAPIKey === undefined ) {
226
+ throw new Error (
227
+ 'Required parameter xAlgoliaAPIKey was null or undefined when calling multipleQueries.'
228
+ ) ;
229
+ }
230
+
231
+ // verify required parameter 'multipleQueriesObject' is not null or undefined
232
+ if ( multipleQueriesObject === null || multipleQueriesObject === undefined ) {
233
+ throw new Error (
234
+ 'Required parameter multipleQueriesObject was null or undefined when calling multipleQueries.'
104
235
) ;
105
236
}
106
237
@@ -123,7 +254,7 @@ export class SearchApi {
123
254
uri : localVarPath ,
124
255
useQuerystring : this . _useQuerystring ,
125
256
json : true ,
126
- body : ObjectSerializer . serialize ( multipleQueries , 'Array<MultipleQueries> ' ) ,
257
+ body : ObjectSerializer . serialize ( multipleQueriesObject , 'MultipleQueriesObject ' ) ,
127
258
} ;
128
259
129
260
let authenticationPromise = Promise . resolve ( ) ;
@@ -162,4 +293,122 @@ export class SearchApi {
162
293
) ;
163
294
} ) ;
164
295
}
296
+ /**
297
+ * Add an object to the index, automatically assigning it an object ID
298
+ * @summary Save object
299
+ * @param xAlgoliaApplicationId Algolia appID
300
+ * @param xAlgoliaAPIKey Algolia API key
301
+ * @param indexName The index in which to perform the request
302
+ * @param requestBody
303
+ */
304
+ public async saveObject (
305
+ xAlgoliaApplicationId : string ,
306
+ xAlgoliaAPIKey : string ,
307
+ indexName : string ,
308
+ requestBody : { [ key : string ] : object } ,
309
+ options : { headers : { [ name : string ] : string } } = { headers : { } }
310
+ ) : Promise < { response : http . IncomingMessage ; body : SaveObjectResponse } > {
311
+ const localVarPath =
312
+ this . basePath +
313
+ '/1/indexes/{indexName}' . replace (
314
+ '{' + 'indexName' + '}' ,
315
+ encodeURIComponent ( String ( indexName ) )
316
+ ) ;
317
+ let localVarQueryParameters : any = { } ;
318
+ let localVarHeaderParams : any = ( < any > Object ) . assign ( { } , this . _defaultHeaders ) ;
319
+ const produces = [ 'application/json' ] ;
320
+ // give precedence to 'application/json'
321
+ if ( produces . indexOf ( 'application/json' ) >= 0 ) {
322
+ localVarHeaderParams . Accept = 'application/json' ;
323
+ } else {
324
+ localVarHeaderParams . Accept = produces . join ( ',' ) ;
325
+ }
326
+ let localVarFormParams : any = { } ;
327
+
328
+ // verify required parameter 'xAlgoliaApplicationId' is not null or undefined
329
+ if ( xAlgoliaApplicationId === null || xAlgoliaApplicationId === undefined ) {
330
+ throw new Error (
331
+ 'Required parameter xAlgoliaApplicationId was null or undefined when calling saveObject.'
332
+ ) ;
333
+ }
334
+
335
+ // verify required parameter 'xAlgoliaAPIKey' is not null or undefined
336
+ if ( xAlgoliaAPIKey === null || xAlgoliaAPIKey === undefined ) {
337
+ throw new Error (
338
+ 'Required parameter xAlgoliaAPIKey was null or undefined when calling saveObject.'
339
+ ) ;
340
+ }
341
+
342
+ // verify required parameter 'indexName' is not null or undefined
343
+ if ( indexName === null || indexName === undefined ) {
344
+ throw new Error (
345
+ 'Required parameter indexName was null or undefined when calling saveObject.'
346
+ ) ;
347
+ }
348
+
349
+ // verify required parameter 'requestBody' is not null or undefined
350
+ if ( requestBody === null || requestBody === undefined ) {
351
+ throw new Error (
352
+ 'Required parameter requestBody was null or undefined when calling saveObject.'
353
+ ) ;
354
+ }
355
+
356
+ localVarHeaderParams [ 'X-Algolia-Application-Id' ] = ObjectSerializer . serialize (
357
+ xAlgoliaApplicationId ,
358
+ 'string'
359
+ ) ;
360
+ localVarHeaderParams [ 'X-Algolia-API-Key' ] = ObjectSerializer . serialize (
361
+ xAlgoliaAPIKey ,
362
+ 'string'
363
+ ) ;
364
+ ( < any > Object ) . assign ( localVarHeaderParams , options . headers ) ;
365
+
366
+ let localVarUseFormData = false ;
367
+
368
+ let localVarRequestOptions : localVarRequest . Options = {
369
+ method : 'POST' ,
370
+ qs : localVarQueryParameters ,
371
+ headers : localVarHeaderParams ,
372
+ uri : localVarPath ,
373
+ useQuerystring : this . _useQuerystring ,
374
+ json : true ,
375
+ body : ObjectSerializer . serialize ( requestBody , '{ [key: string]: object; }' ) ,
376
+ } ;
377
+
378
+ let authenticationPromise = Promise . resolve ( ) ;
379
+ authenticationPromise = authenticationPromise . then ( ( ) =>
380
+ this . authentications . default . applyToRequest ( localVarRequestOptions )
381
+ ) ;
382
+
383
+ let interceptorPromise = authenticationPromise ;
384
+ for ( const interceptor of this . interceptors ) {
385
+ interceptorPromise = interceptorPromise . then ( ( ) => interceptor ( localVarRequestOptions ) ) ;
386
+ }
387
+
388
+ return interceptorPromise . then ( ( ) => {
389
+ if ( Object . keys ( localVarFormParams ) . length ) {
390
+ if ( localVarUseFormData ) {
391
+ ( < any > localVarRequestOptions ) . formData = localVarFormParams ;
392
+ } else {
393
+ localVarRequestOptions . form = localVarFormParams ;
394
+ }
395
+ }
396
+ return new Promise < { response : http . IncomingMessage ; body : SaveObjectResponse } > (
397
+ ( resolve , reject ) => {
398
+ localVarRequest ( localVarRequestOptions , ( error , response , body ) => {
399
+ if ( error ) {
400
+ reject ( error ) ;
401
+ } else {
402
+ body = ObjectSerializer . deserialize ( body , 'SaveObjectResponse' ) ;
403
+ if ( response . statusCode && response . statusCode >= 200 && response . statusCode <= 299 ) {
404
+ resolve ( { response : response , body : body } ) ;
405
+ } else {
406
+ reject ( new HttpError ( response , body , response . statusCode ) ) ;
407
+ }
408
+ }
409
+ } ) ;
410
+ }
411
+ ) ;
412
+ } ) ;
413
+ }
165
414
}
0 commit comments