Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package com.factual;
  import java.util.List;
  import java.util.Map;
Represents the public Factual API. Supports running queries against Factual and inspecting the response. Supports the same levels of authentication supported by Factual's API.

 public class Factual {
   private static final String DRIVER_HEADER_TAG = "factual-java-driver-v1.0";
   private String factHome = "";
   private final String key;
   private final OAuthHmacSigner signer;

Constructor. Represents your authenticated access to Factual.

key your oauth key.
secret your oauth secret.
   public Factual(String keyString secret) {
     this. = key;
     this. = new OAuthHmacSigner();
     this.. = secret;

Change the base URL at which to contact Factual's API. This may be useful if you want to talk to a test or staging server.

Example value:

urlBase the base URL at which to contact Factual's API.
   public void setFactHome(String urlBase) {
     this. = urlBase;

Runs a read query against the specified Factual table.

tableName the name of the table you wish to query (e.g., "places")
query the read query to run against table.
the response of running query against Factual.
   public ReadResponse fetch(String tableNameQuery query) {
     return new ReadResponse(request(urlForFetch(tableNamequery)));

Convenience method to return Crosswalks for the specific query.
   public List<Crosswalkcrosswalks(String tableCrosswalkQuery query) {
     return fetch(tablequery).getCrosswalks();
   public Crosswalk crosswalk(String tableCrosswalkQuery query) {
     return fetch(tablequery).first();

Returns the read response from a Factual Resolve request.

query the Resolve query.
the response from Factual for the Resolve request.
   public ReadResponse resolves(ResolveQuery query) {
     return fetch("places"query);
   public Map<StringObjectresolve(ResolveQuery query) {
     return resolves(query).first();
  public CrosswalkResponse fetch(String tableNameCrosswalkQuery query) {
    return new CrosswalkResponse(request(urlForCrosswalk(tableNamequery)));
  public ReadResponse fetch(String tableNameResolveQuery query) {
    return new ReadResponse(request(urlForResolve(tableNamequery)));
  private String urlForCrosswalk(String tableNameCrosswalkQuery query) {
    return  + tableName + "/crosswalk?" + query.toUrlQuery();
  private String urlForResolve(String tableNameResolveQuery query) {
    return  + tableName + "/resolve?" + query.toUrlQuery();
  private String urlForFetch(String tableNameQuery query) {
    return  + "t/" + tableName + "?" + query.toUrlQuery();
  private String request(String urlStr) {
    GenericUrl url = new GenericUrl(urlStr);
    String requestMethod = "GET";
    // Configure OAuth request params
    OAuthParameters params = new OAuthParameters();
    params.consumerKey = ;
    params.signer = ;
    BufferedReader br = null;
    try {
      // generate the signature
      // make the request
      HttpTransport transport = new NetHttpTransport();
      HttpRequestFactory f = transport.createRequestFactory(params);
      HttpRequest request = f.buildGetRequest(url);
      HttpHeaders headers = new HttpHeaders();
      request.headers = headers;
      // get the response
      br = new BufferedReader(new InputStreamReader(request.execute().getContent()));
      return br.readLine();
    } catch (HttpResponseException e) {
      throw new FactualApiException(e).requestUrl(urlStr).requestMethod(requestMethod).response(e.response);
    } catch (IOException e) {
      throw new FactualApiException(e).requestUrl(urlStr).requestMethod(requestMethod);
    } catch (GeneralSecurityException e) {
      throw new RuntimeException(e);
    } finally {
New to GrepCode? Check out our FAQ X