Exemplo n.º 1
0
    def call(self):
        if not self._req_method_list:
            raise EmptySubrequestChainException()
            
        if (self._position_lat is None) or (self._position_lng is None) or (self._position_alt is None):
            raise NoPlayerPositionSetException()

        if self._auth_provider is None or not self._auth_provider.is_login():
            self.log.info('Not logged in')
            return NotLoggedInException()

        request = RpcApi(self._auth_provider)

        self.log.info('Execution of RPC')
        response = None
        try:
            response = request.request(self._api_endpoint, self._req_method_list, self.get_position())
        except ServerBusyOrOfflineException as e:
            self.log.info('Server seems to be busy or offline - try again!')

        # cleanup after call execution
        self.log.info('Cleanup of request!')
        self._req_method_list = []

        return response
Exemplo n.º 2
0
    def request(self, endpoint, subrequests, player_position):

        if not self._auth_provider or self._auth_provider.is_login() is False:
            raise NotLoggedInException()

        request_proto = self._build_main_request(subrequests, player_position)
        response = self._make_rpc(endpoint, request_proto)

        response_dict = self._parse_main_response(response, subrequests)

        self.check_authentication(response_dict)

        # some response validations
        if isinstance(response_dict, dict):
            status_code = response_dict.get('status_code', None)
            if status_code == 102:
                raise AuthTokenExpiredException()
            elif status_code == 52:
                raise ServerSideRequestThrottlingException("Request throttled by server... slow down man")
            elif status_code == 53:
                api_url = response_dict.get('api_url', None)
                if api_url is not None:
                    exception = ServerApiEndpointRedirectException()
                    exception.set_redirected_endpoint(api_url)
                    raise exception
                else:
                    raise UnexpectedResponseException()

        return response_dict
Exemplo n.º 3
0
    def request(self, endpoint, subrequests, player_position):

        if not self._auth_provider or self._auth_provider.is_login() is False:
            raise NotLoggedInException()

        request_proto = self._build_main_request(subrequests, player_position)
        response = self._make_rpc(endpoint, request_proto)

        response_dict = self._parse_main_response(response, subrequests)

        if isinstance(response_dict, dict) and 'status_code' in response_dict:
            sc = response_dict['status_code']
            if sc == 102:
                raise NotLoggedInException()

        return response_dict
Exemplo n.º 4
0
    def call(self, use_dict=True):
        if (self._position_lat is None) or (self._position_lng is None):
            raise NoPlayerPositionSetException

        if self._auth_provider is None or not self._auth_provider.is_login():
            self.log.info('Not logged in')
            raise NotLoggedInException

        api = self.__parent__
        request = RpcApi(self._auth_provider, self.device_info, self.state,
                         api.get_next_request_id(), api.get_start_time())
        request._session = api._session

        hash_server_token = api.get_hash_server_token()
        request.activate_hash_server(hash_server_token)

        response = None
        execute = True

        while execute:
            execute = False

            try:
                response = request.request(self._api_endpoint,
                                           self._req_method_list,
                                           self._req_platform_list,
                                           self.get_position(), use_dict)
            except AuthTokenExpiredException as e:
                """
                This exception only occures if the OAUTH service provider (google/ptc) didn't send any expiration date
                so that we are assuming, that the access_token is always valid until the API server states differently.
                """
                try:
                    self.log.info(
                        'Access Token rejected! Requesting new one...')
                    self._auth_provider.get_access_token(force_refresh=True)
                except Exception as e:
                    error = 'Reauthentication failed: {}'.format(e)
                    self.log.error(error)
                    raise NotLoggedInException(error)

                request.request_proto = None  # reset request and rebuild
                execute = True  # reexecute the call
            except ServerApiEndpointRedirectException as e:
                self.log.info('API Endpoint redirect... re-execution of call')
                new_api_endpoint = e.get_redirected_endpoint()

                self._api_endpoint = parse_api_endpoint(new_api_endpoint)
                api.set_api_endpoint(self._api_endpoint)

                execute = True  # reexecute the call

        # cleanup after call execution
        self._req_method_list = []

        return response
Exemplo n.º 5
0
    def request(self, endpoint, subrequests, player_position):

        if not self._auth_provider or self._auth_provider.is_login() is False:
            raise NotLoggedInException()

        request_proto = self._build_main_request(subrequests, player_position)
        response = self._make_rpc(endpoint, request_proto)

        response_dict = self._parse_main_response(response, subrequests)

        return response_dict
Exemplo n.º 6
0
    def can_call(self):
        if not self._req_method_list:
            raise EmptySubrequestChainException()

        if (self._position_lat is None) or (self._position_lng is None) or (self._position_alt is None):
            raise NoPlayerPositionSetException()

        if self._auth_provider is None or not self._auth_provider.is_login():
            self.log.info('Not logged in')
            raise NotLoggedInException()

        return True
Exemplo n.º 7
0
    def request(self, endpoint, subrequests, player_position):

        if not self._auth_provider or self._auth_provider.is_login() is False:
            raise NotLoggedInException()

        request_proto = self._build_main_request(subrequests, player_position)
        response = self._make_rpc(endpoint, request_proto)

        response_dict = self._parse_main_response(response, subrequests)

        self.check_authentication(response_dict)

        """ 
        some response validations 
        """
        if isinstance(response_dict, dict) and 'status_code' in response_dict:
            sc = response_dict['status_code']
            if sc == 102:
                raise NotLoggedInException()
            elif sc == 52:
                raise ServerSideRequestThrottlingException("Request throttled by server... slow down man")

        return response_dict
Exemplo n.º 8
0
    def request(self,
                endpoint,
                subrequests,
                platforms,
                player_position,
                use_dict=True):

        if not self._auth_provider or self._auth_provider.is_login() is False:
            raise NotLoggedInException()

        self.request_proto = self.request_proto or self._build_main_request(
            subrequests, platforms, player_position)
        response = self._make_rpc(endpoint, self.request_proto)

        response_dict = self._parse_main_response(response, subrequests,
                                                  use_dict)

        # some response validations
        if isinstance(response_dict, dict):
            if use_dict:
                status_code = response_dict.get('status_code')
                if ('auth_ticket' in response_dict) and (
                        'expire_timestamp_ms' in response_dict['auth_ticket']):
                    ticket = response_dict['auth_ticket']
                    self.check_authentication(ticket['expire_timestamp_ms'],
                                              ticket['start'], ticket['end'])
            else:
                status_code = response_dict['envelope'].status_code
                ticket = response_dict['envelope'].auth_ticket
                if ticket:
                    self.check_authentication(ticket.expire_timestamp_ms,
                                              ticket.start, ticket.end)

            if status_code == 102:
                raise AuthTokenExpiredException
            elif status_code == 52:
                raise NianticThrottlingException(
                    "Request throttled by server... slow down man")
            elif status_code == 53:
                api_url = response_dict.get('api_url')
                if api_url:
                    exception = ServerApiEndpointRedirectException()
                    exception.set_redirected_endpoint(api_url)
                    raise exception
                else:
                    raise UnexpectedResponseException

        return response_dict
Exemplo n.º 9
0
    def call(self):
        if not self._req_method_list:
            raise EmptySubrequestChainException()

        if (self._position_lat is None) or (self._position_lng is None) or (
                self._position_alt is None):
            raise NoPlayerPositionSetException()

        if self._auth_provider is None or not self._auth_provider.is_login():
            self.log.info('Not logged in')
            return NotLoggedInException()

        request = RpcApi(self._auth_provider)

        lib_path = self.__parent__.get_signature_lib()
        if lib_path is not None:
            request.activate_signature(lib_path)

        self.log.info('Execution of RPC')
        response = None

        execute = True
        while execute:
            execute = False

            try:
                response = request.request(self._api_endpoint,
                                           self._req_method_list,
                                           self.get_position())
            except AuthTokenExpiredException as e:
                """
                This exception only occures if the OAUTH service provider (google/ptc) didn't send any expiration date
                so that we are assuming, that the access_token is always valid until the API server states differently.
                """
                try:
                    self.log.info(
                        'Access Token rejected! Requesting new one...')
                    self._auth_provider.get_access_token(force_refresh=True)
                except:
                    error = 'Request for new Access Token failed! Logged out...'
                    self.log.error(error)
                    raise NotLoggedInException(error)
                """ reexecute the call"""
                execute = True
            except ServerApiEndpointRedirectException as e:
                self.log.info('API Endpoint redirect... re-execution of call')
                new_api_endpoint = e.get_redirected_endpoint()

                self._api_endpoint = parse_api_endpoint(new_api_endpoint)
                self.__parent__.set_api_endpoint(self._api_endpoint)
                """ reexecute the call"""
                execute = True
            except ServerBusyOrOfflineException as e:
                """ no execute = True here, as API retries on HTTP level should be done on a lower level, e.g. in rpc_api """
                self.log.info(
                    'Server seems to be busy or offline - try again!')
                self.log.debug('ServerBusyOrOfflineException details: %s', e)
            except UnexpectedResponseException as e:
                self.log.error('Unexpected server response!')
                raise

        # cleanup after call execution
        self.log.info('Cleanup of request!')
        self._req_method_list = []

        return response