Skip to content

AferoSofthub and the AferoClient Interface

Tony Myles edited this page Aug 22, 2018 · 8 revisions

The AferoClient interface is used by the SDK to perform all calls to the Afero Client REST API. The SDK provides a concrete implementation of this interface called AferoClientRetrofit2. However, developers may choose to provide their own implementation if they prefer not to use okhttp3 & Retrofit2, or if they are using their own REST API as a proxy to Afero.

public class MyCustomAferoClient implements AferoClient {
    @Override
    public Observable<DeviceAssociateResponse> deviceAssociate(String s) {

        // code that calls developer's cloud goes here...

        return response;
    }

    @Override
    public String getActiveAccountId() {
        return "my-account";
    }
}

Applications that use the full functionality of the AferoJavaSDK must provide a complete implementation of AferoClient. However, for applications that use only the AferoSofthub, just two AferoClient functions need to be implemented.

deviceAssociate

Observable<DeviceAssociateResponse> deviceAssociate(String associationId);

This function should perform an asynchronous REST API call to the Afero Cloud (or suitable proxy) passing along the specified associationId. The returned rx.Observable must emit a DeviceAssociateResponse on success. The fields of the DeviceAssociateResponse are not used directly by the AferoSofthub, so the values need not be real but they should at least be non-null.

getActiveAccountId

String getActiveAccountId();

This function is used by the AferoSofthub to calculate a unique directory name for the Softhub config files that are persistently in the Android filesystem. Typically these files are stored in separate directories for each account. If the developer application doesn't support this level of account granularity, this function could return a constant or even an empty string.

AferoSofthub.acquireInstance

A custom AferoClient that implements these two functions can then be passed into AferoClient.acquireInstance() like so:

MyCustomAferoClient client = new MyCustomAferoClient();
AferoSofthub hub = AferoSofthub.acquireInstance(context, client, "appInfo");
Clone this wiki locally