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 {
|
||||||
@ -110,6 +111,15 @@ public class FreebaseUtils {
|
|||||||
|
|
||||||
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
|
||||||
|
7
refine
7
refine
@ -46,6 +46,8 @@ 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
|
||||||
|
|
||||||
@ -665,6 +667,10 @@ run() {
|
|||||||
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"
|
||||||
@ -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