A unified treatment of magnetospheric dynamics with applications to magnetic storms