- A
RemoteObject
is a local representation of one or several endpoints on the flexicharge API back end. - For example, for the endpoint /transactions there is a class
RemoteTransaction
which inherits fromRemoteObject<Transaction>
- All functionality of the endpoint should be contained within a
RemoteObject
class.
- Define a
data class
summarizing the information to be contained within the remote object. - The
data class
Chargers
for example contains the information returned by the API-callGET /chargers
. - Make sure that the layout and the names of the fields in the
data class
matches its corresponding JSON object - provided by the backend team. - Create a class inheriting from
RemoteObject<T>
. - For example, the class
RemoteChargers
inherits fromRemoteObject<Chargers>
. - Implement its abstract methods and properties. Android studio can help you in doing this, just hover over what's marked with red "squiggly lines" and perform the recommended action.
- Check the existing Remote____ classes for reference on how to implement API-calls.
- Don't forget to use
withTimeout()
when making API calls! Otherwise, calls that aren't responded to will never finish, which will slowly drain resources.
- All RemoteObjects implement the method
refresh()
which utilizes the abstract methodretrieve()
. retrieve()
should implement the most generalGET
request you can make to the end-point.refresh()
in turn calls the onRefreshed callback which can be defined with the methodsetOnRefreshedCallback()
.- All operations performed by a remote object should return a
Job
instance, which you can store in a variable. - To perform an action after the API-call has been succesfully made, use the method
Job.invokeOnCompletion()
. - To check whether the API-call succeeded you can consult the property
Job.isCancelled
toreturn@invokeOnCompletion
if it failed.
- They help separate business logic from the presentation layer.
- They standardize the way communication with the back end is done.
- They ensure that each API-call is only done in one place.