class Poke::API::Client

Attributes

activity_status[RW]
alt[RW]
android_gps_info[RW]
auth[R]
device_info[RW]
endpoint[RW]
http_client[RW]
lat[RW]
lng[RW]
location_fix[RW]
refresh_token[RW]
sensor_info[RW]
sig_loaded[RW]
sig_path[R]
ticket[RW]

Public Class Methods

new() click to toggle source
# 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

Public Instance Methods

activate_signature(file_path) click to toggle source
# 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
call() click to toggle source
# 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
inspect() click to toggle source
# 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) click to toggle source
# File lib/poke-api/client.rb, line 21
def login(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) click to toggle source
# 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) click to toggle source
# 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

Private Instance Methods

check_expiry() click to toggle source
# File lib/poke-api/client.rb, line 89
def check_expiry
  unless @ticket.has_ticket?
    now = Helpers.fetch_time(ms: false)

    if now < (@auth.expiry - 30)
      duration = format('%02d:%02d:%02d', *Helpers.format_time_diff(now, @auth.expiry, false))
      logger.info "[+] Provider access token is valid for #{duration}"
      return
    end

    logger.info "[+] Refreshing access token as it is no longer valid"
    login(@username, @password, @provider)
  end
end
error(ex) click to toggle source
# File lib/poke-api/client.rb, line 104
def error(ex)
  if Poke::API::Errors.constants.include?(ex.class.to_s.split('::').last.to_sym)
    raise ex.class
  end

  raise Errors::UnknownProtoFault, ex
end
initialize_ticket() click to toggle source
# File lib/poke-api/client.rb, line 84
def initialize_ticket
  get_hatched_eggs
  call
end
method_missing(method, *args) click to toggle source
Calls superclass method
# 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