nsulistiyawan / pogobuf

pogobuf, a Pokémon Go Client Library for node.js

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

pogobuf, a Pokémon Go Client Library for node.js

npm version dependencies

Features

  • Implements all known Pokémon Go API calls (Not all of them tested though)
  • Uses ES6 Promises
  • Includes Pokémon Trainer Club login client (Google login not yet implemented)
  • Optional batch mode to group several requests in one RPC call

Acknowledgements

Usage

Installation

npm install pogobuf

Basic Usage

Generally, every method that makes an API call returns an ES6 Promise that will be resolved with the response message object (or true if there was no response message).

Before using a pogobuf.Client instance to make API calls you need to supply it with an auth token (which you can get from the pogobuf.PTCLogin class) and call init() to make an initial request.

Example usage:

const pogobuf = require('pogobuf');

var login = new pogobuf.PTCLogin(),
    client = new pogobuf.Client();

login.login('username', 'password')
.then(token => {
    client.setAuthInfo('ptc', token);
    client.setPosition(lat, lng);
    return client.init();
}).then(() => {
    // Make some API calls!
    return client.getInventory(0);
}).then(inventory => {
    // Use the returned data
});

See the API documentation below, or example.js for a more sophisticated example that does something useful.

Batch mode

The Pokémon Go API offers the ability to send multiple requests in one call. To do this you can use pogobuf's batch mode:

First call batchStart() to enable batch mode. When in batch mode, all API request methods will append the request to the current batch instead of immediately sending it to the server. Once you have all your requests, call batchCall() which submits them to the server, disables batch mode, and returns a Promise that will be resolved with an array of response messages corresponding to your requests.

When in batch mode, all API request methods (as well as batchStart()) return the Client instance so you can chain them.

Example batch usage:

client.batchStart()
    .getPlayer()
    .getHatchedEggs()
    .getInventory(0)
    .batchCall()
    .then(responses => {
        // responses is: [GetPlayerResponse, GetHatchedEggsResponse, GetInventoryResponse]
    });

API documentation

pogobuf.Client methods

setAuthInfo(authType, authToken)

Sets the authentication type and token (required before making API calls).

Param Type Description
authType string Authentication provider type (ptc or google)
authToken string Authentication token received from authentication provider

setPosition(latitude, longitude)

Sets the player's latitude and longitude. Note that this does not actually update the player location on the server, it only sets the location to be used in following API calls. To update the location on the server you probably want to call updatePlayer.

Param Type Description
latitude number The player's latitude
longitude number The player's longitude

init()Promise

Performs the initial API call.

batchStart()Client

Sets batch mode. All further API requests will be held and executed in one RPC call when batchCall is called.

batchClear()

Clears the list of batched requests and aborts batch mode.

batchCall()Promise

Executes any batched requests.

setRequestCallback(callback)

Sets a callback to be called for any envelope or request just before it is sent to the server (mostly for debugging purposes).

Param Type
callback function

setResponseCallback(callback)

Sets a callback to be called for any envelope or response just after it has been received from the server (mostly for debugging purposes).

Param Type
callback function

pogobuf.Client Pokémon Go API methods

addFortModifier(modifierItemID, fortID)Promise

attackGym(gymID, battleID, attackActions, lastRetrievedAction)Promise

catchPokemon(encounterID, pokeballItemID, normalizedReticleSize, spawnPointID, hitPokemon, spinModifier, normalizedHitPosition)Promise

checkAwardedBadges()Promise

checkCodenameAvailable(codename)Promise

claimCodename(codename)Promise

collectDailyBonus()Promise

collectDailyDefenderBonus()Promise

diskEncounter(encounterID, fortID)Promise

downloadItemTemplates()Promise

downloadRemoteConfigVersion(platform, deviceManufacturer, deviceModel, locale, appVersion)Promise

downloadSettings(hash)Promise

echo()Promise

encounter(encounterID, spawnPointID)Promise

encounterTutorialComplete(pokemonID)Promise

equipBadge(badgeType)Promise

evolvePokemon(pokemonID)Promise

fortDeployPokemon(fortID, pokemonID)Promise

fortDetails(fortID, fortLatitude, fortLongitude)Promise

fortRecallPokemon(fortID, pokemonID)Promise

fortSearch(fortID, fortLatitude, fortLongitude)Promise

getAssetDigest(platform, deviceManufacturer, deviceModel, locale, appVersion)Promise

getDownloadURLs(assetIDs)Promise

getGymDetails(gymID, gymLatitude, gymLongitude)Promise

getHatchedEggs()Promise

getIncensePokemon()Promise

getInventory(lastTimestamp)Promise

getMapObjects(cellIDs, sinceTimestamps)Promise

getPlayer()Promise

getPlayerProfile(playerName)Promise

getSuggestedCodenames()Promise

incenseEncounter(encounterID, encounterLocation)Promise

levelUpRewards(level)Promise

markTutorialComplete(tutorialsCompleted, sendMarketingEmails, sendPushNotifications)Promise

nicknamePokemon(pokemonID, nickname)Promise

playerUpdate()Promise

recycleInventoryItem(itemID, count)Promise

releasePokemon(pokemonID)Promise

setAvatar(skin, hair, shirt, pants, hat, shoes, gender, eyes, backpack)Promise

setContactSettings(sendMarketingEmails, sendPushNotifications)Promise

setFavoritePokemon(pokemonID, isFavorite)Promise

setPlayerTeam(teamColor)Promise

sfidaActionLog()Promise

startGymBattle(gymID, attackingPokemonIDs, defendingPokemonID)Promise

upgradePokemon(pokemonID)Promise

useIncense(itemID)Promise

useItemCapture(itemID, encounterID, spawnPointGUID)Promise

useItemEggIncubator(itemID, pokemonID)Promise

useItemGym(itemID, gymID)Promise

useItemPotion(itemID, pokemonID)Promise

useItemRevive(itemID, pokemonID)Promise

useItemXPBoost(itemID)Promise

pogobuf.PTCLogin methods

login(username, password)Promise

Performs the PTC login process and returns a Promise that will be resolved with the auth token.

Param Type
username string
password string

About

pogobuf, a Pokémon Go Client Library for node.js

License:MIT License


Languages

Language:JavaScript 100.0%