Skip to content

Commit 066f388

Browse files
add interceptor and network interceptor support to mapbox speech (#910)
1 parent 73fd5ca commit 066f388

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

services-speech/src/main/java/com/mapbox/api/speech/v1/MapboxSpeech.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import java.util.logging.Logger;
1313

1414
import okhttp3.Cache;
15+
import okhttp3.Interceptor;
1516
import okhttp3.OkHttpClient;
1617
import okhttp3.ResponseBody;
1718
import okhttp3.logging.HttpLoggingInterceptor;
@@ -54,6 +55,12 @@ protected Call<ResponseBody> initializeCall() {
5455
@Nullable
5556
abstract Cache cache();
5657

58+
@Nullable
59+
abstract Interceptor interceptor();
60+
61+
@Nullable
62+
abstract Interceptor networkInterceptor();
63+
5764
@NonNull
5865
abstract String accessToken();
5966

@@ -75,6 +82,12 @@ public synchronized OkHttpClient getOkHttpClient() {
7582
if (cache() != null) {
7683
httpClient.cache(cache());
7784
}
85+
if (interceptor() != null) {
86+
httpClient.addInterceptor(interceptor());
87+
}
88+
if (networkInterceptor() != null) {
89+
httpClient.addNetworkInterceptor(networkInterceptor());
90+
}
7891

7992
okHttpClient = httpClient.build();
8093
}
@@ -167,6 +180,22 @@ public abstract static class Builder {
167180
*/
168181
public abstract Builder cache(Cache cache);
169182

183+
/**
184+
* Adds an optional interceptor to set in the OkHttp client.
185+
*
186+
* @param interceptor to set for OkHttp
187+
* @return this builder for chaining options together
188+
*/
189+
public abstract Builder interceptor(Interceptor interceptor);
190+
191+
/**
192+
* Adds an optional network interceptor to set in the OkHttp client.
193+
*
194+
* @param interceptor to set for OkHttp
195+
* @return this builder for chaining options together
196+
*/
197+
public abstract Builder networkInterceptor(Interceptor interceptor);
198+
170199
abstract MapboxSpeech autoBuild();
171200

172201
/**

0 commit comments

Comments
 (0)