GithubHelp home page GithubHelp logo

poke-api's Introduction

Gem Version Code Climate Issue Count

Poke API - A Ruby API gem for Pokémon GO.

Poke API is a port for Ruby from pgoapi and also allows for any automatic parsing of a requests and responses.

  • Unofficial, please use at your own RISK.
  • Use a throwaway account if possible.

Features

  • Supports new SIGNATURE generation!
  • Allows you to set optional signature information for every request (:android_gps_info, :sensor_info, :device_info,:activity_status and :location_fix)
  • Proxy support!
  • Automatic access token/ticket refresh upon expiry!
  • S2 Geometry cells are now supported (natively)!
  • PTC & Google Authentication supported (use full e-mail address for Google)
  • Google refresh token support
  • Parses geolocation using Geocoder (parses addresses, postcodes, ip addresses, lat/long, etc)
  • Ability to chain requests and receive response in a single call
  • Logger available, you can also specify your own log formatter and/or log level
  • Lots of RPC calls, they are listed under lib/poke-api/pogoprotos/pogoprotos_networking_requests.rb

Installation

You can use bundler and refer directly to this repository

gem 'poke-go-api',
    git: "https://github.com/nabeelamjad/poke-api.git",
    tag: '0.2.1'

Or, alternatively you can download the repository and run gem build poke-api.gemspec followed with gem install poke-api-0.2.1.gem

The gem is also available by using gem install poke-go-api (poke-api was taken as a name already).

NOTE - This gem relies on header files for Ruby to install the google-protobuf gem.

  • Windows: You will need the Ruby DevKit applied to your Ruby, please see RubyInstaller
  • Linux:
    • Debian based: sudo apt-get install ruby-dev
    • RPM based: sudo yum install ruby-devel
    • SuSe based: sudo zypper install ruby-devel

Example Usage

Running provided example.rb with your own credentials

2016-08-09T02:54:03+01:00]: INFO  > Poke::API::Client         --: [+] Given location: New York, NY, USA
2016-08-09T02:54:03+01:00]: INFO  > Poke::API::Client         --: [+] Lat/Long: 40.7127837, -74.0059413
2016-08-09T02:54:06+01:00]: INFO  > Poke::API::Client         --: [+] Provider access token is valid for 03:00:00
2016-08-09T02:54:06+01:00]: INFO  > Poke::API::RequestBuilder --: [+] Adding 'GET_HATCHED_EGGS' to RPC request
2016-08-09T02:54:06+01:00]: INFO  > Poke::API::RequestBuilder --: [+] Using provider access token
2016-08-09T02:54:06+01:00]: INFO  > Poke::API::RequestBuilder --: [+] Executing RPC request
2016-08-09T02:54:06+01:00]: INFO  > Poke::API::Response       --: [+] Decoding Main RPC responses
2016-08-09T02:54:06+01:00]: INFO  > Poke::API::Response       --: [+] Using auth ticket instead
2016-08-09T02:54:06+01:00]: INFO  > Poke::API::Response       --: [+] Decoding Sub RPC responses
2016-08-09T02:54:06+01:00]: INFO  > Poke::API::Client         --: [+] Cleaning up RPC requests
2016-08-09T02:54:06+01:00]: INFO  > Poke::API::Client         --: [+] Login with PTC Successful
2016-08-09T02:54:06+01:00]: INFO  > Poke::API::Client         --: [+] File <<signature>> has been set for signature generation
2016-08-09T02:54:06+01:00]: INFO  > Poke::API::RequestBuilder --: [+] Adding 'GET_MAP_OBJECTS' to RPC request with ar ents
2016-08-09T02:54:06+01:00]: INFO  > Poke::API::RequestBuilder --: [+] Adding 'GET_PLAYER' to RPC request
2016-08-09T02:54:06+01:00]: INFO  > Poke::API::RequestBuilder --: [+] Adding 'GET_INVENTORY' to RPC request
2016-08-09T02:54:06+01:00]: INFO  > Poke::API::Auth::Ticket   --: [+] Auth ticket is valid for 00:30:01
2016-08-09T02:54:06+01:00]: INFO  > Poke::API::Signature      --: [+] Loaded Signature module
2016-08-09T02:54:06+01:00]: INFO  > Poke::API::RequestBuilder --: [+] Executing RPC request
2016-08-09T02:54:06+01:00]: INFO  > Poke::API::Response       --: [+] Decoding Main RPC responses
2016-08-09T02:54:06+01:00]: INFO  > Poke::API::Response       --: [+] Decoding Sub RPC responses
2016-08-09T02:54:07+01:00]: INFO  > Poke::API::Client         --: [+] Cleaning up RPC requests
<Poke::API::Response:0x000000032f96a0
@request=
 [{:GET_MAP_OBJECTS=>
    {:latitude=>40.7127837,
     :longitude=>-74.0059413,
     :since_timestamp_ms=>
      [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
     :cell_id=>
      [9926595610352287744,
       9926595612499771392,
       9926595614647255040,
       9926595616794738688,
       9926595618942222336,
       9926595621089705984,
       9926595623237189632,
       9926595625384673280,
       9926595627532156928,
       9926595629679640576,
       9926595631827124224,
       9926595633974607872,
       9926595636122091520,
       9926595638269575168,
       9926595640417058816,
       9926595642564542464,
       9926595644712026112,
       9926595646859509760,
       9926595649006993408,
       9926595651154477056,
       9926595653301960704]}},
  :GET_PLAYER,
  :GET_INVENTORY],
@response=
 {:GET_MAP_OBJECTS=>
   {:map_cells=>
     [{:s2_cell_id=>9926595631827124224,
       :current_timestamp_ms=>1470707648730,
       :forts=>
        [{:id=>"44a31b1c990547f49537ca74617bf557.12",
          :last_modified_timestamp_ms=>1470707647002,
          :latitude=>40.712891,
          :longitude=>-74.004869,
          :owned_by_team=>:BLUE,
          :guard_pokemon_id=>:GYARADOS,
          :guard_pokemon_cp=>0,
          :enabled=>true,
          :type=>:GYM,
          :gym_points=>1604,
          :is_in_battle=>true,
          :active_fort_modifier=>"",
          :lure_info=>nil,
          :cooldown_complete_timestamp_ms=>0,
          :sponsor=>:UNSET_SPONSOR,
          :rendering_type=>:DEFAULT},
          ...

RPC call requests and responses

An RPC request can be made on its own or with multiple calls, it also provides the ability to specify arguments. You can find all the supported requests in lib/poke-api/pogoprotos/pogoprotos_networking_requests.rb. Please note that you will need to check if any of these requests require arguments, these can be found in lib/poke-api/pogoprotos/pogoprotos_networking_requests_messages.rb using the same naming convention.

Let's assume we want to delete a few great balls from our inventory
If you open Requests we can see that there's an entry for :RECYCLE_INVENTORY_ITEM. We now know that our call is recycle_inventory_item, next we have to find out if there're any arguments to this call. We can find any possible arguments inside Messages for our call. This shows two argments: item_id and count. Furthermore we can see that item_id directly links to POGOProtos.Inventory.Item.ItemId, this is a file you can open as well with the item ids specified inside. In here we can see the Item ID for a great ball is 2.

Our example request could be as follows:

require 'poke-api'

# Instantiate our client
client = Poke::API::Client.new

# Both PTC/Google available as authentication provider
client.store_location('New York')
client.login('[email protected]', 'password', 'google')

# Activate the encryption method to generate a signature (only required for map objects)
client.activate_signature('/path/to/encrypt/file')

# Add RPC calls
client.recycle_inventory_item(item_id: 2, count: 2)

# You can inspect the client before performing the call
puts client.inspect
=> #<Poke::API::Client @auth=#<Poke::API::Auth::GOOGLE> @reqs=[{:RECYCLE_INVENTORY_ITEM=>{:item_id=>2, :count=>2}}] @lat=4630926632231391130 @lng=13858280158942612615 @alt=0>

# Perform your RPC call
call = client.call

# A <Poke::API::Response> object is returned and decorated with your request and response in a Hash format
# Request
puts call.request.inspect
[
  {
    :RECYCLE_INVENTORY_ITEM => {
      :item_id=>2,
      :count=>2
    }
  }
]

# Response
puts call.response.inspect
{
  :RECYCLE_INVENTORY_ITEM = >{
    :result=>:SUCCESS, 
    :new_count=>14
  },
  :status_code => 1,
  :api_url => "",
  :error => ""
}

Optional Signature Information

You can specify :android_gps_info, :sensor_info, :device_info,:activity_status and :location_fix for every request that is made. Here's an example how this is possible:

require 'poke-api'

client = Poke::API::Client.new
client.activate_signature('/path/to/encrypt/file')
client.store_location('New York')
client.login('username', 'password', 'ptc')

# Set your optional requests here
client.location_fix = {provider: 'foo'}
client.android_gps_info = {satellites_prn: [1]}
client.sensor_info = {magnetometer_x: 1.2}
client.device_info = {device_model: 'some-device'}
client.activity_status = {cycling: false}

cell_ids = Poke::API::Helpers.get_cells(client.lat, client.lng)

client.get_map_objects(
  latitude: client.lat,
  longitude: client.lng,
  since_timestamp_ms: [0] * cell_ids.length,
  cell_id: cell_ids
)

client.call

Please refer to networking_envelopes for more information as to which arguments are supported.

Google Refresh Token

A Google refresh token can be set on Poke::API::Client, this token will automatically be used first to generate an access token if available. You do not need to pass in any username or password if you provide a refresh token. To support backwards compatibility you will still have to call client.login('', '', 'google'), however, you can leave the username and password as blank strings instead.

require 'poke-api'

client = Poke::API::Client.new
client.refresh_token = 'my-refresh-token'
client.login('', '', 'google')

In a future revamp release the login method will change to accept keyword arguments such as client.login(provider: 'google') allowing you to ignore the rest.

To generate a Google refresh token please have a look at this issue, a refresh token will last indefinitely.

Proxy support

If you wish to use a proxy then you can do so by providing your own HTTPClient instantation with your preferred setup to Poke::API::Client using http_client setter/getter.

require 'poke-api'

client = Poke::API::Client.new
client.http_client = HTTPClient.new('http://localhost:8080')
client.http_client.set_proxy_auth(user, password)
...
# Proceed as normal

Logger settings

If you wish to change the log level you can do so before instantiating the client by using Poke::API::Logging.log_level = :INFO where :INFO is the desired level, possible values are: :DEBUG, :INFO, :WARN, :FATAL and UNKNOWN

The log formatter format can also be customised, a default one is provided. You can provide a proc to Poke::API::Logging.formatter to change it. More information can be found at Class#Logger

Example:

require 'poke-api'

# Use :DEBUG for extra verbosity if required to troubleshoot
Poke::API::Logging.log_level = :DEBUG
Poke::API::Logging.formatter = proc do |severity, datetime, progname, msg|
  "My custom logger - #{msg}\n"
end

client = Poke::API::Client.new
client.store_location('London')
#=> My custom logger - [+] Given location: London, UK
#=> My custom logger - [+] Lat/Long: 51.5073509, -0.1277583

Generating S2 Cell Ids

You can use this helper method to generate cells, please note that not all S2 Geometry calls are supported as this has been ported over to native Ruby (without binding). Available instance methods on a S2CellId are parent, level, next and prev.

Example Usage

require 'poke-api'

client = Poke::API::Client.new
client.store_location('New York')

[2016-08-09T02:52:10+01:00]: INFO  > Poke::API::Client         --: [+] Given location: New York, NY, USA
[2016-08-09T02:52:10+01:00]: INFO  > Poke::API::Client         --: [+] Lat/Long: 40.7127837, -74.0059413

Poke::API::Helpers.get_cells(client.lat, client.lng)
=> [9926595610352287744, 9926595612499771392, 9926595614647255040,
    9926595616794738688, 9926595618942222336, 9926595621089705984,
    9926595623237189632, 9926595625384673280, 9926595627532156928, 
    9926595629679640576, 9926595631827124224, 9926595633974607872, 
    9926595636122091520, 9926595638269575168, 9926595640417058816, 
    9926595642564542464, 9926595644712026112, 9926595646859509760, 
    9926595649006993408, 9926595651154477056, 9926595653301960704]

Contribution

Any contributions are most welcome, I don't have much time to spend on this project so I appreciate everything.

Credits

tejado - Pretty much everything as this repository is a direct 'conversion' to the best of my ability
AeonLucid - Protobufs
xssc - GPSOauth (Google Login)

poke-api's People

Contributors

diemer avatar dphuang2 avatar emcmanus avatar ggmichaelgo avatar nabeelamjad avatar penchef avatar xssc avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

poke-api's Issues

Adding proxy support to HTTPClient

Since Niantic is now blocking calls from major cloud services through IP detection - is there anyway we would implement the use of a proxy for HTTPClient ?

It could work this way:

client.store_proxy(url, user, pass)

And

def initialize(auth, pos, endpoint, proxy=nil, proxy_user=nil, proxy_password=nil)
  @access_token = auth.access_token
  @provider     = auth.provider
  @endpoint     = endpoint
  @position     = pos
  @client       = HTTPClient.new(proxy)
  @client.set_proxy_auth(user, password)
  @client.header["User-Agent"] = 'PokeAPI/0.0.1'
  @start_time   = (Time.now.to_f * 1000).to_i
end

https://github.com/nabeelamjad/poke-api/blob/master/lib/poke-api/request_builder.rb

Obtaining cell_ids

Hello, can you say how did you generated cell_id in the exmaple.rb ? And what cell_id we need?

Does not re-set api_url

Sometimes when a status is unsuccessful, it will return a code of 53 and a new api url. Can you add a method that checks for this and updates @endpoint accordingly. example response:

{:GET_PLAYER=>{:success=>false, :player_data=>nil}, :status_code=>53, :api_url=>"pgorelease.nianticlabs.com/plfe/327", :error=>""}

Locating pokestops

  lat = some_lat_here
  lng = some_lng_here

  client.store_lat_lng(lat, lng)

  cell_ids = Poke::API::Helpers.get_cells(lat, lng)

  client.get_map_objects(
    latitude: client.lat,
    longitude: client.lng,
    since_timestamp_ms: [0] * cell_ids.length,
    cell_id: cell_ids
  )

  resp = client.call
  puts resp.response[:GET_MAP_OBJECTS][:map_cells]

The following puts returns objects. In forts, I do see some results. But I dont see any indication of any pokestops. Does get_map_objects support this, at this time?

Heroku deployment login issue

Logging in with the API locally on my computer yields no errors. But when I try to use it on Heroku's servers I get this error.

Loading production environment (Rails 5.0.0)
irb(main):001:0> client = Poke::API::Client.new
=> #<Poke::API::Client @auth= @reqs=[] @lat=0 @lng=0 @alt=0>
irb(main):002:0> client.login("xxx","xxx","ptc")
[2016-07-31T04:49:03+00:00]: INFO  > Poke::API::Client         --: [+] Logging in user: xxx
[2016-07-31T04:49:04+00:00]: INFO  > Poke::API::Client         --: [+] Login with PTC Successful
[2016-07-31T04:49:04+00:00]: INFO  > Poke::API::RequestBuilder --: [+] Adding 'GET_PLAYER' to RPC request
[2016-07-31T04:49:04+00:00]: INFO  > Poke::API::RequestBuilder --: [+] Adding 'GET_HATCHED_EGGS' to RPC request
[2016-07-31T04:49:04+00:00]: INFO  > Poke::API::RequestBuilder --: [+] Adding 'GET_INVENTORY' to RPC request
[2016-07-31T04:49:04+00:00]: INFO  > Poke::API::RequestBuilder --: [+] Adding 'CHECK_AWARDED_BADGES' to RPC request
[2016-07-31T04:49:04+00:00]: INFO  > Poke::API::RequestBuilder --: [+] Adding 'DOWNLOAD_SETTINGS' to RPC request with arguments
[2016-07-31T04:49:04+00:00]: INFO  > Poke::API::RequestBuilder --: [+] Executing RPC request
[2016-07-31T04:49:04+00:00]: INFO  > Poke::API::Response       --: [+] Decoding Main RPC responses
[2016-07-31T04:49:04+00:00]: INFO  > Poke::API::Client         --: [+] Cleaning up RPC requests
Poke::API::Errors::UnknownProtoFault: An unknown proto fault has occured => [Error occurred during parsing: Unmatched ENDGROUP tag. @ /app/vendor/bundle/ruby/2.2.0/bundler/gems/poke-api-85ee2d01f869/lib/poke-api/response.rb:14:in `decode']
    from /app/vendor/bundle/ruby/2.2.0/bundler/gems/poke-api-85ee2d01f869/lib/poke-api/client.rb:39:in `rescue in call'
    from /app/vendor/bundle/ruby/2.2.0/bundler/gems/poke-api-85ee2d01f869/lib/poke-api/client.rb:43:in `call'
    from /app/vendor/bundle/ruby/2.2.0/bundler/gems/poke-api-85ee2d01f869/lib/poke-api/client.rb:70:in `fetch_endpoint'
    from /app/vendor/bundle/ruby/2.2.0/bundler/gems/poke-api-85ee2d01f869/lib/poke-api/client.rb:29:in `login'
    from (irb):2
    from /app/vendor/bundle/ruby/2.2.0/gems/railties-5.0.0/lib/rails/commands/console.rb:65:in `start'
    from /app/vendor/bundle/ruby/2.2.0/gems/railties-5.0.0/lib/rails/commands/console_helper.rb:9:in `start'
    from /app/vendor/bundle/ruby/2.2.0/gems/railties-5.0.0/lib/rails/commands/commands_tasks.rb:78:in `console'
    from /app/vendor/bundle/ruby/2.2.0/gems/railties-5.0.0/lib/rails/commands/commands_tasks.rb:49:in `run_command!'
    from /app/vendor/bundle/ruby/2.2.0/gems/railties-5.0.0/lib/rails/commands.rb:18:in `<top (required)>'
    from bin/rails:9:in `require'
    from bin/rails:9:in `<main>'
irb(main):003:0>

To replicate this error you have to make a Rails project and client.login through Heroku console (accessed by "heroku run console"). I don't know if this is a problem with the API, my development environment, or with heroku itself. But I have tried to figure this out for a while and have gotten nowhere. If anyone has any insight to Rails deployment to Heroku and possible culprits that would be great.

I am using Ruby 2.2.4 and Rails 5.0 and have tried deploying with Ruby 2.2.4 to no avail.

Not all protos files are required

I think you need to require all the Protos files.

It's impossible to retrieve the ID of a Pokemon for example (you get :RATTATA, and the POGOProtos.Enums.PokemonId is required to retrieve the pokedex index of the pokemon)

store_location needed?

Hi,

is store_location needed? It's in all your examples but I am just wondering if it is required/expected or if I can simply skip it?

Thanks!!

S2 geometry library porting

@nabeelamjad
The S2 geometry cells which are natively implemented in ruby will be very helpful in my project. The Lat-Long to cell id conversion code is ported from the S2 Geometry library. But the cell id to lat-long conversion is not available in this gem.
Can you help me to port the rest of the library? And guide me with the required resources for porting the library?

Encryption

Hey

What is encryption file and how i can get it?

undefined method `to_h' for [["error", "invalid_grant"]]:Array

Poke::API::Errors::LoginFailure: Unable to login to PTC => [undefined method to_h' for [["error", "invalid_grant"]]:Array @ /Users/user/.rbenv/versions/2.0.0-p645/lib/ruby/gems/2.0.0/bundler/gems/poke-api-fd27b2c9834f/lib/poke-api/auth/ptc.rb:65:infetch_access_token']
from /Users/user/.rbenv/versions/2.0.0-p645/lib/ruby/gems/2.0.0/bundler/gems/poke-api-fd27b2c9834f/lib/poke-api/client.rb:27:in rescue in login' from /Users/user/.rbenv/versions/2.0.0-p645/lib/ruby/gems/2.0.0/bundler/gems/poke-api-fd27b2c9834f/lib/poke-api/client.rb:23:inlogin'

An unknown proto fault has occured => [Expected number type for integral field. ... poke-api/request_builder.rb:90:in `initialize']

Hello again,

I have tried to integrate the "release_pokemon" RPC call. The output of inspect is the following:

#<Poke::API::Client @auth=#<Poke::API::Auth::GOOGLE:0x007fef17898088> @reqs=[{:RELEASE_POKEMON=>{:pokemon_id=>"1234567890"}}] @lat=0 @lng=0 @alt=0>

(I changed the pokemon_id)

The error is the following:

Poke::API::Errors::UnknownProtoFault (An unknown proto fault has occured => [Expected number type for integral field. @ /xxx/ruby-2.3.0/bundler/gems/poke-api-3223d8bf915b/lib/poke-api/request_builder.rb:90:in initialize']): app/controllers/pokemon_controller.rb:18:intransfer'

Line 18 is simply the call = client.call call.

I am not sure if I used the correct pokemon id, I guessed that this is the id I get from the regular get_inventory call. Is this correct or where do I get the pokemon id from?

Thanks for any help!

Is there any way to do sign in through Google Authentication rather than through the API?

Edit for Clarification:

is it possible to do authentication with Google rather than the API.
For example:

  1. Redirect a user to the google sign in page and retrieve an access token there
  2. Using that access token retrieve the endpoint for the API
  3. Continue to make requests as needed from there.

The purpose of this is to allow for a more secure login rather than inputting your username and password into the API.

Revamp README into a proper Wiki

It's getting slightly out of hand, will need to (time permitting) use Github's wiki and provide a proper documentation on what can and can not be done in their own section without cluttering everything.

EvolvePokemon is not working

I have the error

Poke::API::Errors::UnknownProtoFault - An unknown proto fault has occured => [uninitialized constant RpcSub::EvolvePokemonRequest

403

Hi @nabeelamjad, any idea what Poke::API::Errors::ForbiddenAccess - Your host is unable to receive a response as it is banned. means/how it can be fixed?

Where does this stuff come from?

Hi there!

first of all thanks for your work.

I just have a simple question, I am currently stuck at understanding where the stuff from the fetch_endpoint method comes from:

get_player
get_hatched_eggs
get_inventory
check_awarded_badges
download_settings(hash: '4a2e9bc330dae60e7b74fc85b98868ab4700802e')

Where does it come from, what is it calling?

Thanks for any answer!

Niklas

Dropping inventory items

I'm trying to do an api call that drops items from the inventory, I've used get_inventory and then filtered the items that I want to drop, then I created a call like this

client.recycle_inventory_item(201, 10)
client.call

but then I get this error

Poke::API::Errors::UnknownProtoFault: An unknown proto fault has occured => [uninitialized constant RpcSub::RecycleInventoryItemRequest @ /[gem_path]/gems/poke-api-0.0.2/lib/poke-api/request_builder.rb:87:in `fetch_proto_request_class']

Is this because the RpcSub needs to map all requests, or am I doing something wrong?

Getting unknown type: size_t input_size

Currently getting:

/Users/foo/.rbenv/versions/2.2.5/lib/ruby/gems/2.2.0/gems/poke-go-api-0.1.7/lib/poke-api/client.rb:44:in `rescue in call': An unknown proto fault has occured => [unknown type: size_t input_size @ /Users/foo/.rbenv/versions/2.2.5/lib/ruby/2.2.0/fiddle/cparser.rb:171:in `parse_ctype'] (Poke::API::Errors::UnknownProtoFault)
        from /Users/foo/.rbenv/versions/2.2.5/lib/ruby/gems/2.2.0/gems/poke-go-api-0.1.7/lib/poke-api/client.rb:48:in `call'

This just suddenly appeared. Im guessing due to PoGo API update?

gpsoauth is not compatible with ruby 2.0.0

I know that it's old as my grandma ass but that's my hosting platform and can't change it. Can we do something about it? Do I have to make a pull request in gpsoauth reverting compatibility? I don't want to use Google Login....

Trying to understand fetch_ticket

I am trying to understand this (https://github.com/nabeelamjad/poke-api/blob/master/lib/poke-api/auth/ptc.rb):

        def fetch_ticket(data)
          logger.debug '[>] Fetching PTC ticket'

          ticket = begin
            @client.post_content(PTC_LOGIN_URL, data)
          rescue StandardError => ex
            ex.res.http_header.request_uri.to_s.match(/ticket=(.*)/)[1]
          end

          fetch_access_token(ticket)
        end

I'm tried running the code individually. It seems httpclient lib fails unexpectedly, thats why you need the begin block there. The ticket is used to generate the access token on the next method.

Doing the same thing on httparty (another http gem), doesnt render any errors:

Take for example:

JSON.parse(
  HTTParty.post(
    ptc_login_url,
    headers: {
      'agent_name' => 'PokeAPI/0.0.1'
    },
    body: {
      data: {
        username: 'some_username',
        password: 'password',
        _eventId: 'submit',
        lt: json_response['lt'],
        execution: json_response['execution']
      }
    }
  )
)

However, the response I get instead is {"lt"=>"LT-23868518-ohkebxUhorQIFc11V3441qrSMOhFdF", "execution"=>"e1s1"}

Instead of what you currently need for the ticket: ST-7486015-NGPOWEQLoxc2mJM4flun-sso.pokemon.com

Am I missing something with the HTTParty approach?

Issue with google login

I keep getting this issue when logging in with google:

INFO > Poke::API::Client --: [+] Logging in user: [email protected]
Poke::API::Errors::LoginFailure: Unable to login to GOOGLE => [undefined method split' for :"user-agent":Symbol @ /Users/xxx/.rvm/rubies/ruby-2.2.4/lib/ruby/2.2.0/net/http/header.rb:172:incapitalize']

To recreate:
client = Poke::API::Client.new
client.login("[email protected]","password","google")

get_map_objects always returns with empty pokemon arrays

Not sure if I am getting this.

I do something like:

require 'poke-api'
require 'awesome_print'

# Instantiate our client
client = Poke::API::Client.new

# Both PTC/Google available as authentication provider
client.store_location('New York')
client.store_lat_lng(40.712906, -74.007333) # Some random coordinates from NY (pulled from Google Maps)

client.login('some_username', 'password_here', 'ptc')

cell_ids = Poke::API::Helpers.get_cells(client.lat, client.lng)

# Construct map objects call
client.get_map_objects(
  latitude: client.lat,
  longitude: client.lng,
  since_timestamp_ms: [0] * cell_ids.length,
  cell_id: cell_ids
)

resp = client.call

puts resp.response

All I get are responses with no results:

            [ 0] {
                            :s2_cell_id => some_cell_id_here,
                  :current_timestamp_ms => 1470811515476,
                                 :forts => [],
                          :spawn_points => [],
                         :wild_pokemons => [],
                       :deleted_objects => [],
                     :is_truncated_list => false,
                        :fort_summaries => [],
                :decimated_spawn_points => [],
                    :catchable_pokemons => [],
                       :nearby_pokemons => []
            },

As in wild_pokemons, catchable_pokemons and nearby_pokemons always returns with an empty array []. Is there something I am missing?

syntax error in gpsoauth

Hi! I have a problem running the program because of the syntax error in gpsoauth. I'm trying to log in with google account.
The error looks like below. Do you know how to fix this problem? Thanks in adv.

/Library/Ruby/Gems/2.0.0/gems/gpsoauth-rb-0.1.2/lib/gpsoauth.rb:26: syntax error, unexpected ':', expecting => (SyntaxError)
'accountType': 'HOSTED_OR_GOOGLE',
^
/Library/Ruby/Gems/2.0.0/gems/gpsoauth-rb-0.1.2/lib/gpsoauth.rb:26: syntax error, unexpected ',', expecting keyword_end
/Library/Ruby/Gems/2.0.0/gems/gpsoauth-rb-0.1.2/lib/gpsoauth.rb:27: syntax error, unexpected ':', expecting keyword_end
'Email': email,
^
/Library/Ruby/Gems/2.0.0/gems/gpsoauth-rb-0.1.2/lib/gpsoauth.rb:28: syntax error, unexpected ':', expecting :: or '[' or '.'
'has_permission': 1,
^

re-login fails repeatedly

I am creating an instance of Poke::API::Client and logging in, if it fails, and I try to re-log in, it fails continuously unless I create a new instance, I would try to help further but I had no luck getting it to fail when I turn logs to debug (tried for like 15 mins)

wrong S2 cell ID for given latitude and longitude

(main)> require 'poke-api'
=> true
(main)> lat = -23.59260639636282
=> -23.59260639636282
(main)> lng = -46.680191904206524
=> -46.680191904206524
(main)> Poke::API::Helpers.get_cells(lat, lng)
=> [
    [ 0] 10722603741376151552,
    [ 1] 10722603743523635200,
    [ 2] 10722603745671118848,
    [ 3] 10722603747818602496,
    [ 4] 10722603749966086144,
    [ 5] 10722603752113569792,
    [ 6] 10722603754261053440,
    [ 7] 10722603756408537088,
    [ 8] 10722603758556020736,
    [ 9] 10722603760703504384,
    [10] 10722603762850988032,
    [11] 10722603764998471680,
    [12] 10722603767145955328,
    [13] 10722603769293438976,
    [14] 10722603771440922624,
    [15] 10722603773588406272,
    [16] 10722603775735889920,
    [17] 10722603777883373568,
    [18] 10722603780030857216,
    [19] 10722603782178340864,
    [20] 10722603784325824512
]

which does not contain the S2 Cell ID 10722603763924729856, whose center is lat, lng.

Contrast this with sidewalklabs/s2sphere: Python implementation of the S2 geometry library:

>>> import s2sphere
>>> lat = -23.59260639636282
>>> lng = -46.680191904206524
>>> cell = s2sphere.Cell.from_lat_lng(s2sphere.LatLng.from_degrees(lat, lng))
>>> cell.id().parent(12).id()
10722603763924729856

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.