-
Notifications
You must be signed in to change notification settings - Fork 0
Handling multiple API requests
It is possible to handle several API requests at once and trigger an action after all requests have been successfully processed by the Game Jolt API or trigger an alternative action in case a request has been rejected or failed.
handle_requests(requests: Array, target: Node, resolve_action: String, reject_action: String) -> void
Handle multiple Game Jolt API requests (GameJoltAPIRequest objects).
- If all API requests are successfully processed by the Game Jolt Server, it will call the resolve_action function located in the target node.
- If one of the requests fails, it will call the reject_action function located in the target node. (optional)
Contains the requests (GameJoltAPIRequest objects) that will be handled by the handle_requests
function.
Node that contains the functions resolve_action and reject_action.
Function to be called when all the Game Jolt API requests have been successfully processed. It will contain as parameter the responses given by the API Server, each element of the array will contain the response to the API request made in the same order as the requests
array.
Function to be called if one of the requests fails. If this happens, the resolve_action function will never be called. It will contain as parameter the error message of the failed request.
func _ready():
#create request 1 (e.g adding a score)
var add_score_request = GameJoltAPI.add_score({
"username": GameJoltAPI.username,
"user_token": GameJoltAPI.user_token,
"score": "10",
"sort": 10
})
#create request 2 (e.g getting the max score)
var get_score_request = GameJoltAPI.fetch_score({
"limit": 1
})
#Handle the requests
GameJoltAPI.handle_requests(
[add_score_request, get_score_request],
self,
"_on_requests_completed",
"_on_requests_failed"
)
func _on_requests_completed(responses:Array):
#If all the requests are successfully completed, in this example it will return the following array:
# [[], [{'extra_data': '','guest':'', 'score': '30','sort':30, 'stored': '1 week ago', 'stored_timestamp': 1595295176, 'user': 'gamejolt_username', 'user_id': '101010101' }]]
pass
func _on_requests_failed(error:String):
#If one of the requests failed, then this function will be called
pass