@@ -66,12 +66,13 @@ public static void shutdown() {
6666 OkClient .shutdown ();
6767 }
6868
69- private BandwidthClient (Environment environment , String messagingBasicAuthUserName ,
69+ private BandwidthClient (Environment environment , String baseUrl , String messagingBasicAuthUserName ,
7070 String messagingBasicAuthPassword , String twoFactorAuthBasicAuthUserName ,
7171 String twoFactorAuthBasicAuthPassword , String voiceBasicAuthUserName , String voiceBasicAuthPassword ,
7272 String webRtcBasicAuthUserName , String webRtcBasicAuthPassword , HttpClient httpClient , long timeout ,
7373 ReadonlyHttpClientConfiguration httpClientConfig , Map <String , AuthManager > authManagers ) {
7474 this .environment = environment ;
75+ this .baseUrl = baseUrl ;
7576 this .httpClient = httpClient ;
7677 this .timeout = timeout ;
7778 this .httpClientConfig = httpClientConfig ;
@@ -127,6 +128,11 @@ private BandwidthClient(Environment environment, String messagingBasicAuthUserNa
127128 */
128129 private final Environment environment ;
129130
131+ /**
132+ * baseUrl value
133+ */
134+ private final String baseUrl ;
135+
130136 /**
131137 * The HTTP Client instance to use for making HTTP requests.
132138 */
@@ -175,6 +181,14 @@ public Environment getEnvironment() {
175181 return environment ;
176182 }
177183
184+ /**
185+ * baseUrl value
186+ * @return baseUrl
187+ */
188+ public String getBaseUrl () {
189+ return baseUrl ;
190+ }
191+
178192 /**
179193 * The HTTP Client instance to use for making HTTP requests.
180194 * @return httpClient
@@ -279,6 +293,7 @@ public Map<String, AuthManager> getAuthManagers() {
279293 public String getBaseUri (Server server ) {
280294 StringBuilder baseUrl = new StringBuilder (environmentMapper (environment , server ));
281295 Map <String , SimpleEntry <Object , Boolean >> parameters = new HashMap <>();
296+ parameters .put ("base_url" , new SimpleEntry <Object , Boolean >(this .baseUrl , false ));
282297 ApiHelper .appendUrlWithTemplateParameters (baseUrl , parameters );
283298 return baseUrl .toString ();
284299 }
@@ -315,6 +330,23 @@ private static String environmentMapper(Environment environment, Server server)
315330 return "https://api.webrtc.bandwidth.com/v1" ;
316331 }
317332 }
333+ if (environment .equals (Environment .CUSTOM )) {
334+ if (server .equals (Server .ENUM_DEFAULT )) {
335+ return "{base_url}" ;
336+ }
337+ if (server .equals (Server .MESSAGINGDEFAULT )) {
338+ return "{base_url}" ;
339+ }
340+ if (server .equals (Server .TWOFACTORAUTHDEFAULT )) {
341+ return "{base_url}" ;
342+ }
343+ if (server .equals (Server .VOICEDEFAULT )) {
344+ return "{base_url}" ;
345+ }
346+ if (server .equals (Server .WEBRTCDEFAULT )) {
347+ return "{base_url}" ;
348+ }
349+ }
318350 return "api.bandwidth.com" ;
319351 }
320352
@@ -327,6 +359,7 @@ private static String environmentMapper(Environment environment, Server server)
327359 public Builder newBuilder () {
328360 Builder builder = new Builder ();
329361 builder .environment = getEnvironment ();
362+ builder .baseUrl = getBaseUrl ();
330363 builder .messagingBasicAuthUserName = getMessagingBasicAuthUserName ();
331364 builder .messagingBasicAuthPassword = getMessagingBasicAuthPassword ();
332365 builder .twoFactorAuthBasicAuthUserName = getTwoFactorAuthBasicAuthUserName ();
@@ -347,6 +380,7 @@ public Builder newBuilder() {
347380 */
348381 public static class Builder {
349382 private Environment environment = Environment .PRODUCTION ;
383+ private String baseUrl = "https://www.example.com" ;
350384 private String messagingBasicAuthUserName = "TODO: Replace" ;
351385 private String messagingBasicAuthPassword = "TODO: Replace" ;
352386 private String twoFactorAuthBasicAuthUserName = "TODO: Replace" ;
@@ -433,6 +467,14 @@ public Builder environment(Environment environment) {
433467 this .environment = environment ;
434468 return this ;
435469 }
470+ /**
471+ * baseUrl value
472+ * @param baseUrl
473+ */
474+ public Builder baseUrl (String baseUrl ) {
475+ this .baseUrl = baseUrl ;
476+ return this ;
477+ }
436478 /**
437479 * The timeout to use for making HTTP requests.
438480 * @param timeout must be greater then 0.
@@ -457,7 +499,7 @@ public BandwidthClient build() {
457499 httpClientConfig .setTimeout (timeout );
458500 httpClient = new OkClient (httpClientConfig );
459501
460- return new BandwidthClient (environment , messagingBasicAuthUserName , messagingBasicAuthPassword ,
502+ return new BandwidthClient (environment , baseUrl , messagingBasicAuthUserName , messagingBasicAuthPassword ,
461503 twoFactorAuthBasicAuthUserName , twoFactorAuthBasicAuthPassword , voiceBasicAuthUserName ,
462504 voiceBasicAuthPassword , webRtcBasicAuthUserName , webRtcBasicAuthPassword , httpClient , timeout ,
463505 httpClientConfig , authManagers );
0 commit comments