Search in sources :

Example 1 with SetBuddyPokemonResponse

use of POGOProtos.Networking.Responses.SetBuddyPokemonResponseOuterClass.SetBuddyPokemonResponse in project PokeGOAPI-Java by Grover-c13.

the class PlayerProfile method setBuddy.

/**
	 * Sets the current buddy
	 *
	 * @param pokemon the pokemon to set as your buddy
	 * @return if this task was successfull
	 * @throws RequestFailedException if an exception occurred while sending requests
	 */
public boolean setBuddy(Pokemon pokemon) throws RequestFailedException {
    SetBuddyPokemonMessageOuterClass.SetBuddyPokemonMessage message = SetBuddyPokemonMessageOuterClass.SetBuddyPokemonMessage.newBuilder().setPokemonId(pokemon.getId()).build();
    ServerRequest request = new ServerRequest(RequestType.SET_BUDDY_POKEMON, message);
    api.getRequestHandler().sendServerRequests(request);
    try {
        SetBuddyPokemonResponse response = SetBuddyPokemonResponse.parseFrom(request.getData());
        buddy = new Buddy(api, response.getUpdatedBuddy());
        return response.hasUpdatedBuddy();
    } catch (InvalidProtocolBufferException e) {
        throw new RequestFailedException(e);
    }
}
Also used : RequestFailedException(com.pokegoapi.exceptions.request.RequestFailedException) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) ServerRequest(com.pokegoapi.main.ServerRequest) SetBuddyPokemonMessageOuterClass(POGOProtos.Networking.Requests.Messages.SetBuddyPokemonMessageOuterClass) SetBuddyPokemonResponse(POGOProtos.Networking.Responses.SetBuddyPokemonResponseOuterClass.SetBuddyPokemonResponse) Buddy(com.pokegoapi.api.pokemon.Buddy)

Aggregations

SetBuddyPokemonMessageOuterClass (POGOProtos.Networking.Requests.Messages.SetBuddyPokemonMessageOuterClass)1 SetBuddyPokemonResponse (POGOProtos.Networking.Responses.SetBuddyPokemonResponseOuterClass.SetBuddyPokemonResponse)1 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)1 Buddy (com.pokegoapi.api.pokemon.Buddy)1 RequestFailedException (com.pokegoapi.exceptions.request.RequestFailedException)1 ServerRequest (com.pokegoapi.main.ServerRequest)1