Skip to content
This repository was archived by the owner on Dec 15, 2018. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions pgoapi/pgoapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import re
import six
import logging
import requests

from . import __title__, __version__, __copyright__
from pgoapi.rpc_api import RpcApi
Expand All @@ -54,6 +53,7 @@ def __init__(self, provider=None, oauth2_refresh_token=None, username=None, pass
self.set_authentication(provider, oauth2_refresh_token, username, password)

self.set_api_endpoint("pgorelease.nianticlabs.com/plfe")
self._proxy = None

self._position_lat = position_lat
self._position_lng = position_lng
Expand Down Expand Up @@ -93,6 +93,9 @@ def set_position(self, lat, lng, alt):
self._position_lng = lng
self._position_alt = alt

def set_proxy(self, proxy_config):
self._proxy = proxy_config

def get_api_endpoint(self):
return self._api_endpoint

Expand All @@ -106,7 +109,8 @@ def get_auth_provider(self):
return self._auth_provider

def create_request(self):
request = PGoApiRequest(self, self._position_lat, self._position_lng, self._position_alt)
request = PGoApiRequest(self, self._position_lat, self._position_lng,
self._position_alt, self._proxy)
return request

def activate_signature(self, lib_path):
Expand Down Expand Up @@ -177,7 +181,7 @@ def login(self, provider, username, password, lat=None, lng=None, alt=None, app_


class PGoApiRequest:
def __init__(self, parent, position_lat, position_lng, position_alt):
def __init__(self, parent, position_lat, position_lng, position_alt, proxy=None):
self.log = logging.getLogger(__name__)

self.__parent__ = parent
Expand All @@ -190,6 +194,8 @@ def __init__(self, parent, position_lat, position_lng, position_alt):
self._position_lng = position_lng
self._position_alt = position_alt

self._proxy = proxy

self._req_method_list = []

def call(self):
Expand All @@ -203,7 +209,7 @@ def call(self):
self.log.info('Not logged in')
return NotLoggedInException()

request = RpcApi(self._auth_provider)
request = RpcApi(self._auth_provider, self._proxy)

lib_path = self.__parent__.get_signature_lib()
if lib_path is not None:
Expand Down
10 changes: 7 additions & 3 deletions pgoapi/rpc_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,15 @@ class RpcApi:
RPC_ID = 0
START_TIME = 0

def __init__(self, auth_provider):
def __init__(self, auth_provider, proxy_config=None):

self.log = logging.getLogger(__name__)

self._session = requests.session()

if proxy_config is not None:
self._session.proxies = proxy_config

self._session.headers.update({'User-Agent': 'Niantic App'})
self._session.verify = True

Expand Down Expand Up @@ -113,8 +117,8 @@ def _make_rpc(self, endpoint, request_proto_plain):
request_proto_serialized = request_proto_plain.SerializeToString()
try:
http_response = self._session.post(endpoint, data=request_proto_serialized)
except requests.exceptions.ConnectionError as e:
raise ServerBusyOrOfflineException(e)
except requests.exceptions.ConnectionError:
raise ServerBusyOrOfflineException

return http_response

Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ requests==2.10.0
s2sphere==0.2.4
gpsoauth==0.3.0
six
xxhash
xxhash
requests[socks]