@@ -64,9 +64,10 @@ private ClientOptions(
6464 this .headers .putAll (headers );
6565 this .headers .putAll (new HashMap <String , String >() {
6666 {
67+ put ("User-Agent" , "io.intercom:intercom-java/3.0.0-alpha0" );
6768 put ("X-Fern-Language" , "JAVA" );
6869 put ("X-Fern-SDK-Name" , "com.intercom.fern:api-sdk" );
69- put ("X-Fern-SDK-Version" , "0 .0.155 " );
70+ put ("X-Fern-SDK-Version" , "3 .0.0-alpha0 " );
7071 }
7172 });
7273 this .headerSuppliers = headerSuppliers ;
@@ -133,12 +134,11 @@ public static final class Builder {
133134
134135 private final Map <String , Supplier <String >> headerSuppliers = new HashMap <>();
135136
136- private int timeout = 60 ;
137+ private int maxRetries = 2 ;
137138
138- private OkHttpClient httpClient = new OkHttpClient .Builder ()
139- .addInterceptor (new RetryInterceptor (3 ))
140- .callTimeout (this .timeout , TimeUnit .SECONDS )
141- .build ();
139+ private Optional <Integer > timeout = Optional .empty ();
140+
141+ private OkHttpClient httpClient = null ;
142142
143143 private Optional <ApiVersion > version = Optional .empty ();
144144
@@ -161,10 +161,26 @@ public Builder addHeader(String key, Supplier<String> value) {
161161 * Override the timeout in seconds. Defaults to 60 seconds.
162162 */
163163 public Builder timeout (int timeout ) {
164+ this .timeout = Optional .of (timeout );
165+ return this ;
166+ }
167+
168+ /**
169+ * Override the timeout in seconds. Defaults to 60 seconds.
170+ */
171+ public Builder timeout (Optional <Integer > timeout ) {
164172 this .timeout = timeout ;
165173 return this ;
166174 }
167175
176+ /**
177+ * Override the maximum number of retries. Defaults to 2 retries.
178+ */
179+ public Builder maxRetries (int maxRetries ) {
180+ this .maxRetries = maxRetries ;
181+ return this ;
182+ }
183+
168184 public Builder httpClient (OkHttpClient httpClient ) {
169185 this .httpClient = httpClient ;
170186 return this ;
@@ -179,7 +195,28 @@ public Builder version(ApiVersion version) {
179195 }
180196
181197 public ClientOptions build () {
182- return new ClientOptions (environment , headers , headerSuppliers , httpClient , this .timeout , version );
198+ OkHttpClient .Builder httpClientBuilder =
199+ this .httpClient != null ? this .httpClient .newBuilder () : new OkHttpClient .Builder ();
200+
201+ if (this .httpClient != null ) {
202+ timeout .ifPresent (timeout -> httpClientBuilder
203+ .callTimeout (timeout , TimeUnit .SECONDS )
204+ .connectTimeout (0 , TimeUnit .SECONDS )
205+ .writeTimeout (0 , TimeUnit .SECONDS )
206+ .readTimeout (0 , TimeUnit .SECONDS ));
207+ } else {
208+ httpClientBuilder
209+ .callTimeout (this .timeout .orElse (60 ), TimeUnit .SECONDS )
210+ .connectTimeout (0 , TimeUnit .SECONDS )
211+ .writeTimeout (0 , TimeUnit .SECONDS )
212+ .readTimeout (0 , TimeUnit .SECONDS )
213+ .addInterceptor (new RetryInterceptor (this .maxRetries ));
214+ }
215+
216+ this .httpClient = httpClientBuilder .build ();
217+ this .timeout = Optional .of (httpClient .callTimeoutMillis () / 1000 );
218+
219+ return new ClientOptions (environment , headers , headerSuppliers , httpClient , this .timeout .get (), version );
183220 }
184221 }
185222}
0 commit comments