Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package com.factual.driver;
  
  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.

Author(s):
aaron
 
 public class Factual {
   private static final String DRIVER_HEADER_TAG = "factual-java-driver-v1.0.2";
   private String factHome = "http://api.v3.factual.com/";
   private final String key;
   private final OAuthHmacSigner signer;


  
Constructor. Represents your authenticated access to Factual.

Parameters:
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: http://staging.api.v3.factual.com/t/

Parameters:
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.

Parameters:
tableName the name of the table you wish to query (e.g., "places")
query the read query to run against table.
Returns:
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();
   }

  
Query's Factual for the Crosswalk data matching the specified query.

Parameters:
tableName the name of the table to crosswalk.
query the Crosswalk query.
Returns:
Factual's response to the Crosswalk query.
 
   public CrosswalkResponse fetch(String tableNameCrosswalkQuery query) {
     return new CrosswalkResponse(request(urlForCrosswalk(tableNamequery)));
   }

  
Asks Factual to resolve the Places entity for the attributes specified by query.

Returns the read response from a Factual Resolve request, which includes all records that are potential matches.

Parameters:
query the Resolve query to run against Factual's Places table.
Returns:
the response from Factual for the Resolve request.
  public ReadResponse resolves(ResolveQuery query) {
    return fetch("places"query);
  }

  
Asks Factual to resolve the Places entity for the attributes specified by query. Returns a record representing the resolved entity if Factual successfully identified the entity with full confidence, or null if the entity was not resolved.

Parameters:
query a Resolve query with partial attributes for an entity.
Returns:
a record representing the resolved entity if Factual successfully identified the entity with full confidence, or null if the entity was not resolved.
  public Map<StringObjectresolve(ResolveQuery query) {
    return resolves(query).first();
  }

  
Asks Factual to resolve the entity for the attributes specified by query, within the table called tableName.

Returns the read response from a Factual Resolve request, which includes all records that are potential matches.

Each result record will include a confidence score ("similarity"), and a flag indicating whether Factual decided the entity is the correct resolved match with a high degree of accuracy ("resolved").

There will be 0 or 1 entities returned with "resolved"=true. If there was a full match, it is guaranteed to be the first record in the response.

Parameters:
tableName the name of the table to resolve within.
query a Resolve query with partial attributes for an entity.
Returns:
the response from Factual for the Resolve request.
  public ReadResponse fetch(String tableNameResolveQuery query) {
    return new ReadResponse(request(urlForResolve(tableNamequery)));
  }
  public SchemaResponse schema(String tableName) {
    return new SchemaResponse(request(urlForSchema(tableName)));
  }
  private String urlForSchema(String tableName) {
    return  + "t/" + tableName + "/schema";
  }
  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.computeNonce();
    params.computeTimestamp();
    params.signer = ;
    BufferedReader br = null;
    try {
      // generate the signature
      params.computeSignature(requestMethodurl);
      // make the request
      HttpTransport transport = new NetHttpTransport();
      HttpRequestFactory f = transport.createRequestFactory(params);
      HttpRequest request = f.buildGetRequest(url);
      HttpHeaders headers = new HttpHeaders();
      headers.set("X-Factual-Lib");
      request.setHeaders(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.getResponse());
    } catch (IOException e) {
      throw new FactualApiException(e).requestUrl(urlStr).requestMethod(requestMethod);
    } catch (GeneralSecurityException e) {
      throw new RuntimeException(e);
    } finally {
      Closeables.closeQuietly(br);
    }
  }
New to GrepCode? Check out our FAQ X