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.Credentials;
|
||||||
import com.google.refine.oauth.OAuthUtilities;
|
import com.google.refine.oauth.OAuthUtilities;
|
||||||
import com.google.refine.oauth.Provider;
|
import com.google.refine.oauth.Provider;
|
||||||
|
import com.google.refine.preference.PreferenceStore;
|
||||||
import com.google.refine.util.ParsingUtilities;
|
import com.google.refine.util.ParsingUtilities;
|
||||||
|
|
||||||
public class FreebaseUtils {
|
public class FreebaseUtils {
|
||||||
@ -109,7 +110,16 @@ public class FreebaseUtils {
|
|||||||
static final private int JUDGES = 4;
|
static final private int JUDGES = 4;
|
||||||
|
|
||||||
public static final String API_KEY = "AIzaSyBAZ_EjMPKlOzyyZXv6JKXPPwJFISVji3M";
|
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) {
|
private static String getUserInfoURL(String host) {
|
||||||
// TODO: Needs to be upgraded to new APIs sandbox-freebase.com as host becomes v1sandbox as version
|
// 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";
|
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
|
// We could use the javax.mail package, but it's actually more trouble than it's worth
|
||||||
String body = "--" + BOUNDARY + "\n"
|
String body = "--" + BOUNDARY + "\n"
|
||||||
+ queryToMimeBodyPart("0", query, service_url, API_KEY)
|
+ queryToMimeBodyPart("0", query, service_url, FreebaseUtils.getApiKey())
|
||||||
+ "\n--" + BOUNDARY + "\n" ;
|
+ "\n--" + BOUNDARY + "\n" ;
|
||||||
|
|
||||||
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
||||||
@ -427,7 +437,7 @@ public class FreebaseUtils {
|
|||||||
|
|
||||||
JSONObject params = new JSONObject();
|
JSONObject params = new JSONObject();
|
||||||
params.put("query",query);
|
params.put("query",query);
|
||||||
params.put("key", API_KEY);
|
params.put("key", FreebaseUtils.getApiKey());
|
||||||
|
|
||||||
JSONObject req1 = new JSONObject();
|
JSONObject req1 = new JSONObject();
|
||||||
req1.put("jsonrpc","2.0");
|
req1.put("jsonrpc","2.0");
|
||||||
@ -476,7 +486,7 @@ public class FreebaseUtils {
|
|||||||
private static final HttpTransport HTTP_TRANSPORT = new NetHttpTransport();
|
private static final HttpTransport HTTP_TRANSPORT = new NetHttpTransport();
|
||||||
private static final JsonFactory JSON_FACTORY = new JacksonFactory();
|
private static final JsonFactory JSON_FACTORY = new JacksonFactory();
|
||||||
private static final FreebaseRequestInitializer REQUEST_INITIALIZER =
|
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
|
* Submit a single MQL read query via the standard Google client library
|
||||||
@ -527,4 +537,4 @@ public class FreebaseUtils {
|
|||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
13
refine
13
refine
@ -45,7 +45,9 @@ where [options] include:
|
|||||||
|
|
||||||
-m <memory> max memory heap size to use
|
-m <memory> max memory heap size to use
|
||||||
default: 1024M
|
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]
|
-v <level> verbosity level [from low to high: error,warn,info,debug,trace]
|
||||||
default: info
|
default: info
|
||||||
|
|
||||||
@ -664,7 +666,11 @@ run() {
|
|||||||
if [ "$REFINE_HOST" ] ; then
|
if [ "$REFINE_HOST" ] ; then
|
||||||
add_option "-Drefine.host=$REFINE_HOST"
|
add_option "-Drefine.host=$REFINE_HOST"
|
||||||
fi
|
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/*"
|
CLASSPATH="$REFINE_CLASSES_DIR${SEP}$REFINE_LIB_DIR/*"
|
||||||
|
|
||||||
RUN_CMD="$JAVA -cp $CLASSPATH $OPTS com.google.refine.Refine"
|
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.autoreload=true -Dbutterfly.autoreload=true"
|
||||||
add_option "-Drefine.development=true"
|
add_option "-Drefine.development=true"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
add_option "-Drefine.webapp=broker/core"
|
add_option "-Drefine.webapp=broker/core"
|
||||||
add_option "-Drefine.headless=true"
|
add_option "-Drefine.headless=true"
|
||||||
|
|
||||||
@ -869,6 +875,7 @@ while [ $# -ne 0 ] ; do
|
|||||||
-w) shift; REFINE_WEBAPP="$1"; shift; continue;;
|
-w) shift; REFINE_WEBAPP="$1"; shift; continue;;
|
||||||
-d) shift; REFINE_DATA_DIR="$1"; shift; continue;;
|
-d) shift; REFINE_DATA_DIR="$1"; shift; continue;;
|
||||||
-m) shift; REFINE_MEMORY="$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;;
|
-v) shift; REFINE_VERBOSITY="$1"; shift; continue;;
|
||||||
-x) shift; REFINE_EXTRA_OPTS="$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;;
|
--debug) shift; add_option '-Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n'; continue;;
|
||||||
|
Loading…
Reference in New Issue
Block a user