Skip to content

Commit f94cff3

Browse files
committed
Merge branch 'main' into fix/javascript-template
2 parents aeb2232 + 4dc48f4 commit f94cff3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+936
-1479
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/Pair.java

Lines changed: 0 additions & 48 deletions
This file was deleted.

0 commit comments

Comments
 (0)