File tree Expand file tree Collapse file tree 2 files changed +12
-2
lines changed
src/main/scala/algoliasearch Expand file tree Collapse file tree 2 files changed +12
-2
lines changed Original file line number Diff line number Diff line change @@ -40,6 +40,8 @@ abstract class ApiClient(
4040 throw AlgoliaClientException (" `apiKey` is missing." )
4141 }
4242
43+ private val authInterceptor = new AuthInterceptor (appId, apiKey)
44+
4345 private val requester = options.customRequester match {
4446 case Some (customRequester) => customRequester
4547 case None =>
@@ -62,7 +64,7 @@ abstract class ApiClient(
6264
6365 val builder = HttpRequester
6466 .builder(options.customFormats.getOrElse(formats))
65- .withInterceptor(new AuthInterceptor (appId, apiKey) )
67+ .withInterceptor(authInterceptor )
6668 .withInterceptor(new UserAgentInterceptor (algoliaAgent))
6769 .withInterceptor(new RetryStrategy (statefulHosts))
6870
@@ -89,4 +91,8 @@ abstract class ApiClient(
8991 override def close (): Unit = {
9092 Try (requester.close())
9193 }
94+
95+ def setClientApiKey (apiKey : String ): Unit = {
96+ authInterceptor.setApiKey(apiKey)
97+ }
9298}
Original file line number Diff line number Diff line change @@ -11,12 +11,16 @@ import okhttp3.{Interceptor, Response}
1111 */
1212private [algoliasearch] class AuthInterceptor (
1313 applicationId : String ,
14- apiKey : String
14+ private var apiKey : String
1515) extends Interceptor {
1616
1717 private val HeaderApplicationId = " x-algolia-application-id"
1818 private val HeaderApiKey = " x-algolia-api-key"
1919
20+ def setApiKey (newApiKey : String ): Unit = {
21+ apiKey = newApiKey
22+ }
23+
2024 override def intercept (chain : Interceptor .Chain ): Response = {
2125 val originalRequest = chain.request()
2226 val builder = originalRequest.newBuilder()
You can’t perform that action at this time.
0 commit comments