Search in sources :

Example 1 with FortDeployPokemonMessage

use of POGOProtos.Networking.Requests.Messages.FortDeployPokemonMessageOuterClass.FortDeployPokemonMessage in project PokeGOAPI-Java by Grover-c13.

the class Gym method deployPokemon.

/**
 * Deploy pokemon
 *
 * @param pokemon The pokemon to deploy
 * @return Result of attempt to deploy pokemon
 * @throws RequestFailedException if an exception occurred while sending requests
 */
public FortDeployPokemonResponse.Result deployPokemon(Pokemon pokemon) throws RequestFailedException {
    FortDeployPokemonMessage reqMsg = FortDeployPokemonMessage.newBuilder().setFortId(getId()).setPlayerLatitude(api.latitude).setPlayerLongitude(api.longitude).setPokemonId(pokemon.getId()).build();
    ServerRequest serverRequest = new ServerRequest(RequestType.FORT_DEPLOY_POKEMON, reqMsg);
    api.requestHandler.sendServerRequests(serverRequest, true);
    try {
        return FortDeployPokemonResponse.parseFrom(serverRequest.getData()).getResult();
    } catch (InvalidProtocolBufferException e) {
        throw new RequestFailedException();
    }
}
Also used : RequestFailedException(com.pokegoapi.exceptions.request.RequestFailedException) FortDeployPokemonMessage(POGOProtos.Networking.Requests.Messages.FortDeployPokemonMessageOuterClass.FortDeployPokemonMessage) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) ServerRequest(com.pokegoapi.main.ServerRequest)

Example 2 with FortDeployPokemonMessage

use of POGOProtos.Networking.Requests.Messages.FortDeployPokemonMessageOuterClass.FortDeployPokemonMessage in project PokeGOAPI-Java by Grover-c13.

the class Gym method deployPokemonAsync.

/**
 * Deploy pokemon
 *
 * @param pokemon The pokemon to deploy
 * @return Result of attempt to deploy pokemon
 * @throws RequestFailedException if an exception occurred while sending requests
 */
public Observable<FortDeployPokemonResponse.Result> deployPokemonAsync(Pokemon pokemon) throws RequestFailedException {
    FortDeployPokemonMessage reqMsg = FortDeployPokemonMessage.newBuilder().setFortId(getId()).setPlayerLatitude(api.latitude).setPlayerLongitude(api.longitude).setPokemonId(pokemon.getId()).build();
    ServerRequest asyncServerRequest = new ServerRequest(RequestType.FORT_DEPLOY_POKEMON, reqMsg);
    return api.requestHandler.sendAsyncServerRequests(asyncServerRequest).map(new Func1<ByteString, FortDeployPokemonResponse.Result>() {

        @Override
        public FortDeployPokemonResponse.Result call(ByteString response) {
            try {
                return FortDeployPokemonResponse.parseFrom(response).getResult();
            } catch (InvalidProtocolBufferException e) {
                throw Exceptions.propagate(e);
            }
        }
    });
}
Also used : ByteString(com.google.protobuf.ByteString) FortDeployPokemonMessage(POGOProtos.Networking.Requests.Messages.FortDeployPokemonMessageOuterClass.FortDeployPokemonMessage) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) ServerRequest(com.pokegoapi.main.ServerRequest)

Aggregations

FortDeployPokemonMessage (POGOProtos.Networking.Requests.Messages.FortDeployPokemonMessageOuterClass.FortDeployPokemonMessage)2 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)2 ServerRequest (com.pokegoapi.main.ServerRequest)2 ByteString (com.google.protobuf.ByteString)1 RequestFailedException (com.pokegoapi.exceptions.request.RequestFailedException)1