A Java library for accessing servers based on mia-js.
Helium automatically performs the necessary device registration and session key handling required by mia-js to perform authenticated requests.
Despite having been developed with Android in mind, the Helium should work properly on pure Java environments. The included unit tests do not depend on any way on Android-specific code.
Add the following lines to your root build.gradle:
allprojects {
repositories {
[...]
maven { url "https://jitpack.io" }
}
}
Then reference the library from your module's build.gradle:
dependencies {
[...]
compile 'com.github.7factory:mia-helium:x.y'
}
Helium is based on the popular Retrofit library, making it easy to implement your API through the use of Java Interfaces.
For example, a simple to-do service including a method to fetch to-do items:
public interface TodoApi {
@GET("/todo")
MiddlewareResult<List<TodoItem>> fetchTodoItems();
}
In order to instantiate the API, you will first need is a configured Helium instance:
Config config = new ServiceConfig();
DeviceStore store = new AndroidDeviceStore(context);
Helium helim = new Helium(config, store);
TodoApi todoApi = helium.createApi(Api.class);
The Config
interface needs to be implemented by you and contains your service-specific endpoint URL and secrets.
The DeviceStore
interface allows you to define how Helium generates the DeviceInfo
objects required for authentication, as well as how the resulting session tokens are stored.
Helium ships with AndroidDeviceStore
, an implementation of DeviceStore
based on the Android PackageManager
and SharedPreferences
classes. A MockDeviceStore
that does not depend on any Android classes is also available for unit testing.
A simple integration example is in method testGetTodoItems()
in our unit tests.