Skip to content

Commit 6f8f40a

Browse files
committed
fix(clients): %s/setApiKey/setAlgoliaApiKey
1 parent 4983219 commit 6f8f40a

File tree

21 files changed

+90
-72
lines changed

21 files changed

+90
-72
lines changed

clients/algoliasearch-client-dart/packages/client_core/lib/src/api_client.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ abstract interface class ApiClient {
1212
ClientOptions get options;
1313

1414
/// Allow switching the API key used to authenticate requests.
15-
void setApiKey(String apiKey);
15+
void setAlgoliaApiKey(String apiKey);
1616

1717
/// Dispose of underlying resources.
1818
void dispose();

clients/algoliasearch-client-dart/packages/client_core/lib/src/transport/dio/dio_requester.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ class DioRequester implements Requester {
116116
void close() => _client.close();
117117

118118
@override
119-
void setApiKey(String apiKey) {
119+
void setAlgoliaApiKey(String apiKey) {
120120
var authInterceptor = _client.interceptors
121121
.firstWhere((element) => element is AuthInterceptor) as AuthInterceptor;
122122
_client.interceptors.remove(authInterceptor);

clients/algoliasearch-client-dart/packages/client_core/lib/src/transport/requester.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ abstract class Requester {
1212
Future<HttpResponse> perform(HttpRequest request);
1313

1414
/// Allows to switch the API key used to authenticate requests.
15-
void setApiKey(String apiKey);
15+
void setAlgoliaApiKey(String apiKey);
1616

1717
/// Closes any underlying resources that the Requester might be using.
1818
///

clients/algoliasearch-client-java/algoliasearch/src/main/java/com/algolia/config/Requester.java

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,35 +4,40 @@
44
import java.io.Closeable;
55

66
/**
7-
* Represents a mechanism for executing HTTP requests and deserializing responses. It provides
8-
* methods for making requests and returning the desired object representation. Implementations of
7+
* Represents a mechanism for executing HTTP requests and deserializing
8+
* responses. It provides
9+
* methods for making requests and returning the desired object representation.
10+
* Implementations of
911
* this interface should ensure proper resource management.
1012
*/
1113
public interface Requester extends Closeable {
1214
/**
13-
* Executes an HTTP request and deserializes the response into a specified Java type.
15+
* Executes an HTTP request and deserializes the response into a specified Java
16+
* type.
1417
*
15-
* @param <T> The type of the returned object.
16-
* @param httpRequest The HTTP request to be executed.
18+
* @param <T> The type of the returned object.
19+
* @param httpRequest The HTTP request to be executed.
1720
* @param requestOptions Optional request options.
18-
* @param returnType The class of the response.
19-
* @param innerType The inner class type if the response is a container type.
21+
* @param returnType The class of the response.
22+
* @param innerType The inner class type if the response is a container
23+
* type.
2024
* @return The deserialized response.
2125
*/
2226
<T> T execute(HttpRequest httpRequest, RequestOptions requestOptions, Class<?> returnType, Class<?> innerType);
2327

2428
/**
25-
* Executes an HTTP request and deserializes the response into a specified type reference.
29+
* Executes an HTTP request and deserializes the response into a specified type
30+
* reference.
2631
*
27-
* @param <T> The type of the returned object.
28-
* @param httpRequest The HTTP request to be executed.
32+
* @param <T> The type of the returned object.
33+
* @param httpRequest The HTTP request to be executed.
2934
* @param requestOptions Optional request options.
30-
* @param returnType The type reference of the response.
35+
* @param returnType The type reference of the response.
3136
* @return The deserialized response.
3237
*/
3338
<T> T execute(HttpRequest httpRequest, RequestOptions requestOptions, TypeReference<?> returnType);
3439

35-
default void setApiKey(String apiKey) {
40+
default void setAlgoliaApiKey(String apiKey) {
3641
System.out.println("Nothing to do here");
3742
}
3843
}

clients/algoliasearch-client-java/algoliasearch/src/main/java/com/algolia/internal/HttpRequester.java

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@
2020
import okio.BufferedSink;
2121

2222
/**
23-
* HttpRequester is responsible for making HTTP requests using the OkHttp client. It provides a
24-
* mechanism for request serialization and deserialization using a given {@link JsonSerializer}.
23+
* HttpRequester is responsible for making HTTP requests using the OkHttp
24+
* client. It provides a
25+
* mechanism for request serialization and deserialization using a given
26+
* {@link JsonSerializer}.
2527
*/
2628
public final class HttpRequester implements Requester {
2729

@@ -33,11 +35,11 @@ public final class HttpRequester implements Requester {
3335
/** Private constructor initialized using the builder pattern. */
3436
private HttpRequester(Builder builder, ClientConfig config) {
3537
OkHttpClient.Builder clientBuilder = new OkHttpClient.Builder()
36-
.connectTimeout(config.getConnectTimeout())
37-
.readTimeout(config.getReadTimeout())
38-
.writeTimeout(config.getWriteTimeout())
39-
.addInterceptor(new HeaderInterceptor(config.getDefaultHeaders()))
40-
.addNetworkInterceptor(new LogInterceptor(config.getLogger(), config.getLogLevel()));
38+
.connectTimeout(config.getConnectTimeout())
39+
.readTimeout(config.getReadTimeout())
40+
.writeTimeout(config.getWriteTimeout())
41+
.addInterceptor(new HeaderInterceptor(config.getDefaultHeaders()))
42+
.addNetworkInterceptor(new LogInterceptor(config.getLogger(), config.getLogLevel()));
4143
builder.interceptors.forEach(clientBuilder::addInterceptor);
4244
builder.networkInterceptors.forEach(clientBuilder::addNetworkInterceptor);
4345
if (config.getCompressionType() == CompressionType.GZIP) {
@@ -51,7 +53,8 @@ private HttpRequester(Builder builder, ClientConfig config) {
5153
}
5254

5355
@Override
54-
public <T> T execute(HttpRequest httpRequest, RequestOptions requestOptions, Class<?> returnType, Class<?> innerType) {
56+
public <T> T execute(HttpRequest httpRequest, RequestOptions requestOptions, Class<?> returnType,
57+
Class<?> innerType) {
5558
return execute(httpRequest, requestOptions, serializer.getJavaType(returnType, innerType));
5659
}
5760

@@ -61,7 +64,7 @@ public <T> T execute(HttpRequest httpRequest, RequestOptions requestOptions, Typ
6164
}
6265

6366
@Override
64-
public void setApiKey(@Nonnull String apiKey) {
67+
public void setAlgoliaApiKey(@Nonnull String apiKey) {
6568
this.httpClient.interceptors().add(new HeaderInterceptor(Collections.singletonMap("X-Algolia-API-Key", apiKey)));
6669
}
6770

@@ -77,7 +80,8 @@ private <T> T execute(@Nonnull HttpRequest httpRequest, RequestOptions requestOp
7780
RequestBody requestBody = createRequestBody(httpRequest);
7881

7982
// Build the HTTP request.
80-
Request request = new Request.Builder().url(url).headers(headers).method(httpRequest.getMethod(), requestBody).build();
83+
Request request = new Request.Builder().url(url).headers(headers).method(httpRequest.getMethod(), requestBody)
84+
.build();
8185

8286
// Get or adjust the HTTP client according to request options.
8387
OkHttpClient client = getOkHttpClient(requestOptions);
@@ -106,9 +110,9 @@ private <T> T execute(@Nonnull HttpRequest httpRequest, RequestOptions requestOp
106110
@Nonnull
107111
private static HttpUrl createHttpUrl(@Nonnull HttpRequest request, RequestOptions requestOptions) {
108112
HttpUrl.Builder urlBuilder = new HttpUrl.Builder()
109-
.scheme("https")
110-
.host("algolia.com") // will be overridden by the retry strategy
111-
.encodedPath(request.getPath());
113+
.scheme("https")
114+
.host("algolia.com") // will be overridden by the retry strategy
115+
.encodedPath(request.getPath());
112116
request.getQueryParameters().forEach(urlBuilder::addEncodedQueryParameter);
113117
if (requestOptions != null) {
114118
requestOptions.getQueryParameters().forEach(urlBuilder::addEncodedQueryParameter);
@@ -156,13 +160,18 @@ private Headers createHeaders(@Nonnull HttpRequest request, RequestOptions reque
156160
return builder.build();
157161
}
158162

159-
/** Returns a suitable OkHttpClient instance based on the provided request options. */
163+
/**
164+
* Returns a suitable OkHttpClient instance based on the provided request
165+
* options.
166+
*/
160167
@Nonnull
161168
private OkHttpClient getOkHttpClient(RequestOptions requestOptions) {
162169
// Return the default client if no request options are provided.
163-
if (requestOptions == null) return httpClient;
170+
if (requestOptions == null)
171+
return httpClient;
164172

165-
// Create a new client builder from the default client and adjust timeouts if provided.
173+
// Create a new client builder from the default client and adjust timeouts if
174+
// provided.
166175
OkHttpClient.Builder builder = httpClient.newBuilder();
167176
if (requestOptions.getReadTimeout() != null) {
168177
builder.readTimeout(requestOptions.getReadTimeout());
@@ -175,7 +184,8 @@ private OkHttpClient getOkHttpClient(RequestOptions requestOptions) {
175184

176185
@Override
177186
public void close() throws IOException {
178-
if (isClosed.get()) return;
187+
if (isClosed.get())
188+
return;
179189
httpClient.dispatcher().executorService().shutdown();
180190
httpClient.connectionPool().evictAll();
181191
if (httpClient.cache() != null) {
@@ -185,7 +195,8 @@ public void close() throws IOException {
185195
}
186196

187197
/**
188-
* The Builder class for HttpRequester. It provides a mechanism for constructing an instance of
198+
* The Builder class for HttpRequester. It provides a mechanism for constructing
199+
* an instance of
189200
* HttpRequester with customized configurations.
190201
*/
191202
public static class Builder {

clients/algoliasearch-client-javascript/packages/client-common/src/createAuth.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export function createAuth(
77
): {
88
readonly headers: () => Headers;
99
readonly queryParameters: () => QueryParameters;
10-
readonly setApiKey: (newApiKey: string) => void;
10+
readonly setAlgoliaApiKey: (newApiKey: string) => void;
1111
} {
1212
const credentials = {
1313
'x-algolia-api-key': apiKey,
@@ -23,7 +23,7 @@ export function createAuth(
2323
return authMode === 'WithinQueryParameters' ? credentials : {};
2424
},
2525

26-
setApiKey(newApiKey: string): void {
26+
setAlgoliaApiKey(newApiKey: string): void {
2727
credentials['x-algolia-api-key'] = newApiKey;
2828
},
2929
};

clients/algoliasearch-client-kotlin/client/src/commonMain/kotlin/com/algolia/client/transport/Requester.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public interface Requester {
3131
returnType: TypeInfo,
3232
): T
3333

34-
public fun setApiKey(apiKey: String) {
34+
public fun setAlgoliaApiKey(apiKey: String) {
3535
println("Nothing to do here")
3636
}
3737
}

clients/algoliasearch-client-kotlin/client/src/commonMain/kotlin/com/algolia/client/transport/internal/KtorRequester.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,13 @@ public class KtorRequester(
3939
private val mutex: Mutex = Mutex()
4040
private val retryableHosts = hosts.map { RetryableHost(it) }
4141

42-
override fun setApiKey(apiKey: String) {
42+
override fun setAlgoliaApiKey(apiKey: String) {
4343
httpClient.config {
4444
defaultRequest {
4545
headers {
46-
remove(HEADER_APIKEY)
46+
if (contains(HEADER_APIKEY)) {
47+
remove(HEADER_APIKEY)
48+
}
4749
append(HEADER_APIKEY, apiKey)
4850
}
4951
}

clients/algoliasearch-client-scala/src/main/scala/algoliasearch/ApiClient.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ abstract class ApiClient(
9090
Try(requester.close())
9191
}
9292

93-
def setApiKey(apiKey: String): Unit = {
94-
requester.setApiKey(apiKey)
93+
def setAlgoliaApiKey(apiKey: String): Unit = {
94+
requester.setAlgoliaApiKey(apiKey)
9595
}
9696
}

clients/algoliasearch-client-scala/src/main/scala/algoliasearch/config/Requester.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ trait Requester extends AutoCloseable {
2222
requestOptions: Option[RequestOptions]
2323
): T
2424

25-
def setApiKey(apiKey: String): Unit = {
25+
def setAlgoliaApiKey(apiKey: String): Unit = {
2626
println("Nothing to do here")
2727
}
2828
}

clients/algoliasearch-client-scala/src/main/scala/algoliasearch/internal/HttpRequester.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ private[algoliasearch] class HttpRequester private (
4444
clientBuilder.build()
4545
}
4646

47-
override def setApiKey(apiKey: String): Unit = {
47+
override def setAlgoliaApiKey(apiKey: String): Unit = {
4848
httpClient.newBuilder().addInterceptor(new Interceptor {
4949
override def intercept(chain: Interceptor.Chain): Response = {
5050
val request = chain.request().newBuilder().addHeader("X-Algolia-API-Key", apiKey).build()

clients/algoliasearch-client-swift/Sources/Core/Networking/Transporter.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ open class Transporter {
4343
self.requestBuilder = requestBuilder
4444
}
4545

46-
public func setApiKey(apiKey: String) {
46+
public func setAlgoliaApiKey(apiKey: String) {
4747
self.configuration.defaultHeaders?.updateValue(apiKey, forKey: "X-Algolia-API-Key")
4848
}
4949

templates/dart/api.mustache

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,9 @@ final class {{classname}} implements ApiClient {
8282

8383
/// Allows to switch the API key used to authenticate requests.
8484
@override
85-
void setApiKey(String apiKey) {
85+
void setAlgoliaApiKey(String apiKey) {
8686
this.apiKey = apiKey;
87-
this._retryStrategy.requester.setApiKey(apiKey);
87+
this._retryStrategy.requester.setAlgoliaApiKey(apiKey);
8888
}
8989
{{#operation}}
9090

@@ -221,4 +221,4 @@ final class {{classname}} implements ApiClient {
221221
@override
222222
void dispose() => _retryStrategy.dispose();
223223
}
224-
{{/operations}}
224+
{{/operations}}

templates/java/api.mustache

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,8 @@ public class {{classname}} extends ApiClient {
135135
*
136136
* @param apiKey The new API key to be used from now on.
137137
*/
138-
public void setApiKey(@Nonnull String apiKey) {
139-
this.requester.setApiKey(apiKey);
138+
public void setAlgoliaApiKey(@Nonnull String apiKey) {
139+
this.requester.setAlgoliaApiKey(apiKey);
140140
}
141141

142142
{{#operation}}
@@ -250,4 +250,4 @@ public class {{classname}} extends ApiClient {
250250

251251
{{> api_helpers}}
252252
}
253-
{{/operations}}
253+
{{/operations}}

templates/javascript/clients/api-single.mustache

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ export function create{{#lambda.titlecase}}{{apiName}}{{/lambda.titlecase}}({
8080
*
8181
* @param apiKey - The new API Key to use.
8282
*/
83-
setApiKey(apiKey: string): void {
84-
auth.setApiKey(apiKey);
83+
setAlgoliaApiKey(apiKey: string): void {
84+
auth.setAlgoliaApiKey(apiKey);
8585
},
8686

8787
{{#isSearchClient}}
@@ -159,4 +159,4 @@ export function create{{#lambda.titlecase}}{{apiName}}{{/lambda.titlecase}}({
159159
};
160160
}
161161

162-
{{/operations}}
162+
{{/operations}}

templates/kotlin/api.mustache

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,16 @@ import kotlinx.serialization.json.*
1212
{{#operations}}
1313
public class {{classname}}(
1414
override val appId: String,
15-
apiKey: String,
15+
override var apiKey: String,
1616
{{#hasRegionalHost}}
1717
public val region: String{{#fallbackToAliasHost}}? = null{{/fallbackToAliasHost}},
1818
{{/hasRegionalHost}}
1919
override val options: ClientOptions = ClientOptions(),
2020
) : ApiClient {
2121
22-
public override var apiKey: String = ""
23-
set(value) {
24-
field = value
25-
requester.setApiKey(value)
26-
}
27-
2822
init {
2923
require(appId.isNotBlank()) { "`appId` is missing." }
3024
require(apiKey.isNotBlank()) { "`apiKey` is missing." }
31-
32-
this.apiKey = apiKey
3325
}
3426

3527
override val requester: Requester = requesterOf(clientName = "{{{baseName}}}", appId = appId, apiKey = apiKey, options = options) {
@@ -63,6 +55,14 @@ public class {{classname}}(
6355
{{/hostsWithoutVariables.size}}
6456
}
6557

58+
/**
59+
* Helper method to switch the API key used to authenticate requests.
60+
*/
61+
public fun setAlgoliaApiKey(apiKey: String) {
62+
this.apiKey = apiKey
63+
this.requester.setAlgoliaApiKey(apiKey)
64+
}
65+
6666
{{#operation}}
6767

6868
/**

templates/php/api.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ use {{invokerPackage}}\Support\Helpers;
160160
* @return void
161161
*
162162
*/
163-
public function setApiKey($apiKey) {
163+
public function setAlgoliaApiKey($apiKey) {
164164
$this->config->setAlgoliaApiKey($apiKey);
165165
}
166166

templates/python/api.mustache

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,9 @@ class {{classname}}:
8181
"""Closes the underlying `transporter` of the API client."""
8282
return await self._transporter.close()
8383

84-
def set_api_key(self, api_key: str) -> None:
84+
def set_algolia_api_key(self, api_key: str) -> None:
8585
"""Sets a new API key to authenticate requests."""
86-
self._transporter.set_api_key(api_key)
86+
self._transporter.set_algolia_api_key(api_key)
8787

8888
{{#isSearchClient}}
8989
{{> search_helpers}}
@@ -190,4 +190,4 @@ class {{classname}}:
190190
return (await self.{{operationId}}_with_http_info({{#allParams}}{{paramName}},{{/allParams}}request_options)).deserialize({{{returnType}}})
191191

192192
{{/operation}}
193-
{{/operations}}
193+
{{/operations}}

0 commit comments

Comments
 (0)