def refresh_credentials(self, credentials):
        """
        Refreshes :class:`.Credentials` if it gives sense.

        :param credentials:
            :class:`.Credentials` to be refreshed.

        :returns:
            :class:`.Response`.

        """

        if not self._x_refresh_credentials_if(credentials):
            return

        # We need consumer key and secret to make this kind of request.
        cfg = credentials.config.get(credentials.provider_name)
        credentials.consumer_key = cfg.get('consumer_key')
        credentials.consumer_secret = cfg.get('consumer_secret')

        request_elements = self.create_request_elements(
            request_type=self.REFRESH_TOKEN_REQUEST_TYPE,
            credentials=credentials,
            url=self.access_token_url,
            method='POST'
        )

        self._log(logging.INFO, u'Refreshing credentials.')
        response = self._fetch(*request_elements)

        # We no longer need consumer info.
        credentials.consumer_key = None
        credentials.consumer_secret = None

        # Extract the refreshed data.
        access_token = response.data.get('access_token')
        refresh_token = response.data.get('refresh_token')

        # Update credentials only if there is access token.
        if access_token:
            credentials.token = access_token
            credentials.expire_in = response.data.get('expires_in')

            # Update refresh token only if there is a new one.
            if refresh_token:
                credentials.refresh_token = refresh_token

            # Handle different naming conventions across providers.
            credentials = self._x_credentials_parser(
                credentials, response.data)

        return response
def refresh_credentials(self, credentials):
        """
        Refreshes :class:`.Credentials` if it gives sense.

        :param credentials:
            :class:`.Credentials` to be refreshed.

        :returns:
            :class:`.Response`.

        """

        if not self._x_refresh_credentials_if(credentials):
            return

        # We need consumer key and secret to make this kind of request.
        cfg = credentials.config.get(credentials.provider_name)
        credentials.consumer_key = cfg.get('consumer_key')
        credentials.consumer_secret = cfg.get('consumer_secret')

        request_elements = self.create_request_elements(
            request_type=self.REFRESH_TOKEN_REQUEST_TYPE,
            credentials=credentials,
            url=self.access_token_url,
            method='POST'
        )

        self._log(logging.INFO, u'Refreshing credentials.')
        response = self._fetch(*request_elements)

        # We no longer need consumer info.
        credentials.consumer_key = None
        credentials.consumer_secret = None

        # Extract the refreshed data.
        access_token = response.data.get('access_token')
        refresh_token = response.data.get('refresh_token')

        # Update credentials only if there is access token.
        if access_token:
            credentials.token = access_token
            credentials.expire_in = response.data.get('expires_in')

            # Update refresh token only if there is a new one.
            if refresh_token:
                credentials.refresh_token = refresh_token

            # Handle different naming conventions across providers.
            credentials = self._x_credentials_parser(
                credentials, response.data)

        return response
def refresh_credentials ( self , credentials ) : if not self . _x_refresh_credentials_if ( credentials ) : return # We need consumer key and secret to make this kind of request. cfg = credentials . config . get ( credentials . provider_name ) credentials . consumer_key = cfg . get ( 'consumer_key' ) credentials . consumer_secret = cfg . get ( 'consumer_secret' ) request_elements = self . create_request_elements ( request_type = self . REFRESH_TOKEN_REQUEST_TYPE , credentials = credentials , url = self . access_token_url , method = 'POST' ) self . _log ( logging . INFO , u'Refreshing credentials.' ) response = self . _fetch ( * request_elements ) # We no longer need consumer info. credentials . consumer_key = None credentials . consumer_secret = None # Extract the refreshed data. access_token = response . data . get ( 'access_token' ) refresh_token = response . data . get ( 'refresh_token' ) # Update credentials only if there is access token. if access_token : credentials . token = access_token credentials . expire_in = response . data . get ( 'expires_in' ) # Update refresh token only if there is a new one. if refresh_token : credentials . refresh_token = refresh_token # Handle different naming conventions across providers. credentials = self . _x_credentials_parser ( credentials , response . data ) return response
Refreshes :class:`.Credentials` if it gives sense.

        :param credentials:
            :class:`.Credentials` to be refreshed.

        :returns:
            :class:`.Response`.
Refreshes : class : . Credentials if it gives sense .