├── .gitignore ├── README.md ├── config.json_template ├── handler.js ├── package.json ├── serverless.env.yaml_template └── serverless.yaml /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log 5 | 6 | # Runtime data 7 | pids 8 | *.pid 9 | *.seed 10 | dist 11 | 12 | # Directory for instrumented libs generated by jscoverage/JSCover 13 | lib-cov 14 | 15 | # Coverage directory used by tools like istanbul 16 | coverage 17 | 18 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 19 | .grunt 20 | 21 | # node-waf configuration 22 | .lock-wscript 23 | 24 | # Compiled binary addons (http://nodejs.org/api/addons.html) 25 | build/Release 26 | 27 | # Dependency directory 28 | # https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git 29 | node_modules 30 | 31 | #IDE Stuff 32 | **/.idea 33 | 34 | #OS STUFF 35 | .DS_Store 36 | .tmp 37 | 38 | #SERVERLESS STUFF 39 | *.env.yaml 40 | 41 | config.json 42 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # pokego-serverless 2 | 3 | ![Pokemon](https://upload.wikimedia.org/wikipedia/commons/f/f7/English_Pok%C3%A9mon_logo.svg) 4 | 5 | ## Overview 6 | 7 | Serverless-powered API to fetch nearby Pokemon Go data. Currently returns mapPokemon, nearbyPokemon and wildPokemon. 8 | 9 | Technologies used 10 | * [Serverless v1.0](https://github.com/serverless/serverless/tree/v1.0/) 11 | * [Poke.io](https://github.com/Armax/Pokemon-GO-node-api) 12 | * [Immutable](https://github.com/facebook/immutable-js/) 13 | 14 | ## Live Demo 15 | 16 | ![Live Demo](https://img.jch254.com/PokemonDemo.png) 17 | 18 | https://1kse7tu24a.execute-api.us-east-1.amazonaws.com/dev/nearby?lat=-12.462827&lon=130.841782&alt=27.8 19 | 20 | Adjust lat, lon and alt parameters as needed. 21 | 22 | Please note that live demo is rate-limited ;) 23 | 24 | ## Deploying to AWS 25 | 26 | 1. ```cp config.json_template config.json``` 27 | 2. Update config.json with your Pokemon Go account details 28 | 3. ```npm install -g serverless@alpha``` 29 | 4. ```npm install``` 30 | 5. ```cp serverless.env.yaml_template serverless.env.yaml``` 31 | 6. ```serverless deploy``` 32 | 33 | You will need to build/npm install against an Amazon Linux image on EC2 in order for the compiled node_modules to be usable on their Lambda service. See [here](https://aws.amazon.com/blogs/compute/nodejs-packages-in-lambda/) for more information. 34 | 35 | ## Good times! 36 | -------------------------------------------------------------------------------- /config.json_template: -------------------------------------------------------------------------------- 1 | { 2 | "provider": "google", 3 | "username": "yours@gmail.com", 4 | "password": "saveloy" 5 | } 6 | -------------------------------------------------------------------------------- /handler.js: -------------------------------------------------------------------------------- 1 | const Pokeio = require('pokemon-go-node-api'); 2 | const Immutable = require('immutable'); 3 | const config = require('./config.json'); 4 | 5 | const pokedex = new Immutable.Map(Pokeio.pokemonlist.map(p => [p.id, Immutable.fromJS(p)])); 6 | const locationType = 'coords'; 7 | 8 | module.exports.getPokegoNearby = (event, context, cb) => { 9 | const latitude = parseFloat(event.query.lat) || -37.867877; 10 | const longitude = parseFloat(event.query.lon) || 144.974005; 11 | const altitude = parseFloat(event.query.alt) || 5; 12 | const location = { 13 | type: locationType, 14 | coords: { 15 | latitude: latitude, 16 | longitude: longitude, 17 | altitude: altitude 18 | } 19 | }; 20 | 21 | Pokeio.init(config.username, config.password, location, config.provider, function(err) { 22 | if (err) { 23 | console.log(err); 24 | cb(err); 25 | } 26 | 27 | Pokeio.Heartbeat(function(err, heartbeat) { 28 | if (err) { 29 | console.log(err); 30 | cb(err); 31 | } 32 | 33 | const mapPokemon = new Immutable.Map( 34 | Immutable.fromJS(heartbeat.cells.map(cell => cell.MapPokemon)) 35 | .flatten() 36 | .map(p => [p.PokedexTypeId.toString(), Immutable.fromJS(Object.assign({}, p))]) 37 | ); 38 | 39 | const mapPokemonWithPokedexData = mapPokemon.mergeDeep(pokedex.filter((p, id) => mapPokemon.has(id))); 40 | 41 | const nearbyPokemon = new Immutable.Map( 42 | Immutable.fromJS(heartbeat.cells.map(cell => cell.NearbyPokemon)) 43 | .flatten() 44 | .map(p => [p.PokedexNumber.toString(), Immutable.fromJS(Object.assign({}, p))]) 45 | ); 46 | 47 | const nearbyPokemonWithPokedexData = nearbyPokemon.mergeDeep(pokedex.filter((p, id) => nearbyPokemon.has(id))); 48 | 49 | const wildPokemon = new Immutable.Map( 50 | Immutable.fromJS(heartbeat.cells.map(cell => cell.WildPokemon)) 51 | .flatten() 52 | .map(p => [p.pokemon.PokemonId.toString(), Immutable.fromJS(Object.assign({}, p))]) 53 | ); 54 | 55 | const wildPokemonWithPokedexData = wildPokemon.mergeDeep(pokedex.filter((p, id) => wildPokemon.has(id))); 56 | 57 | const response = { 58 | mapPokemon: mapPokemonWithPokedexData, 59 | nearbyPokemon: nearbyPokemonWithPokedexData, 60 | wildPokemon: wildPokemonWithPokedexData 61 | } 62 | 63 | cb(null, response); 64 | }); 65 | }); 66 | } 67 | 68 | module.exports.getPokegoNearbyRaw = (event, context, cb) => { 69 | const latitude = parseFloat(event.query.lat) || -37.867877; 70 | const longitude = parseFloat(event.query.lon) || 144.974005; 71 | const altitude = parseFloat(event.query.alt) || 5; 72 | const location = { 73 | type: locationType, 74 | coords: { 75 | latitude: latitude, 76 | longitude: longitude, 77 | altitude: altitude 78 | } 79 | }; 80 | 81 | Pokeio.init(username, key, location, provider, function(err) { 82 | if (err) { 83 | console.log(err); 84 | cb(err); 85 | } 86 | 87 | Pokeio.Heartbeat(function(err, hb) { 88 | if (err) { 89 | console.log(err); 90 | cb(err); 91 | } 92 | 93 | cb(null, hb); 94 | }); 95 | }); 96 | } 97 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "pokego-serverless", 3 | "version": "1.0.0", 4 | "description": "Serverless-powered Pokemon Go API", 5 | "author": "Jordan Hornblow", 6 | "license": "MIT", 7 | "dependencies": { 8 | "immutable": "^3.8.1", 9 | "pokemon-go-node-api": "^1.3.0" 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /serverless.env.yaml_template: -------------------------------------------------------------------------------- 1 | vars: null 2 | stages: 3 | dev: 4 | vars: null 5 | regions: 6 | us-east-1: 7 | vars: null 8 | -------------------------------------------------------------------------------- /serverless.yaml: -------------------------------------------------------------------------------- 1 | service: pokego-serverless 2 | provider: aws 3 | runtime: nodejs4.3 4 | defaults: 5 | stage: dev 6 | region: us-east-1 7 | memory: 512 8 | timeout: 60 9 | 10 | functions: 11 | getPokegoNearby: 12 | handler: handler.getPokegoNearby 13 | memory: 512 14 | timeout: 60 15 | events: 16 | - http: 17 | path: nearby 18 | method: get 19 | getPokegoNearbyRaw: 20 | handler: handler.getPokegoNearbyRaw 21 | memory: 512 22 | timeout: 60 23 | events: 24 | - http: 25 | path: nearbyraw 26 | method: get 27 | --------------------------------------------------------------------------------