Created
May 6, 2010 09:22
-
-
Save doitian/391961 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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