QueryState.java :  » App » civilobedience » org » votesmart » localities » Android Open Source

Android Open Source » App » civilobedience 
civilobedience » org » votesmart » localities » QueryState.java
package org.votesmart.localities;

import java.util.HashMap;

import org.votesmart.QueryResult;
import org.votesmart.VoteSmart;

import android.util.Log;

import com.google.gson.Gson;

public class QueryState {
  
  private static String QueryStateTag = "QueryState";

  public static QueryResultStateGetStateIDs GetStateIDs()
  {
    HashMap<String, String> params = new HashMap<String, String>();
    
    String jsonResult = new VoteSmart( "Local.getCounties", params ).query();

    try {
      return
        new Gson().fromJson(jsonResult, QueryResultStateGetStateIDs.class);  
    }
    catch (Exception e)
    {
      //TODO need a better exception handler
      Log.d(QueryStateTag, e.getMessage());
    }
    
    // return an empty but failed query result
    return new QueryResultStateGetStateIDs(QueryResult.Status.FAILED);
  }

  public static QueryResultStateGetState GetState(String stateId)
  {
    HashMap<String, String> params = new HashMap<String, String>();
    
    params.put("stateId", stateId);
    
    String jsonResult = new VoteSmart( "Local.getState", params ).query();

    try {
      return
        new Gson().fromJson(jsonResult, QueryResultStateGetState.class);  
    }
    catch (Exception e)
    {
      //TODO need a better exception handler
      Log.d(QueryStateTag, e.getMessage());
    }
    
    // return an empty but failed query result
    return new QueryResultStateGetState(QueryResult.Status.FAILED);
  }

}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.