Skip to content

Commit 0e250ec

Browse files
committed
manual changes completed in styling
1 parent 3c35002 commit 0e250ec

File tree

3 files changed

+55
-57
lines changed

3 files changed

+55
-57
lines changed

src/main/java/com/opentok/OpenTok.java

Lines changed: 50 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -61,18 +61,17 @@ public class OpenTok {
6161
* @param apiSecret Your OpenTok API secret. (See the <a href="https://dashboard.tokbox.com">OpenTok dashboard</a>
6262
* page.)
6363
*/
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+
}
7675

7776
/**
7877
* 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) {
124123
*
125124
* @return The token string.
126125
*/
127-
public String generateToken(String sessionId, TokenOptions tokenOptions)
128-
throws OpenTokException {
126+
public String generateToken(String sessionId, TokenOptions tokenOptions) throws OpenTokException {
129127
List<String> sessionIdParts = null;
130-
if(sessionId == null || sessionId == "") {
128+
if (sessionId == null || sessionId == "") {
131129
throw new InvalidArgumentException("Session not valid");
132130
}
133131

@@ -252,9 +250,10 @@ public Session createSession(SessionProperties properties) throws OpenTokExcepti
252250
} else {
253251
params = new SessionProperties.Builder().build().toMap();
254252
}
255-
253+
256254
String xmlResponse = this.client.createSession(params);
257255

256+
258257
// NOTE: doing this null check twice is kind of ugly
259258
try {
260259
if (properties != null) {
@@ -263,8 +262,7 @@ public Session createSession(SessionProperties properties) throws OpenTokExcepti
263262
return new Session(readXml(xpathQuery, xmlResponse), apiKey, apiSecret);
264263
}
265264
} 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);
268266
}
269267
}
270268

@@ -435,7 +433,7 @@ public Archive stopArchive(String archiveId) throws OpenTokException {
435433
throw new RequestException("Exception mapping json: " + e.getMessage());
436434
}
437435
}
438-
436+
439437
/**
440438
* Deletes an OpenTok archive.
441439
* <p>
@@ -450,39 +448,37 @@ public void deleteArchive(String archiveId) throws OpenTokException {
450448
}
451449

452450
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+
}
488484
}

src/main/java/com/opentok/constants/DefaultApiUrl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@
88
package com.opentok.constants;
99

1010
public class DefaultApiUrl {
11-
public static final String DEFAULT_API_URI = "https://api.opentok.com";
12-
11+
public static final String DEFAULT_API_URI = "https://api.opentok.com";
12+
1313
}

src/main/java/com/opentok/util/HttpClient.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,11 +313,13 @@ public HttpClient build() {
313313
.setUserAgent("Opentok-Java-SDK/" + Version.VERSION + " JRE/" + System.getProperty("java.version"))
314314
.addRequestFilter(new PartnerAuthRequestFilter(this.apiKey, this.apiSecret));
315315
if (this.apiUrl == null) {
316-
this.apiUrl=DefaultApiUrl.DEFAULT_API_URI;
316+
this.apiUrl=DefaultApiUrl.DEFAULT_API_URI;
317317
}
318+
318319
if (this.proxy != null) {
319320
configBuilder.setProxyServer(createProxyServer(this.proxy));
320321
}
322+
321323
this.config = configBuilder.build();
322324
// NOTE: not thread-safe, config could be modified by another thread here?
323325
HttpClient client = new HttpClient(this);

0 commit comments

Comments
 (0)