'Register at the repository, in Wrike: use client ID and the
authorization code (site key), alternatively username and
password to obtain the refresh_token and store it in the
repository config.
@note: this invalidates the authorization code (if any), so it
will be set to None regardless whether this operation
succeeds or not
@return: True if successful, otherwise False'

def register(self):

    repository = self.repository
    log = repository.log
    success = False
    remote = False
    skip = False
    data = None
    site_key = repository.site_key
    if (not site_key):
        username = repository.username
        password = repository.password
        if (username and password):
            data = {'client_id': repository.client_id, 'client_secret': repository.client_secret, 'username': username, 'password': password, 'grant_type': 'password'}
    else:
        data = {'client_id': repository.client_id, 'client_secret': repository.client_secret, 'grant_type': 'authorization_code', 'code': site_key}
    if (not data):
        if (not repository.refresh_token):
            result = log.WARNING
            message = 'No    credentials    to    obtain    refresh    token    with,    skipping    registration'
        else:
            result = log.SUCCESS
            success = True
            message = None
        skip = True
    else:
        repository.refresh_token = None
        self.access_token = None
        (response, message) = self._send_request(method='POST', data=data, auth=True)
        if (not response):
            result = log.FATAL
            remote = True
        else:
            refresh_token = response.get('refresh_token')
            if (not refresh_token):
                result = log.FATAL
                message = 'No    refresh    token    received'
            else:
                repository.refresh_token = refresh_token
                self.access_token = response.get('access_token')
                result = log.SUCCESS
                success = True
                message = 'Registration    successful'
        self.update_refresh_token()
    log.write(repository_id=repository.id, transmission=log.OUT, mode=log.PUSH, action='request    refresh    token', remote=remote, result=result, message=message)
    if (not success):
        current.log.error(message)
    return (success if (not skip) else True)
