Skip to content

Commit bf5b37c

Browse files
committed
redoes packaging. fixes #12
* all user facing classes are directly under com.opentok.* * all actual constants are under com.opentok.contants, but Version is the only one * all exceptions are under com.opentok.exception, they don't need OpenTok in the name * com.opentok.util has been consolidated
1 parent 66527f6 commit bf5b37c

17 files changed

+59
-73
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ a connection metadata string:
121121

122122
<pre>
123123
import com.opentok.api.OpenTokSDK;
124-
import com.opentok.api.constants.Role;
124+
import com.opentok.Role;
125125

126126
class Test {
127127
public static void main(String argv[]) throws OpenTokException {

sample/ArchivingSample.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import java.util.List;
2-
import com.opentok.api.Archive;
3-
import com.opentok.api.OpenTok;
2+
import com.opentok.Archive;
3+
import com.opentok.OpenTok;
44
import com.opentok.exception.OpenTokException;
55

66
class ArchivingSample {

sample/Sample.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import com.opentok.api.OpenTok;
2-
import com.opentok.api.Session;
3-
import com.opentok.api.constants.Role;
1+
import com.opentok.OpenTok;
2+
import com.opentok.Session;
3+
import com.opentok.Role;
44
import com.opentok.SessionProperties;
55
import com.opentok.exception.OpenTokException;
66

src/main/java/com/opentok/api/Archive.java renamed to src/main/java/com/opentok/Archive.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
1-
package com.opentok.api;
1+
package com.opentok;
22

3-
import java.util.HashMap;
43
import java.util.UUID;
54

65
import org.codehaus.jackson.map.ObjectMapper;
76

8-
import com.opentok.exception.OpenTokException;
9-
import com.opentok.exception.OpenTokRequestException;
10-
117
/**
128
* Represents an archive of an OpenTok session.
139
*/
@@ -166,7 +162,7 @@ public void setStatus(ArchiveState status) {
166162
* The download URL of the available MP4 file. This is only set for an archive with the status set to "available";
167163
* for other archives, (including archives wit the status "uploaded") this method returns null. The download URL is
168164
* obfuscated, and the file is only available from the URL for 10 minutes. To generate a new URL, call
169-
* the {@link OpenTok#listArchives()} or {@link OpenTok#getArchive(String)} method.
165+
* the {@link com.opentok.OpenTok#listArchives()} or {@link com.opentok.OpenTok#getArchive(String)} method.
170166
*/
171167
public String getUrl() {
172168
return url;
@@ -187,7 +183,7 @@ public void setUrl(String url) {
187183
// this.status = updatedArchive.status;
188184
// return this;
189185
// } catch (Exception e) {
190-
// throw new OpenTokRequestException(500, "Exception mapping json: " + e.getMessage());
186+
// throw new RequestException(500, "Exception mapping json: " + e.getMessage());
191187
// }
192188
// }
193189

src/main/java/com/opentok/api/OpenTok.java renamed to src/main/java/com/opentok/OpenTok.java

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Last modified: @opentok.sdk.java.mod_time@
99
*/
1010

11-
package com.opentok.api;
11+
package com.opentok;
1212

1313
import java.io.StringReader;
1414
import java.util.Collection;
@@ -18,11 +18,8 @@
1818
import javax.xml.xpath.XPathExpressionException;
1919
import javax.xml.xpath.XPathFactory;
2020

21-
import com.opentok.api.constants.TokenOptions;
22-
23-
import com.opentok.SessionProperties;
2421
import com.opentok.exception.OpenTokException;
25-
import com.opentok.exception.OpenTokInvalidArgumentException;
22+
import com.opentok.exception.InvalidArgumentException;
2623
import com.opentok.util.HttpClient;
2724
import org.xml.sax.InputSource;
2825

@@ -89,7 +86,7 @@ public OpenTok(int apiKey, String apiSecret, String apiUrl) {
8986
* a connection metadata string:
9087
* <p>
9188
* <pre>
92-
* import com.opentok.api.constants.Role;
89+
* import com.opentok.Role;
9390
*
9491
* class Test {
9592
* public static void main(String argv[]) throws OpenTokException {
@@ -143,7 +140,7 @@ public OpenTok(int apiKey, String apiSecret, String apiUrl) {
143140
public String generateToken(String sessionId, TokenOptions tokenOptions) throws OpenTokException {
144141

145142
if(sessionId == null || sessionId == "") {
146-
throw new OpenTokInvalidArgumentException("Session not valid");
143+
throw new InvalidArgumentException("Session not valid");
147144
}
148145

149146
// TODO: use more succinct codec routines
@@ -159,11 +156,11 @@ public String generateToken(String sessionId, TokenOptions tokenOptions) throws
159156
// }
160157
// }
161158
// } catch (UnsupportedEncodingException e) {
162-
// throw new OpenTokSessionNotFoundException("Session not found");
159+
// throw new SessionNotFoundException("Session not found");
163160
// }
164161
//
165162
// if(!decodedSessionId.split("~")[1].equals(String.valueOf(apiKey))) {
166-
// throw new OpenTokSessionNotFoundException("Session not found");
163+
// throw new SessionNotFoundException("Session not found");
167164
// }
168165

169166
Session session = new Session(sessionId, apiKey, apiSecret);
@@ -325,7 +322,7 @@ private static String readXml(String xpathQuery, String xml) throws XPathExpress
325322
// try {
326323
// return mapper.readValue(archive, Archive.class);
327324
// } catch (Exception e) {
328-
// throw new OpenTokRequestException(500, "Exception mapping json: " + e.getMessage());
325+
// throw new RequestException(500, "Exception mapping json: " + e.getMessage());
329326
// }
330327
//
331328
// }
@@ -360,7 +357,7 @@ private static String readXml(String xpathQuery, String xml) throws XPathExpress
360357
// return mapper.readValue(node.get("items"), new TypeReference<List<Archive>>() {
361358
// });
362359
// } catch (Exception e) {
363-
// throw new OpenTokRequestException(500, "Exception mapping json: " + e.getMessage());
360+
// throw new RequestException(500, "Exception mapping json: " + e.getMessage());
364361
// }
365362
// }
366363

@@ -381,7 +378,7 @@ private static String readXml(String xpathQuery, String xml) throws XPathExpress
381378
*/
382379
// public Archive startArchive(String sessionId, String name) throws OpenTokException {
383380
// if (sessionId == null || sessionId == "") {
384-
// throw new OpenTokInvalidArgumentException("Session not valid");
381+
// throw new InvalidArgumentException("Session not valid");
385382
// }
386383
// HashMap<String, String> headers = new HashMap<String, String>();
387384
// headers.put("content-type", "application/json");
@@ -391,7 +388,7 @@ private static String readXml(String xpathQuery, String xml) throws XPathExpress
391388
// try {
392389
// return mapper.readValue(archive, Archive.class);
393390
// } catch (Exception e) {
394-
// throw new OpenTokRequestException(500, "Exception mapping json: " + e.getMessage());
391+
// throw new RequestException(500, "Exception mapping json: " + e.getMessage());
395392
// }
396393
// }
397394

@@ -413,7 +410,7 @@ private static String readXml(String xpathQuery, String xml) throws XPathExpress
413410
// try {
414411
// return mapper.readValue(archive, Archive.class);
415412
// } catch (Exception e) {
416-
// throw new OpenTokRequestException(500, "Exception mapping json: " + e.getMessage());
413+
// throw new RequestException(500, "Exception mapping json: " + e.getMessage());
417414
// }
418415
// }
419416

src/main/java/com/opentok/api/constants/Role.java renamed to src/main/java/com/opentok/Role.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Copyright 2010, TokBox, Inc.
66
*/
77

8-
package com.opentok.api.constants;
8+
package com.opentok;
99
/**
1010
* Defines values for the role parameter of the <code>OpenTokSDK.generateToken()</code> method.
1111
*

src/main/java/com/opentok/api/Session.java renamed to src/main/java/com/opentok/Session.java

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.opentok.api;
1+
package com.opentok;
22

33
import java.io.UnsupportedEncodingException;
44
import java.net.URLEncoder;
@@ -7,14 +7,11 @@
77
import java.security.SignatureException;
88
import java.util.Random;
99

10-
import com.opentok.api.constants.Role;
10+
import com.opentok.exception.InvalidArgumentException;
1111
import com.opentok.util.Crypto;
1212
import org.apache.commons.codec.binary.Base64;
1313

14-
import com.opentok.SessionProperties;
15-
import com.opentok.api.constants.TokenOptions;
1614
import com.opentok.exception.OpenTokException;
17-
import com.opentok.exception.OpenTokInvalidArgumentException;
1815

1916
public class Session {
2017

@@ -97,7 +94,7 @@ public String generateToken(TokenOptions tokenOptions) throws OpenTokException {
9794
// | "partner_id={apiKey}&sig={sig}:| -- dataStringBuilder -- |
9895

9996
if (tokenOptions == null) {
100-
throw new OpenTokInvalidArgumentException("Token options cannot be null");
97+
throw new InvalidArgumentException("Token options cannot be null");
10198
}
10299

103100
Role role = tokenOptions.getRole();
@@ -121,25 +118,25 @@ public String generateToken(TokenOptions tokenOptions) throws OpenTokException {
121118
if (expireTime == 0) {
122119
expireTime = now + (60*60*24); // 1 day
123120
} else if(expireTime < now-1) {
124-
throw new OpenTokInvalidArgumentException(
121+
throw new InvalidArgumentException(
125122
"Expire time must be in the future. relative time: "+ (expireTime - now));
126123
} else if(expireTime > (now + (60*60*24*30) /* 30 days */)) {
127-
throw new OpenTokInvalidArgumentException(
124+
throw new InvalidArgumentException(
128125
"Expire time must be in the next 30 days. too large by "+ (expireTime - (now + (60*60*24*30))));
129126
}
130127
dataStringBuilder.append("&expire_time=");
131128
dataStringBuilder.append(expireTime);
132129

133130
if (data != null) {
134131
if(data.length() > 1000) {
135-
throw new OpenTokInvalidArgumentException(
132+
throw new InvalidArgumentException(
136133
"Connection data must be less than 1000 characters. length: " + data.length());
137134
}
138135
dataStringBuilder.append("&connection_data=");
139136
try {
140137
dataStringBuilder.append(URLEncoder.encode(data, "UTF-8"));
141138
} catch (UnsupportedEncodingException e) {
142-
throw new OpenTokInvalidArgumentException(
139+
throw new InvalidArgumentException(
143140
"Error during URL encode of your connection data: " + e.getMessage());
144141
}
145142
}

src/main/java/com/opentok/SessionProperties.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.opentok;
22

3-
import com.opentok.exception.OpenTokInvalidArgumentException;
3+
import com.opentok.exception.InvalidArgumentException;
44
import org.apache.commons.validator.routines.InetAddressValidator;
55

66
import java.util.ArrayList;
@@ -10,7 +10,7 @@
1010

1111

1212
/**
13-
* Defines values for the <code>properties</code> parameter of the {@link com.opentok.api.OpenTok#createSession(SessionProperties)} method.
13+
* Defines values for the <code>properties</code> parameter of the {@link OpenTok#createSession(SessionProperties)} method.
1414
*
1515
* @see <a href="../OpenTokSDK.html#createSession(com.opentok.SessionProperties)">OpenTokSDK.createSession(SessionProperties)</a>
1616
*/
@@ -30,9 +30,9 @@ public static class Builder {
3030
private boolean p2p = false;
3131

3232

33-
public Builder location(String location) throws OpenTokInvalidArgumentException {
33+
public Builder location(String location) throws InvalidArgumentException {
3434
if (!InetAddressValidator.getInstance().isValidInet4Address(location)) {
35-
throw new OpenTokInvalidArgumentException("Location must be a valid IPv4 address. location="+location);
35+
throw new InvalidArgumentException("Location must be a valid IPv4 address. location="+location);
3636
}
3737
this.location = location;
3838
return this;

src/main/java/com/opentok/api/constants/TokenOptions.java renamed to src/main/java/com/opentok/TokenOptions.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
package com.opentok.api.constants;
1+
package com.opentok;
22

3-
import com.opentok.exception.OpenTokInvalidArgumentException;
3+
import com.opentok.exception.InvalidArgumentException;
44

55
/**
66
* Created by ankur on 4/14/14.
@@ -49,11 +49,11 @@ public Builder expireTime(double expireTime) {
4949
return this;
5050
}
5151

52-
public Builder data(String data) throws OpenTokInvalidArgumentException {
52+
public Builder data(String data) throws InvalidArgumentException {
5353
if (data.length() <= 1000) {
5454
this.data = data;
5555
} else {
56-
throw new OpenTokInvalidArgumentException(
56+
throw new InvalidArgumentException(
5757
"The given connection data is too long, limit is 1000 characters: "+data.length());
5858
}
5959
return this;

src/main/java/com/opentok/api/package-info.java

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)