@@ -62,25 +62,15 @@ public class OpenTok {
62
62
* page.)
63
63
*/
64
64
public OpenTok (int apiKey , String apiSecret ) {
65
- this (apiKey , apiSecret , defaultApiUrl );
66
- }
67
-
68
- public OpenTok (int apiKey , String apiSecret , String apiUrl ) {
69
- this (apiKey , apiSecret , apiUrl , null );
65
+ this .apiKey = apiKey ;
66
+ this .apiSecret = apiSecret .trim ();
67
+ this .client = new HttpClient .Builder (apiKey , apiSecret ).build ();
70
68
}
71
-
72
- public OpenTok (int apiKey , String apiSecret , String apiUrl , Proxy proxy ) {
69
+
70
+ private OpenTok (int apiKey , String apiSecret , HttpClient httpClient ) {
73
71
this .apiKey = apiKey ;
74
72
this .apiSecret = apiSecret .trim ();
75
- if (apiUrl == null ) {
76
- apiUrl = defaultApiUrl ;
77
- }
78
- HttpClient .Builder clientBuilder = new HttpClient .Builder (apiKey , apiSecret )
79
- .apiUrl (apiUrl );
80
- if (proxy != null ) {
81
- clientBuilder .proxy (proxy );
82
- }
83
- this .client = clientBuilder .build ();
73
+ this .client = httpClient ;
84
74
}
85
75
86
76
/**
@@ -135,7 +125,7 @@ public OpenTok(int apiKey, String apiSecret, String apiUrl, Proxy proxy) {
135
125
*/
136
126
public String generateToken (String sessionId , TokenOptions tokenOptions ) throws OpenTokException {
137
127
List <String > sessionIdParts = null ;
138
- if (sessionId == null || sessionId == "" ) {
128
+ if (sessionId == null || sessionId == "" ) {
139
129
throw new InvalidArgumentException ("Session not valid" );
140
130
}
141
131
@@ -255,7 +245,7 @@ public Session createSession(SessionProperties properties) throws OpenTokExcepti
255
245
String xpathQuery = "/sessions/Session/session_id" ;
256
246
257
247
// NOTE: doing this null check twice is kind of ugly
258
- if (properties != null ) {
248
+ if (properties != null ) {
259
249
params = properties .toMap ();
260
250
} else {
261
251
params = new SessionProperties .Builder ().build ().toMap ();
@@ -324,7 +314,7 @@ private static String readXml(String xpathQuery, String xml) throws XPathExpress
324
314
InputSource source = new InputSource (new StringReader (xml ));
325
315
return xpath .evaluate (xpathQuery , source );
326
316
}
327
-
317
+
328
318
/**
329
319
* Gets an {@link Archive} object for the given archive ID.
330
320
*
@@ -456,4 +446,39 @@ public Archive stopArchive(String archiveId) throws OpenTokException {
456
446
public void deleteArchive (String archiveId ) throws OpenTokException {
457
447
this .client .deleteArchive (archiveId );
458
448
}
449
+
450
+ public static class Builder {
451
+ private int apiKey ;
452
+ private String apiSecret ;
453
+ private String apiUrl ;
454
+ private Proxy proxy ;
455
+
456
+ public Builder (int apiKey , String apiSecret ) {
457
+ this .apiKey = apiKey ;
458
+ this .apiSecret = apiSecret ;
459
+ }
460
+
461
+ public Builder apiUrl (String apiUrl ) {
462
+ this .apiUrl = apiUrl ;
463
+ return this ;
464
+ }
465
+
466
+ public Builder proxy (Proxy proxy ) {
467
+ this .proxy = proxy ;
468
+ return this ;
469
+ }
470
+
471
+ public OpenTok build () {
472
+ HttpClient .Builder clientBuilder = new HttpClient .Builder (apiKey , apiSecret );
473
+
474
+ if (this .apiUrl != null ) {
475
+ clientBuilder .apiUrl (this .apiUrl );
476
+ }
477
+ if (this .proxy != null ) {
478
+ clientBuilder .proxy (this .proxy );
479
+ }
480
+
481
+ return new OpenTok (this .apiKey , this .apiSecret , clientBuilder .build ());
482
+ }
483
+ }
459
484
}
0 commit comments