poke-go-api 0.1.5 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c43516f50725cfda3be25e7cb083dc9a35a4561d
4
- data.tar.gz: a90012ee3e68fcd5b56ec7e8241b5a43acbd69ae
3
+ metadata.gz: 62e2737346452ed25a9d5d7844df4a7389fdbd31
4
+ data.tar.gz: b7695c8567f9e12971a8e2002f5e4962d4625802
5
5
  SHA512:
6
- metadata.gz: cc884ed1e40abf088e060386105d2e0efb38e3bc6da8c7edae696872a80038f864e43fed385c4ad42fe60285a1f6b5379581abdd9111c051d961b46c857b19c8
7
- data.tar.gz: 9193798106a73642003697ae4d48ca0fe0fd8f43d45199006506f5f8aa30b40039013d27fe2d0c1de24eda268320d4fdfca125cc661a4ce884b32f9060c3d8b7
6
+ metadata.gz: 507f26d5261a1a5257bb44c1d5c36755a825d33b1ee1ee82a00155a8596adeaec523ac77522ea053779711a4bb4e85ad8c4fd809e9a9c4175693328faba35a2a
7
+ data.tar.gz: a9554db26d2c2fce91d246d0dd1ff70d8009f4a2ec9b44c64f9caef53dfb4cf01a842abc4f38d28622f878abbc4d3e9a93b6a5c45ad0da0ec39148df56339f62
@@ -13,14 +13,16 @@ module Poke
13
13
  GOOGLE_LOGIN_APP = 'com.nianticlabs.pokemongo'.freeze
14
14
  GOOGLE_LOGIN_CLIENT_SIG = '321187995bc7cdc2b5fc91b11a96e2baa8602c62'.freeze
15
15
 
16
- def initialize(username, password)
17
- @username = username
18
- @password = password
19
- @provider = 'google'
20
- @expiry = 0
16
+ def initialize(username, password, refresh_token)
17
+ @refresh_token = refresh_token
18
+ @username = username
19
+ @password = password
20
+ @provider = 'google'
21
+ @expiry = 0
21
22
  end
22
23
 
23
24
  def connect
25
+ return access_token_from_refresh_token if @refresh_token
24
26
  logger.debug '[>] Fetching Google access token'
25
27
 
26
28
  token_request = perform_request('Token') do
@@ -38,6 +40,27 @@ module Poke
38
40
 
39
41
  private
40
42
 
43
+ def access_token_from_refresh_token
44
+ logger.info '[>] Fetching Google access token from refresh token'
45
+
46
+ body = {
47
+ grant_type: 'refresh_token',
48
+ redirect_uri: 'urn:ietf:wg:oauth:2.0:oob',
49
+ refresh_token: @refresh_token,
50
+ scope: 'email',
51
+ client_secret: 'NCjF1TLi2CcY6t5mt0ZveuL7',
52
+ client_id: '848232511240-73ri3t7plvk96pj4f85uj8otdat2alem.apps.googleusercontent.com',
53
+ }
54
+
55
+ resp = HTTPClient.new.post('https://accounts.google.com/o/oauth2/token', body).body
56
+ data = JSON.parse(resp)
57
+
58
+ @access_token = data['id_token']
59
+ @expiry = data['expires_in'].to_i + Helpers.fetch_time(ms: false)
60
+
61
+ raise 'Invalid refresh token' unless data['id_token']
62
+ end
63
+
41
64
  def perform_request(method)
42
65
  response = yield
43
66
 
@@ -14,7 +14,7 @@ module Poke
14
14
  PTC_LOGIN_OAUTH = 'https://sso.pokemon.com/sso/oauth2.0/accessToken'.freeze
15
15
  PTC_LOGIN_CLIENT_SECRET = 'w8ScCUXJQc6kXKw8FiOhd8Fixzht18Dq3PEVkUCP5ZPxtgyWsbTvWHFLm2wNY0JR'.freeze
16
16
 
17
- def initialize(username, password)
17
+ def initialize(username, password, _refresh_token)
18
18
  @username = username
19
19
  @password = password
20
20
  @provider = 'ptc'
@@ -2,36 +2,32 @@ module Poke
2
2
  module API
3
3
  class Client
4
4
  include Logging
5
- attr_accessor :lat, :lng, :alt, :endpoint, :ticket, :sig_loaded
6
- attr_reader :sig_path, :auth
5
+ attr_accessor :endpoint, :sig_loaded, :refresh_token,
6
+ :lat, :lng, :alt, :http_client, :ticket
7
+ attr_reader :sig_path, :auth
7
8
 
8
9
  def initialize
9
- @auth = nil
10
10
  @endpoint = 'https://pgorelease.nianticlabs.com/plfe/rpc'
11
11
  @reqs = []
12
12
  @lat = 0
13
13
  @lng = 0
14
- @alt = 8
14
+ @alt = rand(1..9)
15
15
  @ticket = Auth::Ticket.new
16
- @sig_path = nil
17
16
  @sig_loaded = false
18
17
  end
19
18
 
20
19
  def login(username, password, provider)
21
20
  @username, @password, @provider = username, password, provider.upcase
22
-
23
21
  raise Errors::InvalidProvider, provider unless %w(PTC GOOGLE).include?(@provider)
24
- logger.info "[+] Logging in user: #{username}"
25
22
 
26
23
  begin
27
- @auth = Auth.const_get(@provider).new(username, password)
24
+ @auth = Auth.const_get(@provider).new(@username, @password, @refresh_token)
28
25
  @auth.connect
29
26
  rescue StandardError => ex
30
27
  raise Errors::LoginFailure.new(@provider, ex)
31
28
  end
32
29
 
33
- get_hatched_eggs
34
- call
30
+ initialize_ticket
35
31
  logger.info "[+] Login with #{@provider} Successful"
36
32
  end
37
33
 
@@ -40,7 +36,7 @@ module Poke
40
36
  raise Errors::NoRequests if @reqs.empty?
41
37
 
42
38
  check_expiry
43
- req = RequestBuilder.new(@auth, [@lat, @lng, @alt], @endpoint)
39
+ req = RequestBuilder.new(@auth, [@lat, @lng, @alt], @endpoint, @http_client)
44
40
 
45
41
  begin
46
42
  resp = req.request(@reqs, self)
@@ -67,9 +63,8 @@ module Poke
67
63
  pos = Poke::API::Helpers.get_position(loc).first
68
64
  logger.info "[+] Given location: #{pos.address}"
69
65
 
70
- logger.info "[+] Lat/Long: #{pos.latitude}, #{pos.longitude}"
71
- @lat = pos.latitude
72
- @lng = pos.longitude
66
+ logger.info "[+] Lat/Long/Alt: #{pos.latitude}, #{pos.longitude}"
67
+ @lat, @lng = pos.latitude, pos.longitude
73
68
  end
74
69
 
75
70
  def store_lat_lng(lat, lng)
@@ -84,6 +79,11 @@ module Poke
84
79
 
85
80
  private
86
81
 
82
+ def initialize_ticket
83
+ get_hatched_eggs
84
+ call
85
+ end
86
+
87
87
  def check_expiry
88
88
  unless @ticket.has_ticket?
89
89
  now = Helpers.fetch_time(ms: false)
@@ -6,12 +6,12 @@ module Poke
6
6
  include Logging
7
7
  attr_reader :position, :start_time
8
8
 
9
- def initialize(auth, pos, endpoint)
9
+ def initialize(auth, pos, endpoint, http_client)
10
10
  @access_token = auth.access_token
11
11
  @provider = auth.provider
12
12
  @endpoint = endpoint
13
13
  @position = pos
14
- @client = HTTPClient.new(agent_name: 'PokeAPI/0.0.1')
14
+ @client = http_client ? http_client : HTTPClient.new
15
15
  @start_time = Helpers.fetch_time
16
16
  end
17
17
 
@@ -27,22 +27,22 @@ OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE
27
27
 
28
28
  #Poke::API::Logging.log_level = :DEBUG
29
29
  client = Poke::API::Client.new
30
- client.activate_signature('encrypt64bit.dll')
31
-
32
- client.store_location('New York')
33
- client.login('username', 'password', 'google')
30
+ #client.refresh_token = "1/QyOAeM7043LCkvyFfm61MXWV9UOBPutLwuLbjePhqPw"
31
+ client.activate_signature('C:\encrypt64bit.dll')
32
+ client.store_location('Glasgow')
33
+ client.login('sof2er@gmail.com', 'kidureallypwnme', 'google')
34
34
 
35
35
  client.get_player
36
36
  client.call
37
37
  #Get cells
38
- # cell_ids = Poke::API::Helpers.get_cells(client.lat, client.lng)
38
+ cell_ids = Poke::API::Helpers.get_cells(client.lat, client.lng)
39
39
 
40
- # # # Construct map objects call
41
- # client.get_map_objects(
42
- # latitude: client.lat,
43
- # longitude: client.lng,
44
- # since_timestamp_ms: [0] * cell_ids.length,
45
- # cell_id: cell_ids
46
- # )
40
+ # Construct map objects call
41
+ client.get_map_objects(
42
+ latitude: client.lat,
43
+ longitude: client.lng,
44
+ since_timestamp_ms: [0] * cell_ids.length,
45
+ cell_id: cell_ids
46
+ )
47
47
 
48
- # p client.call
48
+ p client.call
@@ -1,5 +1,5 @@
1
1
  module Poke
2
2
  module API
3
- VERSION = '0.1.5'.freeze
3
+ VERSION = '0.1.7'.freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: poke-go-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nabeel Amjad
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-08-09 00:00:00.000000000 Z
11
+ date: 2016-08-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httpclient