poke-go-api 0.0.7 → 0.0.8

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: edcbf91a753d6de2dca22476e90170a4b7a5eede
4
- data.tar.gz: a37f12e9e92a30701e2854bd8f9c895264611278
3
+ metadata.gz: f8a4ee180cf34ffc94cebb3b8bb6528b17d19382
4
+ data.tar.gz: b4fd14e947d0427c1ef50784525d3086b6e8fa8e
5
5
  SHA512:
6
- metadata.gz: 6140ba8ffa02732f18497a42d5e09d7c4355f67a6a02700d6814cbf88a673a15bd267c96b2a783b7256e12884f2b77f7801a0d5b2bc8f835f5d5878a247f3afe
7
- data.tar.gz: 9363b5ccf97b224f322f723e70d7f948ae229c44cb45abda08a63e89ffb70954db88de657ebf6948bdfe49dd3ac08d359640defdda79500fe56ba310ffa568d1
6
+ metadata.gz: a9a59b5cc9518cdf34390f1128771490bb382e67d57ae55c69235f4859043f2bb8074195375164a9a628e80b29b36e8ebc26dc1988bd3f148e4873c0a14959bd
7
+ data.tar.gz: ef2d410e34aafa7fb3d1b5f3f85b83e82b22bdf5823177f218b7c84d3f1e5b773f389e4be747c5779944768408a2575acfcbcfad873b5a75795fa09633f6071c
@@ -2,7 +2,7 @@ module Poke
2
2
  module API
3
3
  class Client
4
4
  include Logging
5
- attr_accessor :lat, :lng, :alt
5
+ attr_accessor :lat, :lng, :alt, :endpoint
6
6
 
7
7
  def initialize
8
8
  @auth = nil
@@ -34,7 +34,7 @@ module Poke
34
34
  req = RequestBuilder.new(@auth, [@lat, @lng, @alt], @endpoint)
35
35
 
36
36
  begin
37
- resp = req.request(@reqs)
37
+ resp = req.request(@reqs, self)
38
38
  rescue StandardError => ex
39
39
  raise Errors::UnknownProtoFault, ex
40
40
  ensure
@@ -74,15 +74,7 @@ module Poke
74
74
  check_awarded_badges
75
75
  download_settings(hash: '4a2e9bc330dae60e7b74fc85b98868ab4700802e')
76
76
 
77
- resp = call.response
78
-
79
- if !resp[:api_url] && resp[:api_url].empty?
80
- logger.debug '[+] Login failed, please try again'
81
- return
82
- end
83
-
84
- @endpoint = "https://#{resp[:api_url]}/rpc"
85
- logger.debug "[+] Setting endpoint to #{@endpoint}"
77
+ call
86
78
  end
87
79
 
88
80
  def method_missing(method, *args)
@@ -42,6 +42,12 @@ module Poke
42
42
  super("Unable to login to #{provider} => [#{error} @ #{error.backtrace.first}]")
43
43
  end
44
44
  end
45
+
46
+ class InvalidEndpoint < StandardError
47
+ def initialize
48
+ super("Unable to fetch endpoint, please try to login again.")
49
+ end
50
+ end
45
51
  end
46
52
  end
47
53
  end
@@ -11,7 +11,7 @@ module Poke
11
11
  @client = HTTPClient.new(agent_name: 'PokeAPI/0.0.1')
12
12
  end
13
13
 
14
- def request(reqs)
14
+ def request(reqs, client)
15
15
  logger.debug '[+] Creating new request'
16
16
  request_proto = build_main_request(reqs)
17
17
 
@@ -19,7 +19,7 @@ module Poke
19
19
  resp = execute_rpc_request(request_proto)
20
20
 
21
21
  resp = Response.new(resp.body, reqs)
22
- resp.decode_response
22
+ resp.decode_response(client)
23
23
 
24
24
  resp
25
25
  end
@@ -29,8 +29,8 @@ module Poke
29
29
  def build_main_request(sub_reqs)
30
30
  request_envelope = POGOProtos::Networking::Envelopes::RequestEnvelope
31
31
  req = request_envelope.new(
32
- status_code: 2,
33
- request_id: 814_580_613_288_820_746_0,
32
+ status_code: 2,
33
+ request_id: 814_580_613_288_820_746_0,
34
34
  unknown12: 989
35
35
  )
36
36
  req.latitude, req.longitude, req.altitude = @position
@@ -51,7 +51,7 @@ module Poke
51
51
  elsif sub_req.is_a?(Hash)
52
52
  append_hash_request(req, sub_req)
53
53
  else
54
- raise Errors::InvalidRequestEntry.new(sub_req)
54
+ raise Errors::InvalidRequestEntry, sub_req
55
55
  end
56
56
  end
57
57
  end
@@ -9,13 +9,14 @@ module Poke
9
9
  @request = request
10
10
  end
11
11
 
12
- def decode_response
12
+ def decode_response(client)
13
13
  logger.info '[+] Decoding Main RPC responses'
14
+ logger.debug "[+] RPC response \r\n#{@response.inspect}"
15
+
14
16
  @response = POGOProtos::Networking::Envelopes::ResponseEnvelope.decode(@response)
17
+ logger.debug "[+] Decoded RPC response \r\n#{@response.inspect}"
15
18
 
16
- logger.debug "[+] Decoding RPC response \r\n#{@response.inspect}"
17
19
  logger.info '[+] Decoding Sub RPC responses'
18
-
19
20
  decoded_resp = parse_rpc_fields(decode_sub_responses)
20
21
 
21
22
  loop do
@@ -23,6 +24,7 @@ module Poke
23
24
  parse_rpc_fields(decoded_resp)
24
25
  end
25
26
 
27
+ store_endpoint(client)
26
28
  decoded_resp.merge!(status_code: @response.status_code,
27
29
  api_url: @response.api_url, error: @response.error)
28
30
 
@@ -32,28 +34,43 @@ module Poke
32
34
 
33
35
  private
34
36
 
37
+ def store_endpoint(client)
38
+ logger.debug "[+] Current Endpoint #{client.endpoint}"
39
+
40
+ if client.endpoint == 'https://pgorelease.nianticlabs.com/plfe/rpc'
41
+ raise Errors::InvalidEndpoint if @response.api_url.empty?
42
+ end
43
+
44
+ return if @response.api_url.empty?
45
+
46
+ logger.debug "[+] Setting Endpoint to #{@response.api_url}"
47
+ client.endpoint = "https://#{@response.api_url}/rpc"
48
+ end
49
+
35
50
  def decode_sub_responses
36
51
  @response.returns.zip(@request).each_with_object({}) do |(resp, req), memo|
52
+ logger.debug "[+] Decoding Sub RPC response for #{req}\r\n#{resp.inspect}"
37
53
  proto_name, entry_name = fetch_proto_response_metadata(req)
38
54
 
39
- resp = begin
55
+ response = begin
40
56
  POGOProtos::Networking::Responses.const_get(proto_name).decode(resp).to_hash
41
57
  rescue StandardError
42
58
  logger.error "[+] Protobuf definition mismatch/not found for #{entry_name}"
43
59
  'Mismatched/Invalid Protobuf Definition'
44
60
  end
45
61
 
46
- memo[entry_name] = resp
62
+ logger.debug "[+] Decoded Sub RPC response \r\n#{response.inspect}"
63
+ memo[entry_name] = response
47
64
  end
48
65
  end
49
66
 
50
67
  def fetch_proto_response_metadata(req)
51
- entry_name = req.is_a?(Symbol) ? req : req.keys.first
52
- proto_name = Poke::API::Helpers.camel_case_lower(entry_name) + 'Response'
68
+ entry_name = req.is_a?(Symbol) ? req : req.keys.first
69
+ proto_name = Poke::API::Helpers.camel_case_lower(entry_name) + 'Response'
53
70
 
54
- require "poke-api/POGOProtos/Networking/Responses/#{proto_name}"
71
+ require "poke-api/POGOProtos/Networking/Responses/#{proto_name}"
55
72
 
56
- [ proto_name, entry_name ]
73
+ [proto_name, entry_name]
57
74
  end
58
75
 
59
76
  def parse_rpc_fields(responses)
@@ -0,0 +1,24 @@
1
+ # Load Poke-API related classes
2
+ require 'pp'
3
+ require 'pry'
4
+ require_relative 'logging'
5
+ require_relative 'client'
6
+ require_relative 'helpers'
7
+ require_relative 'request_builder'
8
+ require_relative 'response'
9
+ require_relative 'errors'
10
+ require_relative 'version'
11
+ require_relative 'auth/ptc'
12
+ require_relative 'auth/google'
13
+
14
+ # Load Google Generated POGOProtos
15
+ require_relative 'POGOProtos/Networking/Envelopes/RequestEnvelope'
16
+ require_relative 'POGOProtos/Networking/Envelopes/ResponseEnvelope'
17
+
18
+ client = Poke::API::Client.new
19
+ Poke::API::Logging.log_level = :DEBUG
20
+ #client.store_lat_lng(55.864237, -4.251806)
21
+ client.login('srn720', 'illi0wnz', 'ptc')
22
+ #client.get_player
23
+ #resp = client.call
24
+ #pp resp
@@ -1,5 +1,5 @@
1
1
  module Poke
2
2
  module API
3
- VERSION = '0.0.7'.freeze
3
+ VERSION = '0.0.8'.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.0.7
4
+ version: 0.0.8
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-01 00:00:00.000000000 Z
11
+ date: 2016-08-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httpclient
@@ -526,6 +526,7 @@ files:
526
526
  - lib/poke-api/logging.rb
527
527
  - lib/poke-api/request_builder.rb
528
528
  - lib/poke-api/response.rb
529
+ - lib/poke-api/testing.rb
529
530
  - lib/poke-api/version.rb
530
531
  homepage: https://github.com/nabeelamjad/poke-api
531
532
  licenses: