Skip to content

Commit

Permalink
added configurable api_url
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian Schröder committed Apr 12, 2012
1 parent 8071ed0 commit 99a6b09
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 16 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -1 +1,2 @@
*.class
/build
19 changes: 12 additions & 7 deletions com/opentok/api/API_Config.java
Expand Up @@ -9,12 +9,17 @@
package com.opentok.api;

public class API_Config {
public static final int API_KEY = 4317;

public static final String API_SECRET = "91e6f7609074be23b40747a4651ba5a7";

public static final String API_URL = "http://staging.tokbox.com/hl";
// Uncomment this line when you launch your app
// public static final String API_URL = "https://api.opentok.com/hl";
public static final String STAGING_URL = "http://staging.tokbox.com/hl";
public static final String PRODUCTION_URL = "https://api.opentok.com/hl";

final int api_key;
final String api_secret;
final String api_url;

API_Config(int api_key, String api_secret, String api_url){
this.api_key = api_key;
this.api_secret = api_secret;
this.api_url = api_url;
}
}

25 changes: 16 additions & 9 deletions com/opentok/api/OpenTokSDK.java
Expand Up @@ -28,13 +28,20 @@
import com.opentok.api.OpenTokSession;

public class OpenTokSDK {
protected final API_Config apiConfig;

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

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

/**
Expand Down Expand Up @@ -88,12 +95,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(this.api_key);
inner_builder.append(apiConfig.api_key);

inner_builder.append("&sig=");

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

Expand Down Expand Up @@ -162,9 +169,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", this.api_key + ":" + this.api_secret);
headers.put("X-TB-PARTNER-AUTH", apiConfig.api_key + ":" + apiConfig.api_secret);

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

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

0 comments on commit 99a6b09

Please sign in to comment.