Home

Awesome

hook-android Download

Android client for hook.

#How to Use

Configure as a depedency

In your application build.gradle file, add the following lines:

dependencies {
    // ...
    compile 'com.doubleleft.hook:hook-android-client:0.2.3'
}

Setup

Context context = this;
String appId = "1";
String appKey = "aaf4c61ddcc5e8a2dabede0f3b482cd9aea9434d";
String endpoint = "http://localhost:4665/";
Client client = new Client(context, endpoint, appKey, appId);

Create Collection Item

JSONObject data = new JSONObject();
data.put("name", "My Book Name");
data.put("edition", 1.0);

client.collection("books").create(data, new JsonHttpResponseHandler() {
	@Override
	public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
		Log.d("success: ", response.toString());
	}

	@Override
	public void onFailure(int statusCode, Header[] headers, Throwable throwable, JSONObject errorResponse) {
		Log.d("failure: ", errorResponse.toString());
	}
});

Fetching (and filtering) items

client.collection("books").where("edition", 1).get(new JsonHttpResponseHandler() {
	@Override
	public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
		Log.d("success: ", response.toString());
	}

	@Override
	public void onFailure(int statusCode, Header[] headers, Throwable throwable, JSONObject errorResponse) {
		Log.d("failure: ", errorResponse.toString());
	}
});

Other available methods

Authentication: create user

JSONObject data = new JSONObject();
data.put("email", "gabriel@doubleleft.com");
data.put("name", "Gabriel Laet");
data.put("password", "123");
client.auth.register(data, new JsonHttpResponseHandler() {...});

Once the user is created, you don't need to verify/login again. The library also takes care to store the current user internally.

Authentication: login user

JSONObject data = new JSONObject();
data.put("email", "gabriel@doubleleft.com");
data.put("password", "123");
client.auth.login(data, new JsonHttpResponseHandler() {...});

Authentication: other methods

Contributing

Creating a new release version

cd Hook
gradle generateRelease

Log-in on bintray, create a new version. Click on "Upload Files", from the recently version created, and attach the .zip file genereated via gradle generateRelease task. Make sure to select "Explode this archive" from the "Attached Files" list.

License

MIT