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);
}
}
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);
}
}
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();
}
}
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);
}
}
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;
}
Aggregations