def __init__(self, name=glbl.MODULE_NAME): """ Client constructor. :param name: Name identifier of the client :type name: basestring """ if isinstance(name, basestring) and len(name) > 0: self._name = name if not glbl.BOOTSTRAPPED: bootstrap._bootstrap() self._build_managers()
def __init__(self, fb_user, fb_pass=None): """ Initialize client class. :param fb_user: Tinder user's Facebook login username :param fb_pass: Tinder user's Facebook login password :type fb_user: basestring :type fb_pass: basestring """ if not glbl.BOOTSTRAPPED: _bootstrap() rebuild_cred = True if isinstance(fb_user, basestring): if len(fb_user) > 0: self.storage = storage.AuthStorage() self._id = self.storage.get_user(fb_user) # try to load user from storage (if exists) if self.id: rebuild_cred = False self.deserialize() if self._raw is None: glbl.LOG.warning(( 'credentials for user `{}` no longer exists, ' 'rebuilding ...' ).format(self._id)) self.storage.remove_cred(self._id) rebuild_cred = True # build credentials via authentication methods if rebuild_cred: if fb_pass is not None: if isinstance(fb_pass, basestring): if len(fb_pass) > 0: # get facebook credentials fb_cred = auth.Facebook.credentials( fb_user, fb_pass ) # set _raw to tinder credentials self._raw = auth.Tinder.credentials( fb_cred['token'], fb_cred['id'] )['user'] self._id = self._raw['_id'] # serialize newly build credentials self.serialize() self.storage.store_cred( fb_user, fb_cred['token'], fb_cred['id'], self.token, self.id ) else: raise exceptions.\ FacebookCredentialsFormatException(( 'missing Facebook password, ' 'parameter is empty' )) else: raise exceptions.\ FacebookCredentialsFormatException(( 'invalid Facebook password format, ' 'expected password string' )) else: raise exceptions.MissingCredentialsException(( 'missing required Facebook password parameter' )) else: raise exceptions.FacebookCredentialsFormatException(( 'invalid passed Facebook credentials, ' 'user empty' )) else: raise exceptions.FacebookCredentialsFormatException(( 'invalid passed Facebook credentials, ' 'required user string' ))
def __init__(self, fb_user, fb_pass=None): """ Initialize client class. :param fb_user: Tinder user's Facebook login username :param fb_pass: Tinder user's Facebook login password :type fb_user: basestring :type fb_pass: basestring """ if not glbl.BOOTSTRAPPED: _bootstrap() rebuild_cred = True if isinstance(fb_user, basestring): if len(fb_user) > 0: self.storage = storage.AuthStorage() self._id = self.storage.get_user(fb_user) # try to load user from storage (if exists) if self.id: rebuild_cred = False self.deserialize() if self._raw is None: glbl.LOG.warning( ('credentials for user `{}` no longer exists, ' 'rebuilding ...').format(self._id)) self.storage.remove_cred(self._id) rebuild_cred = True # build credentials via authentication methods if rebuild_cred: if fb_pass is not None: if isinstance(fb_pass, basestring): if len(fb_pass) > 0: # get facebook credentials fb_cred = auth.Facebook.credentials( fb_user, fb_pass) # set _raw to tinder credentials self._raw = auth.Tinder.credentials( fb_cred['token'], fb_cred['id'])['user'] self._id = self._raw['_id'] # serialize newly build credentials self.serialize() self.storage.store_cred( fb_user, fb_cred['token'], fb_cred['id'], self.token, self.id) else: raise exceptions.\ FacebookCredentialsFormatException(( 'missing Facebook password, ' 'parameter is empty' )) else: raise exceptions.\ FacebookCredentialsFormatException(( 'invalid Facebook password format, ' 'expected password string' )) else: raise exceptions.MissingCredentialsException( ('missing required Facebook password parameter')) else: raise exceptions.FacebookCredentialsFormatException( ('invalid passed Facebook credentials, ' 'user empty')) else: raise exceptions.FacebookCredentialsFormatException( ('invalid passed Facebook credentials, ' 'required user string'))