Class: Poke::API::Client

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/poke-api/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logging

formatter=, log_level=, #logger

Constructor Details

#initializeClient

Returns a new instance of Client.



11
12
13
14
15
16
17
18
19
# File 'lib/poke-api/client.rb', line 11

def initialize
  @endpoint   = 'https://pgorelease.nianticlabs.com/plfe/rpc'
  @reqs       = []
  @lat        = 0
  @lng        = 0
  @alt        = rand(1..9)
  @ticket     = Auth::Ticket.new
  @sig_loaded = false
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object (private)



112
113
114
115
116
117
# File 'lib/poke-api/client.rb', line 112

def method_missing(method, *args)
  POGOProtos::Networking::Requests::RequestType.const_get(method.upcase)
  @reqs << (args.empty? ? method.to_sym.upcase : { method.to_sym.upcase => args.first })
rescue NameError
  super
end

Instance Attribute Details

#activity_statusObject

Returns the value of attribute activity_status.



5
6
7
# File 'lib/poke-api/client.rb', line 5

def activity_status
  @activity_status
end

#altObject

Returns the value of attribute alt.



5
6
7
# File 'lib/poke-api/client.rb', line 5

def alt
  @alt
end

#android_gps_infoObject

Returns the value of attribute android_gps_info.



5
6
7
# File 'lib/poke-api/client.rb', line 5

def android_gps_info
  @android_gps_info
end

#authObject (readonly)

Returns the value of attribute auth.



9
10
11
# File 'lib/poke-api/client.rb', line 9

def auth
  @auth
end

#device_infoObject

Returns the value of attribute device_info.



5
6
7
# File 'lib/poke-api/client.rb', line 5

def device_info
  @device_info
end

#endpointObject

Returns the value of attribute endpoint.



5
6
7
# File 'lib/poke-api/client.rb', line 5

def endpoint
  @endpoint
end

#http_clientObject

Returns the value of attribute http_client.



5
6
7
# File 'lib/poke-api/client.rb', line 5

def http_client
  @http_client
end

#latObject

Returns the value of attribute lat.



5
6
7
# File 'lib/poke-api/client.rb', line 5

def lat
  @lat
end

#lngObject

Returns the value of attribute lng.



5
6
7
# File 'lib/poke-api/client.rb', line 5

def lng
  @lng
end

#location_fixObject

Returns the value of attribute location_fix.



5
6
7
# File 'lib/poke-api/client.rb', line 5

def location_fix
  @location_fix
end

#refresh_tokenObject

Returns the value of attribute refresh_token.



5
6
7
# File 'lib/poke-api/client.rb', line 5

def refresh_token
  @refresh_token
end

#sensor_infoObject

Returns the value of attribute sensor_info.



5
6
7
# File 'lib/poke-api/client.rb', line 5

def sensor_info
  @sensor_info
end

#sig_loadedObject

Returns the value of attribute sig_loaded.



5
6
7
# File 'lib/poke-api/client.rb', line 5

def sig_loaded
  @sig_loaded
end

#sig_pathObject (readonly)

Returns the value of attribute sig_path.



9
10
11
# File 'lib/poke-api/client.rb', line 9

def sig_path
  @sig_path
end

#ticketObject

Returns the value of attribute ticket.



5
6
7
# File 'lib/poke-api/client.rb', line 5

def ticket
  @ticket
end

Instance Method Details

#activate_signature(file_path) ⇒ Object



55
56
57
58
59
60
61
62
# File 'lib/poke-api/client.rb', line 55

def activate_signature(file_path)
  if File.exist?(file_path)
    logger.info "[+] File #{file_path} has been set for signature generation"
    @sig_path = file_path
  else
    raise Errors::InvalidSignatureFilePath, file_path
  end
end

#callObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/poke-api/client.rb', line 36

def call
  raise Errors::LoginRequired unless @auth
  raise Errors::NoRequests if @reqs.empty?

  check_expiry
  req = RequestBuilder.new(@auth, [@lat, @lng, @alt], @endpoint, @http_client)

  begin
    resp = req.request(@reqs, self)
  rescue StandardError => ex
    error(ex)
  ensure
    @reqs = []
    logger.info '[+] Cleaning up RPC requests'
  end

  resp
end

#inspectObject



77
78
79
80
# File 'lib/poke-api/client.rb', line 77

def inspect
  "#<#{self.class.name} @auth=#{@auth} @reqs=#{@reqs} " \
  "@lat=#{@lat} @lng=#{@lng} @alt=#{@alt}>"
end

#login(username, password, provider) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/poke-api/client.rb', line 21

def (username, password, provider)
  @username, @password, @provider = username, password, provider.upcase
  raise Errors::InvalidProvider, provider unless %w(PTC GOOGLE).include?(@provider)

  begin
    @auth = Auth.const_get(@provider).new(@username, @password, @refresh_token)
    @auth.connect
  rescue StandardError => ex
    raise Errors::LoginFailure.new(@provider, ex)
  end

  initialize_ticket
  logger.info "[+] Login with #{@provider} Successful"
end

#store_lat_lng(lat, lng) ⇒ Object



72
73
74
75
# File 'lib/poke-api/client.rb', line 72

def store_lat_lng(lat, lng)
  logger.info "[+] Lat/Long: #{lat}, #{lng}"
  @lat, @lng = lat, lng
end

#store_location(loc) ⇒ Object



64
65
66
67
68
69
70
# File 'lib/poke-api/client.rb', line 64

def store_location(loc)
  pos = Poke::API::Helpers.get_position(loc).first
  logger.info "[+] Given location: #{pos.address}"

  logger.info "[+] Lat/Long/Alt: #{pos.latitude}, #{pos.longitude}"
  @lat, @lng = pos.latitude, pos.longitude
end