Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
   package com.factual.driver;
   
   import java.io.IOException;
   import java.util.HashMap;
   import java.util.Map;
   import java.util.Map.Entry;
  
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.8.2";
    private static final String DEFAULT_HOST_HEADER = "api.v3.factual.com";
    private String factHome = "http://api.v3.factual.com/";
    private String host = ;
    private final String key;
    private final OAuthHmacSigner signer;
    private boolean debug = false;
    private int readTimeout = -1;
    private int connectionTimeout = -1;
    private StreamHandler debugHandler = null;
    private Logger logger = null;

  
Constructor. Represents your authenticated access to Factual.

Parameters:
key your oauth key.
secret your oauth secret.
  
    public Factual(String keyString secret) {
      this(keysecretfalse);
    }

  
Constructor. Represents your authenticated access to Factual.

Parameters:
key your oauth key.
secret your oauth secret.
debug whether or not this is in debug mode
  
    public Factual(String keyString secretboolean debug) {
      this. = key;
      this. = new OAuthHmacSigner();
      this.. = secret;
      debug(debug);
    }

  
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 synchronized void setFactHome(String urlBase) {
      this. = urlBase;
    }

  
Change the host header value for a request to Factual's API.

Parameters:
host the host header value for a request to Factual's API.
  
    public synchronized void setRequestHost(String host) {
      this. = host;
    }

  
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(getInternal(urlForFetch(tableName), query.toUrlParams()));
   }

  
Runs a read query against the specified Factual table.

Parameters:
tableName the name of the table you wish to query (e.g., "places")
factualId the factual id
query the read query to run against table.
Returns:
the response of running query against Factual.
 
   public RowResponse fetchRow(String tableNameString factualIdRowQuery query) {
     return new RowResponse(getInternal(urlForFetchRow(tableNamefactualId), query.toUrlParams()));
   }

  
Runs a read query against the specified Factual table.

Parameters:
tableName the name of the table you wish to query (e.g., "places")
factualId the factual id
Returns:
the response of running query against Factual.
 
   public RowResponse fetchRow(String tableNameString factualId) {
     return fetchRow(tableNamefactualIdnew RowQuery());
   }
 
   protected static String urlForResolve(String tableName) {
     return "t/" + tableName + "/resolve";
   }
 
   protected static String urlForMatch(String tableName) {
     return "t/" + tableName + "/match";
   }
 
   protected static String urlForFetch(String tableName) {
     return "t/" + tableName;
   }
 
   protected static String urlForFetchRow(String tableNameString factualId) {
     return "t/" + tableName + "/" + factualId;
   }
 
   protected static String urlForFacets(String tableName) {
     return "t/" + tableName + "/facets";
   }
 
   protected static String urlForGeocode() {
     return "places/geocode";
   }
 
   protected static String urlForGeopulse() {
     return "geopulse/context";
   }

  
Runs a geopulse query against Factual.

Parameters:
geopulse the geopulse query to run.
Returns:
the response of running geopulse against Factual.
 
   public ReadResponse geopulse(Geopulse geopulse) {
     return new ReadResponse(getInternal(urlForGeopulse(), geopulse.toUrlParams()));
   }

  
Reverse geocodes by returning a response containing the address nearest to the given point.

Parameters:
point the point for which the nearest address is returned
Returns:
the response of running a reverse geocode query for point against Factual.
 
   public ReadResponse reverseGeocode(Point point) {
     return new ReadResponse(getInternal(urlForGeocode(),
         new Geocode(point).toUrlParams()));
   }

  
Runs a facet read against the specified Factual table.

Parameters:
tableName the name of the table you wish to query for facets (e.g., "places")
facet the facet query to run against table
Returns:
the response of running facet against Factual.
 
   public FacetResponse fetch(String tableNameFacetQuery facet) {
     return new FacetResponse(getInternal(urlForFacets(tableName), facet.toUrlParams()));
   }

  
Runs a submit input against the specified Factual table.

Parameters:
tableName the name of the table you wish to submit updates for (e.g., "places")
factualId the factual id on which the submit is run
submit the submit parameters to run against table
metadata the metadata to send with information on this request
Returns:
the response of running submit against Factual.
 
   public SubmitResponse submit(String tableNameString factualId,
       Submit submitMetadata metadata) {
     return submitCustom("t/" + tableName + "/" + factualId + "/submit"submit,
         metadata);
   }

  
Runs a insert to add a row against the specified Factual table. Insert is virtually identical to submit. The only difference between the two is that insert will not search for potential duplicate rows first.

Parameters:
tableName the name of the table you wish to insert the add for (e.g., "places")
insert the insert parameters to run against table
metadata the metadata to send with information on this request
Returns:
the response of running insert against Factual.
 
   public InsertResponse insert(String tableNameInsert insert,
       Metadata metadata) {
     return insertCustom("t/" + tableName + "/insert"insertmetadata);
   }

  
Runs a insert against the specified Factual table. Insert is virtually identical to submit. The only difference between the two is that insert will not search for potential duplicate rows first.

Parameters:
tableName the name of the table you wish to insert updates for (e.g., "places")
factualId the factual id on which the insert is run
insert the insert parameters to run against table
metadata the metadata to send with information on this request
Returns:
the response of running insert against Factual.
 
   public InsertResponse insert(String tableNameString factualId,
       Insert insertMetadata metadata) {
     return insertCustom("t/" + tableName + "/" + factualId + "/insert"insert,
         metadata);
   }

  
Runs a clear against the specified Factual table. Insert is virtually identical to submit. The only difference between the two is that insert will not search for potential duplicate rows first.

Parameters:
tableName the name of the table you wish to insert updates for (e.g., "places")
factualId the factual id on which the insert is run
clear the clear parameters to run against table
metadata the metadata to send with information on this request
Returns:
the response of running insert against Factual.
 
   public ClearResponse clear(String tableNameString factualIdClear clear,
       Metadata metadata) {
     return clearCustom("t/" + tableName + "/" + factualId + "/clear"clear,
         metadata);
   }

  
Runs a submit to add a row against the specified Factual table.

Parameters:
tableName the name of the table you wish to submit the add for (e.g., "places")
submit the submit parameters to run against table
metadata the metadata to send with information on this request
Returns:
the response of running submit against Factual.
 
   public SubmitResponse submit(String tableNameSubmit submit,
       Metadata metadata) {
     return submitCustom("t/" + tableName + "/submit"submitmetadata);
   }

  
Flags a row as a duplicate in the specified Factual table.

Parameters:
tableName the name of the table you wish to flag a duplicate for (e.g., "places")
factualId the factual id that is the duplicate
metadata the metadata to send with information on this request
Returns:
the response from flagging a duplicate row.
 
   public FlagResponse flagDuplicate(String tableNameString factualId,
       Metadata metadata) {
     return flagCustom(urlForFlag(tableNamefactualId), "duplicate"metadata);
   }
 
   protected static String urlForFlag(String tableNameString factualId) {
     return "t/" + tableName + "/" + factualId + "/flag";
   }

  
Flags a row as inaccurate in the specified Factual table.

Parameters:
tableName the name of the table you wish to flag an inaccurate row for (e.g., "places")
factualId the factual id that is inaccurate
metadata the metadata to send with information on this request
Returns:
the response from flagging an inaccurate row.
 
   public FlagResponse flagInaccurate(String tableNameString factualId,
       Metadata metadata) {
     return flagCustom(urlForFlag(tableNamefactualId), "inaccurate"metadata);
   }

  
Flags a row as inappropriate in the specified Factual table.

Parameters:
tableName the name of the table you wish to flag an inappropriate row for (e.g., "places")
factualId the factual id that is inappropriate
metadata the metadata to send with information on this request
Returns:
the response from flagging an inappropriate row.
 
   public FlagResponse flagInappropriate(String tableNameString factualId,
       Metadata metadata) {
     return flagCustom(urlForFlag(tableNamefactualId), "inappropriate",
         metadata);
   }

  
Flags a row as non-existent in the specified Factual table.

Parameters:
tableName the name of the table you wish to flag a non-existent row for (e.g., "places")
factualId the factual id that is non-existent
metadata the metadata to send with information on this request
Returns:
the response from flagging a non-existent row.
 
   public FlagResponse flagNonExistent(String tableNameString factualId,
       Metadata metadata) {
     return flagCustom(urlForFlag(tableNamefactualId), "nonexistent"metadata);
   }

  
Flags a row as spam in the specified Factual table.

Parameters:
tableName the name of the table you wish to flag a row as spam (e.g., "places")
factualId the factual id that is spam
metadata the metadata to send with information on this request
Returns:
the response from flagging a row as spam.
 
   public FlagResponse flagSpam(String tableNameString factualId,
       Metadata metadata) {
     return flagCustom(urlForFlag(tableNamefactualId), "spam"metadata);
   }

  
Flags a row as problematic in the specified Factual table.

Parameters:
tableName the name of the table for which you wish to flag as problematic (e.g., "places")
factualId the factual id that has a problem other than duplicate, inaccurate, inappropriate, non-existent, or spam.
metadata the metadata to send with information on this request
Returns:
the response from flagging a row as problematic.
 
   public FlagResponse flagOther(String tableNameString factualId,
       Metadata metadata) {
     return flagCustom(urlForFlag(tableNamefactualId), "other"metadata);
   }

  
Runs a GET request against the specified endpoint path, using the given parameters and your OAuth credentials. Returns the raw response body returned by Factual.

The necessary URL base will be automatically prepended to path. If you need to change it, e.g. to make requests against a development instance of the Factual service, please see setFactHome(java.lang.String).

Parameters:
path the endpoint path to run the request against. example: "t/places"
queryParams the query string parameters to send with the request. do not encode or escape these; that will be done automatically.
Returns:
the response body from running this GET request against Factual.
Throws:
FactualApiException if something goes wrong.
 
   public String get(String pathMap<StringObjectqueryParams) {
     return getInternal(pathqueryParams).getContent();
   }
 
   private InternalResponse getInternal(String pathMap<StringObjectqueryParams) {
     return request(new RawReadRequest(pathqueryParams));
   }

  
Runs a "GET" request against the path specified using the parameter string specified and your Oauth token.

Parameters:
path the path to run the request against
params the url-encoded parameter string to send with the request
Returns:
the response body from running this GET request against Factual.
 
   public String get(String pathString params) {
     return request(new SimpleGetRequest(pathparams)).getContent();
   }

  
Runs a POST request against the specified endpoint path, using the given parameters and your OAuth credentials. Returns the raw response body returned by Factual.

The necessary URL base will be automatically prepended to path. If you need to change it, e.g. to make requests against a development instance of the Factual service, please see setFactHome(java.lang.String).

Parameters:
path the endpoint path to run the request against. example: "t/places"
queryParams the query parameters to send with the request. send null or empty to specify none. do not encode or escape these; that will be done automatically.
postContent the POST content parameters to send with the request. do not encode or escape these; that will be done automatically.
Returns:
the response body from running this POST request against Factual.
Throws:
FactualApiException if something goes wrong.
 
   public String post(String pathMap<StringObjectqueryParams,
       Map<StringStringpostContent) {
     return postInternal(pathqueryParamspostContent).getContent();
   }
 
   private InternalResponse postInternal(String pathMap<StringObjectqueryParams,
       Map<StringStringpostContent) {
     return requestPost(new RawReadRequest(pathqueryParamspostContent));
   }
 
   public FactualStream stream(String tableNameDiffsQuery diffDiffsCallback cb) {
     return stream(new DiffsRequest(urlForFetch(tableName) + "/diffs"diff.toUrlParams(), cb), "GET"true);
   }
 
   public DiffsResponse fetch(String tableNameDiffsQuery diff) {
     DiffsResponse resp = new DiffsResponse();
     FactualStream stream = stream(tableNamediffresp);
     stream.start();
     return resp;
   }
 
   private ClearResponse clearCustom(String rootClear clearMetadata metadata) {
     Map<StringObjectparams = Maps.newHashMap();
     params.putAll(metadata.toUrlParams());
     params.putAll(clear.toUrlParams());
     // Oauth library currently doesn't support POST body content.
     InternalResponse resp = postInternal(rootparamsnew HashMap<StringString>());
     return new ClearResponse(resp);
   }
 
   private InsertResponse insertCustom(String rootInsert insert,
       Metadata metadata) {
     Map<StringObjectparams = Maps.newHashMap();
     params.putAll(metadata.toUrlParams());
     params.putAll(insert.toUrlParams());
     // Oauth library currently doesn't support POST body content.
     InternalResponse resp = postInternal(rootparamsnew HashMap<StringString>());
     return new InsertResponse(resp);
   }
 
   private SubmitResponse submitCustom(String rootSubmit submit,
       Metadata metadata) {
     Map<StringObjectparams = Maps.newHashMap();
     params.putAll(metadata.toUrlParams());
     params.putAll(submit.toUrlParams());
     // Oauth library currently doesn't support POST body content.
     InternalResponse resp = postInternal(rootparamsnew HashMap<StringString>());
     return new SubmitResponse(resp);
   }
 
   private FlagResponse flagCustom(String rootString flagType,
       Metadata metadata) {
     Map<StringObjectparams = Maps.newHashMap();
     params.putAll(metadata.toUrlParams());
     params.put("problem"flagType);
     // Oauth library currently doesn't support POST body content.
     InternalResponse resp = postInternal(rootparamsnew HashMap<StringString>());
     return new FlagResponse(resp);
   }

  
Use this to send all queued reads as a multi request

Returns:
response for a multi request
 
   public MultiResponse sendRequests(MultiRequest multiRequest) {
     Map<StringStringmulti = Maps.newHashMap();
     Map<StringRequestImplqueries = multiRequest.getQueries();
     for (Entry<StringRequestImplentry : queries.entrySet()) {
       RequestImpl fullQuery = entry.getValue();
       String url = "/" + fullQuery.toUrlString();
       multi.put(entry.getKey(), url);
     }
 
     String json = JsonUtil.toJsonStr(multi);
     Map<StringObjectparams = Maps.newHashMap();
     params.put("queries"json);
     InternalResponse internalResp = getInternal("multi"params);
     MultiResponse resp = new MultiResponse(queries);
     resp.setJson(internalResp.getContent());
     return resp;
   }

  
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 ResolveResponse resolves(ResolveQuery query) {
     return resolves("places"query);
   }

  
Asks Factual to resolve the 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 ResolveResponse resolves(String tableIdResolveQuery query) {
     query.allCandidates();
     return fetch(tableIdquery);
   }

  
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 resolve("places"query);
   }

  
Asks Factual to resolve the 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(String tableIdResolveQuery query) {
     ResolveResponse resp = resolves(tableIdquery);
     if (resp.isResolved())
       return resp.getResolved();
     else
       return null;
   }

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

Parameters:
query a Match query with partial attributes for an entity.
Returns:
a factual id for the resolved entity if Factual successfully identified the entity with full confidence, or null if the entity was not resolved.
 
   public String match(String tableIdMatchQuery query) {
     ResolveResponse resp = new ResolveResponse(request(new ReadRequest(
         urlForMatch(tableId), query.toUrlParams())));
     if (resp.getData().size() > 0)
       return String.valueOf(resp.getData().get(0).get("factual_id"));
     else
       return null;
   }

  
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 ResolveResponse fetch(String tableNameResolveQuery query) {
     return new ResolveResponse(request(new ReadRequest(
         urlForResolve(tableName), query.toUrlParams())));
   }

  

Parameters:
tableName
factualId The Factual ID of an entity that should be boosted in search results.
Returns:
 
   public BoostResponse boost(String tableNameString factualId) {
     return boost(tableNamefactualIdnullnull);
   }

  

Parameters:
tableName
factualId The Factual ID of an entity that should be boosted in search results.
search full-text-search query parameter value for q from a read request.
Returns:
 
   public BoostResponse boost(String tableNameString factualIdString search) {
     return boost(tableNamefactualIdsearchnull);
   }

  

Parameters:
tableName
factualId The Factual ID of an entity that should be boosted in search results.
search full-text-search query parameter value for q from a read request.
user An arbitrary token for correlating read and boost requests to a single app/session/etc. Factual does not use this token to track users. The function of this information is only to help evaluate how a boost relates to a search.
Returns:
 
   public BoostResponse boost(String tableNameString factualIdString searchString user) {
     Boost boost = new Boost(factualId);
     if (search != null)
       boost.search(search);
     if (user != null)
       boost.user(user);
     return boost(tableNameboost);
   }

  

Parameters:
tableName
factualId
query Perform boost request against settings from an existing read query
Returns:
 
   public BoostResponse boost(String tableNameString factualIdQuery query) {
     return boost(tableNamenew Boost(factualIdquery));
   }

  

Parameters:
tableName
boost
Returns:
 
   public BoostResponse boost(String tableNameBoost boost) {
     // Oauth library currently doesn't support POST body content.
     InternalResponse resp = postInternal("t/" + tableName + "/boost"boost.toUrlParams(), new HashMap<StringString>());
     return new BoostResponse(resp);
   }
 
 
   public SchemaResponse schema(String tableName) {
     Map<StringObjectparams = Maps.newHashMap();
     return new SchemaResponse(getInternal(urlForSchema(tableName), params));
   }
 
   private String urlForSchema(String tableName) {
     return "t/" + tableName + "/schema";
   }
 
   private InternalResponse request(Request query) {
     return request(querytrue);
   }
 
   private InternalResponse request(Request queryboolean useOAuth) {
     return request(query"GET"useOAuth);
   }
 
   private InternalResponse requestPost(Request query) {
     return requestPost(querytrue);
   }
 
   private InternalResponse requestPost(Request queryboolean useOAuth) {
     return request(query"POST"useOAuth);
   }
 
   private InternalResponse request(Request fullQueryString requestMethod,
       boolean useOAuth) {
     String urlStr =  + fullQuery.toUrlString();
 
     BufferedReader br = null;
     try {
       HttpRequest request = createRequest(urlStrfullQueryrequestMethoduseOAuth);
       // get the response
       HttpResponse resp = request.execute();
 
       InternalResponse internalResponse = new InternalResponse(respfullQuery.getLineCallback());
       /*
       br = new BufferedReader(new InputStreamReader(resp
           .getContent()));
       String line = null;
       StringBuffer sb = new StringBuffer();
       LineCallback cb = fullQuery.getLineCallback();
       while ((line = br.readLine()) != null) {
         if (cb != null)
           cb.onLine(line);
         sb.append(line);
       }
       return sb.toString();
        */
       return internalResponse;
     } catch (HttpResponseException e) {
       throw new FactualApiException(e).requestUrl(urlStr)
       .requestMethod(requestMethod).response(e.getStatusCode(), e.getMessage());
     } catch (IOException e) {
       throw new FactualApiException(e).requestUrl(urlStr).requestMethod(
           requestMethod);
     } catch (GeneralSecurityException e) {
       throw new RuntimeException(e);
     } finally {
       Closeables.closeQuietly(br);
     }
   }
 
   private FactualStream stream(Request fullQueryString requestMethod,
       boolean useOAuth) {
     String urlStr =  + fullQuery.toUrlString();
 
     BufferedReader br = null;
     try {
       HttpRequest request = createRequest(urlStrfullQueryrequestMethoduseOAuth);
 
       // get the response
       br = new BufferedReader(new InputStreamReader(request.execute()
           .getContent()));
       return new FactualStream(brfullQuery.getLineCallback());
     } catch (HttpResponseException e) {
       throw new FactualApiException(e).requestUrl(urlStr)
       .requestMethod(requestMethod).response(e.getStatusCode(), e.getMessage());
     } catch (IOException e) {
       throw new FactualApiException(e).requestUrl(urlStr).requestMethod(
           requestMethod);
     } catch (GeneralSecurityException e) {
       throw new RuntimeException(e);
     }
   }
 
   private HttpRequest createRequest(String urlStrRequest fullQueryString requestMethod,
       boolean useOAuththrows GeneralSecurityExceptionIOException {
     Map<StringStringpostData = fullQuery.getPostData();
     GenericUrl url = new GenericUrl(urlStr);
     if () {
       fullQuery.printDebug();
        = Logger.getLogger(HttpTransport.class.getName());
       .setLevel(.);
     }
 
     // Configure OAuth request params
     OAuthParameters params = new OAuthParameters();
     params.consumerKey = ;
     params.computeNonce();
     params.computeTimestamp();
     params.signer = ;
 
     // generate the signature
     params.computeSignature(requestMethodurl);
 
     // make the request
     HttpTransport transport = new NetHttpTransport();
     HttpRequestFactory f = null;
     if (useOAuth) {
       f = transport.createRequestFactory(params);
     } else {
       f = transport.createRequestFactory();
     }
     HttpRequest request = null;
     if ("POST".equals(requestMethod))
       if (postData == null)
         request = f.buildPostRequest(urlnull);
       else
         request = f.buildPostRequest(urlnew UrlEncodedContent(postData));
     else
       request = f.buildGetRequest(url);
 
     if ( != -1)
       request.setReadTimeout();
     if ( != -1)
       request.setConnectTimeout();
 
     HttpHeaders headers = new HttpHeaders();
     headers.set("X-Factual-Lib");
     headers.set("Host");
     request.setHeaders(headers);
     return request;
   }

  
Set the driver in or out of debug mode.

Parameters:
debug whether or not this is in debug mode
 
   public synchronized void debug(boolean debug) {
     this. = debug;
     if (debug &&  == null) {
        = new StreamHandler(.new SimpleFormatter());
     }
   }

  
Sets the timeout in milliseconds to establish a connection or 0 for an infinite timeout.

By default it is 20000 (20 seconds).

 
   public void setConnectionTimeout(int connectionTimeout) {
     this. = connectionTimeout;
   }

  
Sets the timeout in milliseconds to read data from an established connection or 0 for an infinite timeout.

By default it is 20000 (20 seconds).

 
   public void setReadTimeout(int readTimeout) {
     this. = readTimeout;
   }
 
   protected static interface Request {
 
     public String toUrlString();
 
     public Map<StringStringgetPostData();
 
     public Response getResponse(InternalResponse resp);
 
     public void printDebug();
 
     public LineCallback getLineCallback();
   }
 
   protected static class ReadRequest extends RequestImpl {
     public ReadRequest(String pathMap<StringObjectparams) {
       super(pathparams);
     }
 
     @Override
     public Response getResponse(InternalResponse resp) {
       return new ReadResponse(resp);
     }
 
   }

  
Represents a request against Factual given a path and parameters

Author(s):
brandon
 
   protected static abstract class RequestImpl implements Request {
 
     private final Map<StringObjectparams;
     private final Map<StringStringpostData;
     private final String path;
     protected LineCallback cb;
 
     public RequestImpl(String pathMap<StringObjectparams) {
       this(pathparamsnew HashMap<StringString>());
     }
 
     public RequestImpl(String pathMap<StringObjectparams,
         Map<StringStringpostData) {
       this. = path;
       this. = params;
       this. = postData;
     }
 
     public Map<StringObjectgetRequestParams() {
       return ;
     }
 
     @Override
     public String toUrlString() {
       return UrlUtil.toUrl(getRequestParams());
     }
 
     @Override
     public Map<StringStringgetPostData() {
       return ;
     }
 
     @Override
     public abstract Response getResponse(InternalResponse resp);
 
     @Override
    public void printDebug() {
      ..println("=== " +  + " ===");
      ..println("Parameters:");
      if ( != null) {
        for (String key : .keySet()) {
          ..println(key + ": " + .get(key));
        }
      }
    }
    @Override
    public LineCallback getLineCallback() {
      return ;
    }
  }
  protected static class ResolveRequest extends RequestImpl {
    public ResolveRequest(String pathMap<StringObjectparams) {
      super(pathparams);
    }
    @Override
    public Response getResponse(InternalResponse resp) {
      return new ResolveResponse(resp);
    }
  }
  protected static class FacetRequest extends RequestImpl {
    public FacetRequest(String pathMap<StringObjectparams) {
      super(pathparams);
    }
    @Override
    public Response getResponse(InternalResponse resp) {
      return new FacetResponse(resp);
    }
  }
  protected static class SchemaRequest extends RequestImpl {
    public SchemaRequest(String pathMap<StringObjectparams) {
      super(pathparams);
    }
    @Override
    public Response getResponse(InternalResponse resp) {
      return new SchemaResponse(resp);
    }
  }
  protected static class DiffsRequest extends RequestImpl {
    public DiffsRequest(String pathMap<StringObjectparamsfinal DiffsCallback cb) {
      super(pathparams);
      this. = new LineCallback() {
        @Override
        public void onLine(String line) {
          cb.onDiff(line);
        }
      };
    }
    @Override
    public Response getResponse(InternalResponse resp) {
      return new RawReadResponse(resp);
    }
  }
  protected static class RawReadRequest extends RequestImpl {
    public RawReadRequest(String pathMap<StringObjectparams) {
      super(pathparams);
    }
    public RawReadRequest(String pathMap<StringObjectparams,
        Map<StringStringpostData) {
      super(pathparamspostData);
    }
    @Override
    public Response getResponse(InternalResponse resp) {
      return new RawReadResponse(resp);
    }
  }
  protected static class SimpleGetRequest implements Request {
    private final String path;
    private final String params;
    public SimpleGetRequest(String pathString params) {
      this. = path;
      this. = params;
    }
    @Override
    public String toUrlString() {
      return UrlUtil.toUrl();
    }
    @Override
    public Map<StringStringgetPostData() {
      return null;
    }
    @Override
    public Response getResponse(InternalResponse resp) {
      return new RawReadResponse(resp);
    }
    @Override
    public void printDebug() {
      ..println("=== " +  + " ===");
      ..println("Parameters:");
    }
    @Override
    public LineCallback getLineCallback() {
      return null;
    }
  }
New to GrepCode? Check out our FAQ X