def get_users(self, identifiers): """Gets the user data corresponding to the specified identifiers. There are no ordering guarantees; in particular, the nth entry in the result list is not guaranteed to correspond to the nth entry in the input parameters list. A maximum of 100 identifiers may be supplied. If more than 100 identifiers are supplied, this method raises a `ValueError`. Args: identifiers (list[Identifier]): A list of ``Identifier`` instances used to indicate which user records should be returned. Must have <= 100 entries. Returns: GetUsersResult: A ``GetUsersResult`` instance corresponding to the specified identifiers. Raises: ValueError: If any of the identifiers are invalid or if more than 100 identifiers are specified. """ response = self._user_manager.get_users(identifiers=identifiers) def _matches(identifier, user_record): if isinstance(identifier, _user_identifier.UidIdentifier): return identifier.uid == user_record.uid if isinstance(identifier, _user_identifier.EmailIdentifier): return identifier.email == user_record.email if isinstance(identifier, _user_identifier.PhoneIdentifier): return identifier.phone_number == user_record.phone_number if isinstance(identifier, _user_identifier.ProviderIdentifier): return next((True for user_info in user_record.provider_data if identifier.provider_id == user_info.provider_id and identifier.provider_uid == user_info.uid), False) raise TypeError("Unexpected type: {}".format(type(identifier))) def _is_user_found(identifier, user_records): return any( _matches(identifier, user_record) for user_record in user_records) users = [_user_mgt.UserRecord(user) for user in response] not_found = [ identifier for identifier in identifiers if not _is_user_found(identifier, users) ] return _user_mgt.GetUsersResult(users=users, not_found=not_found)
def get_user_by_email(self, email): """Gets the user data corresponding to the specified user email. Args: email: A user email address string. Returns: UserRecord: A user record instance. Raises: ValueError: If the email is None, empty or malformed. UserNotFoundError: If no user exists for the specified email address. FirebaseError: If an error occurs while retrieving the user. """ response = self._user_manager.get_user(email=email) return _user_mgt.UserRecord(response)
def get_user_by_phone_number(self, phone_number): """Gets the user data corresponding to the specified phone number. Args: phone_number: A phone number string. Returns: UserRecord: A user record instance. Raises: ValueError: If the phone number is ``None``, empty or malformed. UserNotFoundError: If no user exists for the specified phone number. FirebaseError: If an error occurs while retrieving the user. """ response = self._user_manager.get_user(phone_number=phone_number) return _user_mgt.UserRecord(response)
def get_user(self, uid): """Gets the user data corresponding to the specified user ID. Args: uid: A user ID string. Returns: UserRecord: A user record instance. Raises: ValueError: If the user ID is None, empty or malformed. UserNotFoundError: If the specified user ID does not exist. FirebaseError: If an error occurs while retrieving the user. """ response = self._user_manager.get_user(uid=uid) return _user_mgt.UserRecord(response)