Esempio n. 1
0
    def call(self):
        if not self._req_method_list:
            return False

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

        player_position = self.get_position()

        request = RpcApi(self._auth_provider)

        if self._api_endpoint:
            api_endpoint = self._api_endpoint
        else:
            api_endpoint = self.API_ENTRY

        self.log.info('Execution of RPC')
        response = None
        try:
            response = request.request(api_endpoint, self._req_method_list,
                                       player_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
Esempio n. 2
0
    def call(self):
        if not self._req_method_list:
            return False

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

        player_position = self.get_position()

        request = RpcApi(self._auth_provider)

        if self._api_endpoint:
            api_endpoint = self._api_endpoint
        else:
            api_endpoint = self.API_ENTRY

        self.log.info('Execution of RPC')
        response = None
        try:
            response = request.request(api_endpoint, self._req_method_list, player_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
Esempio n. 3
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
Esempio 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
Esempio n. 5
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

        request = RpcApi(self._auth_provider, self.device_info)
        request._session = self.__parent__._session

        hash_server_token = self.__parent__.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)
                self.__parent__.set_api_endpoint(self._api_endpoint)

                execute = True  # reexecute the call

        # cleanup after call execution
        self._req_method_list = []

        return response
Esempio n. 6
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)
        request._session = self.__parent__._session

        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
Esempio n. 7
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