Skip to content

Commit 4dc48f4

Browse files
chore: generated code for commit 949c3f2. [skip ci]
Co-authored-by: Clément Vannicatte <[email protected]>
1 parent 949c3f2 commit 4dc48f4

File tree

27 files changed

+670
-1003
lines changed

27 files changed

+670
-1003
lines changed

clients/algoliasearch-client-java-2/algoliasearch-core/src/main/java/com/algolia/ApiClient.java

Lines changed: 7 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -188,118 +188,6 @@ public String parameterToString(Object param) {
188188
}
189189
}
190190

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-
303191
/**
304192
* Check if the given MIME is a JSON MIME. JSON MIME examples: application/json application/json;
305193
* 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)
574462
public Call buildCall(
575463
String path,
576464
String method,
577-
List<Pair> queryParams,
465+
Map<String, String> queryParams,
578466
Object body,
579467
Map<String, String> headerParams,
580468
ApiCallback callback
@@ -607,23 +495,21 @@ public Call buildCall(
607495
public Request buildRequest(
608496
String path,
609497
String method,
610-
List<Pair> queryParams,
498+
Map<String, String> queryParams,
611499
Object body,
612500
Map<String, String> headerParams,
613501
ApiCallback callback
614502
) throws AlgoliaRuntimeException {
615503
headerParams.put("X-Algolia-Application-Id", this.appId);
616504
headerParams.put("X-Algolia-API-Key", this.apiKey);
505+
headerParams.put("Accept", "application/json");
506+
headerParams.put("Content-Type", "application/json");
617507

618508
final String url = buildUrl(path, queryParams);
619509
final Request.Builder reqBuilder = new Request.Builder().url(url);
620510
processHeaderParams(headerParams, reqBuilder);
621511

622512
String contentType = (String) headerParams.get("Content-Type");
623-
// ensuring a default content type
624-
if (contentType == null) {
625-
contentType = "application/json";
626-
}
627513

628514
RequestBody reqBody;
629515
if (!HttpMethod.permitsRequestBody(method)) {
@@ -666,7 +552,7 @@ public Request buildRequest(
666552
* @param queryParams The query parameters
667553
* @return The full URL
668554
*/
669-
public String buildUrl(String path, List<Pair> queryParams) {
555+
public String buildUrl(String path, Map<String, String> queryParams) {
670556
final StringBuilder url = new StringBuilder();
671557

672558
// The real host will be assigned by the retry strategy
@@ -675,7 +561,7 @@ public String buildUrl(String path, List<Pair> queryParams) {
675561
if (queryParams != null && !queryParams.isEmpty()) {
676562
// support (constant) query string in `path`, e.g. "/posts?draft=1"
677563
String prefix = path.contains("?") ? "&" : "?";
678-
for (Pair param : queryParams) {
564+
for (Entry<String, String> param : queryParams.entrySet()) {
679565
if (param.getValue() != null) {
680566
if (prefix != null) {
681567
url.append(prefix);
@@ -685,7 +571,7 @@ public String buildUrl(String path, List<Pair> queryParams) {
685571
}
686572
String value = parameterToString(param.getValue());
687573
url
688-
.append(escapeString(param.getName()))
574+
.append(escapeString(param.getKey()))
689575
.append("=")
690576
.append(escapeString(value));
691577
}

clients/algoliasearch-client-java-2/algoliasearch-core/src/main/java/com/algolia/api/AbtestingClient.java

Lines changed: 23 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import com.algolia.ApiCallback;
44
import com.algolia.ApiClient;
55
import com.algolia.ApiResponse;
6-
import com.algolia.Pair;
76
import com.algolia.exceptions.*;
87
import com.algolia.model.abtesting.*;
98
import com.algolia.utils.*;
@@ -85,12 +84,9 @@ private Call addABTestsCall(
8584
// create path and map variables
8685
String requestPath = "/2/abtests";
8786

88-
List<Pair> queryParams = new ArrayList<Pair>();
87+
Map<String, String> queryParams = new HashMap<String, String>();
8988
Map<String, String> headers = new HashMap<String, String>();
9089

91-
headers.put("Accept", "application/json");
92-
headers.put("Content-Type", "application/json");
93-
9490
return this.buildCall(
9591
requestPath,
9692
"POST",
@@ -175,20 +171,18 @@ private Call delCall(
175171
// create path and map variables
176172
String requestPath = "/1{path}".replaceAll("\\{path\\}", path.toString());
177173

178-
List<Pair> queryParams = new ArrayList<Pair>();
174+
Map<String, String> queryParams = new HashMap<String, String>();
179175
Map<String, String> headers = new HashMap<String, String>();
180176

181177
if (parameters != null) {
182178
for (Map.Entry<String, Object> parameter : parameters.entrySet()) {
183-
queryParams.addAll(
184-
this.parameterToPair(parameter.getKey(), parameter.getValue())
179+
queryParams.put(
180+
parameter.getKey().toString(),
181+
parameterToString(parameter.getValue())
185182
);
186183
}
187184
}
188185

189-
headers.put("Accept", "application/json");
190-
headers.put("Content-Type", "application/json");
191-
192186
return this.buildCall(
193187
requestPath,
194188
"DELETE",
@@ -282,12 +276,9 @@ private Call deleteABTestCall(
282276
this.escapeString(id.toString())
283277
);
284278

285-
List<Pair> queryParams = new ArrayList<Pair>();
279+
Map<String, String> queryParams = new HashMap<String, String>();
286280
Map<String, String> headers = new HashMap<String, String>();
287281

288-
headers.put("Accept", "application/json");
289-
headers.put("Content-Type", "application/json");
290-
291282
return this.buildCall(
292283
requestPath,
293284
"DELETE",
@@ -368,20 +359,18 @@ private Call getCall(
368359
// create path and map variables
369360
String requestPath = "/1{path}".replaceAll("\\{path\\}", path.toString());
370361

371-
List<Pair> queryParams = new ArrayList<Pair>();
362+
Map<String, String> queryParams = new HashMap<String, String>();
372363
Map<String, String> headers = new HashMap<String, String>();
373364

374365
if (parameters != null) {
375366
for (Map.Entry<String, Object> parameter : parameters.entrySet()) {
376-
queryParams.addAll(
377-
this.parameterToPair(parameter.getKey(), parameter.getValue())
367+
queryParams.put(
368+
parameter.getKey().toString(),
369+
parameterToString(parameter.getValue())
378370
);
379371
}
380372
}
381373

382-
headers.put("Accept", "application/json");
383-
headers.put("Content-Type", "application/json");
384-
385374
return this.buildCall(
386375
requestPath,
387376
"GET",
@@ -473,12 +462,9 @@ private Call getABTestCall(Integer id, final ApiCallback<ABTest> callback)
473462
this.escapeString(id.toString())
474463
);
475464

476-
List<Pair> queryParams = new ArrayList<Pair>();
465+
Map<String, String> queryParams = new HashMap<String, String>();
477466
Map<String, String> headers = new HashMap<String, String>();
478467

479-
headers.put("Accept", "application/json");
480-
headers.put("Content-Type", "application/json");
481-
482468
return this.buildCall(
483469
requestPath,
484470
"GET",
@@ -556,20 +542,17 @@ private Call listABTestsCall(
556542
// create path and map variables
557543
String requestPath = "/2/abtests";
558544

559-
List<Pair> queryParams = new ArrayList<Pair>();
545+
Map<String, String> queryParams = new HashMap<String, String>();
560546
Map<String, String> headers = new HashMap<String, String>();
561547

562548
if (offset != null) {
563-
queryParams.addAll(this.parameterToPair("offset", offset));
549+
queryParams.put("offset", parameterToString(offset));
564550
}
565551

566552
if (limit != null) {
567-
queryParams.addAll(this.parameterToPair("limit", limit));
553+
queryParams.put("limit", parameterToString(limit));
568554
}
569555

570-
headers.put("Accept", "application/json");
571-
headers.put("Content-Type", "application/json");
572-
573556
return this.buildCall(
574557
requestPath,
575558
"GET",
@@ -658,20 +641,18 @@ private Call postCall(
658641
// create path and map variables
659642
String requestPath = "/1{path}".replaceAll("\\{path\\}", path.toString());
660643

661-
List<Pair> queryParams = new ArrayList<Pair>();
644+
Map<String, String> queryParams = new HashMap<String, String>();
662645
Map<String, String> headers = new HashMap<String, String>();
663646

664647
if (parameters != null) {
665648
for (Map.Entry<String, Object> parameter : parameters.entrySet()) {
666-
queryParams.addAll(
667-
this.parameterToPair(parameter.getKey(), parameter.getValue())
649+
queryParams.put(
650+
parameter.getKey().toString(),
651+
parameterToString(parameter.getValue())
668652
);
669653
}
670654
}
671655

672-
headers.put("Accept", "application/json");
673-
headers.put("Content-Type", "application/json");
674-
675656
return this.buildCall(
676657
requestPath,
677658
"POST",
@@ -767,20 +748,18 @@ private Call putCall(
767748
// create path and map variables
768749
String requestPath = "/1{path}".replaceAll("\\{path\\}", path.toString());
769750

770-
List<Pair> queryParams = new ArrayList<Pair>();
751+
Map<String, String> queryParams = new HashMap<String, String>();
771752
Map<String, String> headers = new HashMap<String, String>();
772753

773754
if (parameters != null) {
774755
for (Map.Entry<String, Object> parameter : parameters.entrySet()) {
775-
queryParams.addAll(
776-
this.parameterToPair(parameter.getKey(), parameter.getValue())
756+
queryParams.put(
757+
parameter.getKey().toString(),
758+
parameterToString(parameter.getValue())
777759
);
778760
}
779761
}
780762

781-
headers.put("Accept", "application/json");
782-
headers.put("Content-Type", "application/json");
783-
784763
return this.buildCall(
785764
requestPath,
786765
"PUT",
@@ -878,12 +857,9 @@ private Call stopABTestCall(
878857
this.escapeString(id.toString())
879858
);
880859

881-
List<Pair> queryParams = new ArrayList<Pair>();
860+
Map<String, String> queryParams = new HashMap<String, String>();
882861
Map<String, String> headers = new HashMap<String, String>();
883862

884-
headers.put("Accept", "application/json");
885-
headers.put("Content-Type", "application/json");
886-
887863
return this.buildCall(
888864
requestPath,
889865
"POST",

0 commit comments

Comments
 (0)