Skip to content

Instantly share code, notes, and snippets.

@smuldr
Created August 12, 2013 12:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save smuldr/6210477 to your computer and use it in GitHub Desktop.
Save smuldr/6210477 to your computer and use it in GitHub Desktop.
import nl.sense_os.service.commonsense.SenseApi;
public class Foo extends Activity {
/**
* Sends a JSON object to /foo/bar at CommonSense API and checks the response
*/
public void foo() {
String urlString = "https://api.sense-os.nl/foo/bar";
JSONObject content = null; // TODO
String cookie = authPrefs.getString(Auth.LOGIN_COOKIE, null);
Map<String, String> response = SenseApi.request(context, urlString, content, cookie);
// check response code
String code = response.get("http response code");
if (!("201".equals(code) || "200".equals(code))) {
Log.w(TAG, "Failed to do the call at CommonSense! Response code: " + code);
// TODO handle error
return;
}
// check result
JSONObject res = new JSONObject(response.get("content"));
if (null == res || res.length() == 0) {
Log.w(TAG, "Unexpected response from CommonSense! Response: " + res);
// TODO handle error
return;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment