Search in sources :

Example 1 with DownloadItemTemplatesMessage

use of POGOProtos.Networking.Requests.Messages.DownloadItemTemplatesMessageOuterClass.DownloadItemTemplatesMessage in project PokeGOAPI-Java by Grover-c13.

the class ItemTemplates method updatePage.

/**
 * Updates {@link ItemTemplate} pages recursively
 *
 * @param api the current api
 * @param page the current page index
 * @param timestamp the timestamp of this page
 * @param loadTime the time at which the templates started loading
 * @throws RequestFailedException if the page update is not successfully sent
 */
private void updatePage(PokemonGo api, int page, long timestamp, long loadTime) throws RequestFailedException {
    DownloadItemTemplatesMessage message = DownloadItemTemplatesMessage.newBuilder().setPaginate(true).setPageOffset(page).setPageTimestamp(timestamp).build();
    ServerRequest request = new ServerRequest(RequestType.DOWNLOAD_ITEM_TEMPLATES, message);
    api.requestHandler.sendServerRequests(request, true);
    try {
        DownloadItemTemplatesResponse response = DownloadItemTemplatesResponse.parseFrom(request.getData());
        provider.updateTemplates(response, loadTime);
        if (response.getResult() == Result.PAGE) {
            updatePage(api, response.getPageOffset(), response.getTimestampMs(), loadTime);
        }
    } catch (IOException e) {
        throw new RequestFailedException(e);
    }
}
Also used : RequestFailedException(com.pokegoapi.exceptions.request.RequestFailedException) DownloadItemTemplatesMessage(POGOProtos.Networking.Requests.Messages.DownloadItemTemplatesMessageOuterClass.DownloadItemTemplatesMessage) DownloadItemTemplatesResponse(POGOProtos.Networking.Responses.DownloadItemTemplatesResponseOuterClass.DownloadItemTemplatesResponse) IOException(java.io.IOException) ServerRequest(com.pokegoapi.main.ServerRequest)

Aggregations

DownloadItemTemplatesMessage (POGOProtos.Networking.Requests.Messages.DownloadItemTemplatesMessageOuterClass.DownloadItemTemplatesMessage)1 DownloadItemTemplatesResponse (POGOProtos.Networking.Responses.DownloadItemTemplatesResponseOuterClass.DownloadItemTemplatesResponse)1 RequestFailedException (com.pokegoapi.exceptions.request.RequestFailedException)1 ServerRequest (com.pokegoapi.main.ServerRequest)1 IOException (java.io.IOException)1