|
26 | 26 | */ |
27 | 27 | public class RestClient { |
28 | 28 |
|
29 | | - private static final String userAgent = String.format("TeleSignSDK/java-%s Java/%s OkHttp/%s", BuildConfig.VERSION, |
30 | | - System.getProperty("java.version"), OkHttp.VERSION); |
| 29 | + private static final String sdkVersion = BuildConfig.VERSION; |
31 | 30 |
|
32 | 31 | public static final String URL_FORM_ENCODED_CONTENT_TYPE = "application/x-www-form-urlencoded"; |
33 | 32 | public static final String JSON_CONTENT_TYPE = "application/json"; |
34 | 33 |
|
35 | | - private String customerId; |
36 | | - private String apiKey; |
| 34 | + protected String customerId; |
| 35 | + protected String apiKey; |
37 | 36 | private String restEndpoint; |
38 | 37 | private OkHttpClient client; |
| 38 | + private String userAgent; |
39 | 39 |
|
40 | 40 | public RestClient(String customerId, String apiKey) { |
41 | 41 |
|
42 | | - this(customerId, apiKey, null, null, null, null, null, null, null); |
| 42 | + this(customerId, apiKey, null, null, null, null, null, null, null, null, null, null); |
43 | 43 | } |
44 | 44 |
|
45 | | - public RestClient(String customerId, String apiKey, String restEndpoint) { |
| 45 | + public RestClient(String customerId, String apiKey, String restEndpoint, String source, String sdkVersionOrigin, String sdkVersionDependency) { |
46 | 46 |
|
47 | | - this(customerId, apiKey, restEndpoint, null, null, null, null, null, null); |
| 47 | + this(customerId, apiKey, restEndpoint, null, null, null, null, null, null, source, sdkVersionOrigin, sdkVersionDependency); |
48 | 48 | } |
49 | 49 |
|
50 | 50 | /** |
@@ -75,11 +75,17 @@ public RestClient(String customerId, String apiKey, String restEndpoint) { |
75 | 75 | */ |
76 | 76 | public RestClient(String customerId, String apiKey, String restEndpoint, Integer connectTimeout, |
77 | 77 | Integer readTimeout, Integer writeTimeout, Proxy proxy, final String proxyUsername, |
78 | | - final String proxyPassword) { |
| 78 | + final String proxyPassword, final String source, final String sdkVersionOrigin, final String sdkVersionDependency) { |
79 | 79 |
|
80 | 80 | this.customerId = customerId; |
81 | 81 | this.apiKey = apiKey; |
82 | 82 |
|
| 83 | + this.userAgent = String.format("TeleSignSDK/java Java/%s OkHttp/%s OriginatingSDK/%s SDKVersion/%s", |
| 84 | + System.getProperty("java.version"), OkHttp.VERSION, (source == null ? "java_telesign" : source), (sdkVersionOrigin == null ? sdkVersion : sdkVersionOrigin)); |
| 85 | + |
| 86 | + if (!Objects.equals(source, "java_telesign") && sdkVersionDependency != null) |
| 87 | + this.userAgent += String.format(" DependencySDKVersion/%s", sdkVersionDependency); |
| 88 | + |
83 | 89 | if (restEndpoint == null) { |
84 | 90 | this.restEndpoint = "https://rest-api.telesign.com"; |
85 | 91 | } else { |
@@ -138,10 +144,6 @@ static byte[] parseBase64(String encoded) { |
138 | 144 | return Base64.getDecoder().decode(sb.toString()); |
139 | 145 | } |
140 | 146 |
|
141 | | - public void setRestEndpoint(String baseUrl) { |
142 | | - this.restEndpoint = baseUrl; |
143 | | - } |
144 | | - |
145 | 147 | static String encodeBase64(byte[] data) { |
146 | 148 | return Base64.getEncoder().encodeToString(data); |
147 | 149 | } |
@@ -459,7 +461,7 @@ private TelesignResponse execute(String methodName, String resource, Map<String, |
459 | 461 | } |
460 | 462 |
|
461 | 463 | Map<String, String> headers = RestClient.generateTelesignHeaders(this.customerId, this.apiKey, |
462 | | - methodName, resource, requestParams, null, null, RestClient.userAgent, contentType, authMethod); |
| 464 | + methodName, resource, requestParams, null, null, this.userAgent, contentType, authMethod); |
463 | 465 |
|
464 | 466 | Request.Builder requestBuilder = new Request.Builder().url(httpUrl).method(methodName, requestBody); |
465 | 467 | for (Map.Entry<String, String> entry : headers.entrySet()) { |
|
0 commit comments