Merge David's API key changes
- support both API key storage mechanisms for the interim
This commit is contained in:
parent
8a8639f7aa
commit
c91a377eed
@ -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 {
|
||||
@ -109,7 +110,16 @@ public class FreebaseUtils {
|
||||
static final private int JUDGES = 4;
|
||||
|
||||
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
|
||||
@ -527,4 +537,4 @@ public class FreebaseUtils {
|
||||
return response;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
13
refine
13
refine
@ -45,7 +45,9 @@ 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
|
||||
|
||||
@ -664,7 +666,11 @@ run() {
|
||||
if [ "$REFINE_HOST" ] ; then
|
||||
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"
|
||||
@ -701,7 +707,7 @@ broker_run() {
|
||||
add_option "-Drefine.autoreload=true -Dbutterfly.autoreload=true"
|
||||
add_option "-Drefine.development=true"
|
||||
fi
|
||||
|
||||
|
||||
add_option "-Drefine.webapp=broker/core"
|
||||
add_option "-Drefine.headless=true"
|
||||
|
||||
@ -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;;
|
||||
|
Loading…
Reference in New Issue
Block a user