Search in sources :

Example 1 with RequestFailedException

use of com.pokegoapi.exceptions.request.RequestFailedException in project PokeGOAPI-Java by Grover-c13.

the class Map method requestIncensePokemon.

/**
	 * Requests and returns incense pokemon from the server.
	 *
	 * @return the returned incense pokemon response
	 * @throws RequestFailedException if an exception occurred while sending requests
	 */
protected GetIncensePokemonResponse requestIncensePokemon() throws RequestFailedException {
    GetIncensePokemonMessage message = GetIncensePokemonMessage.newBuilder().setPlayerLatitude(api.getLatitude()).setPlayerLongitude(api.getLongitude()).build();
    ServerRequest request = new ServerRequest(RequestType.GET_INCENSE_POKEMON, message);
    api.getRequestHandler().sendServerRequests(request);
    try {
        return GetIncensePokemonResponse.parseFrom(request.getData());
    } catch (InvalidProtocolBufferException e) {
        throw new RequestFailedException(e);
    }
}
Also used : GetIncensePokemonMessage(POGOProtos.Networking.Requests.Messages.GetIncensePokemonMessageOuterClass.GetIncensePokemonMessage) RequestFailedException(com.pokegoapi.exceptions.request.RequestFailedException) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) ServerRequest(com.pokegoapi.main.ServerRequest)

Example 2 with RequestFailedException

use of com.pokegoapi.exceptions.request.RequestFailedException in project PokeGOAPI-Java by Grover-c13.

the class RequestHandler method sendServerRequests.

/**
	 * Sends a single ServerRequest
	 *
	 * @param request the request to send
	 * @param commons whether this request should include commons
	 * @param commonExclusions the common requests to exclude from this request
	 * @return the result from this request
	 * @throws RequestFailedException if an exception occurred while sending requests
	 */
public ByteString sendServerRequests(ServerRequest request, boolean commons, RequestType... commonExclusions) throws RequestFailedException {
    ServerRequestEnvelope envelope = ServerRequestEnvelope.create();
    envelope.add(request);
    envelope.setCommons(commons);
    envelope.excludeCommons(commonExclusions);
    AsyncHelper.toBlocking(sendAsyncServerRequests(envelope));
    try {
        return request.getData();
    } catch (InvalidProtocolBufferException e) {
        throw new RequestFailedException(e);
    }
}
Also used : RequestFailedException(com.pokegoapi.exceptions.request.RequestFailedException) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException)

Example 3 with RequestFailedException

use of com.pokegoapi.exceptions.request.RequestFailedException in project PokeGOAPI-Java by Grover-c13.

the class PokemonGo method initialize.

private void initialize() throws RequestFailedException {
    if (requestHandler != null) {
        requestHandler.exit();
    }
    requestHandler = new RequestHandler(this, client);
    requestHandler.sendServerRequests(ServerRequestEnvelope.create());
    playerProfile.updateProfile();
    ServerRequest downloadConfigRequest = new ServerRequest(RequestType.DOWNLOAD_REMOTE_CONFIG_VERSION, CommonRequests.getDownloadRemoteConfigVersionMessageRequest(this));
    requestHandler.sendServerRequests(downloadConfigRequest, true);
    getAssetDigest();
    try {
        ByteString configVersionData = downloadConfigRequest.getData();
        if (itemTemplates.requiresUpdate(DownloadRemoteConfigVersionResponse.parseFrom(configVersionData))) {
            itemTemplates.update(this);
        }
    } catch (InvalidProtocolBufferException e) {
        throw new RequestFailedException(e);
    }
    playerProfile.getProfile();
    try {
        LevelUpRewardsMessage rewardsMessage = LevelUpRewardsMessage.newBuilder().setLevel(playerProfile.getStats().getLevel()).build();
        ServerRequest request = new ServerRequest(RequestType.LEVEL_UP_REWARDS, rewardsMessage);
        ServerRequestEnvelope envelope = ServerRequestEnvelope.createCommons(request, this);
        requestHandler.sendServerRequests(envelope);
        LevelUpRewardsResponse levelUpRewardsResponse = LevelUpRewardsResponse.parseFrom(request.getData());
        if (levelUpRewardsResponse.getResult() == Result.SUCCESS) {
            inventories.itemBag.addAwardedItems(levelUpRewardsResponse);
        }
    } catch (InvalidProtocolBufferException e) {
        throw new RequestFailedException(e);
    }
    ByteString getStoreItems = GetStoreItemsRequest.newBuilder().build().toByteString();
    ServerRequestEnvelope envelope = ServerRequestEnvelope.create();
    envelope.addPlatform(new ServerPlatformRequest(PlatformRequestType.GET_STORE_ITEMS, getStoreItems));
    requestHandler.sendServerRequests(envelope);
    try {
        FetchAllNewsMessageOuterClass.FetchAllNewsMessage msg = FetchAllNewsMessageOuterClass.FetchAllNewsMessage.newBuilder().build();
        ServerRequest request = new ServerRequest(RequestType.FETCH_ALL_NEWS, msg);
        envelope = ServerRequestEnvelope.create(request);
        requestHandler.sendServerRequests(envelope);
        FetchAllNewsResponseOuterClass.FetchAllNewsResponse response = FetchAllNewsResponseOuterClass.FetchAllNewsResponse.parseFrom(request.getData());
        if (response.getResult() == FetchAllNewsResponseOuterClass.FetchAllNewsResponse.Result.SUCCESS) {
            Log.i(TAG, "FetchAllNewsMessage Success: total News=" + response.getCurrentNews().getNewsArticlesCount());
            this.news.setCurrentNews(response.getCurrentNews());
            // mark all un-read new to read
            this.news.markUnreadNews();
        } else {
            Log.d(TAG, "FetchAllNewsMessage Failed. Result=" + response.getResult());
        }
    } catch (Exception e) {
        Log.d(TAG, "Exceptions FetchAllNew");
    }
    List<LoginListener> loginListeners = getListeners(LoginListener.class);
    for (LoginListener listener : loginListeners) {
        listener.onLogin(this);
    }
    loggingIn = false;
    active = true;
    ArrayList<TutorialState> tutorialStates = playerProfile.getTutorialState().getTutorialStates();
    if (tutorialStates.isEmpty()) {
        playerProfile.activateAccount();
    }
    if (!tutorialStates.contains(TutorialState.AVATAR_SELECTION)) {
        playerProfile.setupAvatar();
    }
    heartbeat.start();
    if (!tutorialStates.contains(TutorialState.POKEMON_CAPTURE)) {
        playerProfile.encounterTutorialComplete();
    }
    int remainingCodenameClaims = playerProfile.getPlayerData().getRemainingCodenameClaims();
    if (!tutorialStates.contains(TutorialState.NAME_SELECTION) && remainingCodenameClaims > 0) {
        playerProfile.claimCodeName();
    }
    if (!tutorialStates.contains(TutorialState.FIRST_TIME_EXPERIENCE_COMPLETE)) {
        playerProfile.firstTimeExperienceComplete();
    }
}
Also used : LevelUpRewardsMessage(POGOProtos.Networking.Requests.Messages.LevelUpRewardsMessageOuterClass.LevelUpRewardsMessage) ByteString(com.google.protobuf.ByteString) FetchAllNewsMessageOuterClass(POGOProtos.Networking.Requests.Messages.FetchAllNewsMessageOuterClass) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) RequestFailedException(com.pokegoapi.exceptions.request.RequestFailedException) IOException(java.io.IOException) Point(com.pokegoapi.api.map.Point) FetchAllNewsResponseOuterClass(POGOProtos.Networking.Responses.FetchAllNewsResponseOuterClass) ServerRequestEnvelope(com.pokegoapi.main.ServerRequestEnvelope) LoginListener(com.pokegoapi.api.listener.LoginListener) RequestHandler(com.pokegoapi.main.RequestHandler) RequestFailedException(com.pokegoapi.exceptions.request.RequestFailedException) ServerRequest(com.pokegoapi.main.ServerRequest) LevelUpRewardsResponse(POGOProtos.Networking.Responses.LevelUpRewardsResponseOuterClass.LevelUpRewardsResponse) ServerPlatformRequest(com.pokegoapi.main.ServerPlatformRequest) TutorialState(POGOProtos.Enums.TutorialStateOuterClass.TutorialState)

Example 4 with RequestFailedException

use of com.pokegoapi.exceptions.request.RequestFailedException in project PokeGOAPI-Java by Grover-c13.

the class PokemonGo method verifyChallenge.

/**
 * Verifies the current challenge with the given token.
 *
 * @param token the challenge response token
 * @return if the token was valid or not
 * @throws RequestFailedException if an exception occurred while sending requests
 */
public boolean verifyChallenge(String token) throws RequestFailedException {
    hasChallenge = false;
    VerifyChallengeMessage message = VerifyChallengeMessage.newBuilder().setToken(token).build();
    ServerRequest request = new ServerRequest(RequestType.VERIFY_CHALLENGE, message);
    ByteString responseData = requestHandler.sendServerRequests(request, true);
    try {
        VerifyChallengeResponse response = VerifyChallengeResponse.parseFrom(responseData);
        hasChallenge = !response.getSuccess();
        if (!hasChallenge) {
            challengeURL = null;
            synchronized (challengeLock) {
                challengeLock.notifyAll();
            }
        }
        return response.getSuccess();
    } catch (InvalidProtocolBufferException e) {
        throw new RequestFailedException(e);
    }
}
Also used : RequestFailedException(com.pokegoapi.exceptions.request.RequestFailedException) ByteString(com.google.protobuf.ByteString) VerifyChallengeResponse(POGOProtos.Networking.Responses.VerifyChallengeResponseOuterClass.VerifyChallengeResponse) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) VerifyChallengeMessage(POGOProtos.Networking.Requests.Messages.VerifyChallengeMessageOuterClass.VerifyChallengeMessage) ServerRequest(com.pokegoapi.main.ServerRequest)

Example 5 with RequestFailedException

use of com.pokegoapi.exceptions.request.RequestFailedException in project PokeGOAPI-Java by Grover-c13.

the class PokemonGo method checkChallenge.

/**
 * Checks for a challenge / captcha
 *
 * @return the new challenge URL, if any
 * @throws RequestFailedException if an exception occurred while sending requests
 * @deprecated CHECK_CHALLENGE is sent as a common request, should not be needed
 */
@Deprecated
public String checkChallenge() throws RequestFailedException {
    CheckChallengeMessage message = CheckChallengeMessage.newBuilder().build();
    try {
        ServerRequest request = new ServerRequest(RequestType.CHECK_CHALLENGE, message);
        ByteString responseData = requestHandler.sendServerRequests(request, false);
        CheckChallengeResponse response = CheckChallengeResponse.parseFrom(responseData);
        String newChallenge = response.getChallengeUrl();
        if (response.getShowChallenge() && newChallenge != null && newChallenge.length() > 0) {
            updateChallenge(newChallenge, true);
            return newChallenge;
        }
    } catch (InvalidProtocolBufferException e) {
        throw new RequestFailedException(e);
    }
    return null;
}
Also used : CheckChallengeMessage(POGOProtos.Networking.Requests.Messages.CheckChallengeMessageOuterClass.CheckChallengeMessage) RequestFailedException(com.pokegoapi.exceptions.request.RequestFailedException) ByteString(com.google.protobuf.ByteString) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) CheckChallengeResponse(POGOProtos.Networking.Responses.CheckChallengeResponseOuterClass.CheckChallengeResponse) ByteString(com.google.protobuf.ByteString) ServerRequest(com.pokegoapi.main.ServerRequest)

Aggregations

RequestFailedException (com.pokegoapi.exceptions.request.RequestFailedException)50 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)39 ServerRequest (com.pokegoapi.main.ServerRequest)37 ByteString (com.google.protobuf.ByteString)10 OkHttpClient (okhttp3.OkHttpClient)9 PokemonGo (com.pokegoapi.api.PokemonGo)7 PtcCredentialProvider (com.pokegoapi.auth.PtcCredentialProvider)7 HashProvider (com.pokegoapi.util.hash.HashProvider)7 ArrayList (java.util.ArrayList)6 TutorialListener (com.pokegoapi.api.listener.TutorialListener)4 Pokemon (com.pokegoapi.api.pokemon.Pokemon)4 GetPlayerMessage (POGOProtos.Networking.Requests.Messages.GetPlayerMessageOuterClass.GetPlayerMessage)3 Item (com.pokegoapi.api.inventory.Item)3 ItemBag (com.pokegoapi.api.inventory.ItemBag)3 Point (com.pokegoapi.api.map.Point)3 IOException (java.io.IOException)3 PokemonFamilyId (POGOProtos.Enums.PokemonFamilyIdOuterClass.PokemonFamilyId)2 PokemonId (POGOProtos.Enums.PokemonIdOuterClass.PokemonId)2 TutorialState (POGOProtos.Enums.TutorialStateOuterClass.TutorialState)2 LevelUpRewardsMessage (POGOProtos.Networking.Requests.Messages.LevelUpRewardsMessageOuterClass.LevelUpRewardsMessage)2