@@ -61,18 +61,17 @@ public class OpenTok {
61
61
* @param apiSecret Your OpenTok API secret. (See the <a href="https://dashboard.tokbox.com">OpenTok dashboard</a>
62
62
* page.)
63
63
*/
64
- public OpenTok (int apiKey , String apiSecret ) {
65
- this .apiKey = apiKey ;
66
- this .apiSecret = apiSecret ;
67
- this .client = new HttpClient .Builder (apiKey , apiSecret ).build ();
68
- }
69
-
70
- private OpenTok (int apiKey , String apiSecret , HttpClient httpClient ) {
71
- this .apiKey = apiKey ;
72
- this .apiSecret = apiSecret ;
73
- this .client = httpClient ;
74
-
75
- }
64
+ public OpenTok (int apiKey , String apiSecret ) {
65
+ this .apiKey = apiKey ;
66
+ this .apiSecret = apiSecret .trim ();
67
+ this .client = new HttpClient .Builder (apiKey , apiSecret ).build ();
68
+ }
69
+
70
+ private OpenTok (int apiKey , String apiSecret , HttpClient httpClient ) {
71
+ this .apiKey = apiKey ;
72
+ this .apiSecret = apiSecret .trim ();
73
+ this .client = httpClient ;
74
+ }
76
75
77
76
/**
78
77
* Creates a token for connecting to an OpenTok session. In order to authenticate a user
@@ -124,10 +123,9 @@ private OpenTok(int apiKey, String apiSecret, HttpClient httpClient) {
124
123
*
125
124
* @return The token string.
126
125
*/
127
- public String generateToken (String sessionId , TokenOptions tokenOptions )
128
- throws OpenTokException {
126
+ public String generateToken (String sessionId , TokenOptions tokenOptions ) throws OpenTokException {
129
127
List <String > sessionIdParts = null ;
130
- if (sessionId == null || sessionId == "" ) {
128
+ if (sessionId == null || sessionId == "" ) {
131
129
throw new InvalidArgumentException ("Session not valid" );
132
130
}
133
131
@@ -252,9 +250,10 @@ public Session createSession(SessionProperties properties) throws OpenTokExcepti
252
250
} else {
253
251
params = new SessionProperties .Builder ().build ().toMap ();
254
252
}
255
-
253
+
256
254
String xmlResponse = this .client .createSession (params );
257
255
256
+
258
257
// NOTE: doing this null check twice is kind of ugly
259
258
try {
260
259
if (properties != null ) {
@@ -263,8 +262,7 @@ public Session createSession(SessionProperties properties) throws OpenTokExcepti
263
262
return new Session (readXml (xpathQuery , xmlResponse ), apiKey , apiSecret );
264
263
}
265
264
} catch (XPathExpressionException e ) {
266
- throw new OpenTokException (
267
- "Cannot create session. Could not read the response: " + xmlResponse );
265
+ throw new OpenTokException ("Cannot create session. Could not read the response: " + xmlResponse );
268
266
}
269
267
}
270
268
@@ -435,7 +433,7 @@ public Archive stopArchive(String archiveId) throws OpenTokException {
435
433
throw new RequestException ("Exception mapping json: " + e .getMessage ());
436
434
}
437
435
}
438
-
436
+
439
437
/**
440
438
* Deletes an OpenTok archive.
441
439
* <p>
@@ -450,39 +448,37 @@ public void deleteArchive(String archiveId) throws OpenTokException {
450
448
}
451
449
452
450
public static class Builder {
453
- private int apiKey ;
454
- private String apiSecret ;
455
- private String apiUrl ;
456
- private Proxy proxy ;
457
-
458
- public Builder (int apiKey , String apiSecret ) {
459
- this .apiKey = apiKey ;
460
- this .apiSecret = apiSecret ;
461
- }
462
-
463
- public Builder apiUrl (String apiUrl ) {
464
- this .apiUrl = apiUrl ;
465
- return this ;
466
- }
467
-
468
- public Builder proxy (Proxy proxy ) {
469
- this .proxy = proxy ;
470
- return this ;
471
- }
472
-
473
- public OpenTok build () {
474
- HttpClient .Builder clientBuilder = new HttpClient .Builder (apiKey , apiSecret );
475
-
476
- if (this .apiUrl != null ) {
477
- clientBuilder .apiUrl (this .apiUrl );
478
- }
479
- if (this .proxy != null ) {
480
- clientBuilder .proxy (this .proxy );
481
- }
482
-
483
- return new OpenTok (this .apiKey , this .apiSecret , clientBuilder .build ());
484
-
485
- }
486
-
487
- }
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
+ }
488
484
}
0 commit comments