Fetch sections from blocks

Setting the specific block_id, it is possible to obtain the corresponding section’s data.

If you want, you can include whether or not you want to filter the elements of the section by adding an array of filters.

The process to reach the result is the same as the blocks’ example:

  • Create, initialize and pause the BroadcastReceiver (using “forSections” method).

  • Call the task.

  • Fetch the sections from the response of onApiResult.

Your code should be like this:

override fun onResume() {
    super.onResume()
    /**Create your sections’ receiver**/
    bRec = MBurgerApiActionInitializer.initializeNookoReceiverForSections(this, this)

    /**Add custom filters to the API call or leave it null**/
    val arrayOfFilters : ArrayList<Any> = null

    /**Id of the block you wish to retrieve sections**/
     val block_id = block.getId()

     /**Inside the sections the “elements” field will be valorized**/
     val getElements = true

     /**Call sections’ API**/
     MBurgerTasks.askForSections(this, block_id, arrayOfFilters, getElements)
}

override fun onPause() {
    super.onPause()
    MBurgerApiActionInitializer.pauseNookoReceiver(getActivity(), bRec)
}

override fun onApiResult(response: MBAPIResponse ) {
    if (response.getResult()) {
       val sections = response.getPayload().get(MBApiPayloadKeys.key_sections) as ArrayList<MBSection>
        if (sections.size() > 0) {
            //Your code
        } else {
            Log.w(“WARNINGS HOME”, “THE HOME’ S SECTION IS EMPTY”)
        }
    } else {
        Log.e(“ERROR RESPONSE API”, “THERE WAS AN ERROR DURING HOME’ S LOADING”)
    }
}

If you specify more filters of the same type inside the array, only the last one of those type will be considered.

Last updated