├── LICENSE.txt ├── README.md ├── composer.json ├── examples ├── AuthenticationExample.php ├── CheckChallengeExample.php ├── GUI_BestCpPokemonDetails.php ├── ProxyExample.php ├── ReleaseOnePidgeExample.php ├── RetrieveAppliedItemsExample.php ├── RetrieveJournalExample.php ├── RetrievePlayerPokedexExample.php ├── RetrievePlayerProfileExample.php ├── RetrievePlayerStatsExample.php ├── RetrievePokemonCandyCountExample.php ├── RetrievePokemonCountExample.php ├── RetrievePokemonTraitExample.php └── VerifyChallengeExample.php ├── includes ├── config.php └── protocolbuffers.inc.php └── src ├── Api ├── Data │ ├── Data.php │ ├── Device.php │ └── Location.php ├── Map │ ├── Data │ │ ├── Resource.php │ │ ├── Resources │ │ │ ├── CatchablePokemon.php │ │ │ ├── Fort.php │ │ │ ├── NearbyPokemon.php │ │ │ ├── SpawnPoint.php │ │ │ └── WildPokemon.php │ │ └── Results │ │ │ └── PokestopSpinResult.php │ ├── Map.php │ ├── Pokestop.php │ └── Support │ │ └── S2.php ├── Player │ ├── CheckChallenge.php │ ├── Data │ │ ├── CheckChallenge │ │ │ └── CheckChallengeData.php │ │ ├── Inventory │ │ │ ├── AppliedItem.php │ │ │ ├── AppliedItems.php │ │ │ ├── CandyBank.php │ │ │ ├── CandyItem.php │ │ │ ├── EggIncubator.php │ │ │ ├── EggIncubators.php │ │ │ ├── EggPokemon.php │ │ │ ├── Item.php │ │ │ ├── Items.php │ │ │ ├── PokeBank.php │ │ │ ├── Pokedex.php │ │ │ ├── PokedexItem.php │ │ │ ├── PokemonItem.php │ │ │ └── Stats.php │ │ ├── Journal │ │ │ ├── Fort.php │ │ │ ├── Item.php │ │ │ ├── Log.php │ │ │ └── Pokemon.php │ │ └── Profile │ │ │ ├── Avatar.php │ │ │ ├── Badge.php │ │ │ ├── ContactSettings.php │ │ │ ├── Currencies.php │ │ │ ├── Currency.php │ │ │ ├── DailyBonus.php │ │ │ ├── ProfileData.php │ │ │ └── TutorialState.php │ ├── Inventory.php │ ├── Journal.php │ └── Profile.php ├── Pokemon │ ├── Collection │ │ └── PokemonCollection.php │ ├── Data │ │ ├── MovementType.php │ │ ├── PokemonClass.php │ │ ├── PokemonMeta.php │ │ ├── PokemonMetaRegistry.php │ │ └── PokemonMove.php │ ├── Pokemon.php │ └── Support │ │ ├── BasePokemonRetriever.php │ │ ├── CombatPointsCalculator.php │ │ └── PokemonDetailsTrait.php ├── PokemonGoApi.php ├── Procedure.php └── Support │ ├── Enums │ ├── AbstractEnum.php │ ├── GenericEnum.php │ ├── ItemId.php │ ├── PokemonFamilyId.php │ ├── PokemonId.php │ ├── PokemonMove.php │ └── PokemonType.php │ └── Traits │ ├── MakeApiResourcesAvailable.php │ └── MakeDataPropertiesCallable.php ├── Authentication ├── AccessToken.php ├── Config │ └── Config.php ├── Contracts │ └── Authenticator.php ├── Exceptions │ ├── AuthenticationException.php │ ├── IllegalAuthenticationTypeException.php │ └── ResponseException.php ├── Factory │ └── Factory.php ├── Manager.php └── Managers │ ├── Google │ ├── AuthenticationCode │ │ ├── Authenticator.php │ │ ├── Clients │ │ │ └── AuthenticationClient.php │ │ └── Parsers │ │ │ ├── OauthTokenParser.php │ │ │ ├── Parser.php │ │ │ └── Results │ │ │ ├── AuthenticationTokenResult.php │ │ │ └── Result.php │ ├── AuthenticationCodeManager.php │ ├── AuthenticationCredentials │ │ ├── Authenticator.php │ │ ├── Clients │ │ │ └── AuthenticationClient.php │ │ ├── Parsers │ │ │ ├── OauthTokenParser.php │ │ │ ├── Parser.php │ │ │ ├── Results │ │ │ │ ├── AuthenticationTokenResult.php │ │ │ │ └── Result.php │ │ │ └── TokenParser.php │ │ └── Support │ │ │ └── Signature.php │ ├── AuthenticationCredentialsManager.php │ ├── AuthenticationOauthTokenManager.php │ ├── AuthenticationRefreshToken │ │ ├── Authenticator.php │ │ ├── Clients │ │ │ └── AuthenticationClient.php │ │ └── Parsers │ │ │ ├── OauthTokenParser.php │ │ │ ├── Parser.php │ │ │ └── Results │ │ │ ├── AuthenticationTokenResult.php │ │ │ └── Result.php │ └── AuthenticationRefreshTokenManager.php │ └── PTC │ ├── AuthenticationCredentials │ ├── Authenticator.php │ ├── Clients │ │ └── AuthenticationClient.php │ └── Parsers │ │ ├── AuthenticationInformationParser.php │ │ ├── Parser.php │ │ ├── Results │ │ ├── AuthenticationInformationResult.php │ │ ├── Result.php │ │ ├── TicketResult.php │ │ └── TokenResult.php │ │ ├── TicketParser.php │ │ └── TokenParser.php │ ├── AuthenticationCredentialsManager.php │ └── AuthenticationOauthTokenManager.php ├── Clients └── Proxies │ └── ClientProxy.php ├── Facades ├── App.php └── Log.php ├── Handlers ├── RequestHandler.php ├── RequestHandler │ └── Exceptions │ │ ├── AuthenticationException.php │ │ └── ResponseException.php └── Session.php ├── Kernels ├── ApplicationKernel.php └── Kernel.php ├── Providers ├── PokemonGoApiServiceProvider.php ├── RequestHandlerServiceProvider.php └── ServiceProvider.php ├── Requests ├── AuthenticateRequest.php ├── CheckChallengeRequest.php ├── Envelops │ ├── AuthInfoEnvelope.php │ └── Factory.php ├── EvolvePokemonRequest.php ├── FortSearchRequest.php ├── GetInventoryRequest.php ├── GetJournalRequest.php ├── GetMapResourcesRequest.php ├── GetPlayerRequest.php ├── RecycleInventoryItemRequest.php ├── RenamePokemonRequest.php ├── Request.php ├── SetFavoritePokemonRequest.php ├── TransferPokemonRequest.php ├── UpgradePokemonRequest.php ├── UseIncenseRequest.php ├── UseItemXpBoostRequest.php └── VerifyChallengeRequest.php └── Services ├── Request ├── CheckChallengeRequestService.php ├── InventoryRequestService.php ├── JournalRequestService.php ├── MapRequestService.php ├── PlayerRequestService.php ├── PokemonRequestService.php └── PokestopRequestService.php └── RequestService.php /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2016, Nicklas Wallgren 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 2. Redistributions in binary form must reproduce the above copyright notice, 10 | this list of conditions and the following disclaimer in the documentation 11 | and/or other materials provided with the distribution. 12 | 13 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 14 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 15 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 16 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 17 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 18 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 19 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 20 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 21 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 22 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # PokemonGoAPI-PHP 2 | 3 | [![Total Downloads][ico-downloads]][link-packagist] 4 | [![PHP7 Ready](https://img.shields.io/badge/PHP7-ready-green.svg)][link-packagist] 5 | 6 | Pokemon GO PHP API library 7 | 8 | # Install 9 | Run the command `composer require nicklasw/pkm-go-api`. 10 | 11 | # Usage 12 | EG: 13 | ```php 14 | // Create the authentication config 15 | $config = new Config(); 16 | $config->setProvider(Factory::PROVIDER_PTC); 17 | $config->setUser('INSERT_USER'); 18 | $config->setPassword('INSERT_PASSWORD'); 19 | 20 | // Create the authentication manager 21 | $manager = Factory::create($config); 22 | 23 | // Add a event listener, 24 | $manager->addListener(function ($event, $value) { 25 | if ($event === Manager::EVENT_ACCESS_TOKEN) { 26 | /** @var AccessToken $accessToken */ 27 | $accessToken = $value; 28 | 29 | // Persist the access token in session storage, cache or whatever. 30 | } 31 | }); 32 | 33 | // Initialize the pokemon go application 34 | $application = new ApplicationKernel($manager); 35 | 36 | // Retrieve the pokemon go api instance 37 | $pokemonGoApi = $application->getPokemonGoApi(); 38 | 39 | // Retrieve the inventory 40 | $inventory = $pokemonGoApi->getInventory(); 41 | 42 | // Retrieve the poke bank 43 | $pokeBank = $inventory->getPokeBank(); 44 | 45 | // Retrieve a pokemon of type pidgey 46 | $pokemon = $pokeBank->getPokemonsByType(PokemonId::PIDGEY)->first(); 47 | 48 | // Transfer / Release the pokemon (Send to the meat grinder) 49 | $pokemon->transfer(); 50 | ``` 51 | 52 | ## TODO 53 | - Implement the Map API 54 | - Improve logging 55 | 56 | ## Contributors 57 | - [Nicklas Wallgren](https://github.com/NicklasWallgren) 58 | - [Ni42](https://github.com/Ni42) 59 | - [All Contributors][link-contributors] 60 | 61 | ## Testing 62 | 63 | ``` bash 64 | $ composer test 65 | ``` 66 | 67 | ## Slack Chat 68 | 69 | We use [Slack](https://slack.com) for community discussions. You can find our team here: https://pokemongoapi-php.slack.com 70 | 71 | ## Credits 72 | - [Grover-c13](https://github.com/Grover-c13) for the inspiration 73 | - [AeonLucid](https://github.com/AeonLucid/POGOProtos) for improved protos 74 | 75 | [ico-downloads]: https://img.shields.io/packagist/dt/nicklasw/pkm-go-api.svg?style=flat-square 76 | 77 | [link-packagist]: https://packagist.org/packages/nicklasw/pkm-go-api 78 | [link-contributors]: ../../contributors 79 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "nicklasw/pkm-go-api", 3 | "description": "The Pokemon Go API library.", 4 | "keywords": ["Pokemon Go API"], 5 | "license": "MIT", 6 | "type": "project", 7 | "require": { 8 | "php": ">=5.6", 9 | "paquettg/php-html-parser": "1.7", 10 | "guzzlehttp/guzzle": "^6.2.1", 11 | "jeremeamia/xstatic": "^1.0", 12 | "php-di/php-di": "^5.3", 13 | "phpseclib/phpseclib": "^2.0", 14 | "nicklasw/s2-geometry-library-php": "^v2.0", 15 | "nicklasw/pogoprotos-php": "^v2.0", 16 | "psr/log": "^1.0", 17 | "illuminate/support": "^5.2" 18 | }, 19 | "require-dev": { 20 | "phpunit/phpunit": "~4.0||~5.0" 21 | }, 22 | "autoload": { 23 | "psr-4": { 24 | "NicklasW\\PkmGoApi\\": "src/" 25 | }, 26 | "files": [ 27 | "includes/config.php" 28 | ] 29 | }, 30 | "autoload-dev": { 31 | "psr-4": { 32 | "NicklasW\\PkmGoApi\\Test\\": "tests/" 33 | } 34 | }, 35 | "scripts": { 36 | "test": "phpunit" 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /examples/AuthenticationExample.php: -------------------------------------------------------------------------------- 1 | setProvider(Factory::PROVIDER_GOOGLE); 23 | $config->setUser('INSERT_EMAIL'); 24 | $config->setPassword('INSERT_PASSWORD'); 25 | 26 | // Create the authentication manager 27 | $manager = Factory::create($config); 28 | 29 | // EXAMPLE Authentication via PTC user credentials 30 | $config = new Config(); 31 | $config->setProvider(Factory::PROVIDER_PTC); 32 | $config->setUser('INSERT_USER'); 33 | $config->setPassword('INSERT_PASSWORD'); 34 | 35 | // Create the authentication manager 36 | $manager = Factory::create($config); 37 | 38 | // EXAMPLE Authentication via Google authentication code 39 | $config = new Config(); 40 | $config->setProvider(Factory::PROVIDER_GOOGLE); 41 | $config->setAuthToken('INSERT_AUTHENTICATION_CODE'); 42 | 43 | // EXAMPLE Authentication via Google refresh token 44 | $config = new Config(); 45 | $config->setProvider(Factory::PROVIDER_GOOGLE); 46 | $config->setRefreshToken('INSERT_AUTHENTICATION_REFRESH_TOKEN'); 47 | 48 | // Add a event listener, 49 | $manager->addListener(function ($event, $value) { 50 | 51 | if ($event === Manager::EVENT_ACCESS_TOKEN) { 52 | /** @var AccessToken $accessToken */ 53 | $accessToken = $value; 54 | 55 | // Persist the access token in session storage, cache or whatever. 56 | // The persisted access token should be passed to the Authentication factory for authentication 57 | } 58 | 59 | }); 60 | 61 | // Initialize the pokemon go application 62 | $application = new ApplicationKernel($manager); 63 | } 64 | 65 | } 66 | 67 | echo "This is not a runnable example script."; 68 | -------------------------------------------------------------------------------- /examples/ProxyExample.php: -------------------------------------------------------------------------------- 1 | setProvider(Factory::PROVIDER_PTC); 21 | $config->setUser('INSERT_USER'); 22 | $config->setPassword('INSERT_PASSWORD'); 23 | 24 | // Create the authentication manager 25 | $manager = Factory::create($config); 26 | 27 | // Initialize the pokemon go application 28 | $application = new ApplicationKernel($manager); 29 | 30 | // Pass a custom client to the library 31 | $application->setClient(new Client(array(RequestOptions::PROXY => 'INSERT_PROXY'))); 32 | 33 | // Retrieve the pokemon go api instance 34 | $pokemonGoApi = $application->getPokemonGoApi(); 35 | 36 | // Retrieve the profile 37 | $profile = $pokemonGoApi->getProfile(); 38 | 39 | // Retrieve the profile data 40 | $profileData = $profile->getData(); 41 | 42 | echo sprintf('The profile data: %s', print_r($profileData, true)); 43 | } 44 | 45 | } 46 | 47 | $example = new RetrievePlayerProfileExample(); 48 | $example->run(); -------------------------------------------------------------------------------- /examples/ReleaseOnePidgeExample.php: -------------------------------------------------------------------------------- 1 | setProvider(Factory::PROVIDER_PTC); 20 | $config->setUser('INSERT_USER'); 21 | $config->setPassword('INSERT_PASSWORD'); 22 | 23 | // Create the authentication manager 24 | $manager = Factory::create($config); 25 | 26 | // Initialize the pokemon go application 27 | $application = new ApplicationKernel($manager); 28 | 29 | // Retrieve the pokemon go api instance 30 | $pokemonGoApi = $application->getPokemonGoApi(); 31 | 32 | // Retrieve the inventory 33 | $inventory = $pokemonGoApi->getInventory(); 34 | 35 | // Retrieve the poke bank 36 | $pokeBank = $inventory->getPokeBank(); 37 | 38 | // Retrieve a pokemon of type pidgey 39 | $pokemon = $pokeBank->getPokemonsByType(PokemonId::PIDGEY)->first(); 40 | 41 | // Check if we retrieved a pokemon 42 | if (!$pokemon) { 43 | throw new Exception('No pokemon of type pidgey found. Please check your inventory'); 44 | } 45 | 46 | // Transfer / Release the pokemon 47 | $pokemon->transfer(); 48 | } 49 | 50 | } 51 | 52 | $example = new ReleaseOnePidgeExample(); 53 | $example->run(); -------------------------------------------------------------------------------- /examples/RetrieveAppliedItemsExample.php: -------------------------------------------------------------------------------- 1 | setProvider(Factory::PROVIDER_PTC); 21 | $config->setUser('INSERT_USER'); 22 | $config->setPassword('INSERT_PASSWORD'); 23 | 24 | // Create the authentication manager 25 | $manager = Factory::create($config); 26 | 27 | // Initialize the pokemon go application 28 | $application = new ApplicationKernel($manager); 29 | 30 | // Retrieve the pokemon go api instance 31 | $pokemonGoApi = $application->getPokemonGoApi(); 32 | 33 | // Retrieve the inventory 34 | $inventory = $pokemonGoApi->getInventory(); 35 | 36 | // Retrieve the applied items instance 37 | $appliedItems = $inventory->getAppliedItems(); 38 | 39 | // Retrieve the items within the applied items instance 40 | $items = $appliedItems->getAppliedItems(); 41 | 42 | foreach($items as $item) 43 | { 44 | // Retrieve item name 45 | $item->setName(ItemId::name($item->getItemId())); 46 | 47 | echo sprintf('Applied item: %s', print_r($item, true)); 48 | } 49 | } 50 | } 51 | 52 | $example = new RetrieveAppliedItemsExample(); 53 | $example->run(); 54 | -------------------------------------------------------------------------------- /examples/RetrieveJournalExample.php: -------------------------------------------------------------------------------- 1 | setProvider(Factory::PROVIDER_PTC); 21 | $config->setUser('INSERT_USER'); 22 | $config->setPassword('INSERT_PASSWORD'); 23 | 24 | // Create the authentication manager 25 | $manager = Factory::create($config); 26 | 27 | // Initialize the pokemon go application 28 | $application = new ApplicationKernel($manager); 29 | 30 | // Retrieve the pokemon go api instance 31 | $pokemonGoApi = $application->getPokemonGoApi(); 32 | 33 | // Retrieve the journal data 34 | $journal = $pokemonGoApi->getJournal(); 35 | 36 | // Loop across all Pokemon encounters 37 | foreach($journal->getPokemons() as $pkmn) { 38 | echo sprintf("[%s] [Pokemon] #%s %s, Result: %s, %s CP\n", 39 | (new DateTime('@'.floor($pkmn->getTimestampMs()/1000)))->format('d.m.Y H:i'), 40 | $pkmn->getPokemonId(), PokemonId::name($pkmn->getPokemonId()), $pkmn->getResult() == 2 ? 'flee' : 'captured', 41 | $pkmn->getCombatPoints()); 42 | } 43 | 44 | // Loop across all Pokestop interactions 45 | foreach($journal->getForts() as $fort) { 46 | echo sprintf("[%s] [Fort] Eggs: %s, Items: %s\n", 47 | (new DateTime('@'.floor($fort->getTimestampMs()/1000)))->format('d.m.Y H:i'), 48 | $fort->getEggs(), 49 | array_reduce( 50 | $fort->getItems(), 51 | function($val, $e) { 52 | if($val) $val.=', '; 53 | return $val.$e->getCount().'x '.ItemId::name($e->getItemId()); 54 | } 55 | ) 56 | ); 57 | } 58 | } 59 | 60 | } 61 | 62 | $example = new RetrieveJournalExample(); 63 | $example->run(); -------------------------------------------------------------------------------- /examples/RetrievePlayerPokedexExample.php: -------------------------------------------------------------------------------- 1 | setProvider(Factory::PROVIDER_PTC); 20 | $config->setUser('INSERT_USER'); 21 | $config->setPassword('INSERT_PASSWORD'); 22 | 23 | // Create the authentication manager 24 | $manager = Factory::create($config); 25 | 26 | // Initialize the pokemon go application 27 | $application = new ApplicationKernel($manager); 28 | 29 | // Retrieve the pokemon go api instance 30 | $pokemonGoApi = $application->getPokemonGoApi(); 31 | 32 | // Retrieve the inventory 33 | $inventory = $pokemonGoApi->getInventory(); 34 | 35 | // Retrieve the pokedex 36 | $pokedex = $inventory->getPokedex(); 37 | 38 | // Show info about pokemons 39 | for($i=1; $i<= 151; $i++) 40 | { 41 | // Retrieve MetaRegistry for pokemon 42 | $pokemonmeta = PokemonMetaRegistry::getByPokemonId($i); 43 | 44 | // Retrieve Pokedex entry for pokemon 45 | $pokemondata = $pokedex->get($i); 46 | 47 | // If pokedex is empty we don't 'know' that creature 48 | if($pokemondata !== null) 49 | { 50 | echo sprintf("Informations about Pokemon %d. Name: %s \n", $i, $pokemonmeta->getuniqueId()); 51 | } 52 | else 53 | echo sprintf("No information about id: %d \n", $i); 54 | } 55 | } 56 | } 57 | 58 | $example = new RetrievePlayerPokedexExample(); 59 | $example->run(); 60 | -------------------------------------------------------------------------------- /examples/RetrievePlayerProfileExample.php: -------------------------------------------------------------------------------- 1 | setProvider(Factory::PROVIDER_PTC); 19 | $config->setUser('INSERT_USER'); 20 | $config->setPassword('INSERT_PASSWORD'); 21 | 22 | // Create the authentication manager 23 | $manager = Factory::create($config); 24 | 25 | // Initialize the pokemon go application 26 | $application = new ApplicationKernel($manager); 27 | 28 | // Retrieve the pokemon go api instance 29 | $pokemonGoApi = $application->getPokemonGoApi(); 30 | 31 | // Retrieve the profile 32 | $profile = $pokemonGoApi->getProfile(); 33 | 34 | // Retrieve the profile data 35 | $profileData = $profile->getData(); 36 | 37 | echo sprintf('The profile data: %s', print_r($profileData, true)); 38 | } 39 | 40 | } 41 | 42 | $example = new RetrievePlayerProfileExample(); 43 | $example->run(); -------------------------------------------------------------------------------- /examples/RetrievePlayerStatsExample.php: -------------------------------------------------------------------------------- 1 | setProvider(Factory::PROVIDER_PTC); 19 | $config->setUser('INSERT_USER'); 20 | $config->setPassword('INSERT_PASSWORD'); 21 | 22 | // Create the authentication manager 23 | $manager = Factory::create($config); 24 | 25 | // Initialize the pokemon go application 26 | $application = new ApplicationKernel($manager); 27 | 28 | // Retrieve the pokemon go api instance 29 | $pokemonGoApi = $application->getPokemonGoApi(); 30 | 31 | // Retrieve the inventory 32 | $inventory = $pokemonGoApi->getInventory(); 33 | 34 | // Retrieve the player stats 35 | $playerStats = $inventory->getStats(); 36 | 37 | echo sprintf('The player level: %s', $playerStats->getLevel()); 38 | } 39 | 40 | } 41 | 42 | $example = new RetrievePlayerStatsExample(); 43 | $example->run(); -------------------------------------------------------------------------------- /examples/RetrievePokemonCandyCountExample.php: -------------------------------------------------------------------------------- 1 | setProvider(Factory::PROVIDER_PTC); 20 | $config->setUser('INSERT_USER'); 21 | $config->setPassword('INSERT_PASSWORD'); 22 | 23 | // Create the authentication manager 24 | $manager = Factory::create($config); 25 | 26 | // Initialize the pokemon go application 27 | $application = new ApplicationKernel($manager); 28 | 29 | // Retrieve the pokemon go api instance 30 | $pokemonGoApi = $application->getPokemonGoApi(); 31 | 32 | // Retrieve the inventory 33 | $inventory = $pokemonGoApi->getInventory(); 34 | 35 | // Retrieve the candy bank 36 | $candyBank = $inventory->getCandyBank(); 37 | 38 | // Retrieve the pidgey candy item 39 | $candyItem = $candyBank->get(PokemonFamilyId::FAMILY_PIDGEY); 40 | 41 | echo sprintf('Number or pidgey candies \'%s\'', $candyItem->getCount()); 42 | } 43 | 44 | } 45 | 46 | $example = new RetrievePokemonCandyCountExample(); 47 | $example->run(); -------------------------------------------------------------------------------- /examples/RetrievePokemonCountExample.php: -------------------------------------------------------------------------------- 1 | setProvider(Factory::PROVIDER_PTC); 20 | $config->setUser('INSERT_USER'); 21 | $config->setPassword('INSERT_PASSWORD'); 22 | 23 | // Create the authentication manager 24 | $manager = Factory::create($config); 25 | 26 | // Initialize the pokemon go application 27 | $application = new ApplicationKernel($manager); 28 | 29 | // Retrieve the pokemon go api instance 30 | $pokemonGoApi = $application->getPokemonGoApi(); 31 | 32 | // Retrieve the inventory 33 | $inventory = $pokemonGoApi->getInventory(); 34 | 35 | // Retrieve the poke bank 36 | $pokeBank = $inventory->getPokeBank(); 37 | 38 | // Retrieve a pokemons of type pidgey 39 | $pokemons = $pokeBank->getPokemonsByType(PokemonId::PIDGEY); 40 | 41 | echo sprintf('Number of pokemon of type pidgey: \'%s\'', sizeof($pokemons)); 42 | } 43 | 44 | } 45 | 46 | $example = new RetrievePokemonCountExample(); 47 | $example->run(); -------------------------------------------------------------------------------- /examples/RetrievePokemonTraitExample.php: -------------------------------------------------------------------------------- 1 | setProvider(Factory::PROVIDER_PTC); 20 | $config->setUser('INSERT_USER'); 21 | $config->setPassword('INSERT_PASSWORD'); 22 | 23 | // Create the authentication manager 24 | $manager = Factory::create($config); 25 | 26 | // Initialize the pokemon go application 27 | $application = new ApplicationKernel($manager); 28 | 29 | // Retrieve the pokemon go api instance 30 | $pokemonGoApi = $application->getPokemonGoApi(); 31 | 32 | // Retrieve the inventory 33 | $inventory = $pokemonGoApi->getInventory(); 34 | 35 | // Retrieve the poke bank 36 | $pokeBank = $inventory->getPokeBank(); 37 | 38 | // Retrieve a pokemon of type pidgey 39 | $pokemon = $pokeBank->getPokemons()->first(); 40 | 41 | // Check if we retrieved a pokemon 42 | if (!$pokemon) { 43 | throw new Exception('Cannot find any pokemons in your PokeBank.'); 44 | } 45 | 46 | echo sprintf("Pokemon %s, Id: %s, Cp: %d, type: %s, attacks: %s and %s, ", $pokemon->getName(), $pokemon->getId(), $pokemon->getCp(), $pokemon->getType1String(), $pokemon->getMove1String(), $pokemon->getMove2String()); 47 | 48 | } 49 | 50 | } 51 | 52 | $example = new RetrievePokemonTraitExample(); 53 | $example->run(); -------------------------------------------------------------------------------- /includes/config.php: -------------------------------------------------------------------------------- 1 | 1 && Str::startsWith($value, '"') && Str::endsWith($value, '"')) { 40 | return substr($value, 1, -1); 41 | } 42 | 43 | return $value; 44 | } 45 | } -------------------------------------------------------------------------------- /src/Api/Data/Data.php: -------------------------------------------------------------------------------- 1 | getName()); 34 | 35 | // Check if the same property exists within the data class 36 | if (!array_key_exists($propertyName, $properties)) { 37 | continue; 38 | } 39 | 40 | // Sets the property value 41 | $instance->{'set' . $propertyName}($data->{'get' . $propertyName}()); 42 | } 43 | 44 | return $instance; 45 | } 46 | 47 | /** 48 | * @param $name 49 | * @param $arguments 50 | */ 51 | public function __call($name, $arguments) 52 | { 53 | if ($this->isSetMethod($name)) { 54 | $attribute = $this->getAttribute($name); 55 | 56 | $this->{$attribute} = current($arguments); 57 | 58 | } elseif ($this->isGetMethod($name)) { 59 | $attribute = $this->getAttribute($name); 60 | 61 | return $this->{$attribute}; 62 | } 63 | } 64 | 65 | /** 66 | * Returns the class properties of a class. 67 | * 68 | * @param mixed $instance 69 | * @return array 70 | */ 71 | protected static function getClassProperties($instance) 72 | { 73 | $reflection = new ReflectionClass($instance); 74 | 75 | return $reflection->getProperties(); 76 | } 77 | 78 | /** 79 | * Returns the class properties of a class. 80 | * 81 | * @param mixed $instance 82 | * @return array 83 | */ 84 | protected static function getClassDefaultProperties($instance) 85 | { 86 | $reflection = new ReflectionClass($instance); 87 | 88 | return $reflection->getDefaultProperties(); 89 | } 90 | 91 | /** 92 | * Returns the corresponding attribute. 93 | * 94 | * @param $method 95 | * @return string 96 | */ 97 | protected function getAttribute($method) 98 | { 99 | return lcfirst(substr($method, 3)); 100 | } 101 | 102 | /** 103 | * Returns true if the method corresponds to a setter method, false otherwise. 104 | * 105 | * @param string $method 106 | * @return boolean 107 | */ 108 | protected function isSetMethod($method) 109 | { 110 | return strpos($method, 'set') !== FALSE; 111 | } 112 | 113 | /** 114 | * Returns true if the method corresponds to a getter method, false otherwise. 115 | * 116 | * @param string $method 117 | * @return boolean 118 | */ 119 | protected function isGetMethod($method) 120 | { 121 | return strpos($method, 'get') !== FALSE; 122 | } 123 | 124 | 125 | } -------------------------------------------------------------------------------- /src/Api/Data/Device.php: -------------------------------------------------------------------------------- 1 | latitude = $latitude; 33 | $this->longitude = $longitude; 34 | } 35 | 36 | } -------------------------------------------------------------------------------- /src/Api/Map/Data/Resources/CatchablePokemon.php: -------------------------------------------------------------------------------- 1 | result; 51 | } 52 | 53 | /** 54 | * @return array 55 | */ 56 | public function getItemsAwarded() 57 | { 58 | return $this->itemsAwarded; 59 | } 60 | 61 | /** 62 | * @return int 63 | */ 64 | public function getGemsAwarded() 65 | { 66 | return $this->gemsAwarded; 67 | } 68 | 69 | /** 70 | * @return null 71 | */ 72 | public function getPokemonDataEgg() 73 | { 74 | return $this->pokemonDataEgg; 75 | } 76 | 77 | /** 78 | * @return int 79 | */ 80 | public function getExperienceAwarded() 81 | { 82 | return $this->experienceAwarded; 83 | } 84 | 85 | /** 86 | * @return int 87 | */ 88 | public function getCooldownCompleteTimestampMs() 89 | { 90 | return $this->cooldownCompleteTimestampMs; 91 | } 92 | 93 | /** 94 | * @return int 95 | */ 96 | public function getChainHackSequenceNumber() 97 | { 98 | return $this->chainHackSequenceNumber; 99 | } 100 | 101 | } -------------------------------------------------------------------------------- /src/Api/Map/Map.php: -------------------------------------------------------------------------------- 1 | data = new Resource(); 21 | } 22 | 23 | /** 24 | * Returns the pokestops. 25 | * 26 | * @return Fort[] 27 | */ 28 | public function getPokestops() 29 | { 30 | return $this->data->getPokestops(); 31 | } 32 | 33 | /** 34 | * Returns gyms. 35 | * 36 | * @return Fort[] 37 | */ 38 | public function getGyms() 39 | { 40 | return $this->data->getGyms(); 41 | } 42 | 43 | /** 44 | * Returns the catchable pokemon located on the map. 45 | */ 46 | public function getCatchablePokemon() 47 | { 48 | 49 | 50 | } 51 | 52 | /** 53 | * Returns the map resources. 54 | * 55 | * @throws Exception 56 | */ 57 | public function update() 58 | { 59 | // Retrieve the map resources 60 | $resources = $this->getMapResources(); 61 | 62 | // Create the resource data instance 63 | $this->data = Resource::create($resources); 64 | } 65 | 66 | /** 67 | * Returns the map resources. 68 | * 69 | * @return GetMapObjectsResponse 70 | */ 71 | protected function getMapResources() 72 | { 73 | // Retrieved the latitude 74 | $latitude = $this->getApplication()->getLatitude(); 75 | 76 | // Retrieved the longitude 77 | $longitude = $this->getApplication()->getLongitude(); 78 | 79 | // Retrieve a list of cell ids from the latitude and longitude 80 | $cellIds = S2::getCellIds($latitude, $longitude); 81 | 82 | // Retrieve the map resources 83 | return $this->getRequestService()->getResources($latitude, $longitude, $cellIds); 84 | } 85 | 86 | /** 87 | * Returns the request service. 88 | * 89 | * @return MapRequestService 90 | */ 91 | protected function getRequestService() 92 | { 93 | return new MapRequestService(); 94 | } 95 | 96 | } -------------------------------------------------------------------------------- /src/Api/Map/Support/S2.php: -------------------------------------------------------------------------------- 1 | parent(15); 25 | 26 | // Calculate the size 27 | $size = 1 * (2 ** (S2CellId::MAX_LEVEL - $cellId->level())); 28 | 29 | $index = 0; 30 | $jindex = 0; 31 | 32 | $face = $cellId->toFaceIJOrientation($index, $jindex); 33 | 34 | $cells = array(); 35 | 36 | $halfWidth = (int)floor($width / 2); 37 | 38 | for ($x = -$halfWidth; $x <= $halfWidth; $x++) { 39 | for ($y = -$halfWidth; $y <= $halfWidth; $y++) { 40 | $s2CellID = S2CellId::fromFaceIJ($face, $index + $x * $size, $jindex + $y * $size); 41 | 42 | $cells[] = $s2CellID->parent(15)->id(); 43 | } 44 | } 45 | 46 | return $cells; 47 | } 48 | 49 | } -------------------------------------------------------------------------------- /src/Api/Player/CheckChallenge.php: -------------------------------------------------------------------------------- 1 | getRequestService()->checkChallenge(); 31 | 32 | // Set the checkChallenge data 33 | $this->data = CheckChallengeData::create($data); 34 | } 35 | 36 | /** 37 | * Returns the request service. 38 | * 39 | * @return CheckChallengeRequestService 40 | */ 41 | protected function getRequestService() 42 | { 43 | return new CheckChallengeRequestService(); 44 | } 45 | } 46 | 47 | -------------------------------------------------------------------------------- /src/Api/Player/Data/CheckChallenge/CheckChallengeData.php: -------------------------------------------------------------------------------- 1 | showChallenge = $data->getShowChallenge(); 38 | 39 | // Set the challengeUrl 40 | $instance->challengeUrl = $data->getChallengeUrl(); 41 | 42 | return $instance; 43 | } 44 | } 45 | 46 | -------------------------------------------------------------------------------- /src/Api/Player/Data/Inventory/AppliedItem.php: -------------------------------------------------------------------------------- 1 | appliedItems[] = AppliedItem::create($appliedItem); 30 | } 31 | 32 | /** 33 | * Creates a data instance from a Protobuf Message. 34 | * 35 | * @param AppliedItemsData $data 36 | * @return static 37 | */ 38 | public static function create($data) 39 | { 40 | // Create a instance 41 | $instance = new static(); 42 | 43 | // Retrieve the items 44 | $items = $data->getItem(); 45 | 46 | // Iterate through the list of items 47 | foreach ($items as $item) { 48 | // Add a applied item to the list of applied items 49 | $instance->add($item); 50 | } 51 | 52 | return $instance; 53 | } 54 | 55 | } -------------------------------------------------------------------------------- /src/Api/Player/Data/Inventory/CandyBank.php: -------------------------------------------------------------------------------- 1 | getFamilyId(), $this->candies)) { 33 | // Retrieve the candy item 34 | $storedCandyItem = $this->candies[$candyItem->getFamilyId()]; 35 | 36 | // Update the number of candy item 37 | $storedCandyItem->setCandy($storedCandyItem->getCandy() + $candyItem->getCandy()); 38 | } else { 39 | $this->candies[$candyItem->getFamilyId()] = $candyItem; 40 | } 41 | } 42 | 43 | /** 44 | * Gets candy item by pokemon family id. 45 | * 46 | * @param integer $familyId 47 | * @return CandyItem 48 | * @throws Exception 49 | */ 50 | public function get($familyId) 51 | { 52 | // Check if the provided family id is valid 53 | if (!PokemonFamilyId::isValid($familyId)) { 54 | throw new Exception(sprintf('Invalid pokemon family id provided. Pokemon family id \'%s\'', $familyId)); 55 | } 56 | 57 | // Check if the candy bank contains the pokemon family id 58 | if (!array_key_exists($familyId, $this->candies)) { 59 | throw new Exception(sprintf('The candy bank does not contain candy for the pokemon family. Pokemon family id \'%s\'', $familyId)); 60 | } 61 | 62 | return $this->candies[$familyId]; 63 | } 64 | 65 | } -------------------------------------------------------------------------------- /src/Api/Player/Data/Inventory/CandyItem.php: -------------------------------------------------------------------------------- 1 | candy; 34 | } 35 | 36 | } -------------------------------------------------------------------------------- /src/Api/Player/Data/Inventory/EggIncubator.php: -------------------------------------------------------------------------------- 1 | eggIncubators[] = EggIncubator::create($eggIncubator); 29 | } 30 | 31 | /** 32 | * Creates a data instance from a Protobuf Message. 33 | * 34 | * @param EggIncubatorsData $data 35 | * @return static 36 | */ 37 | public static function create($data) 38 | { 39 | // Create a instance 40 | $instance = new static(); 41 | 42 | // Iterate through the list of egg incubators 43 | foreach ($data->getEggIncubator() as $eggIncubator) { 44 | // Add a egg incubator to the list of egg incubators 45 | $instance->add($eggIncubator); 46 | } 47 | 48 | return $instance; 49 | } 50 | 51 | 52 | } -------------------------------------------------------------------------------- /src/Api/Player/Data/Inventory/EggPokemon.php: -------------------------------------------------------------------------------- 1 | items[$item->getPokemonId()] = $item; 33 | } 34 | 35 | /** 36 | * Gets the pokedex item by pokemon id 37 | * 38 | * @param integer $pokemonId 39 | * @return PokedexItem|null 40 | */ 41 | public function get($pokemonId) 42 | { 43 | // Check whether a valid pokemon id was provided 44 | if (!PokemonId::isValid($pokemonId)) { 45 | return null; 46 | } 47 | 48 | // Check if the pokemon exists within the pokedex 49 | if (array_key_exists($pokemonId, $this->items)) { 50 | return $this->items[$pokemonId]; 51 | } 52 | 53 | return $this->createEmptyItem($pokemonId); 54 | } 55 | 56 | /** 57 | * Creates a empty PokedexItem. 58 | * 59 | * @param integer $pokemonId 60 | * @return PokedexItem 61 | */ 62 | protected function createEmptyItem($pokemonId) 63 | { 64 | // Create a new pokedex item 65 | $entry = new PokedexItem(); 66 | 67 | // Set the pokemon id 68 | $entry->setPokemonId($pokemonId); 69 | 70 | return $entry; 71 | } 72 | 73 | } -------------------------------------------------------------------------------- /src/Api/Player/Data/Inventory/PokedexItem.php: -------------------------------------------------------------------------------- 1 | result = $data->getResult(); 52 | 53 | // Set the fort id 54 | $instance->fortId = $data->getFortId(); 55 | 56 | // Set the egg count 57 | $instance->eggs = $data->getEggs(); 58 | 59 | foreach ($data->getItems() as $item) { 60 | // Add the item to the list of items 61 | $instance->items[] = Item::create($item); 62 | } 63 | 64 | return $instance; 65 | } 66 | 67 | } -------------------------------------------------------------------------------- /src/Api/Player/Data/Journal/Item.php: -------------------------------------------------------------------------------- 1 | itemId; 32 | } 33 | 34 | /** 35 | * Returns the count. 36 | * 37 | * @return int 38 | */ 39 | public function getCount() 40 | { 41 | return $this->count; 42 | } 43 | 44 | /** 45 | * Return true if unseen, false otherwise. 46 | * 47 | * @return boolean 48 | */ 49 | public function isUnseen() 50 | { 51 | return $this->unseen; 52 | } 53 | 54 | 55 | } -------------------------------------------------------------------------------- /src/Api/Player/Data/Journal/Log.php: -------------------------------------------------------------------------------- 1 | forts; 27 | } 28 | 29 | /** 30 | * @return Pokemon[] 31 | */ 32 | public function getPokemons() 33 | { 34 | return $this->pokemons; 35 | } 36 | 37 | /** 38 | * Creates a data instance from a Protobuf Message. 39 | * 40 | * @param ActionLogEntry[] $data 41 | * @return static 42 | */ 43 | public static function create($data) 44 | { 45 | $instance = new static(); 46 | 47 | // Check if we retrieved valid data 48 | if ($data == null) { 49 | return $instance; 50 | } 51 | 52 | foreach ($data as $logEntry) { 53 | if ($logEntry->getCatchPokemon()) { 54 | $element = Pokemon::create($logEntry->getCatchPokemon()); 55 | $element->setTimestampMs($logEntry->getTimestampMs()); 56 | 57 | // Adds pokemon to the list of pokemon log entries 58 | $instance->pokemons[] = $element; 59 | } elseif ($logEntry->getFortSearch()) { 60 | $element = Fort::create($logEntry->getFortSearch());; 61 | $element->setTimestampMs($logEntry->getTimestampMs()); 62 | 63 | // Add fort to the list of fort log entries 64 | $instance->forts[] = $element; 65 | } 66 | } 67 | 68 | return $instance; 69 | } 70 | 71 | 72 | } -------------------------------------------------------------------------------- /src/Api/Player/Data/Journal/Pokemon.php: -------------------------------------------------------------------------------- 1 | timestampMs; 47 | } 48 | 49 | /** 50 | * Returns the catch result. 51 | * (1=success, 2=escaped) 52 | * @return int 53 | */ 54 | public function getResult() 55 | { 56 | return $this->result; 57 | } 58 | 59 | /** 60 | * Returns pokemon id. 61 | * 62 | * @return int 63 | */ 64 | public function getPokemonId() 65 | { 66 | return $this->pokemonId; 67 | } 68 | 69 | /** 70 | * Returns the combat points. 71 | * 72 | * @return int 73 | */ 74 | public function getCombatPoints() 75 | { 76 | return $this->combatPoints; 77 | } 78 | 79 | /** 80 | * Returns the pokemon data id. 81 | * 82 | * @return int 83 | */ 84 | public function getPokemonDataId() 85 | { 86 | return $this->pokemonDataId; 87 | } 88 | 89 | /** 90 | * Returns the pokemon metadata. 91 | * 92 | * @return PokemonMeta 93 | */ 94 | public function getPokemonMeta() 95 | { 96 | return PokemonMetaRegistry::getByPokemonId($this->pokemonId); 97 | } 98 | 99 | /** 100 | * Returns the pokedex entry. 101 | * 102 | * @return PokedexItem 103 | */ 104 | public function getPokedexEntry() 105 | { 106 | return $this->pokedex()->get($this->pokemonId); 107 | } 108 | 109 | 110 | } -------------------------------------------------------------------------------- /src/Api/Player/Data/Profile/Avatar.php: -------------------------------------------------------------------------------- 1 | setName($playerCurrency->getName()); 45 | $currency->setAmount($playerCurrency->getAmount()); 46 | 47 | $instance->currencies[$playerCurrency->getName()] = $currency; 48 | } 49 | 50 | return $instance; 51 | } 52 | 53 | /** 54 | * Returns the currency by currency type. 55 | * 56 | * @param string $type 57 | * @return Currency 58 | * @throws Exception 59 | */ 60 | public function getByType($type) 61 | { 62 | // Check if the provided type is a valid currency type 63 | if (!array_key_exists($type, $this->currencies)) { 64 | throw new Exception('Invalid currency type provided'); 65 | } 66 | 67 | return $this->currencies[$type]; 68 | } 69 | 70 | /** 71 | * Returns the pokecoins currency. 72 | * 73 | * @return Currency 74 | * @throws Exception 75 | */ 76 | public function getPokecoins() 77 | { 78 | return $this->getByType(self::CURRENCY_TYPE_POKECOIN); 79 | } 80 | 81 | /** 82 | * Returns stardust currency. 83 | * 84 | * @return Currency 85 | * @throws Exception 86 | */ 87 | public function getStardust() 88 | { 89 | return $this->getByType(self::CURRENCY_TYPE_STARDUST); 90 | } 91 | 92 | /** 93 | * Returns all currency types. 94 | * 95 | * @return array 96 | */ 97 | public function toArray() 98 | { 99 | return $this->currencies; 100 | } 101 | 102 | } -------------------------------------------------------------------------------- /src/Api/Player/Data/Profile/Currency.php: -------------------------------------------------------------------------------- 1 | setState($tutorialState); 30 | 31 | return $instance; 32 | } 33 | 34 | 35 | } -------------------------------------------------------------------------------- /src/Api/Player/Journal.php: -------------------------------------------------------------------------------- 1 | getData()->getForts(); 19 | } 20 | 21 | /** 22 | * Returns the pokemon log entries. 23 | * 24 | * @return Data\Journal\Pokemon[] 25 | */ 26 | public function getPokemons() 27 | { 28 | return $this->getData()->getPokemons(); 29 | } 30 | 31 | /** 32 | * Returns the log entries. 33 | * 34 | * @return Log 35 | */ 36 | public function getEntries() 37 | { 38 | return $this->getData(); 39 | } 40 | 41 | /** 42 | * 43 | */ 44 | public function update() 45 | { 46 | // Retrieves the player metadata 47 | $data = $this->getRequestService()->getJournal(); 48 | 49 | // Set the log entries 50 | $this->data = Log::create($data->getLogEntries()); 51 | } 52 | 53 | /** 54 | * Returns the request service. 55 | * 56 | * @return JournalRequestService 57 | */ 58 | protected function getRequestService() 59 | { 60 | return new JournalRequestService(); 61 | } 62 | 63 | } -------------------------------------------------------------------------------- /src/Api/Player/Profile.php: -------------------------------------------------------------------------------- 1 | getRequestService()->getPlayer(); 59 | 60 | // Set the profile data 61 | $this->data = ProfileData::create($data->getPlayerData()); 62 | } 63 | 64 | /** 65 | * Returns the request service. 66 | * 67 | * @return PlayerRequestService 68 | */ 69 | protected function getRequestService() 70 | { 71 | return new PlayerRequestService(); 72 | } 73 | 74 | } -------------------------------------------------------------------------------- /src/Api/Pokemon/Collection/PokemonCollection.php: -------------------------------------------------------------------------------- 1 | sortBy(function (Pokemon $pokemon1) { 19 | return $pokemon1->getName(); 20 | }, SORT_REGULAR, $descending); 21 | } 22 | 23 | /** 24 | * Returns a sorted collection by level. 25 | * 26 | * @param bool $descending 27 | * @return static 28 | */ 29 | public function sortByLevel($descending = false) 30 | { 31 | return $this->sortBy(function (Pokemon $pokemon1) { 32 | return $pokemon1->getLevel(); 33 | }, SORT_REGULAR, $descending); 34 | 35 | } 36 | 37 | /** 38 | * Returns a sorted collection by combat points. 39 | * 40 | * @param bool $descending 41 | * @return static 42 | */ 43 | public function sortByCp($descending = false) 44 | { 45 | return $this->sortBy(function (Pokemon $pokemon1) { 46 | return $pokemon1->getCp(); 47 | }, SORT_REGULAR, $descending); 48 | 49 | } 50 | 51 | /** 52 | * Returns a sorted collection by Pokedex index. 53 | * 54 | * @param bool $descending 55 | * @return static 56 | */ 57 | public function sortByPokedexIndex($descending = false) 58 | { 59 | return $this->sortBy(function (Pokemon $pokemon1) { 60 | return $pokemon1->getPokemonId(); 61 | }, SORT_REGULAR, $descending); 62 | 63 | } 64 | 65 | /** 66 | * Returns a sorted collection by IV ratio. 67 | * 68 | * @param bool $descending 69 | * @return static 70 | */ 71 | public function sortByIVRatio($descending = false) 72 | { 73 | return $this->sortBy(function (Pokemon $pokemon1) { 74 | return $pokemon1->getIVRatio(); 75 | }, SORT_REGULAR, $descending); 76 | } 77 | 78 | /** 79 | * Returns a sorted collection by date captured. 80 | * 81 | * @param bool $descending 82 | * @return static 83 | */ 84 | public function sortByDate($descending = false) 85 | { 86 | return $this->sortBy(function (Pokemon $pokemon1) { 87 | return $pokemon1->getCreationTimeMs(); 88 | }, SORT_REGULAR, $descending); 89 | } 90 | 91 | } -------------------------------------------------------------------------------- /src/Api/Pokemon/Data/MovementType.php: -------------------------------------------------------------------------------- 1 | 4 | */ 5 | 6 | namespace NicklasW\PkmGoApi\Api\Pokemon\Data; 7 | 8 | use NicklasW\PkmGoApi\Api\Support\Enums\PokemonMove as PokemonMoveEnumSupport; 9 | use POGOProtos\Enums\PokemonMove as PokemonMoveEnum; 10 | 11 | class PokemonMove 12 | { 13 | /** @var array|int[]|PokemonMoveEnum[] */ 14 | protected $moves; 15 | 16 | /** 17 | * PokemonMove constructor. 18 | * 19 | * @param array|int[]|PokemonMoveEnum[] $moves 20 | */ 21 | public function __construct(array $moves) 22 | { 23 | $this->moves = $moves; 24 | } 25 | 26 | /** 27 | * Get the moves (raw). 28 | * 29 | * @return array|\int[]|PokemonMoveEnum[] 30 | */ 31 | public function getMoves() 32 | { 33 | return $this->moves; 34 | } 35 | 36 | /** 37 | * Get the moves as names. 38 | * 39 | * @return string[] 40 | */ 41 | public function getMovesStrings() 42 | { 43 | return array_map(function ($move) { 44 | return PokemonMoveEnumSupport::name($move); 45 | }, $this->getMoves()); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/Api/Pokemon/Support/BasePokemonRetriever.php: -------------------------------------------------------------------------------- 1 | data === null) { 37 | $this->update(); 38 | } 39 | 40 | return $this->data; 41 | } 42 | 43 | /** 44 | * @param string $name 45 | * @param mixed $arguments 46 | * @return mixed 47 | */ 48 | public function __call($name, $arguments) 49 | { 50 | // Check if the data is defined 51 | if ($this->data == null) { 52 | $this->update(); 53 | } 54 | 55 | return $this->data->{$name}($arguments); 56 | } 57 | 58 | /** 59 | * Returns the request service. 60 | * 61 | * @return RequestService 62 | */ 63 | protected function getRequestService() 64 | { 65 | return $this->getPokemonGoApi()->getRequestService(); 66 | } 67 | 68 | } -------------------------------------------------------------------------------- /src/Api/Support/Enums/AbstractEnum.php: -------------------------------------------------------------------------------- 1 | getConstants()); 64 | } 65 | 66 | return static::$CACHED_ENTRIES; 67 | } 68 | 69 | } -------------------------------------------------------------------------------- /src/Api/Support/Enums/GenericEnum.php: -------------------------------------------------------------------------------- 1 | getConstants()); 65 | } 66 | 67 | return self::$CACHED_ENTRIES[$class]; 68 | } 69 | 70 | } -------------------------------------------------------------------------------- /src/Api/Support/Enums/ItemId.php: -------------------------------------------------------------------------------- 1 | getPokemonGoApi()->getInventory()->getPokeBank(); 24 | } 25 | 26 | /** 27 | * Returns the candy bank. 28 | * 29 | * @return Pokedex 30 | */ 31 | protected function pokedex() 32 | { 33 | return $this->inventory()->getPokedex(); 34 | } 35 | 36 | /** 37 | * Returns the candy bank. 38 | * 39 | * @return CandyBank 40 | */ 41 | protected function candyBank() 42 | { 43 | return $this->inventory()->getCandyBank(); 44 | } 45 | 46 | /** 47 | * Returns the candy bank. 48 | * 49 | * @return Profile 50 | */ 51 | protected function profile() 52 | { 53 | return $this->getPokemonGoApi()->getProfile(); 54 | } 55 | 56 | /** 57 | * Returns the inventory. 58 | * 59 | * @return Inventory 60 | */ 61 | protected function inventory() 62 | { 63 | return $this->getPokemonGoApi()->getInventory(); 64 | } 65 | 66 | /** 67 | * Returns the pokemon go api. 68 | * 69 | * @return PokemonGoApi 70 | */ 71 | protected function getPokemonGoApi() 72 | { 73 | return App::getPokemonGoApi(); 74 | } 75 | 76 | /** 77 | * Returns the application. 78 | * 79 | * @return ApplicationKernel 80 | */ 81 | protected function getApplication() 82 | { 83 | return App::getInstance(); 84 | } 85 | } 86 | 87 | -------------------------------------------------------------------------------- /src/Api/Support/Traits/MakeDataPropertiesCallable.php: -------------------------------------------------------------------------------- 1 | data->{$name}($arguments); 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /src/Authentication/Config/Config.php: -------------------------------------------------------------------------------- 1 | user; 46 | } 47 | 48 | /** 49 | * @param string $user 50 | */ 51 | public function setUser($user) 52 | { 53 | $this->user = $user; 54 | } 55 | 56 | /** 57 | * @return string 58 | */ 59 | public function getPassword() 60 | { 61 | return $this->password; 62 | } 63 | 64 | /** 65 | * @param string $password 66 | */ 67 | public function setPassword($password) 68 | { 69 | $this->password = $password; 70 | } 71 | 72 | /** 73 | * @return string 74 | */ 75 | public function getAuthToken() 76 | { 77 | return $this->authToken; 78 | } 79 | 80 | /** 81 | * @param string $authToken 82 | */ 83 | public function setAuthToken($authToken) 84 | { 85 | $this->authToken = $authToken; 86 | } 87 | 88 | /** 89 | * @return string 90 | */ 91 | public function getRefreshToken() 92 | { 93 | return $this->refreshToken; 94 | } 95 | 96 | /** 97 | * @param string $refreshToken 98 | */ 99 | public function setRefreshToken($refreshToken) 100 | { 101 | $this->refreshToken = $refreshToken; 102 | } 103 | 104 | /** 105 | * @return string 106 | */ 107 | public function getOauthToken() 108 | { 109 | return $this->oauthToken; 110 | } 111 | 112 | /** 113 | * @param string $oauthToken 114 | */ 115 | public function setOauthToken($oauthToken) 116 | { 117 | $this->oauthToken = $oauthToken; 118 | } 119 | 120 | /** 121 | * @return string 122 | */ 123 | public function getProvider() 124 | { 125 | return $this->provider; 126 | } 127 | 128 | /** 129 | * @param string $provider 130 | */ 131 | public function setProvider($provider) 132 | { 133 | $this->provider = $provider; 134 | } 135 | 136 | /** 137 | * @return boolean 138 | */ 139 | public function isGoogle() 140 | { 141 | return $this->provider === Factory::PROVIDER_GOOGLE; 142 | } 143 | 144 | /** 145 | * @return boolean 146 | */ 147 | public function isPTC() 148 | { 149 | return $this->provider === Factory::PROVIDER_PTC; 150 | } 151 | 152 | } -------------------------------------------------------------------------------- /src/Authentication/Contracts/Authenticator.php: -------------------------------------------------------------------------------- 1 | getCode(); 34 | 35 | return $code == static::PTC_INVALID_GRANT_ERROR || $code == static::AUTH_SERVER_ERROR; 36 | } 37 | 38 | } -------------------------------------------------------------------------------- /src/Authentication/Exceptions/IllegalAuthenticationTypeException.php: -------------------------------------------------------------------------------- 1 | getOauthTokenByAuthenticationCode($token); 26 | 27 | return new AccessToken($result->getToken(), AccessToken::PROVIDER_GOOGLE, $result->getExpiryTimestamp(), $result->getRefreshToken()); 28 | } 29 | 30 | /** 31 | * Returns the authentication identifier. 32 | * 33 | * @return string 34 | */ 35 | public function identifier() 36 | { 37 | return 'google'; 38 | } 39 | 40 | /** 41 | * Returns the oauth token by authentication code. 42 | * 43 | * @param string $authenticationCode 44 | * @return AuthenticationTokenResult 45 | */ 46 | protected function getOauthTokenByAuthenticationCode($authenticationCode) 47 | { 48 | return $this->client()->getOauthTokenByAuthenticationCode($authenticationCode); 49 | } 50 | 51 | /** 52 | * Returns the Authentication client 53 | * 54 | * @return AuthenticationClient 55 | */ 56 | protected function client() 57 | { 58 | // Check if the authentication client is initialized 59 | if ($this->authenticationClient == null) { 60 | $this->authenticationClient = new AuthenticationClient(); 61 | } 62 | 63 | return $this->authenticationClient; 64 | } 65 | } -------------------------------------------------------------------------------- /src/Authentication/Managers/Google/AuthenticationCode/Clients/AuthenticationClient.php: -------------------------------------------------------------------------------- 1 | self::$PARAMETER_CLIENT_ID, 58 | 'client_secret' => self::$PARAMETER_CLIENT_SECRET, 59 | 'code' => $authenticationCode, 60 | 'grant_type' => self::$PARAMETER_GRANT_TYPE, 61 | 'redirect_uri' => self::$PARAMETER_REDIRECT_URI, 62 | ); 63 | 64 | // Retrieve the content 65 | $response = $this->post(self::$URL_TOKEN_URL, array('form_params' => $parameters)); 66 | 67 | // Get the authentication token parser 68 | $parser = new OauthTokenParser(); 69 | 70 | // Parse the content 71 | return $parser->parse($response); 72 | } 73 | 74 | /** 75 | * Execute a POST request and returns the response content. 76 | * 77 | * @param string $url 78 | * @param array $parameters 79 | * @return ResponseInterface 80 | */ 81 | protected function post($url, $parameters = array()) 82 | { 83 | // Execute the POST request 84 | $response = $this->client()->post($url, $parameters); 85 | 86 | // Retrieve the content 87 | return $response; 88 | } 89 | 90 | /** 91 | * Returns the Client. 92 | * 93 | * @return Client 94 | */ 95 | protected function client() 96 | { 97 | return App::get('client'); 98 | } 99 | 100 | } -------------------------------------------------------------------------------- /src/Authentication/Managers/Google/AuthenticationCode/Parsers/Parser.php: -------------------------------------------------------------------------------- 1 | dom = $dom; 41 | } 42 | 43 | /** 44 | * The method which parses the content. 45 | * 46 | * @param string $content 47 | * @return Result 48 | */ 49 | abstract public function parse($content); 50 | 51 | /** 52 | * Validate the request response. 53 | * 54 | * @param ResponseInterface $response 55 | * @throws ResponseException 56 | */ 57 | protected function validateResponse($response) 58 | { 59 | Log::debug(sprintf('[#%s] Validating response. Status code: \'%s\'', __CLASS__, $response->getStatusCode())); 60 | 61 | // Check if the response corresponds to a server error 62 | if (!$this->isServerError($response)) { 63 | return; 64 | } 65 | 66 | Log::debug(sprintf('[#%s] Retrieved a invalid response. Content: \'%s\'', __CLASS__, $response->getBody())); 67 | 68 | throw new ResponseException( 69 | sprintf('Retrieved a invalid response. Response: \'%s\'', (string)$response->getBody())); 70 | } 71 | 72 | /** 73 | * Returns true if the status code corresponds to a server error, false otherwise. 74 | * 75 | * @param ResponseInterface $response 76 | * @return boolean 77 | */ 78 | protected function isServerError($response) 79 | { 80 | // Retrieve the initial integer from the status code 81 | $responseCode = substr($response->getStatusCode(), 0, 1); 82 | 83 | return $responseCode == 5 || $responseCode == 4; 84 | } 85 | 86 | } -------------------------------------------------------------------------------- /src/Authentication/Managers/Google/AuthenticationCode/Parsers/Results/AuthenticationTokenResult.php: -------------------------------------------------------------------------------- 1 | data['token']; 15 | } 16 | 17 | /** 18 | * Returns the refresh token. 19 | * 20 | * @return string 21 | */ 22 | public function getRefreshToken() 23 | { 24 | return $this->data['refresh_token']; 25 | } 26 | 27 | /** 28 | * Returns the expiry timestamp. 29 | * 30 | * @return string 31 | */ 32 | public function getExpiryTimestamp() 33 | { 34 | return $this->data['timestamp']; 35 | } 36 | 37 | } -------------------------------------------------------------------------------- /src/Authentication/Managers/Google/AuthenticationCode/Parsers/Results/Result.php: -------------------------------------------------------------------------------- 1 | data = $data; 20 | } 21 | 22 | /** 23 | * @return mixed The parsed data 24 | */ 25 | public function getData() 26 | { 27 | return $this->data; 28 | } 29 | 30 | /** 31 | * @param $data The parsed data 32 | */ 33 | public function setData($data) 34 | { 35 | $this->data = $data; 36 | } 37 | 38 | } -------------------------------------------------------------------------------- /src/Authentication/Managers/Google/AuthenticationCodeManager.php: -------------------------------------------------------------------------------- 1 | authenticationCode = $authenticationCode; 24 | } 25 | 26 | /** 27 | * Returns the Oauth token. 28 | * 29 | * @return AccessToken 30 | */ 31 | public function getAccessToken() 32 | { 33 | // Check if we are authenticated 34 | if ($this->isAuthenticated()) { 35 | // Try to refresh the token if required and possible 36 | return $this->refreshTokenIfPossible(); 37 | } 38 | 39 | // Retrieve the Google authenticator 40 | $authenticator = $this->authenticator(); 41 | 42 | // Retrieve the access token by authentication code 43 | $accessToken = $authenticator->loginByToken($this->authenticationCode); 44 | 45 | // Dispatch event to listeners 46 | $this->dispatchEvent(static::EVENT_ACCESS_TOKEN, $accessToken); 47 | 48 | // Add the access token to the manager 49 | $this->setAccessToken($accessToken); 50 | 51 | return $accessToken; 52 | } 53 | 54 | /** 55 | * Returns the identifier. 56 | * 57 | * @return string 58 | */ 59 | public function getIdentifier() 60 | { 61 | return $this->authenticator()->identifier(); 62 | } 63 | 64 | /** 65 | * Returns the authenticator. 66 | * 67 | * @return Authenticator 68 | */ 69 | protected function authenticator() 70 | { 71 | return new Authenticator(); 72 | } 73 | } -------------------------------------------------------------------------------- /src/Authentication/Managers/Google/AuthenticationCredentials/Authenticator.php: -------------------------------------------------------------------------------- 1 | getAuthenticationToken($email, $password); 28 | 29 | Log::debug(sprintf('[#%s] Token: \'%s\'', __CLASS__, $tokenResult->getToken())); 30 | 31 | // Retrieve the oauth token 32 | $result = $this->getOauthTokenByUserCredentials($email, $tokenResult->getToken()); 33 | 34 | Log::debug(sprintf('[#%s] OAuth token: \'%s\'', __CLASS__, $result->getToken())); 35 | 36 | return new AccessToken($result->getToken(), AccessToken::PROVIDER_GOOGLE, $result->getExpiryTimestamp()); 37 | } 38 | 39 | 40 | /** 41 | * Returns the authentication identifier. 42 | * 43 | * @return string 44 | */ 45 | public function identifier() 46 | { 47 | return 'google'; 48 | } 49 | 50 | /** 51 | * Returns the authentication token. 52 | * 53 | * @param $email 54 | * @param $password 55 | * @return AuthenticationTokenResult 56 | */ 57 | protected function getAuthenticationToken($email, $password) 58 | { 59 | return $this->client()->getAuthenticationToken($email, $password); 60 | } 61 | 62 | /** 63 | * Returns the oauth token by user credentials. 64 | * 65 | * @param string $email 66 | * @param string $token 67 | * @return AuthenticationTokenResult 68 | */ 69 | protected function getOauthTokenByUserCredentials($email, $token) 70 | { 71 | return $this->client()->getOauthTokenByUserCredentials($email, $token); 72 | } 73 | 74 | /** 75 | * Returns the Authentication client 76 | * 77 | * @return AuthenticationClient 78 | */ 79 | protected function client() 80 | { 81 | // Check if the authentication client is initialized 82 | if ($this->authenticationClient == null) { 83 | $this->authenticationClient = new AuthenticationClient(); 84 | } 85 | 86 | return $this->authenticationClient; 87 | } 88 | } -------------------------------------------------------------------------------- /src/Authentication/Managers/Google/AuthenticationCredentials/Parsers/OauthTokenParser.php: -------------------------------------------------------------------------------- 1 | validateResponse($response); 30 | 31 | // Retrieve the content 32 | $content = (string)$response->getBody(); 33 | 34 | Log::debug(sprintf('[#%s] Retrieved response. Content: \'%s\'', __CLASS__, $content)); 35 | 36 | return new AuthenticationTokenResult( 37 | array('token' => $this->parseAuthId($content), 'timestamp' => $this->parseExpiryTimestamp($content))); 38 | } 39 | 40 | /** 41 | * Returns the parsed auth id. 42 | * 43 | * @param string $content 44 | * @return string 45 | */ 46 | protected function parseAuthId($content) 47 | { 48 | $matches = array(); 49 | 50 | preg_match('/Auth=(?.*)/', $content, $matches); 51 | 52 | return $matches['token']; 53 | } 54 | 55 | /** 56 | * Returns the expiry timestamp. 57 | * 58 | * @param string $content 59 | * @return string 60 | */ 61 | protected function parseExpiryTimestamp($content) 62 | { 63 | $matches = array(); 64 | 65 | preg_match('/Expiry=(?.*)/', $content, $matches); 66 | 67 | return $matches['expiry']; 68 | } 69 | 70 | } -------------------------------------------------------------------------------- /src/Authentication/Managers/Google/AuthenticationCredentials/Parsers/Parser.php: -------------------------------------------------------------------------------- 1 | dom = $dom; 41 | } 42 | 43 | /** 44 | * The method which parses the content. 45 | * 46 | * @param string $content 47 | * @return Result 48 | */ 49 | abstract public function parse($content); 50 | 51 | /** 52 | * Validate the request response. 53 | * 54 | * @param ResponseInterface $response 55 | * @throws ResponseException 56 | */ 57 | protected function validateResponse($response) 58 | { 59 | Log::debug(sprintf('[#%s] Validating response. Status code: \'%s\'', __CLASS__, $response->getStatusCode())); 60 | 61 | // Check if the response corresponds to a server error 62 | if (!$this->isServerError($response)) { 63 | return; 64 | } 65 | 66 | Log::debug(sprintf('[#%s] Retrieved a invalid response. Content: \'%s\'', __CLASS__, $response->getBody())); 67 | 68 | throw new ResponseException( 69 | sprintf('Retrieved a invalid response. Response: \'%s\'', (string)$response->getBody())); 70 | } 71 | 72 | /** 73 | * Returns true if the status code corresponds to a server error, false otherwise. 74 | * 75 | * @param ResponseInterface $response 76 | * @return boolean 77 | */ 78 | protected function isServerError($response) 79 | { 80 | // Retrieve the initial integer from the status code 81 | $responseCode = substr($response->getStatusCode(), 0, 1); 82 | 83 | return $responseCode === 5; 84 | } 85 | 86 | 87 | } -------------------------------------------------------------------------------- /src/Authentication/Managers/Google/AuthenticationCredentials/Parsers/Results/AuthenticationTokenResult.php: -------------------------------------------------------------------------------- 1 | data['token']; 16 | } 17 | 18 | /** 19 | * Returns the auth id. 20 | * 21 | * @return string 22 | */ 23 | public function getAuthId() 24 | { 25 | return $this->data['auth']; 26 | } 27 | 28 | /** 29 | * Returns the expiry timestamp. 30 | * 31 | * @return string 32 | */ 33 | public function getExpiryTimestamp() 34 | { 35 | return $this->data['timestamp']; 36 | } 37 | 38 | } -------------------------------------------------------------------------------- /src/Authentication/Managers/Google/AuthenticationCredentials/Parsers/Results/Result.php: -------------------------------------------------------------------------------- 1 | data = $data; 21 | } 22 | 23 | /** 24 | * @return The parsed data 25 | */ 26 | public function getData() 27 | { 28 | return $this->data; 29 | } 30 | 31 | /** 32 | * @param mixed $data The parsed data 33 | */ 34 | public function setData($data) 35 | { 36 | $this->data = $data; 37 | } 38 | 39 | } -------------------------------------------------------------------------------- /src/Authentication/Managers/Google/AuthenticationCredentials/Parsers/TokenParser.php: -------------------------------------------------------------------------------- 1 | validateResponse($response); 34 | 35 | // Retrieve the content 36 | $content = (string)$response->getBody(); 37 | 38 | // Check if we provided valid user credentials 39 | if ($response->getStatusCode() === self::$RESPONSE_STATUS_FORBIDDEN) { 40 | Log::debug(sprintf('[#%s] Retrieved invalid response. Content: \'%s\' Status code: \'%s\' ', 41 | __CLASS__, $content, $response->getStatusCode())); 42 | 43 | throw new AuthenticationException( 44 | sprintf('Invalid user credentials. Response: \'%s\'', $content)); 45 | } 46 | 47 | Log::debug(sprintf('[#%s] Response content: \'%s\'', __CLASS__, $content)); 48 | 49 | return new AuthenticationTokenResult(array('token' => $this->parseToken($content))); 50 | } 51 | 52 | /** 53 | * Returns the parsed ticket. 54 | * 55 | * @param string $content 56 | * @return string mixed 57 | */ 58 | protected function parseToken($content) 59 | { 60 | $matches = array(); 61 | 62 | preg_match('/Token=(?.*)/', $content, $matches); 63 | 64 | return $matches['token']; 65 | } 66 | 67 | } -------------------------------------------------------------------------------- /src/Authentication/Managers/Google/AuthenticationCredentials/Support/Signature.php: -------------------------------------------------------------------------------- 1 | setPublicKeyFormat("CRYPT_RSA_PUBLIC_FORMAT_RAW"); 96 | $rsa->setEncryptionMode("CRYPT_RSA_ENCRYPTION_OAEP"); 97 | $rsa->loadKey(array('n' => $modulus, 'e' => $exponent)); 98 | 99 | $rsa->setPublicKey(); 100 | 101 | $plain = "{$email}\x00{$password}"; 102 | 103 | return bin2hex($rsa->encrypt($plain)); 104 | } 105 | 106 | } -------------------------------------------------------------------------------- /src/Authentication/Managers/Google/AuthenticationCredentialsManager.php: -------------------------------------------------------------------------------- 1 | email = $email; 31 | $this->password = $password; 32 | } 33 | 34 | /** 35 | * Returns the Oauth token. 36 | * 37 | * @return AccessToken 38 | */ 39 | public function getAccessToken() 40 | { 41 | // Check if we are authenticated 42 | if ($this->isAuthenticated() && ($token = $this->refreshTokenIfPossible())) { 43 | return $token; 44 | } 45 | 46 | // Retrieve the Google authenticator 47 | $authenticator = $this->authenticator(); 48 | 49 | // Retrieve the access token by user credentials 50 | $accessToken = $authenticator->login($this->email, $this->password); 51 | 52 | // Dispatch event to listeners 53 | $this->dispatchEvent(static::EVENT_ACCESS_TOKEN, $accessToken); 54 | 55 | // Add the access token to the manager 56 | $this->setAccessToken($accessToken); 57 | 58 | return $accessToken; 59 | } 60 | 61 | /** 62 | * Returns the identifier. 63 | * 64 | * @return string 65 | */ 66 | public function getIdentifier() 67 | { 68 | return $this->authenticator()->identifier(); 69 | } 70 | 71 | /** 72 | * Refresh the token if possible. 73 | * 74 | * @return AccessToken|null 75 | * @throws AuthenticationException 76 | */ 77 | protected function refreshTokenIfPossible() 78 | { 79 | // Check if the oauth token is valid 80 | if ($this->isTokenValid()) { 81 | return $this->accessToken; 82 | } 83 | 84 | // Check if a refresh token is defined 85 | if ($this->hasFreshToken()) { 86 | // Use refresh token to retrieve new oauth token 87 | 88 | // Dispatch event to listeners 89 | $this->dispatchEvent(static::EVENT_ACCESS_TOKEN, $this->accessToken); 90 | 91 | return $this->accessToken; 92 | } 93 | 94 | return null; 95 | } 96 | 97 | /** 98 | * Returns the authenticator. 99 | * 100 | * @return Authenticator 101 | */ 102 | protected function authenticator() 103 | { 104 | return new Authenticator(); 105 | } 106 | } -------------------------------------------------------------------------------- /src/Authentication/Managers/Google/AuthenticationOauthTokenManager.php: -------------------------------------------------------------------------------- 1 | setAccessToken($token); 24 | } else { 25 | $this->token = $token; 26 | } 27 | } 28 | 29 | /** 30 | * Returns the Oauth token. 31 | * 32 | * @return AccessToken 33 | */ 34 | public function getAccessToken() 35 | { 36 | if (!$this->accessToken) { 37 | $this->accessToken = new AccessToken($this->token, AccessToken::PROVIDER_GOOGLE); 38 | } 39 | 40 | // Dispatch event to listeners 41 | $this->dispatchEvent(static::EVENT_ACCESS_TOKEN, $this->accessToken); 42 | 43 | return $this->accessToken; 44 | } 45 | 46 | /** 47 | * Returns the identifier. 48 | * 49 | * @return string 50 | */ 51 | public function getIdentifier() 52 | { 53 | return 'google'; 54 | } 55 | 56 | } -------------------------------------------------------------------------------- /src/Authentication/Managers/Google/AuthenticationRefreshToken/Authenticator.php: -------------------------------------------------------------------------------- 1 | getOauthTokenByAuthenticationRefreshToken($token); 26 | 27 | return new AccessToken($result->getToken(), AccessToken::PROVIDER_GOOGLE, $result->getExpiryTimestamp()); 28 | } 29 | 30 | /** 31 | * Returns the authentication identifier. 32 | * 33 | * @return string 34 | */ 35 | public function identifier() 36 | { 37 | return 'google'; 38 | } 39 | 40 | /** 41 | * Returns the oauth token by refresh code. 42 | * 43 | * @param string $AuthenticationRefreshToken 44 | * @return AuthenticationTokenResult 45 | */ 46 | protected function getOauthTokenByAuthenticationRefreshToken($AuthenticationRefreshToken) 47 | { 48 | return $this->client()->getOauthTokenByAuthenticationRefreshToken($AuthenticationRefreshToken); 49 | } 50 | 51 | /** 52 | * Returns the Authentication client 53 | * 54 | * @return AuthenticationClient 55 | */ 56 | protected function client() 57 | { 58 | // Check if the authentication client is initialized 59 | if ($this->authenticationClient == null) { 60 | $this->authenticationClient = new AuthenticationClient(); 61 | } 62 | 63 | return $this->authenticationClient; 64 | } 65 | } -------------------------------------------------------------------------------- /src/Authentication/Managers/Google/AuthenticationRefreshToken/Parsers/Parser.php: -------------------------------------------------------------------------------- 1 | dom = $dom; 41 | } 42 | 43 | /** 44 | * The method which parses the content. 45 | * 46 | * @param string $content 47 | * @return Result 48 | */ 49 | abstract public function parse($content); 50 | 51 | /** 52 | * Validate the request response. 53 | * 54 | * @param ResponseInterface $response 55 | * @throws ResponseException 56 | */ 57 | protected function validateResponse($response) 58 | { 59 | Log::debug(sprintf('[#%s] Validating response. Status code: \'%s\'', __CLASS__, $response->getStatusCode())); 60 | 61 | // Check if the response corresponds to a server error 62 | if (!$this->isServerError($response)) { 63 | return; 64 | } 65 | 66 | Log::debug(sprintf('[#%s] Retrieved a invalid response. Content: \'%s\'', __CLASS__, $response->getBody())); 67 | 68 | throw new ResponseException( 69 | sprintf('Retrieved a invalid response. Response: \'%s\'', (string)$response->getBody())); 70 | } 71 | 72 | /** 73 | * Returns true if the status code corresponds to a server error, false otherwise. 74 | * 75 | * @param ResponseInterface $response 76 | * @return boolean 77 | */ 78 | protected function isServerError($response) 79 | { 80 | // Retrieve the initial integer from the status code 81 | $responseCode = substr($response->getStatusCode(), 0, 1); 82 | 83 | return $responseCode == 5 || $responseCode == 4; 84 | } 85 | 86 | } -------------------------------------------------------------------------------- /src/Authentication/Managers/Google/AuthenticationRefreshToken/Parsers/Results/AuthenticationTokenResult.php: -------------------------------------------------------------------------------- 1 | data['token']; 15 | } 16 | 17 | /** 18 | * Returns the expiry timestamp. 19 | * 20 | * @return string 21 | */ 22 | public function getExpiryTimestamp() 23 | { 24 | return $this->data['timestamp']; 25 | } 26 | 27 | } -------------------------------------------------------------------------------- /src/Authentication/Managers/Google/AuthenticationRefreshToken/Parsers/Results/Result.php: -------------------------------------------------------------------------------- 1 | data = $data; 21 | } 22 | 23 | /** 24 | * @return mixed The parsed data 25 | */ 26 | public function getData() 27 | { 28 | return $this->data; 29 | } 30 | 31 | /** 32 | * @param mixed $data The parsed data 33 | */ 34 | public function setData($data) 35 | { 36 | $this->data = $data; 37 | } 38 | 39 | } -------------------------------------------------------------------------------- /src/Authentication/Managers/Google/AuthenticationRefreshTokenManager.php: -------------------------------------------------------------------------------- 1 | token = $token; 24 | } 25 | 26 | /** 27 | * Returns the Oauth token. 28 | * 29 | * @return AccessToken 30 | */ 31 | public function getAccessToken() 32 | { 33 | // Check if we are authenticated 34 | if ($this->isAuthenticated()) { 35 | // Try to refresh the token if required and possible 36 | return $this->refreshTokenIfPossible(); 37 | } 38 | 39 | // Retrieve the Google authenticator 40 | $authenticator = $this->authenticator(); 41 | 42 | // Retrieve the access token by refresh token 43 | $accessToken = $authenticator->loginByRefreshToken($this->token); 44 | 45 | // Add the refresh token to the access token 46 | $accessToken->setRefreshToken($this->token); 47 | 48 | // Dispatch event to listeners 49 | $this->dispatchEvent(static::EVENT_ACCESS_TOKEN, $accessToken); 50 | 51 | // Add the access token to the manager 52 | $this->setAccessToken($accessToken); 53 | 54 | return $accessToken; 55 | } 56 | 57 | /** 58 | * Returns the identifier. 59 | * 60 | * @return string 61 | */ 62 | public function getIdentifier() 63 | { 64 | return $this->authenticator()->identifier(); 65 | } 66 | 67 | /** 68 | * Returns the authenticator. 69 | * 70 | * @return Authenticator 71 | */ 72 | protected function authenticator() 73 | { 74 | return new Authenticator(); 75 | } 76 | 77 | } -------------------------------------------------------------------------------- /src/Authentication/Managers/PTC/AuthenticationCredentials/Authenticator.php: -------------------------------------------------------------------------------- 1 | client()->authenticationInformation(); 28 | 29 | // Retrieve the authentication ticket 30 | $ticketInformation = $this->client()->ticket($username, $password, $authenticationInformation); 31 | 32 | Log::debug(sprintf('[#%s] Retrieved ticket: \'%s\'', __CLASS__, $ticketInformation->getTicket())); 33 | 34 | // Retrieve the authentication token 35 | $tokenInformation = $this->client()->token($ticketInformation->getTicket()); 36 | 37 | Log::debug(sprintf('[#%s] Retrieved token: \'%s\'', __CLASS__, $tokenInformation->getToken())); 38 | 39 | return new AccessToken($tokenInformation->getToken(), AccessToken::PROVIDER_PTC, $tokenInformation->getTimestamp()); 40 | } 41 | 42 | /** 43 | * Returns the authentication identifier. 44 | * 45 | * @return string 46 | */ 47 | public function identifier() 48 | { 49 | return 'ptc'; 50 | } 51 | 52 | /** 53 | * Returns the Authentication client 54 | * 55 | * @return AuthenticationClient 56 | */ 57 | protected function client() 58 | { 59 | // Check if the authentication client is initialized 60 | if ($this->authenticationClient == null) { 61 | $this->authenticationClient = new AuthenticationClient(); 62 | } 63 | 64 | return $this->authenticationClient; 65 | } 66 | } -------------------------------------------------------------------------------- /src/Authentication/Managers/PTC/AuthenticationCredentials/Parsers/AuthenticationInformationParser.php: -------------------------------------------------------------------------------- 1 | validateResponse($response); 32 | 33 | // Retrieve the content 34 | $content = (string)$response->getBody(); 35 | 36 | // Decode the content 37 | $content = $this->content($content); 38 | 39 | Log::debug(sprintf('[#%s] Retrieved content: \'%s\' ', __CLASS__, var_export($content, true))); 40 | 41 | return new AuthenticationInformationResult(array('lt' => $content->lt, 'execution' => $content->execution)); 42 | } 43 | 44 | /** 45 | * Returns the content. 46 | * 47 | * @param ResponseInterface $response 48 | * @return mixed 49 | */ 50 | protected function content($response) 51 | { 52 | return json_decode($response); 53 | } 54 | 55 | } -------------------------------------------------------------------------------- /src/Authentication/Managers/PTC/AuthenticationCredentials/Parsers/Parser.php: -------------------------------------------------------------------------------- 1 | dom = $dom; 37 | } 38 | 39 | /** 40 | * The method which parses the content. 41 | * 42 | * @param mixed $content 43 | * @return Result 44 | */ 45 | abstract public function parse($content); 46 | 47 | /** 48 | * @param ResponseInterface $response 49 | * @throws ResponseException 50 | */ 51 | protected function validateResponse($response) 52 | { 53 | Log::debug(sprintf('[#%s] Validating response. Status code: \'%s\'', __CLASS__, $response->getStatusCode())); 54 | 55 | // Check if we retrieved a valid response status code 56 | if ($this->isSuccessfulResponse($response) || $this->isRedirect($response)) { 57 | return; 58 | } 59 | 60 | Log::debug(sprintf('[#%s] Retrieved a invalid response. Content: \'%s\'', __CLASS__, $response->getBody())); 61 | 62 | throw new ResponseException('Retrieved a invalid response from the server. Please try again later'); 63 | } 64 | 65 | /** 66 | * Returns true if the response was successful, false otherwise. 67 | * 68 | * @param ResponseInterface $response 69 | * @return bool 70 | */ 71 | protected function isSuccessfulResponse($response) 72 | { 73 | return $response->getStatusCode() === self::$RESPONSE_STATUS_SUCCESS; 74 | } 75 | 76 | /** 77 | * Returns true if the response corresponds to a redirect, false otherwise 78 | * 79 | * @param ResponseInterface $response 80 | * @return bool 81 | */ 82 | protected function isRedirect($response) 83 | { 84 | return $response->getStatusCode() === self::$RESPONSE_STATUS_REDIRECT; 85 | } 86 | 87 | } -------------------------------------------------------------------------------- /src/Authentication/Managers/PTC/AuthenticationCredentials/Parsers/Results/AuthenticationInformationResult.php: -------------------------------------------------------------------------------- 1 | data['lt']; 15 | } 16 | 17 | /** 18 | * Returns the execution code. 19 | */ 20 | public function getExecutionCode() 21 | { 22 | return $this->data['execution']; 23 | } 24 | 25 | } -------------------------------------------------------------------------------- /src/Authentication/Managers/PTC/AuthenticationCredentials/Parsers/Results/Result.php: -------------------------------------------------------------------------------- 1 | data = $data; 20 | } 21 | 22 | /** 23 | * @return mixed The parsed data 24 | */ 25 | public function getData() 26 | { 27 | return $this->data; 28 | } 29 | 30 | /** 31 | * @param mixed $data The parsed data 32 | */ 33 | public function setData($data) 34 | { 35 | $this->data = $data; 36 | } 37 | 38 | } -------------------------------------------------------------------------------- /src/Authentication/Managers/PTC/AuthenticationCredentials/Parsers/Results/TicketResult.php: -------------------------------------------------------------------------------- 1 | data['ticket']; 15 | } 16 | 17 | } -------------------------------------------------------------------------------- /src/Authentication/Managers/PTC/AuthenticationCredentials/Parsers/Results/TokenResult.php: -------------------------------------------------------------------------------- 1 | data['token']; 15 | } 16 | 17 | /** 18 | * Returns the timestamp. 19 | * 20 | * @return string 21 | */ 22 | public function getTimestamp() 23 | { 24 | return $this->data['timestamp']; 25 | } 26 | 27 | } -------------------------------------------------------------------------------- /src/Authentication/Managers/PTC/AuthenticationCredentials/Parsers/TicketParser.php: -------------------------------------------------------------------------------- 1 | validateResponse($response); 35 | 36 | Log::debug(sprintf('[#%s] Retrieved content: \'%s\'', __CLASS__, $response->getBody())); 37 | 38 | // Parse the content 39 | $content = $this->parseContent($response); 40 | 41 | // Check if the response includes any error messages 42 | if (array_key_exists('errors', $content)) { 43 | // Retrieve the error messages 44 | $errors = $content['errors']; 45 | 46 | // Check if there are any available error messages 47 | if (sizeof($errors) > 0) { 48 | Log::debug(sprintf('[#%s] Error messages in response. Errors: \'%s\'', __CLASS__, 49 | print_r($errors, true))); 50 | // A code of 503 indicates a service unavailable or unexpected error response. 0 is default 51 | $code = (strpos(implode($errors), 'unexpected error') !== false) ? AuthenticationException::AUTH_SERVER_ERROR : 0; 52 | throw new AuthenticationException(current($errors),$code); 53 | } 54 | } 55 | 56 | // Retrieves the location header 57 | $location = current($response->getHeader('Location')); 58 | 59 | Log::debug(sprintf('[#%s] Retrieved location header: \'%s\'', __CLASS__, $location)); 60 | 61 | return new TicketResult(array('ticket' => $this->parseTicket($location))); 62 | } 63 | 64 | /** 65 | * Returns the parsed content. 66 | * 67 | * @param ResponseInterface $response 68 | * @return array 69 | */ 70 | protected function parseContent($response) 71 | { 72 | // Retrieve the content 73 | $content = (string)$response->getBody(); 74 | 75 | // Decode the response body 76 | $content = json_decode($content, true); 77 | 78 | // Check if the response body is null 79 | if ($content === null) { 80 | return array(); 81 | } 82 | 83 | return $content; 84 | } 85 | 86 | /** 87 | * Returns the parsed ticket. 88 | * 89 | * @param string $location 90 | * @return string mixed 91 | */ 92 | protected function parseTicket($location) 93 | { 94 | return substr($location, strpos($location, '=') + 1); 95 | } 96 | 97 | } -------------------------------------------------------------------------------- /src/Authentication/Managers/PTC/AuthenticationCredentials/Parsers/TokenParser.php: -------------------------------------------------------------------------------- 1 | getBody(); 32 | 33 | $errors = array(); 34 | 35 | // Check if the response includes any error messages 36 | preg_match('/error=(?.*)/', $content->getContents(), $errors); 37 | if (sizeof($errors) > 0) { 38 | Log::debug(sprintf('[#%s] Error messages in response. Errors: \'%s\'', __CLASS__, 39 | print_r($errors, true))); 40 | // A code of 498 indicates an expired or otherwise invalid token. 0 is default 41 | $code = in_array('invalid_grant', $errors) ? AuthenticationException::PTC_INVALID_GRANT_ERROR : 0; 42 | throw new AuthenticationException(current($errors),$code); 43 | } 44 | 45 | $content = (string)$content; 46 | Log::debug(sprintf('[#%s] Retrieved content: \'%s\'', __CLASS__, $content)); 47 | 48 | return new TokenResult( 49 | array('token' => $this->parseToken($content), 'timestamp' => $this->parseExpiresTimestamp($content))); 50 | } 51 | 52 | /** 53 | * Returns the parsed ticket. 54 | * 55 | * @param string $content 56 | * @return string mixed 57 | */ 58 | protected function parseToken($content) 59 | { 60 | $matches = array(); 61 | 62 | preg_match('/access_token=(?.*)&expires/', $content, $matches); 63 | 64 | return $matches['token']; 65 | } 66 | 67 | /** 68 | * Returns the parsed ticket. 69 | * 70 | * @param string $content 71 | * @return string mixed 72 | */ 73 | protected function parseExpiresTimestamp($content) 74 | { 75 | $matches = array(); 76 | 77 | preg_match('/expires=(?.*)/', $content, $matches); 78 | 79 | return time() + intval($matches['expires']); 80 | } 81 | 82 | } 83 | 84 | -------------------------------------------------------------------------------- /src/Authentication/Managers/PTC/AuthenticationCredentialsManager.php: -------------------------------------------------------------------------------- 1 | username = $username; 30 | $this->password = $password; 31 | } 32 | 33 | /** 34 | * Returns the Oauth token. 35 | * 36 | * @return AccessToken 37 | */ 38 | public function getAccessToken() 39 | { 40 | // Check if we are authenticated 41 | if ($this->isAuthenticated() && ($token = $this->refreshTokenIfPossible())) { 42 | return $token; 43 | } 44 | 45 | // Retrieve the PTC authenticator 46 | $authenticator = $this->authenticator(); 47 | 48 | // Retrieve the access token by user credentials 49 | $accessToken = $authenticator->login($this->username, $this->password); 50 | 51 | // Dispatch event to listeners 52 | $this->dispatchEvent(static::EVENT_ACCESS_TOKEN, $accessToken); 53 | 54 | // Add the access token to the manager 55 | $this->setAccessToken($accessToken); 56 | 57 | return $accessToken; 58 | } 59 | 60 | /** 61 | * Returns the identifier. 62 | * 63 | * @return string 64 | */ 65 | public function getIdentifier() 66 | { 67 | return $this->authenticator()->identifier(); 68 | } 69 | 70 | /** 71 | * Refresh the token if possible. 72 | * 73 | * @return AccessToken|null 74 | * @throws AuthenticationException 75 | */ 76 | protected function refreshTokenIfPossible() 77 | { 78 | // Check if the oauth token is valid 79 | if ($this->isTokenValid()) { 80 | return $this->accessToken; 81 | } 82 | 83 | // Check if a refresh token is defined 84 | if ($this->hasFreshToken()) { 85 | // Use refresh token to retrieve new oauth token 86 | 87 | // Dispatch event to listeners 88 | $this->dispatchEvent(static::EVENT_ACCESS_TOKEN, $this->accessToken); 89 | 90 | return $this->accessToken; 91 | } 92 | 93 | return null; 94 | } 95 | 96 | /** 97 | * Returns the authenticator. 98 | * 99 | * @return Authenticator 100 | */ 101 | protected function authenticator() 102 | { 103 | return new Authenticator(); 104 | } 105 | } -------------------------------------------------------------------------------- /src/Authentication/Managers/PTC/AuthenticationOauthTokenManager.php: -------------------------------------------------------------------------------- 1 | 5 | */ 6 | 7 | namespace NicklasW\PkmGoApi\Authentication\Managers\PTC; 8 | 9 | use NicklasW\PkmGoApi\Authentication\AccessToken; 10 | use NicklasW\PkmGoApi\Authentication\Factory\Factory; 11 | use NicklasW\PkmGoApi\Authentication\Manager; 12 | 13 | class AuthenticationOauthTokenManager extends Manager 14 | { 15 | /** 16 | * AuthenticationOauthTokenManager constructor. 17 | * 18 | * @param AccessToken $token 19 | */ 20 | public function __construct(AccessToken $token) 21 | { 22 | $this->setAccessToken($token); 23 | } 24 | 25 | public function getAccessToken() 26 | { 27 | $this->dispatchEvent(static::EVENT_ACCESS_TOKEN, $this->accessToken); 28 | 29 | return $this->accessToken; 30 | } 31 | 32 | public function getIdentifier() 33 | { 34 | return Factory::PROVIDER_PTC; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/Facades/App.php: -------------------------------------------------------------------------------- 1 | getAuthenticationTicket(); 34 | 35 | // Check if we have not authenticated yet 36 | if ($authenticationTicket === null && $this->getAuthenticationInformation() !== null) { 37 | return true; 38 | } 39 | 40 | // Check if the expire timestamp is valid 41 | if ($authenticationTicket->getExpireTimestampMs() > microtime()) { 42 | return true; 43 | } 44 | 45 | return false; 46 | } 47 | 48 | /** 49 | * @return AuthTicket 50 | */ 51 | public function getAuthenticationTicket() 52 | { 53 | return $this->authenticationTicket; 54 | } 55 | 56 | /** 57 | * @param AuthTicket $authenticationTicket 58 | */ 59 | public function setAuthenticationTicket($authenticationTicket) 60 | { 61 | $this->authenticationTicket = $authenticationTicket; 62 | } 63 | 64 | /** 65 | * @return RequestEnvelope_AuthInfo_JWT 66 | */ 67 | public function getAuthenticationInformation() 68 | { 69 | return $this->authenticationInformation; 70 | } 71 | 72 | /** 73 | * @param RequestEnvelope_AuthInfo_JWT $authenticationInformation 74 | */ 75 | public function setAuthenticationInformation($authenticationInformation) 76 | { 77 | $this->authenticationInformation = $authenticationInformation; 78 | } 79 | 80 | /** 81 | * @return string 82 | */ 83 | public function getApiUrl() 84 | { 85 | return $this->apiUrl; 86 | } 87 | 88 | /** 89 | * @param string $apiUrl 90 | */ 91 | public function setApiUrl($apiUrl) 92 | { 93 | $this->apiUrl = $apiUrl; 94 | } 95 | 96 | } -------------------------------------------------------------------------------- /src/Kernels/ApplicationKernel.php: -------------------------------------------------------------------------------- 1 | manager = $manager; 35 | $this->location = new Location(); 36 | 37 | // Add the defined service providers 38 | $this->addServiceProviders(); 39 | 40 | parent::__construct(); 41 | } 42 | 43 | /** 44 | * Initializes the library. 45 | */ 46 | public function initialize() 47 | { 48 | parent::initialize(); 49 | 50 | // Initialize the client 51 | $this->initializeClient(); 52 | 53 | // Add the application object to the container 54 | $this->container->set('app', $this); 55 | } 56 | 57 | /** 58 | * Sets the HTTP client. 59 | * 60 | * @param Client $client 61 | */ 62 | public function setClient($client) 63 | { 64 | $this->container()->set('client', new ClientProxy($client)); 65 | } 66 | 67 | /** 68 | * Returns the pokemon go api. 69 | * 70 | * @return PokemonGoApi 71 | * @throws NotFoundException 72 | */ 73 | public function getPokemonGoApi() 74 | { 75 | return $this->container->get('PokemonGoApi'); 76 | } 77 | 78 | /** 79 | * Sets the location. 80 | * 81 | * @param Location $location 82 | */ 83 | public function setLocation($location) 84 | { 85 | $this->location = $location; 86 | } 87 | 88 | /** 89 | * @return Location 90 | */ 91 | public function getLocation() 92 | { 93 | return $this->location; 94 | } 95 | 96 | /** 97 | * @return Manager 98 | */ 99 | public function getManager() 100 | { 101 | return $this->manager; 102 | } 103 | 104 | /** 105 | * Initialize client. 106 | */ 107 | public function initializeClient() 108 | { 109 | $this->container->set('client', new ClientProxy(new Client())); 110 | } 111 | 112 | /** 113 | * Add the facades classes. 114 | */ 115 | protected function addFacades() 116 | { 117 | $this->proxyManager->addProxy('App', 'NicklasW\PkmGoApi\Facades\App'); 118 | 119 | parent::addFacades(); 120 | } 121 | 122 | /** 123 | * Add the service providers classes. 124 | */ 125 | protected function addServiceProviders() 126 | { 127 | // Add the pokemon go api service provider 128 | $this->register(new PokemonGoApiServiceProvider($this)); 129 | 130 | // Add the request handler service provider 131 | $this->register(new RequestHandlerServiceProvider($this)); 132 | } 133 | 134 | } 135 | -------------------------------------------------------------------------------- /src/Providers/PokemonGoApiServiceProvider.php: -------------------------------------------------------------------------------- 1 | app->container()->set('PokemonGoApi', new PokemonGoApi()); 19 | } 20 | 21 | } -------------------------------------------------------------------------------- /src/Providers/RequestHandlerServiceProvider.php: -------------------------------------------------------------------------------- 1 | app->container()->set('RequestHandler', new RequestHandler($this->app)); 32 | } 33 | 34 | } -------------------------------------------------------------------------------- /src/Providers/ServiceProvider.php: -------------------------------------------------------------------------------- 1 | app = $app; 22 | } 23 | 24 | /** 25 | * Register the service provider. 26 | * 27 | * @return mixed 28 | */ 29 | abstract public function register(); 30 | 31 | } -------------------------------------------------------------------------------- /src/Requests/AuthenticateRequest.php: -------------------------------------------------------------------------------- 1 | getReturns(); 49 | 50 | // Initialize the player response 51 | $checkChallengeResponse = new CheckChallengeResponse(); 52 | 53 | // Unmarshall the response 54 | $checkChallengeResponse->decode($requestData[0]); 55 | $this->setData($checkChallengeResponse); 56 | } 57 | } 58 | 59 | -------------------------------------------------------------------------------- /src/Requests/Envelops/AuthInfoEnvelope.php: -------------------------------------------------------------------------------- 1 | authInfoEnvelope(...$parameters); 32 | 33 | break; 34 | 35 | } 36 | 37 | return $envelope; 38 | } 39 | 40 | /** 41 | * Creates AuthInfoEnvelope. 42 | * 43 | * @param string $type 44 | * @param AccessToken $token 45 | * @return RequestEnvelope_AuthInfo 46 | */ 47 | protected function authInfoEnvelope($type, $token) 48 | { 49 | $authInfoJWT = new RequestEnvelope_AuthInfo_JWT(); 50 | $authInfoJWT->setContents($token->getToken()); 51 | $authInfoJWT->setUnknown2(59); 52 | 53 | $authInfoEnvelope = new RequestEnvelope_AuthInfo(); 54 | $authInfoEnvelope->setProvider($type); 55 | $authInfoEnvelope->setToken($authInfoJWT); 56 | 57 | return $authInfoEnvelope; 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /src/Requests/EvolvePokemonRequest.php: -------------------------------------------------------------------------------- 1 | pokemonId = $pokemonId; 36 | } 37 | 38 | /** 39 | * @return int 40 | */ 41 | public function getType() 42 | { 43 | return RequestType::EVOLVE_POKEMON; 44 | } 45 | 46 | /** 47 | * @return Message 48 | */ 49 | public function getMessage() 50 | { 51 | $evolvePokemonMessage = new EvolvePokemonMessage(); 52 | $evolvePokemonMessage->setPokemonId($this->pokemonId); 53 | 54 | return $evolvePokemonMessage; 55 | } 56 | 57 | /** 58 | * Handles the request data. 59 | * 60 | * @param ResponseEnvelope $data 61 | * @return EvolvePokemonResponse 62 | */ 63 | public function handleResponse($data) 64 | { 65 | // Retrieve the specific request data 66 | $requestData = $data->getReturns(); 67 | 68 | // Initialize the evolve pokemon response 69 | $evolvePokemonResponse = new EvolvePokemonResponse(); 70 | 71 | // Unmarshall the response 72 | $evolvePokemonResponse->decode($requestData[0]); 73 | 74 | $this->setData($evolvePokemonResponse); 75 | } 76 | } -------------------------------------------------------------------------------- /src/Requests/FortSearchRequest.php: -------------------------------------------------------------------------------- 1 | id = $id; 51 | $this->latitude = $latitude; 52 | $this->longitude = $longitude; 53 | } 54 | 55 | /** 56 | * @return int 57 | */ 58 | public function getType() 59 | { 60 | return RequestType::FORT_SEARCH;; 61 | } 62 | 63 | /** 64 | * @return GetMapObjectsMessage 65 | */ 66 | public function getMessage() 67 | { 68 | $message = new FortSearchMessage(); 69 | 70 | $message->setFortId($this->id); 71 | $message->setFortLatitude($this->latitude); 72 | $message->setFortLongitude($this->longitude); 73 | 74 | $message->setPlayerLatitude($this->getCurrentLatitude()); 75 | $message->setPlayerLongitude($this->getCurrentLongitude()); 76 | 77 | return $message; 78 | } 79 | 80 | /** 81 | * Handles the request data. 82 | * 83 | * @param ResponseEnvelope $data 84 | * @return mixed 85 | */ 86 | public function handleResponse($data) 87 | { 88 | // Retrieve the specific request data 89 | $requestData = $data->getReturns(); 90 | 91 | // Initialize the fort search response 92 | $fortSearchResponse = new FortSearchResponse(); 93 | 94 | // Unmarshall the response 95 | $fortSearchResponse->decode($requestData[0]); 96 | 97 | $this->setData($fortSearchResponse); 98 | } 99 | 100 | /** 101 | * Returns the current latitude of the player. 102 | * 103 | * @return float 104 | */ 105 | protected function getCurrentLatitude() 106 | { 107 | return $this->getApplication()->getLatitude(); 108 | } 109 | 110 | /** 111 | * Returns the current longitude of the player. 112 | * 113 | * @return float 114 | */ 115 | protected function getCurrentLongitude() 116 | { 117 | return $this->getApplication()->getLongitude(); 118 | } 119 | 120 | /** 121 | * Returns the application. 122 | * 123 | * @return ApplicationKernel 124 | */ 125 | protected function getApplication() 126 | { 127 | return App::getInstance(); 128 | } 129 | 130 | } -------------------------------------------------------------------------------- /src/Requests/GetInventoryRequest.php: -------------------------------------------------------------------------------- 1 | getReturns(); 49 | 50 | // Initialize the inventory response 51 | $inventoryResponse = new GetInventoryResponse(); 52 | 53 | // Unmarshall the response 54 | $inventoryResponse->decode($requestData[0]); 55 | 56 | $this->setData($inventoryResponse); 57 | } 58 | } -------------------------------------------------------------------------------- /src/Requests/GetJournalRequest.php: -------------------------------------------------------------------------------- 1 | getReturns(); 48 | 49 | // Initialize the sfida action log response 50 | $sfidaActionResponse = new SfidaActionLogResponse(); 51 | 52 | // Unmarshall the response 53 | $sfidaActionResponse->decode($requestData[0]); 54 | 55 | $this->setData($sfidaActionResponse); 56 | } 57 | } -------------------------------------------------------------------------------- /src/Requests/GetMapResourcesRequest.php: -------------------------------------------------------------------------------- 1 | latitude = $latitude; 48 | $this->longitude = $longitude; 49 | $this->cellIds = $cellIds; 50 | } 51 | 52 | /** 53 | * @return int 54 | */ 55 | public function getType() 56 | { 57 | return RequestType::GET_MAP_OBJECTS;; 58 | } 59 | 60 | /** 61 | * @return GetMapObjectsMessage 62 | */ 63 | public function getMessage() 64 | { 65 | $message = new GetMapObjectsMessage(); 66 | 67 | $message->setLatitude($this->latitude); 68 | $message->setLongitude($this->longitude); 69 | 70 | foreach ($this->cellIds as $cellId) { 71 | $message->addCellId($cellId); 72 | $message->addSinceTimestampMs(0); 73 | } 74 | 75 | return $message; 76 | } 77 | 78 | /** 79 | * Handles the request data. 80 | * 81 | * @param ResponseEnvelope $data 82 | * @return mixed 83 | */ 84 | public function handleResponse($data) 85 | { 86 | // Retrieve the specific request data 87 | $requestData = $data->getReturnsArray(); 88 | 89 | // Initialize the map objects response 90 | $mapObjectsResponse = new GetMapObjectsResponse(); 91 | 92 | // Unmarshall the response 93 | $mapObjectsResponse->read($requestData[0]); 94 | 95 | $this->setData($mapObjectsResponse); 96 | } 97 | } -------------------------------------------------------------------------------- /src/Requests/GetPlayerRequest.php: -------------------------------------------------------------------------------- 1 | getReturns(); 49 | 50 | // Initialize the player response 51 | $playerResponse = new GetPlayerResponse(); 52 | 53 | // Unmarshall the response 54 | $playerResponse->decode($requestData[0]); 55 | 56 | $this->setData($playerResponse); 57 | } 58 | } -------------------------------------------------------------------------------- /src/Requests/RecycleInventoryItemRequest.php: -------------------------------------------------------------------------------- 1 | itemId = $itemId; 43 | $this->itemCount = $count; 44 | } 45 | 46 | /** 47 | * @return int 48 | */ 49 | public function getType() 50 | { 51 | return RequestType::RECYCLE_INVENTORY_ITEM; 52 | } 53 | 54 | /** 55 | * @return Message 56 | */ 57 | public function getMessage() 58 | { 59 | $recycleInventoryItemMessage = new RecycleInventoryItemMessage(); 60 | $recycleInventoryItemMessage->setItemId($this->itemId); 61 | $recycleInventoryItemMessage->setCount($this->itemCount); 62 | 63 | return $recycleInventoryItemMessage; 64 | } 65 | 66 | /** 67 | * Handles the request data. 68 | * 69 | * @param ResponseEnvelope $data 70 | * @return RecycleInventoryItemResponse 71 | */ 72 | public function handleResponse($data) 73 | { 74 | // Retrieve the specific request data 75 | $requestData = $data->getReturns(); 76 | 77 | // Initialize the rename pokemon response 78 | $recycleInventoryItemResponse = new RecycleInventoryItemResponse(); 79 | 80 | // Unmarshall the response 81 | $recycleInventoryItemResponse->decode($requestData[0]); 82 | 83 | $this->setData($recycleInventoryItemResponse); 84 | } 85 | } -------------------------------------------------------------------------------- /src/Requests/RenamePokemonRequest.php: -------------------------------------------------------------------------------- 1 | pokemonId = $pokemonId; 42 | $this->name = $name; 43 | } 44 | 45 | /** 46 | * @return int 47 | */ 48 | public function getType() 49 | { 50 | return RequestType::NICKNAME_POKEMON; 51 | } 52 | 53 | /** 54 | * @return Message 55 | */ 56 | public function getMessage() 57 | { 58 | $nicknamePokemonMessage = new NicknamePokemonMessage(); 59 | $nicknamePokemonMessage->setPokemonId($this->pokemonId); 60 | $nicknamePokemonMessage->setNickname($this->name); 61 | 62 | return $nicknamePokemonMessage; 63 | } 64 | 65 | /** 66 | * Handles the request data. 67 | * 68 | * @param ResponseEnvelope $data 69 | * @return NicknamePokemonResponse 70 | */ 71 | public function handleResponse($data) 72 | { 73 | // Retrieve the specific request data 74 | $requestData = $data->getReturns(); 75 | 76 | // Initialize the rename pokemon response 77 | $nicknamePokemonResponse = new NicknamePokemonResponse(); 78 | 79 | // Unmarshall the response 80 | $nicknamePokemonResponse->decode($requestData[0]); 81 | 82 | $this->setData($nicknamePokemonResponse); 83 | } 84 | } -------------------------------------------------------------------------------- /src/Requests/Request.php: -------------------------------------------------------------------------------- 1 | data; 37 | } 38 | 39 | /** 40 | * @param mixed $data 41 | */ 42 | public function setData($data) 43 | { 44 | $this->data = $data; 45 | } 46 | 47 | } -------------------------------------------------------------------------------- /src/Requests/SetFavoritePokemonRequest.php: -------------------------------------------------------------------------------- 1 | pokemonId = $pokemonId; 43 | $this->favorite = $favorite; 44 | } 45 | 46 | /** 47 | * @return int 48 | */ 49 | public function getType() 50 | { 51 | return RequestType::SET_FAVORITE_POKEMON; 52 | } 53 | 54 | /** 55 | * @return Message 56 | */ 57 | public function getMessage() 58 | { 59 | $setFavoritePokemonMessage = new SetFavoritePokemonMessage(); 60 | $setFavoritePokemonMessage->setPokemonId($this->pokemonId); 61 | $setFavoritePokemonMessage->setIsFavorite($this->favorite); 62 | 63 | return $setFavoritePokemonMessage; 64 | } 65 | 66 | /** 67 | * Handles the request data. 68 | * 69 | * @param ResponseEnvelope $data 70 | * @return SetFavoritePokemonResponse 71 | */ 72 | public function handleResponse($data) 73 | { 74 | // Retrieve the specific request data 75 | $requestData = $data->getReturns(); 76 | 77 | // Initialize the rename pokemon response 78 | $setFavoritePokemonResponse = new SetFavoritePokemonResponse(); 79 | 80 | // Unmarshall the response 81 | $setFavoritePokemonResponse->decode($requestData[0]); 82 | 83 | $this->setData($setFavoritePokemonResponse); 84 | } 85 | } -------------------------------------------------------------------------------- /src/Requests/TransferPokemonRequest.php: -------------------------------------------------------------------------------- 1 | pokemonId = $pokemonId; 36 | } 37 | 38 | /** 39 | * @return int 40 | */ 41 | public function getType() 42 | { 43 | return RequestType::RELEASE_POKEMON; 44 | } 45 | 46 | /** 47 | * @return Message 48 | */ 49 | public function getMessage() 50 | { 51 | $releasePokemonMessage = new ReleasePokemonMessage(); 52 | $releasePokemonMessage->setPokemonId($this->pokemonId); 53 | 54 | return $releasePokemonMessage; 55 | } 56 | 57 | /** 58 | * Handles the request data. 59 | * 60 | * @param ResponseEnvelope $data 61 | * @return mixed 62 | */ 63 | public function handleResponse($data) 64 | { 65 | // Retrieve the specific request data 66 | $requestData = $data->getReturns(); 67 | 68 | // Initialize the release pokemon response 69 | $releasePokemonResponse = new ReleasePokemonResponse(); 70 | 71 | // Unmarshall the response 72 | $releasePokemonResponse->decode($requestData[0]); 73 | 74 | $this->setData($releasePokemonResponse); 75 | } 76 | } -------------------------------------------------------------------------------- /src/Requests/UpgradePokemonRequest.php: -------------------------------------------------------------------------------- 1 | pokemonId = $pokemonId; 36 | } 37 | 38 | /** 39 | * @return int 40 | */ 41 | public function getType() 42 | { 43 | return RequestType::UPGRADE_POKEMON; 44 | } 45 | 46 | /** 47 | * @return Message 48 | */ 49 | public function getMessage() 50 | { 51 | $upgradePokemonMessage = new UpgradePokemonMessage(); 52 | $upgradePokemonMessage->setPokemonId($this->pokemonId); 53 | 54 | return $upgradePokemonMessage; 55 | } 56 | 57 | /** 58 | * Handles the request data. 59 | * 60 | * @param ResponseEnvelope $data 61 | * @return mixed 62 | */ 63 | public function handleResponse($data) 64 | { 65 | // Retrieve the specific request data 66 | $requestData = $data->getReturns(); 67 | 68 | // Initialize the release pokemon response 69 | $upgradePokemonResponse = new UpgradePokemonResponse(); 70 | 71 | // Unmarshall the response 72 | $upgradePokemonResponse->decode($requestData[0]); 73 | 74 | $this->setData($upgradePokemonResponse); 75 | } 76 | } -------------------------------------------------------------------------------- /src/Requests/UseIncenseRequest.php: -------------------------------------------------------------------------------- 1 | itemId = $itemId; 36 | } 37 | 38 | /** 39 | * @return int 40 | */ 41 | public function getType() 42 | { 43 | return RequestType::USE_INCENSE; 44 | } 45 | 46 | /** 47 | * @return Message 48 | */ 49 | public function getMessage() 50 | { 51 | $useIncenseMessage = new UseIncenseMessage(); 52 | $useIncenseMessage->setIncenseType($this->itemId); 53 | 54 | return $useIncenseMessage; 55 | } 56 | 57 | /** 58 | * Handles the request data. 59 | * 60 | * @param ResponseEnvelope $data 61 | * @return UseIncenseResponse 62 | */ 63 | public function handleResponse($data) 64 | { 65 | // Retrieve the specific request data 66 | $requestData = $data->getReturns(); 67 | 68 | // Initialize the rename pokemon response 69 | $useIncenseResponse = new UseIncenseResponse(); 70 | 71 | // Unmarshall the response 72 | $useIncenseResponse->decode($requestData[0]); 73 | 74 | $this->setData($useIncenseResponse); 75 | } 76 | } -------------------------------------------------------------------------------- /src/Requests/UseItemXpBoostRequest.php: -------------------------------------------------------------------------------- 1 | itemId = $itemId; 36 | } 37 | 38 | /** 39 | * @return int 40 | */ 41 | public function getType() 42 | { 43 | return RequestType::USE_ITEM_XP_BOOST; 44 | } 45 | 46 | /** 47 | * @return Message 48 | */ 49 | public function getMessage() 50 | { 51 | $useItemXpBoostMessage = new UseItemXpBoostMessage(); 52 | $useItemXpBoostMessage->setItemId($this->itemId); 53 | 54 | return $useItemXpBoostMessage; 55 | } 56 | 57 | /** 58 | * Handles the request data. 59 | * 60 | * @param ResponseEnvelope $data 61 | * @return UseItemXpBoostResponse 62 | */ 63 | public function handleResponse($data) 64 | { 65 | // Retrieve the specific request data 66 | $requestData = $data->getReturns(); 67 | 68 | // Initialize the rename pokemon response 69 | $useItemXpBoostResponse = new UseItemXpBoostResponse(); 70 | 71 | // Unmarshall the response 72 | $useItemXpBoostResponse->decode($requestData[0]); 73 | 74 | $this->setData($useItemXpBoostResponse); 75 | } 76 | } -------------------------------------------------------------------------------- /src/Requests/VerifyChallengeRequest.php: -------------------------------------------------------------------------------- 1 | token = $token; 35 | } 36 | 37 | /** 38 | * @return int 39 | */ 40 | public function getType() 41 | { 42 | return RequestType::VERIFY_CHALLENGE; 43 | } 44 | 45 | /** 46 | * @return Message 47 | */ 48 | public function getMessage() 49 | { 50 | $verifyChallengeMessage = new VerifyChallengeMessage(); 51 | $verifyChallengeMessage->setToken($this->token); 52 | 53 | return $verifyChallengeMessage; 54 | } 55 | 56 | /** 57 | * Handles the request data. 58 | * 59 | * @param ResponseEnvelope $data 60 | * @return mixed 61 | */ 62 | public function handleResponse($data) 63 | { 64 | // DEBUG - dump response object 65 | //var_dump($data); 66 | // DEBUG - check status code of response for error handling, but error can return both 1 and 2 - not sure why? 67 | //echo "StatusCode: " . $data->getStatusCode(); 68 | 69 | // Initialize the VerifyChallenge response 70 | $verifyChallengeResponse = new VerifyChallengeResponse(); 71 | 72 | // Retrieve the specific request data 73 | $requestData = $data->getReturns(); 74 | if ($requestData) { 75 | // Unmarshall the response 76 | $verifyChallengeResponse->decode($requestData[0]); 77 | }else { 78 | // HACK to instansiate a valid VerifyChallengeResponse object when $requestData == NULL - sets success to "0"; 79 | $verifyChallengeResponse->setSuccess(true); 80 | } 81 | 82 | $this->setData($verifyChallengeResponse); 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /src/Services/Request/CheckChallengeRequestService.php: -------------------------------------------------------------------------------- 1 | requestHandler()->handle($checkChallengeRequest); 23 | 24 | return $checkChallengeRequest->getData(); 25 | } 26 | } 27 | 28 | -------------------------------------------------------------------------------- /src/Services/Request/InventoryRequestService.php: -------------------------------------------------------------------------------- 1 | requestHandler()->handle($inventoryRequest); 28 | 29 | return $inventoryRequest->getData(); 30 | } 31 | 32 | /** 33 | * Recycle item. 34 | * 35 | * @param integer $itemId 36 | * @param int $count 37 | * @return RecycleInventoryItemResponse 38 | */ 39 | public function recycle($itemId, $count) 40 | { 41 | $recycleInventoryItemRequest = new RecycleInventoryItemRequest($itemId, $count); 42 | 43 | $this->requestHandler()->handle($recycleInventoryItemRequest); 44 | 45 | return $recycleInventoryItemRequest->getData(); 46 | } 47 | 48 | /** 49 | * Use incense item. 50 | * 51 | * @param integer $itemId 52 | * @return UseIncenseResponse 53 | */ 54 | public function useIncense($itemId) 55 | { 56 | $useIncenseRequest = new UseIncenseRequest($itemId); 57 | 58 | $this->requestHandler()->handle($useIncenseRequest); 59 | 60 | return $useIncenseRequest->getData(); 61 | } 62 | 63 | /** 64 | * Use xp boost item. 65 | * 66 | * @param integer $itemId 67 | * @return UseItemXpBoostResponse 68 | */ 69 | public function useItemXpBoost($itemId) 70 | { 71 | $useItemXpBoostRequest = new UseItemXpBoostRequest($itemId); 72 | 73 | $this->requestHandler()->handle($useItemXpBoostRequest); 74 | 75 | return $useItemXpBoostRequest->getData(); 76 | } 77 | } -------------------------------------------------------------------------------- /src/Services/Request/JournalRequestService.php: -------------------------------------------------------------------------------- 1 | requestHandler()->handle($journalRequest); 23 | 24 | return $journalRequest->getData(); 25 | } 26 | 27 | } -------------------------------------------------------------------------------- /src/Services/Request/MapRequestService.php: -------------------------------------------------------------------------------- 1 | requestHandler()->handle($mapResourcesRequest); 27 | 28 | return $mapResourcesRequest->getData(); 29 | } 30 | 31 | } -------------------------------------------------------------------------------- /src/Services/Request/PlayerRequestService.php: -------------------------------------------------------------------------------- 1 | requestHandler()->handle($playerRequest); 23 | 24 | return $playerRequest->getData(); 25 | } 26 | 27 | } -------------------------------------------------------------------------------- /src/Services/Request/PokemonRequestService.php: -------------------------------------------------------------------------------- 1 | requestHandler()->handle($transferPokemonRequest); 35 | 36 | return $transferPokemonRequest->getData(); 37 | } 38 | 39 | /** 40 | * Renames a pokemon. 41 | * 42 | * @param integer $pokemonId 43 | * @param string $name 44 | * @return NicknamePokemonResponse 45 | */ 46 | public function rename($pokemonId, $name) 47 | { 48 | $renamePokemonRequest = new RenamePokemonRequest($pokemonId, $name); 49 | 50 | $this->requestHandler()->handle($renamePokemonRequest); 51 | 52 | return $renamePokemonRequest->getData(); 53 | } 54 | 55 | /** 56 | * Evolves the pokemon. 57 | * 58 | * @param integer $pokemonId 59 | * @return EvolvePokemonResponse 60 | * @throws AuthenticationException 61 | * @throws Exception 62 | */ 63 | public function envolve($pokemonId) 64 | { 65 | $evolvePokemonRequest = new EvolvePokemonRequest($pokemonId); 66 | 67 | $this->requestHandler()->handle($evolvePokemonRequest); 68 | 69 | return $evolvePokemonRequest->getData(); 70 | } 71 | 72 | /** 73 | * Upgrade the pokemon. 74 | * 75 | * @param integer $pokemonId 76 | * @return UpgradePokemonResponse 77 | * @throws AuthenticationException 78 | * @throws Exception 79 | */ 80 | public function upgrade($pokemonId) 81 | { 82 | $upgradePokemonRequest = new UpgradePokemonRequest($pokemonId); 83 | 84 | $this->requestHandler()->handle($upgradePokemonRequest); 85 | 86 | return $upgradePokemonRequest->getData(); 87 | } 88 | 89 | /** 90 | * Set pokemon favorite. 91 | * 92 | * @param integer $pokemonId 93 | * @param boolean $fav 94 | * @return SetFavoritePokemonResponse 95 | * @throws AuthenticationException 96 | * @throws Exception 97 | */ 98 | public function favorite($pokemonId, $fav) 99 | { 100 | $setFavoritePokemonRequest = new SetFavoritePokemonRequest($pokemonId, $fav); 101 | 102 | $this->requestHandler()->handle($setFavoritePokemonRequest); 103 | 104 | return $setFavoritePokemonRequest->getData(); 105 | } 106 | } -------------------------------------------------------------------------------- /src/Services/Request/PokestopRequestService.php: -------------------------------------------------------------------------------- 1 | requestHandler()->handle($fortSearchRequest); 35 | 36 | return $fortSearchRequest->getData(); 37 | } 38 | 39 | } -------------------------------------------------------------------------------- /src/Services/RequestService.php: -------------------------------------------------------------------------------- 1 | getContainer()->get('RequestHandler'); 20 | } 21 | 22 | /** 23 | * Returns the container. 24 | * 25 | * @return Container 26 | */ 27 | protected function getContainer() 28 | { 29 | return App::container(); 30 | } 31 | 32 | } --------------------------------------------------------------------------------