Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package com.factual.driver;
 
 import  org.json.JSONException;
 import  org.json.JSONObject;


Represents the basic concept of a response from Factual.

Author(s):
aaron
public abstract class Response {
  public static final int UNDEFINED = -1;
  private String version;
  private String status;
  private int totalRowCount = ;
  private int includedRows;


  
The status returned by the Factual API server, e.g. "ok".

Returns:
status returned by the Factual API server.
  public String getStatus() {
    return ;
  }

  
The version tag returned by the Factual API server, e.g. "3".

Returns:
the version tag returned by the Factual API server.
  public String getVersion() {
    return ;
  }

  

Returns:
total underlying row count, or UNDEFINED if unknown.
  public int getTotalRowCount() {
    return ;
  }

  

Returns:
amount of result rows returned in this response.
  public int getIncludedRowCount() {
    return ;
  }

  

Returns:
true if Factual's response did not include any results records for the query, false otherwise.
  public boolean isEmpty() {
    return  == 0;
  }

  
Parses response metadata from rootJsonObj and adds it to response

Parameters:
response the response object to which to add metadata.
rootJsonObj the top-level JSON response Object built from a Factual response.
  public static void withMeta(Response resp, JSONObject rootJsonObj) {
    try {
      resp.version = rootJsonObj.getString("version");
      resp.status = rootJsonObj.getString("status");
      JSONObject respJson = rootJsonObj.getJSONObject("response");
      if(respJson.has("total_row_count")) {
        resp.totalRowCount = respJson.getInt("total_row_count");
      }
      if(respJson.has("included_rows")) {
        resp.includedRows = respJson.getInt("included_rows");
      }
    } catch (JSONException e) {
      throw new RuntimeException(e);
    }
  }
  public String toString() {
    return getJson();
  }

  
Subclasses of Response must provide access to the original JSON representation of Factual's response.

Returns:
the original JSON representation of Factual's response.
  public abstract String getJson();
New to GrepCode? Check out our FAQ X