@@ -190,111 +190,6 @@ public class ApiClient {
190
190
}
191
191
}
192
192
193
- /**
194
- * Formats the specified query parameter to a list containing a single {@code Pair} object.
195
- *
196
- * Note that {@code value} must not be a collection.
197
- *
198
- * @param name The name of the parameter.
199
- * @param value The value of the parameter.
200
- * @return A list containing a single {@code Pair} object.
201
- */
202
- public List<Pair> parameterToPair(String name, Object value) {
203
- List<Pair> params = new ArrayList<Pair>();
204
-
205
- // preconditions
206
- if (name == null || name.isEmpty() || value == null) {
207
- return params;
208
- }
209
-
210
- params.add(new Pair(name, parameterToString(value)));
211
- return params;
212
- }
213
-
214
- /**
215
- * Formats the specified collection query parameters to a list of {@code Pair} objects.
216
- *
217
- * Note that the values of each of the returned Pair objects are percent-encoded.
218
- *
219
- * @param collectionFormat The collection format of the parameter.
220
- * @param name The name of the parameter.
221
- * @param value The value of the parameter.
222
- * @return A list of {@code Pair} objects.
223
- */
224
- public List<Pair> parameterToPairs(String collectionFormat, String name, Collection value) {
225
- List<Pair> params = new ArrayList<Pair>();
226
-
227
- // preconditions
228
- if (name == null || name.isEmpty() || value == null || value.isEmpty()) {
229
- return params;
230
- }
231
-
232
- // create the params based on the collection format
233
- if (" multi" .equals(collectionFormat)) {
234
- for (Object item : value) {
235
- params.add(new Pair(name, escapeString(parameterToString(item))));
236
- }
237
- return params;
238
- }
239
-
240
- // collectionFormat is assumed to be " csv" by default
241
- String delimiter = " ," ;
242
-
243
- // escape all delimiters except commas, which are URI reserved
244
- // characters
245
- if (" ssv" .equals(collectionFormat)) {
246
- delimiter = escapeString(" " );
247
- } else if (" tsv" .equals(collectionFormat)) {
248
- delimiter = escapeString(" \t" );
249
- } else if (" pipes" .equals(collectionFormat)) {
250
- delimiter = escapeString(" |" );
251
- }
252
-
253
- StringBuilder sb = new StringBuilder();
254
- for (Object item : value) {
255
- sb.append(delimiter);
256
- sb.append(escapeString(parameterToString(item)));
257
- }
258
-
259
- params.add(new Pair(name, sb.substring(delimiter.length())));
260
-
261
- return params;
262
- }
263
-
264
- /**
265
- * Formats the specified collection path parameter to a string value.
266
- *
267
- * @param collectionFormat The collection format of the parameter.
268
- * @param value The value of the parameter.
269
- * @return String representation of the parameter
270
- */
271
- public String collectionPathParameterToString(String collectionFormat, Collection value) {
272
- // create the value based on the collection format
273
- if (" multi" .equals(collectionFormat)) {
274
- // not valid for path params
275
- return parameterToString(value);
276
- }
277
-
278
- // collectionFormat is assumed to be " csv" by default
279
- String delimiter = " ," ;
280
-
281
- if (" ssv" .equals(collectionFormat)) {
282
- delimiter = " " ;
283
- } else if (" tsv" .equals(collectionFormat)) {
284
- delimiter = " \t" ;
285
- } else if (" pipes" .equals(collectionFormat)) {
286
- delimiter = " |" ;
287
- }
288
-
289
- StringBuilder sb = new StringBuilder() ;
290
- for (Object item : value) {
291
- sb.append(delimiter);
292
- sb.append(parameterToString(item));
293
- }
294
-
295
- return sb.substring(delimiter.length());
296
- }
297
-
298
193
/**
299
194
* Check if the given MIME is a JSON MIME.
300
195
* JSON MIME examples:
@@ -534,7 +429,7 @@ public class ApiClient {
534
429
* @return The HTTP call
535
430
* @throws AlgoliaRuntimeException If fail to serialize the request body object
536
431
*/
537
- public Call buildCall(String path, String method, List< Pair > queryParams, Object body, Map<String , String > headerParams, ApiCallback callback) throws AlgoliaRuntimeException {
432
+ public Call buildCall(String path, String method, Map< String , String > queryParams, Object body, Map<String , String > headerParams, ApiCallback callback) throws AlgoliaRuntimeException {
538
433
Request request = buildRequest(path, method, queryParams, body, headerParams, callback);
539
434
540
435
return requester.newCall(request);
@@ -552,19 +447,17 @@ public class ApiClient {
552
447
* @return The HTTP request
553
448
* @throws AlgoliaRuntimeException If fail to serialize the request body object
554
449
*/
555
- public Request buildRequest(String path, String method, List< Pair > queryParams, Object body, Map<String , String > headerParams, ApiCallback callback) throws AlgoliaRuntimeException {
450
+ public Request buildRequest(String path, String method, Map< String , String > queryParams, Object body, Map<String , String > headerParams, ApiCallback callback) throws AlgoliaRuntimeException {
556
451
headerParams.put(" X-Algolia-Application-Id" , this.appId);
557
452
headerParams.put(" X-Algolia-API-Key" , this.apiKey);
453
+ headerParams.put(" Accept" , " application/json" );
454
+ headerParams.put(" Content-Type" , " application/json" );
558
455
559
456
final String url = buildUrl(path, queryParams);
560
457
final Request.Builder reqBuilder = new Request.Builder().url(url);
561
458
processHeaderParams(headerParams, reqBuilder);
562
459
563
460
String contentType = (String) headerParams.get(" Content-Type" );
564
- // ensuring a default content type
565
- if (contentType == null) {
566
- contentType = " application/json" ;
567
- }
568
461
569
462
RequestBody reqBody;
570
463
if (! HttpMethod.permitsRequestBody(method)) {
@@ -604,7 +497,7 @@ public class ApiClient {
604
497
* @param queryParams The query parameters
605
498
* @return The full URL
606
499
*/
607
- public String buildUrl(String path, List< Pair > queryParams) {
500
+ public String buildUrl(String path, Map< String , String > queryParams) {
608
501
final StringBuilder url = new StringBuilder();
609
502
610
503
//The real host will be assigned by the retry strategy
@@ -613,7 +506,7 @@ public class ApiClient {
613
506
if (queryParams != null && ! queryParams.isEmpty()) {
614
507
// support (constant ) query string in `path`, e.g. " /posts?draft=1"
615
508
String prefix = path.contains(" ?" ) ? " &" : " ?" ;
616
- for (Pair param : queryParams) {
509
+ for (Entry < String, String > param : queryParams.entrySet() ) {
617
510
if (param.getValue() != null) {
618
511
if (prefix != null) {
619
512
url.append(prefix);
@@ -622,7 +515,7 @@ public class ApiClient {
622
515
url.append(" &" );
623
516
}
624
517
String value = parameterToString(param.getValue());
625
- url.append(escapeString(param.getName ())).append("=").append(escapeString(value));
518
+ url.append(escapeString(param.getKey ())).append("=").append(escapeString(value));
626
519
}
627
520
}
628
521
}
0 commit comments