You should use MBurgerTasks static methods to retrieve data from MBurger dashboard.
This class has public static functions that will call asynchronously MBurger API.
You have 2 ways to retrieve data from API:
The Listener approach is the easiest one.
With every method of the MBurgerTasks class you should pass the corresponding listener to return data from the function to your control.
All the listeners are inside the MBApiResultsListeners and all of them are simple interfaces that will return the MBurger object you asked for or an error message.
For example, you should use a MBApiProjectResultListener (implementing it to your Activity or Fragment or creating a new one runtime) to obtain Project basic data, so the class will implement these methods:
/*API call went well*/
/*There was an error, you should show it*/
The Action approach is more complicated but more flexible.
It uses LocalBroadcastMessages to send data from the API to your Activity/Fragment using an Action which your Activity/Fragment is listening to.
You can also use this method also if you are doing your own API calls to your server. First you must implement MBGenericApiResultListener which will automatically implement the method.Java
For example, to obtain the blocks and the project you have to follow these few steps:
Create a BroadcastReceiver.
Initialize the BroadcastReceiver in your onResume method with the MBurgerApiActionInitializer class specific function.
Pause the BroadcastReceiver in your onPause method with the MBurgerApiActionInitializer class specific function.
Call the task to send the blocks’ request according to the parameters given in this sample.
Fetch the blocks from the response variable of onApiResult.
The code will result:
val actions =arrayOf(MBAPIConstants.ACTION_GET_BLOCKS, MBAPIConstants.ACTION_GET_PROJECT)