Skip to content

Commit

Permalink
reintegrated the upstream/master
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian Schröder committed Sep 13, 2012
1 parent 02e9062 commit 138cf96
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 22 deletions.
4 changes: 2 additions & 2 deletions sample/Sample.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
import com.opentok.api.constants.RoleConstants;
import com.opentok.exception.OpenTokException;

class Sample {
class Test {
public static void main(String argv[]) throws OpenTokException {
OpenTokSDK sdk = OpenTokSDK.testing();
OpenTokSDK sdk = new OpenTokSDK(API_Config.API_KEY,API_Config.API_SECRET);

//Generate a token
String s = sdk.generate_token("session");
Expand Down
1 change: 0 additions & 1 deletion src/main/java/com/opentok/api/API_Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
package com.opentok.api;

public class API_Config {

public static final int API_KEY = 4317;

public static final String API_SECRET = "91e6f7609074be23b40747a4651ba5a7";
Expand Down
28 changes: 9 additions & 19 deletions src/main/java/com/opentok/api/OpenTokSDK.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,13 @@
import com.opentok.api.OpenTokSession;

public class OpenTokSDK {
protected final API_Config apiConfig;

private OpenTokSDK(API_Config apiConfig){
this.apiConfig = apiConfig;
}
protected int api_key;
protected String api_secret;

public static OpenTokSDK staging(int api_key, String api_secret) {
return create(api_key, api_secret, API_Config.STAGING_URL);
}
public static OpenTokSDK production(int api_key, String api_secret) {
return create(api_key, api_secret, API_Config.PRODUCTION_URL);
}
public static OpenTokSDK create(int api_key, String api_secret, String api_url) {
return new OpenTokSDK(new API_Config(api_key, api_secret, api_url));
}
public static OpenTokSDK testing() {
return new OpenTokSDK(API_Config.TEST_API_CONFIG);
public OpenTokSDK(int api_key, String api_secret) {
this.api_key = api_key;
this.api_secret = api_secret.trim();
}

/**
Expand Down Expand Up @@ -103,12 +93,12 @@ public String generate_token(String session_id, String role, Long expire_time, S

StringBuilder inner_builder = new StringBuilder();
inner_builder.append("partner_id=");
inner_builder.append(apiConfig.api_key);
inner_builder.append(this.api_key);

inner_builder.append("&sig=");

inner_builder.append(GenerateMac.calculateRFC2104HMAC(data_string_builder.toString(),
apiConfig.api_secret));
this.api_secret));
inner_builder.append(":");
inner_builder.append(data_string_builder.toString());

Expand Down Expand Up @@ -177,9 +167,9 @@ public OpenTokSession create_session(String location, Map<String, String> params
protected TokBoxXML do_request(String url, Map<String, String> params) throws OpenTokException {
TokBoxNetConnection n = new TokBoxNetConnection();
Map<String, String> headers = new HashMap<String, String>();
headers.put("X-TB-PARTNER-AUTH", apiConfig.api_key + ":" + apiConfig.api_secret);
headers.put("X-TB-PARTNER-AUTH", this.api_key + ":" + this.api_secret);

return new TokBoxXML(n.request(apiConfig.api_url + url, params, headers));
return new TokBoxXML(n.request(API_Config.API_URL + url, params, headers));
}

protected static String join(List<String> s, String delimiter) throws java.io.UnsupportedEncodingException{
Expand Down

0 comments on commit 138cf96

Please sign in to comment.