Merge David's API key changes

- support both API key storage mechanisms for the interim
This commit is contained in:
Tom Morris 2013-03-18 17:47:50 -04:00
parent 8a8639f7aa
commit c91a377eed
2 changed files with 25 additions and 8 deletions

View File

@ -84,6 +84,7 @@ import com.google.refine.RefineServlet;
import com.google.refine.oauth.Credentials;
import com.google.refine.oauth.OAuthUtilities;
import com.google.refine.oauth.Provider;
import com.google.refine.preference.PreferenceStore;
import com.google.refine.util.ParsingUtilities;
public class FreebaseUtils {
@ -110,6 +111,15 @@ public class FreebaseUtils {
public static final String API_KEY = "AIzaSyBAZ_EjMPKlOzyyZXv6JKXPPwJFISVji3M";
public static String getApiKey() {
PreferenceStore ps = ProjectManager.singleton.getPreferenceStore();
String key = (String) ps.get("freebase.api.key");
if (key == null) {
key = System.getProperty("refine.google_api_key");
}
return key == null ? API_KEY : key;
}
private static String getUserInfoURL(String host) {
// TODO: Needs to be upgraded to new APIs sandbox-freebase.com as host becomes v1sandbox as version
return "http://api." + host + "/api/service/user_info";
@ -353,7 +363,7 @@ public class FreebaseUtils {
// We could use the javax.mail package, but it's actually more trouble than it's worth
String body = "--" + BOUNDARY + "\n"
+ queryToMimeBodyPart("0", query, service_url, API_KEY)
+ queryToMimeBodyPart("0", query, service_url, FreebaseUtils.getApiKey())
+ "\n--" + BOUNDARY + "\n" ;
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
@ -427,7 +437,7 @@ public class FreebaseUtils {
JSONObject params = new JSONObject();
params.put("query",query);
params.put("key", API_KEY);
params.put("key", FreebaseUtils.getApiKey());
JSONObject req1 = new JSONObject();
req1.put("jsonrpc","2.0");
@ -476,7 +486,7 @@ public class FreebaseUtils {
private static final HttpTransport HTTP_TRANSPORT = new NetHttpTransport();
private static final JsonFactory JSON_FACTORY = new JacksonFactory();
private static final FreebaseRequestInitializer REQUEST_INITIALIZER =
new FreebaseRequestInitializer(FreebaseUtils.API_KEY);
new FreebaseRequestInitializer(FreebaseUtils.getApiKey());
/**
* Submit a single MQL read query via the standard Google client library

7
refine
View File

@ -46,6 +46,8 @@ where [options] include:
-m <memory> max memory heap size to use
default: 1024M
-k <google api key> a server API key for calling Google APIs
-v <level> verbosity level [from low to high: error,warn,info,debug,trace]
default: info
@ -665,6 +667,10 @@ run() {
add_option "-Drefine.host=$REFINE_HOST"
fi
if [ "$REFINE_GOOGLE_API_KEY" ] ; then
add_option "-Drefine.google_api_key=$REFINE_GOOGLE_API_KEY"
fi
CLASSPATH="$REFINE_CLASSES_DIR${SEP}$REFINE_LIB_DIR/*"
RUN_CMD="$JAVA -cp $CLASSPATH $OPTS com.google.refine.Refine"
@ -869,6 +875,7 @@ while [ $# -ne 0 ] ; do
-w) shift; REFINE_WEBAPP="$1"; shift; continue;;
-d) shift; REFINE_DATA_DIR="$1"; shift; continue;;
-m) shift; REFINE_MEMORY="$1"; shift; continue;;
-k) shift; REFINE_GOOGLE_API_KEY="$1"; shift; continue;;
-v) shift; REFINE_VERBOSITY="$1"; shift; continue;;
-x) shift; REFINE_EXTRA_OPTS="$1"; shift; continue;;
--debug) shift; add_option '-Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n'; continue;;