10
10
11
11
import okhttp3 .OkHttpClient ;
12
12
13
+ import static com .assemblyai .api .core .Constants .SDK_VERSION ;
14
+
13
15
public final class ClientOptions {
14
16
private final Environment environment ;
15
17
@@ -30,7 +32,7 @@ private ClientOptions(
30
32
this .headers .putAll (new HashMap <String , String >() {
31
33
{
32
34
put ("X-Fern-SDK-Name" , "com.assemblyai.fern:api-sdk" );
33
- put ("X-Fern-SDK-Version" , "1.1.3" );
35
+ put ("X-Fern-SDK-Version" , SDK_VERSION );
34
36
put ("X-Fern-Language" , "JAVA" );
35
37
}
36
38
});
@@ -77,6 +79,7 @@ public static Builder builder() {
77
79
78
80
public static final class Builder {
79
81
private Environment environment ;
82
+ private UserAgent userAgent = UserAgent .getDefault ();
80
83
81
84
private final Map <String , String > headers = new HashMap <>();
82
85
@@ -100,7 +103,30 @@ public Builder addHeader(String key, Supplier<String> value) {
100
103
}
101
104
102
105
/**
103
- * This is a temporary measure ot disable timeouts for LeMUR client.
106
+ * Merges AssemblyAI user agent with the default AssemblyAI user agent.
107
+ * If null, sets the AssemblyAI user agent to null.
108
+ *
109
+ * @param userAgent The AssemblyAI user agent
110
+ * @return ClientOptionsBuilder
111
+ */
112
+ public Builder userAgent (UserAgent userAgent ) {
113
+ if (userAgent == null ) {
114
+ this .userAgent = null ;
115
+ return this ;
116
+ }
117
+
118
+ // if current and incoming user agent is default user agent, no-op
119
+ if (userAgent == UserAgent .getDefault () && this .userAgent == UserAgent .getDefault ()) {
120
+ return this ;
121
+ }
122
+
123
+ // create a new user agent that merges existing and incoming user agent
124
+ this .userAgent = new UserAgent (this .userAgent , userAgent );
125
+ return this ;
126
+ }
127
+
128
+ /**
129
+ * This is a temporary measure to disable timeouts for LeMUR client.
104
130
* Don't use this method.
105
131
*
106
132
* @return ClientOptionsBuilder
@@ -113,15 +139,21 @@ public Builder disableTimeouts() {
113
139
114
140
public ClientOptions build () {
115
141
OkHttpClient .Builder okhttpClientBuilder = new OkHttpClient .Builder ()
116
- .addInterceptor (new RetryInterceptor (3 ));
142
+ .addInterceptor (new RetryInterceptor (3 ))
143
+ .addInterceptor (new UserAgentInterceptor (this .userAgent ));
117
144
if (this .disableTimeouts ) {
118
145
okhttpClientBuilder
119
146
.callTimeout (0 , TimeUnit .SECONDS )
120
147
.connectTimeout (0 , TimeUnit .SECONDS )
121
148
.writeTimeout (0 , TimeUnit .SECONDS )
122
149
.readTimeout (0 , TimeUnit .SECONDS );
123
150
}
124
- return new ClientOptions (environment , headers , headerSuppliers , okhttpClientBuilder .build ());
151
+ return new ClientOptions (
152
+ environment ,
153
+ headers ,
154
+ headerSuppliers ,
155
+ okhttpClientBuilder .build ()
156
+ );
125
157
}
126
158
}
127
159
}
0 commit comments