@@ -188,118 +188,6 @@ public String parameterToString(Object param) {
188
188
}
189
189
}
190
190
191
- /**
192
- * Formats the specified query parameter to a list containing a single {@code Pair} object.
193
- *
194
- * <p>Note that {@code value} must not be a collection.
195
- *
196
- * @param name The name of the parameter.
197
- * @param value The value of the parameter.
198
- * @return A list containing a single {@code Pair} object.
199
- */
200
- public List <Pair > parameterToPair (String name , Object value ) {
201
- List <Pair > params = new ArrayList <Pair >();
202
-
203
- // preconditions
204
- if (name == null || name .isEmpty () || value == null ) {
205
- return params ;
206
- }
207
-
208
- params .add (new Pair (name , parameterToString (value )));
209
- return params ;
210
- }
211
-
212
- /**
213
- * Formats the specified collection query parameters to a list of {@code Pair} objects.
214
- *
215
- * <p>Note that the values of each of the returned Pair objects are percent-encoded.
216
- *
217
- * @param collectionFormat The collection format of the parameter.
218
- * @param name The name of the parameter.
219
- * @param value The value of the parameter.
220
- * @return A list of {@code Pair} objects.
221
- */
222
- public List <Pair > parameterToPairs (
223
- String collectionFormat ,
224
- String name ,
225
- Collection value
226
- ) {
227
- List <Pair > params = new ArrayList <Pair >();
228
-
229
- // preconditions
230
- if (name == null || name .isEmpty () || value == null || value .isEmpty ()) {
231
- return params ;
232
- }
233
-
234
- // create the params based on the collection format
235
- if ("multi" .equals (collectionFormat )) {
236
- for (Object item : value ) {
237
- params .add (new Pair (name , escapeString (parameterToString (item ))));
238
- }
239
- return params ;
240
- }
241
-
242
- // collectionFormat is assumed to be "csv" by default
243
- String delimiter = "," ;
244
-
245
- // escape all delimiters except commas, which are URI reserved
246
- // characters
247
- if ("ssv" .equals (collectionFormat )) {
248
- delimiter = escapeString (" " );
249
- } else if ("tsv" .equals (collectionFormat )) {
250
- delimiter = escapeString ("\t " );
251
- } else if ("pipes" .equals (collectionFormat )) {
252
- delimiter = escapeString ("|" );
253
- }
254
-
255
- StringBuilder sb = new StringBuilder ();
256
- for (Object item : value ) {
257
- sb .append (delimiter );
258
- sb .append (escapeString (parameterToString (item )));
259
- }
260
-
261
- params .add (new Pair (name , sb .substring (delimiter .length ())));
262
-
263
- return params ;
264
- }
265
-
266
- /**
267
- * Formats the specified collection path parameter to a string value.
268
- *
269
- * @param collectionFormat The collection format of the parameter.
270
- * @param value The value of the parameter.
271
- * @return String representation of the parameter
272
- */
273
- public String collectionPathParameterToString (
274
- String collectionFormat ,
275
- Collection value
276
- ) {
277
- // create the value based on the collection format
278
- if ("multi" .equals (collectionFormat )) {
279
- // not valid for path params
280
- return parameterToString (value );
281
- }
282
-
283
- // collectionFormat is assumed to be "csv" by default
284
- String delimiter = "," ;
285
-
286
- if ("ssv" .equals (collectionFormat )) {
287
- delimiter = " " ;
288
- } else if ("tsv" .equals (collectionFormat )) {
289
- delimiter = "\t " ;
290
- } else if ("pipes" .equals (collectionFormat )) {
291
- delimiter = "|" ;
292
- }
293
-
294
- StringBuilder sb = new StringBuilder ();
295
- for (Object item : value ) {
296
- sb .append (delimiter );
297
- sb .append (parameterToString (item ));
298
- }
299
-
300
- return sb .substring (delimiter .length ());
301
- }
302
-
303
191
/**
304
192
* Check if the given MIME is a JSON MIME. JSON MIME examples: application/json application/json;
305
193
* charset=UTF8 APPLICATION/JSON application/vnd.company+json "* / *" is also default to JSON
@@ -574,7 +462,7 @@ public <T> T handleResponse(Response response, Type returnType)
574
462
public Call buildCall (
575
463
String path ,
576
464
String method ,
577
- List < Pair > queryParams ,
465
+ Map < String , String > queryParams ,
578
466
Object body ,
579
467
Map <String , String > headerParams ,
580
468
ApiCallback callback
@@ -607,23 +495,21 @@ public Call buildCall(
607
495
public Request buildRequest (
608
496
String path ,
609
497
String method ,
610
- List < Pair > queryParams ,
498
+ Map < String , String > queryParams ,
611
499
Object body ,
612
500
Map <String , String > headerParams ,
613
501
ApiCallback callback
614
502
) throws AlgoliaRuntimeException {
615
503
headerParams .put ("X-Algolia-Application-Id" , this .appId );
616
504
headerParams .put ("X-Algolia-API-Key" , this .apiKey );
505
+ headerParams .put ("Accept" , "application/json" );
506
+ headerParams .put ("Content-Type" , "application/json" );
617
507
618
508
final String url = buildUrl (path , queryParams );
619
509
final Request .Builder reqBuilder = new Request .Builder ().url (url );
620
510
processHeaderParams (headerParams , reqBuilder );
621
511
622
512
String contentType = (String ) headerParams .get ("Content-Type" );
623
- // ensuring a default content type
624
- if (contentType == null ) {
625
- contentType = "application/json" ;
626
- }
627
513
628
514
RequestBody reqBody ;
629
515
if (!HttpMethod .permitsRequestBody (method )) {
@@ -666,7 +552,7 @@ public Request buildRequest(
666
552
* @param queryParams The query parameters
667
553
* @return The full URL
668
554
*/
669
- public String buildUrl (String path , List < Pair > queryParams ) {
555
+ public String buildUrl (String path , Map < String , String > queryParams ) {
670
556
final StringBuilder url = new StringBuilder ();
671
557
672
558
// The real host will be assigned by the retry strategy
@@ -675,7 +561,7 @@ public String buildUrl(String path, List<Pair> queryParams) {
675
561
if (queryParams != null && !queryParams .isEmpty ()) {
676
562
// support (constant) query string in `path`, e.g. "/posts?draft=1"
677
563
String prefix = path .contains ("?" ) ? "&" : "?" ;
678
- for (Pair param : queryParams ) {
564
+ for (Entry < String , String > param : queryParams . entrySet () ) {
679
565
if (param .getValue () != null ) {
680
566
if (prefix != null ) {
681
567
url .append (prefix );
@@ -685,7 +571,7 @@ public String buildUrl(String path, List<Pair> queryParams) {
685
571
}
686
572
String value = parameterToString (param .getValue ());
687
573
url
688
- .append (escapeString (param .getName ()))
574
+ .append (escapeString (param .getKey ()))
689
575
.append ("=" )
690
576
.append (escapeString (value ));
691
577
}
0 commit comments