Search in sources :

Example 1 with SetFavoritePokemonResponse

use of POGOProtos.Networking.Responses.SetFavoritePokemonResponseOuterClass.SetFavoritePokemonResponse in project PokeGOAPI-Java by Grover-c13.

the class Pokemon method setFavoritePokemon.

/**
	 * Function to mark the pokemon as favorite or not.
	 *
	 * @param markFavorite Mark Pokemon as Favorite?
	 * @return the SetFavoritePokemonResponse.Result
	 * @throws RequestFailedException if an exception occurred while sending requests
	 */
public SetFavoritePokemonResponse.Result setFavoritePokemon(boolean markFavorite) throws RequestFailedException {
    SetFavoritePokemonMessage reqMsg = SetFavoritePokemonMessage.newBuilder().setPokemonId(getId()).setIsFavorite(markFavorite).build();
    ServerRequest serverRequest = new ServerRequest(RequestType.SET_FAVORITE_POKEMON, reqMsg);
    api.getRequestHandler().sendServerRequests(serverRequest, true);
    SetFavoritePokemonResponse response;
    try {
        response = SetFavoritePokemonResponse.parseFrom(serverRequest.getData());
        if (response.getResult() == SetFavoritePokemonResponse.Result.SUCCESS) {
            favorite = markFavorite ? 1 : 0;
        }
    } catch (InvalidProtocolBufferException e) {
        throw new RequestFailedException(e);
    }
    api.getInventories().getPokebank().removePokemon(this);
    return response.getResult();
}
Also used : SetFavoritePokemonResponse(POGOProtos.Networking.Responses.SetFavoritePokemonResponseOuterClass.SetFavoritePokemonResponse) RequestFailedException(com.pokegoapi.exceptions.request.RequestFailedException) SetFavoritePokemonMessage(POGOProtos.Networking.Requests.Messages.SetFavoritePokemonMessageOuterClass.SetFavoritePokemonMessage) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) ServerRequest(com.pokegoapi.main.ServerRequest)

Aggregations

SetFavoritePokemonMessage (POGOProtos.Networking.Requests.Messages.SetFavoritePokemonMessageOuterClass.SetFavoritePokemonMessage)1 SetFavoritePokemonResponse (POGOProtos.Networking.Responses.SetFavoritePokemonResponseOuterClass.SetFavoritePokemonResponse)1 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)1 RequestFailedException (com.pokegoapi.exceptions.request.RequestFailedException)1 ServerRequest (com.pokegoapi.main.ServerRequest)1