Skip to content

Instantly share code, notes, and snippets.

@doitian
Created May 6, 2010 09:22
Show Gist options
  • Save doitian/391961 to your computer and use it in GitHub Desktop.
Save doitian/391961 to your computer and use it in GitHub Desktop.
import org.json.simple.JSONObject;
class CmClient
{
private String cmServerUrl;
public CmClient(String url)
{
cmServerUrl = url;
}
// returns category id if success, negative integer otherwise
public long authenticateCategory(String user, String password, String category)
throws java.io.IOException
{
JsonHttpClient client = new JsonHttpClient();
JSONObject content = new JSONObject();
content.put("login", user);
content.put("password", password);
content.put("category", category);
JSONObject result = client.post(cmServerUrl + "/authenticate_category", content);
Object resultContent = result.get("content");
long categoryId = -1;
if (resultContent != null)
{
categoryId =
((Long)(((JSONObject)resultContent).get("category_id"))).longValue();
}
return categoryId;
}
public boolean isUserExist(String user)
throws java.io.IOException
{
JsonHttpClient client = new JsonHttpClient();
JSONObject result = client.get(cmServerUrl + "/users/" + user);
int statusCode = ((Integer)result.get("status")).intValue();
return statusCode == 200;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment